1 """Support for HomematicIP Cloud cover devices."""
3 from __future__
import annotations
7 from homematicip.aio.device
import (
11 AsyncFullFlushShutter,
12 AsyncGarageDoorModuleTormatic,
13 AsyncHoermannDrivesModule,
15 from homematicip.aio.group
import AsyncExtendedLinkedShutterGroup
16 from homematicip.base.enums
import DoorCommand, DoorState
28 from .const
import DOMAIN
29 from .entity
import HomematicipGenericEntity
30 from .hap
import HomematicipHAP
40 config_entry: ConfigEntry,
41 async_add_entities: AddEntitiesCallback,
43 """Set up the HomematicIP cover from a config entry."""
44 hap = hass.data[DOMAIN][config_entry.unique_id]
45 entities: list[HomematicipGenericEntity] = [
47 for group
in hap.home.groups
48 if isinstance(group, AsyncExtendedLinkedShutterGroup)
50 for device
in hap.home.devices:
51 if isinstance(device, AsyncBlindModule):
53 elif isinstance(device, AsyncDinRailBlind4):
56 for channel
in range(1, 5)
58 elif isinstance(device, AsyncFullFlushBlind):
60 elif isinstance(device, AsyncFullFlushShutter):
63 device, (AsyncHoermannDrivesModule, AsyncGarageDoorModuleTormatic)
71 """Representation of the HomematicIP blind module."""
73 _attr_device_class = CoverDeviceClass.BLIND
77 """Return current position of cover."""
78 if self.
_device_device.primaryShadingLevel
is not None:
79 return int((1 - self.
_device_device.primaryShadingLevel) * 100)
84 """Return current tilt position of cover."""
85 if self.
_device_device.secondaryShadingLevel
is not None:
86 return int((1 - self.
_device_device.secondaryShadingLevel) * 100)
90 """Move the cover to a specific position."""
91 position = kwargs[ATTR_POSITION]
93 level = 1 - position / 100.0
94 await self.
_device_device.set_primary_shading_level(primaryShadingLevel=level)
97 """Move the cover to a specific tilt position."""
98 position = kwargs[ATTR_TILT_POSITION]
100 level = 1 - position / 100.0
101 await self.
_device_device.set_secondary_shading_level(
102 primaryShadingLevel=self.
_device_device.primaryShadingLevel,
103 secondaryShadingLevel=level,
108 """Return if the cover is closed."""
109 if self.
_device_device.primaryShadingLevel
is not None:
110 return self.
_device_device.primaryShadingLevel == HMIP_COVER_CLOSED
114 """Open the cover."""
115 await self.
_device_device.set_primary_shading_level(
116 primaryShadingLevel=HMIP_COVER_OPEN
120 """Close the cover."""
121 await self.
_device_device.set_primary_shading_level(
122 primaryShadingLevel=HMIP_COVER_CLOSED
126 """Stop the device if in motion."""
127 await self.
_device_device.stop()
130 """Open the slats."""
131 await self.
_device_device.set_secondary_shading_level(
132 primaryShadingLevel=self.
_device_device.primaryShadingLevel,
133 secondaryShadingLevel=HMIP_SLATS_OPEN,
137 """Close the slats."""
138 await self.
_device_device.set_secondary_shading_level(
139 primaryShadingLevel=self.
_device_device.primaryShadingLevel,
140 secondaryShadingLevel=HMIP_SLATS_CLOSED,
144 """Stop the device if in motion."""
145 await self.
_device_device.stop()
149 """Representation of the HomematicIP cover shutter."""
151 _attr_device_class = CoverDeviceClass.SHUTTER
158 is_multi_channel=
True,
160 """Initialize the multi cover entity."""
162 hap, device, channel=channel, is_multi_channel=is_multi_channel
167 """Return current position of cover."""
168 if self.
_device_device.functionalChannels[self.
_channel_channel].shutterLevel
is not None:
170 (1 - self.
_device_device.functionalChannels[self.
_channel_channel].shutterLevel) * 100
175 """Move the cover to a specific position."""
176 position = kwargs[ATTR_POSITION]
178 level = 1 - position / 100.0
179 await self.
_device_device.set_shutter_level(level, self.
_channel_channel)
183 """Return if the cover is closed."""
184 if self.
_device_device.functionalChannels[self.
_channel_channel].shutterLevel
is not None:
186 self.
_device_device.functionalChannels[self.
_channel_channel].shutterLevel
192 """Open the cover."""
193 await self.
_device_device.set_shutter_level(HMIP_COVER_OPEN, self.
_channel_channel)
196 """Close the cover."""
197 await self.
_device_device.set_shutter_level(HMIP_COVER_CLOSED, self.
_channel_channel)
200 """Stop the device if in motion."""
205 """Representation of the HomematicIP cover shutter."""
207 def __init__(self, hap: HomematicipHAP, device) ->
None:
208 """Initialize the multi cover entity."""
209 super().
__init__(hap, device, is_multi_channel=
False)
213 """Representation of the HomematicIP multi cover slats."""
220 is_multi_channel=
True,
222 """Initialize the multi slats entity."""
224 hap, device, channel=channel, is_multi_channel=is_multi_channel
229 """Return current tilt position of cover."""
230 if self.
_device_device.functionalChannels[self.
_channel_channel].slatsLevel
is not None:
232 (1 - self.
_device_device.functionalChannels[self.
_channel_channel].slatsLevel) * 100
237 """Move the cover to a specific tilt position."""
238 position = kwargs[ATTR_TILT_POSITION]
240 level = 1 - position / 100.0
241 await self.
_device_device.set_slats_level(slatsLevel=level, channelIndex=self.
_channel_channel)
244 """Open the slats."""
245 await self.
_device_device.set_slats_level(
246 slatsLevel=HMIP_SLATS_OPEN, channelIndex=self.
_channel_channel
250 """Close the slats."""
251 await self.
_device_device.set_slats_level(
252 slatsLevel=HMIP_SLATS_CLOSED, channelIndex=self.
_channel_channel
256 """Stop the device if in motion."""
261 """Representation of the HomematicIP cover slats."""
263 def __init__(self, hap: HomematicipHAP, device) ->
None:
264 """Initialize the multi slats entity."""
265 super().
__init__(hap, device, is_multi_channel=
False)
269 """Representation of the HomematicIP Garage Door Module."""
271 _attr_device_class = CoverDeviceClass.GARAGE
275 """Return current position of cover."""
276 door_state_to_position = {
279 DoorState.VENTILATION_POSITION: 10,
280 DoorState.POSITION_UNKNOWN:
None,
282 return door_state_to_position.get(self.
_device_device.doorState)
286 """Return if the cover is closed."""
287 return self.
_device_device.doorState == DoorState.CLOSED
290 """Open the cover."""
291 await self.
_device_device.send_door_command(DoorCommand.OPEN)
294 """Close the cover."""
295 await self.
_device_device.send_door_command(DoorCommand.CLOSE)
298 """Stop the cover."""
299 await self.
_device_device.send_door_command(DoorCommand.STOP)
303 """Representation of the HomematicIP cover shutter group."""
305 _attr_device_class = CoverDeviceClass.SHUTTER
307 def __init__(self, hap: HomematicipHAP, device, post: str =
"ShutterGroup") ->
None:
308 """Initialize switching group."""
309 device.modelType = f
"HmIP-{post}"
310 super().
__init__(hap, device, post, is_multi_channel=
False)
314 """Return current position of cover."""
315 if self.
_device_device.shutterLevel
is not None:
316 return int((1 - self.
_device_device.shutterLevel) * 100)
321 """Return current tilt position of cover."""
322 if self.
_device_device.slatsLevel
is not None:
323 return int((1 - self.
_device_device.slatsLevel) * 100)
328 """Return if the cover is closed."""
329 if self.
_device_device.shutterLevel
is not None:
330 return self.
_device_device.shutterLevel == HMIP_COVER_CLOSED
334 """Move the cover to a specific position."""
335 position = kwargs[ATTR_POSITION]
337 level = 1 - position / 100.0
338 await self.
_device_device.set_shutter_level(level)
341 """Move the cover to a specific tilt position."""
342 position = kwargs[ATTR_TILT_POSITION]
344 level = 1 - position / 100.0
345 await self.
_device_device.set_slats_level(level)
348 """Open the cover."""
349 await self.
_device_device.set_shutter_level(HMIP_COVER_OPEN)
352 """Close the cover."""
353 await self.
_device_device.set_shutter_level(HMIP_COVER_CLOSED)
356 """Stop the group if in motion."""
357 await self.
_device_device.set_shutter_stop()
360 """Open the slats."""
361 await self.
_device_device.set_slats_level(HMIP_SLATS_OPEN)
364 """Close the slats."""
365 await self.
_device_device.set_slats_level(HMIP_SLATS_CLOSED)
368 """Stop the group if in motion."""
369 await self.
_device_device.set_shutter_stop()
current_cover_tilt_position
None async_stop_cover_tilt(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None async_set_cover_tilt_position(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_close_cover_tilt(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
bool|None is_closed(self)
None async_open_cover_tilt(self, **Any kwargs)
None async_open_cover_tilt(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
bool|None is_closed(self)
None async_set_cover_tilt_position(self, **Any kwargs)
None async_close_cover_tilt(self, **Any kwargs)
None async_stop_cover_tilt(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device, str post="ShutterGroup")
None async_stop_cover(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device)
None __init__(self, HomematicipHAP hap, device)
bool|None is_closed(self)
None async_close_cover(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device, channel=1, is_multi_channel=True)
bool|None is_closed(self)
None async_stop_cover_tilt(self, **Any kwargs)
None async_open_cover_tilt(self, **Any kwargs)
None async_close_cover_tilt(self, **Any kwargs)
None async_set_cover_tilt_position(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device, channel=1, is_multi_channel=True)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)