1 """Support for deCONZ covers."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from pydeconz.interfaces.lights
import CoverAction
8 from pydeconz.models
import ResourceType
9 from pydeconz.models.event
import EventType
10 from pydeconz.models.light.cover
import Cover
15 DOMAIN
as COVER_DOMAIN,
24 from .entity
import DeconzDevice
25 from .hub
import DeconzHub
27 DECONZ_TYPE_TO_DEVICE_CLASS = {
28 ResourceType.LEVEL_CONTROLLABLE_OUTPUT.value: CoverDeviceClass.DAMPER,
29 ResourceType.WINDOW_COVERING_CONTROLLER.value: CoverDeviceClass.SHADE,
30 ResourceType.WINDOW_COVERING_DEVICE.value: CoverDeviceClass.SHADE,
36 config_entry: ConfigEntry,
37 async_add_entities: AddEntitiesCallback,
39 """Set up covers for deCONZ component."""
40 hub = DeconzHub.get_hub(hass, config_entry)
41 hub.entities[COVER_DOMAIN] = set()
44 def async_add_cover(_: EventType, cover_id: str) ->
None:
45 """Add cover from deCONZ."""
48 hub.register_platform_add_device_callback(
50 hub.api.lights.covers,
55 """Representation of a deCONZ cover."""
59 def __init__(self, cover_id: str, hub: DeconzHub) ->
None:
60 """Set up cover device."""
61 super().
__init__(cover := hub.api.lights.covers[cover_id], hub)
64 CoverEntityFeature.OPEN
65 | CoverEntityFeature.CLOSE
66 | CoverEntityFeature.STOP
67 | CoverEntityFeature.SET_POSITION
70 if self._device.tilt
is not None:
72 CoverEntityFeature.OPEN_TILT
73 | CoverEntityFeature.CLOSE_TILT
74 | CoverEntityFeature.STOP_TILT
75 | CoverEntityFeature.SET_TILT_POSITION
80 self.
legacy_modelegacy_mode = cover.type == ResourceType.LEVEL_CONTROLLABLE_OUTPUT.value
84 """Return the current position of the cover."""
85 return 100 - self._device.lift
89 """Return if the cover is closed."""
90 return not self._device.is_open
93 """Move the cover to a specific position."""
94 position = 100 - cast(int, kwargs[ATTR_POSITION])
95 await self.hub.api.lights.covers.set_state(
96 id=self._device.resource_id,
103 await self.hub.api.lights.covers.set_state(
104 id=self._device.resource_id,
105 action=CoverAction.OPEN,
111 await self.hub.api.lights.covers.set_state(
112 id=self._device.resource_id,
113 action=CoverAction.CLOSE,
119 await self.hub.api.lights.covers.set_state(
120 id=self._device.resource_id,
121 action=CoverAction.STOP,
127 """Return the current tilt position of the cover."""
128 if self._device.tilt
is not None:
129 return 100 - self._device.tilt
133 """Tilt the cover to a specific position."""
134 position = 100 - cast(int, kwargs[ATTR_TILT_POSITION])
135 await self.hub.api.lights.covers.set_state(
136 id=self._device.resource_id,
142 """Open cover tilt."""
143 await self.hub.api.lights.covers.set_state(
144 id=self._device.resource_id,
150 """Close cover tilt."""
151 await self.hub.api.lights.covers.set_state(
152 id=self._device.resource_id,
158 """Stop cover tilt."""
159 await self.hub.api.lights.covers.set_state(
160 id=self._device.resource_id,
161 action=CoverAction.STOP,
current_cover_tilt_position
None async_stop_cover(self, **Any kwargs)
None __init__(self, str cover_id, DeconzHub hub)
None async_close_cover_tilt(self, **Any kwargs)
None async_open_cover_tilt(self, **Any kwargs)
None async_set_cover_tilt_position(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_stop_cover_tilt(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)