"""Cover platform for the Carefree BT12 awning.""" from __future__ import annotations from typing import Any from homeassistant.components.cover import CoverDeviceClass, CoverEntity, CoverEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN from .coordinator import Bt12Coordinator async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: coordinator: Bt12Coordinator = hass.data[DOMAIN][entry.entry_id] device_info = DeviceInfo( identifiers={(DOMAIN, entry.data["address"])}, name=entry.data.get("name", "BT12 Awning"), manufacturer="Carefree of Colorado", model="BT12", ) async_add_entities([Bt12Cover(coordinator, device_info)]) class Bt12Cover(CoverEntity): """The awning. Open = extended, close = retracted. Blind control only -- no position/status feedback decoded yet, so state here is entirely assumed/optimistic (see coordinator.py's last_notifications for the raw, still-undecoded notify traffic). There's also no dedicated stop command on this device: re-sending whichever direction is currently moving is what stops it, so stop_cover just replays the last-commanded direction. """ _attr_has_entity_name = True _attr_name = None _attr_assumed_state = True _attr_should_poll = False _attr_device_class = CoverDeviceClass.AWNING _attr_supported_features = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP ) def __init__(self, coordinator: Bt12Coordinator, device_info: DeviceInfo) -> None: self._coordinator = coordinator self._attr_unique_id = f"{coordinator.address}_awning" self._attr_device_info = device_info @property def is_closed(self) -> bool | None: return None # unknown -- no position feedback decoded yet @property def is_opening(self) -> bool: return self._coordinator.moving_direction == "extend" @property def is_closing(self) -> bool: return self._coordinator.moving_direction == "retract" async def async_open_cover(self, **kwargs: Any) -> None: await self._coordinator.async_extend() async def async_close_cover(self, **kwargs: Any) -> None: await self._coordinator.async_retract() async def async_stop_cover(self, **kwargs: Any) -> None: await self._coordinator.async_stop() async def async_added_to_hass(self) -> None: self.async_on_remove(self._coordinator.async_add_listener(self._handle_update)) @callback def _handle_update(self) -> None: self.async_write_ha_state()