from homeassistant.components.cover import CoverDeviceClass, CoverEntity, CoverEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from .client.onecontrol_client import MovementState from .coordinator import OneControlCoordinator from .const import DOMAIN, COVER_DEVICES async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: coordinator: OneControlCoordinator = hass.data[DOMAIN][entry.entry_id] async_add_entities( OneControlCover(coordinator, device_id, name) for device_id, name in COVER_DEVICES.items() ) class OneControlCover(CoordinatorEntity, CoverEntity): _attr_device_class = CoverDeviceClass.AWNING _attr_supported_features = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP ) def __init__(self, coordinator: OneControlCoordinator, device_id: int, name: str) -> None: super().__init__(coordinator) self._device_id = device_id self._attr_name = name self._attr_unique_id = f"{coordinator.address}_cover_{device_id}" @property def is_closed(self) -> bool | None: # State tracking not yet decoded from cover_raw events; return None (unknown) return None @property def available(self) -> bool: return self.coordinator.is_connected async def async_open_cover(self, **kwargs) -> None: await self.coordinator.async_control_movement(self._device_id, MovementState.EXTEND) async def async_close_cover(self, **kwargs) -> None: await self.coordinator.async_control_movement(self._device_id, MovementState.RETRACT) async def async_stop_cover(self, **kwargs) -> None: await self.coordinator.async_control_movement(self._device_id, MovementState.STOP)