1 """Elmax cover platform."""
3 from __future__
import annotations
8 from elmax_api.model.command
import CoverCommand
9 from elmax_api.model.cover_status
import CoverStatus
16 from .const
import DOMAIN
17 from .coordinator
import ElmaxCoordinator
18 from .entity
import ElmaxEntity
20 _LOGGER = logging.getLogger(__name__)
22 _COMMAND_BY_MOTION_STATUS = {
23 CoverStatus.DOWN: CoverCommand.DOWN,
24 CoverStatus.UP: CoverCommand.UP,
25 CoverStatus.IDLE:
None,
31 config_entry: ConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Set up the Elmax cover platform."""
35 coordinator: ElmaxCoordinator = hass.data[DOMAIN][config_entry.entry_id]
37 if coordinator.data
is None or not coordinator.data.cover_feature:
42 def _discover_new_devices():
43 if (panel_status := coordinator.data)
is None:
48 for cover
in panel_status.covers:
50 if cover.endpoint_id
in known_devices:
54 panel_version=panel_status.release,
55 coordinator=coordinator,
57 entities.append(entity)
61 known_devices.update([e.unique_id
for e
in entities])
64 config_entry.async_on_unload(coordinator.async_add_listener(_discover_new_devices))
67 _discover_new_devices()
71 """Elmax Cover entity implementation."""
73 _attr_supported_features = (
74 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
78 """Check if the current cover entity is in a specific state."""
83 return state == status_to_check
87 """Tells if the cover is closed or not."""
92 """Return current position of cover.
94 None is unknown, 0 is closed, 100 is fully open.
100 """Tells if the cover is opening or not."""
105 """Return if the cover is closing or not."""
109 """Stop the cover."""
114 self.
_device_device.endpoint_id
116 command = _COMMAND_BY_MOTION_STATUS[motion_status]
118 await self.coordinator.http_client.execute_command(
119 endpoint_id=self.
_device_device.endpoint_id, command=command
122 _LOGGER.debug(
"Ignoring stop request as the cover is IDLE")
125 """Open the cover."""
126 await self.coordinator.http_client.execute_command(
127 endpoint_id=self.
_device_device.endpoint_id, command=CoverCommand.UP
131 """Close the cover."""
132 await self.coordinator.http_client.execute_command(
133 endpoint_id=self.
_device_device.endpoint_id, command=CoverCommand.DOWN
Cover get_cover_state(self, str cover_id)
None async_open_cover(self, **Any kwargs)
bool|None is_opening(self)
bool|None is_closing(self)
bool|None is_closed(self)
None async_close_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
bool|None __check_cover_status(self, CoverStatus status_to_check)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)