Use more attr instead of properties in deCONZ integration (#52098)

This commit is contained in:
Robert Svensson 2021-06-23 21:40:34 +02:00 committed by GitHub
parent 1f4fdb50dc
commit 6352d8fb0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 80 additions and 124 deletions

View file

@ -18,10 +18,22 @@ from homeassistant.components.cover import (
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import COVER_TYPES, DAMPERS, NEW_LIGHT, WINDOW_COVERS
from .const import (
COVER_TYPES,
LEVEL_CONTROLLABLE_OUTPUT,
NEW_LIGHT,
WINDOW_COVERING_CONTROLLER,
WINDOW_COVERING_DEVICE,
)
from .deconz_device import DeconzDevice
from .gateway import get_gateway_from_config_entry
DEVICE_CLASS = {
LEVEL_CONTROLLABLE_OUTPUT: DEVICE_CLASS_DAMPER,
WINDOW_COVERING_CONTROLLER: DEVICE_CLASS_SHADE,
WINDOW_COVERING_DEVICE: DEVICE_CLASS_SHADE,
}
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up covers for deCONZ component."""
@ -61,29 +73,18 @@ class DeconzCover(DeconzDevice, CoverEntity):
"""Set up cover device."""
super().__init__(device, gateway)
self._features = SUPPORT_OPEN
self._features |= SUPPORT_CLOSE
self._features |= SUPPORT_STOP
self._features |= SUPPORT_SET_POSITION
self._attr_supported_features = SUPPORT_OPEN
self._attr_supported_features |= SUPPORT_CLOSE
self._attr_supported_features |= SUPPORT_STOP
self._attr_supported_features |= SUPPORT_SET_POSITION
if self._device.tilt is not None:
self._features |= SUPPORT_OPEN_TILT
self._features |= SUPPORT_CLOSE_TILT
self._features |= SUPPORT_STOP_TILT
self._features |= SUPPORT_SET_TILT_POSITION
self._attr_supported_features |= SUPPORT_OPEN_TILT
self._attr_supported_features |= SUPPORT_CLOSE_TILT
self._attr_supported_features |= SUPPORT_STOP_TILT
self._attr_supported_features |= SUPPORT_SET_TILT_POSITION
@property
def supported_features(self):
"""Flag supported features."""
return self._features
@property
def device_class(self):
"""Return the class of the cover."""
if self._device.type in DAMPERS:
return DEVICE_CLASS_DAMPER
if self._device.type in WINDOW_COVERS:
return DEVICE_CLASS_SHADE
self._attr_device_class = DEVICE_CLASS.get(self._device.type)
@property
def current_cover_position(self):