73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""Cover platform for Sternwarte."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.cover import CoverEntity, CoverEntityFeature
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .const import DOMAIN, ENTITY_ROOF_COVER
|
|
from .entity import SternwarteEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up Sternwarte cover."""
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities([SternwarteRoofCover(coordinator)])
|
|
|
|
|
|
class SternwarteRoofCover(SternwarteEntity, CoverEntity):
|
|
"""Representation of the observatory roof."""
|
|
|
|
_attr_name = "Dach"
|
|
_attr_supported_features = (
|
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
|
)
|
|
|
|
def __init__(self, coordinator):
|
|
super().__init__(coordinator, ENTITY_ROOF_COVER)
|
|
|
|
@property
|
|
def is_closed(self) -> bool | None:
|
|
if self.coordinator.data.roof_closed and not self.coordinator.data.roof_open:
|
|
return True
|
|
if self.coordinator.data.roof_open and not self.coordinator.data.roof_closed:
|
|
return False
|
|
return None
|
|
|
|
@property
|
|
def is_opening(self) -> bool:
|
|
if not self.coordinator.data.roof_moving or self.coordinator.data.roof_open:
|
|
return False
|
|
direction = self.coordinator._last_roof_direction
|
|
if direction is not None:
|
|
return direction == "opening"
|
|
return not self.coordinator.data.roof_closed
|
|
|
|
@property
|
|
def is_closing(self) -> bool:
|
|
if not self.coordinator.data.roof_moving or self.coordinator.data.roof_closed:
|
|
return False
|
|
direction = self.coordinator._last_roof_direction
|
|
if direction is not None:
|
|
return direction == "closing"
|
|
return not self.coordinator.data.roof_open
|
|
|
|
@property
|
|
def current_cover_position(self) -> int | None:
|
|
return self.coordinator.roof_position_percent
|
|
|
|
async def async_open_cover(self, **kwargs) -> None:
|
|
await self.coordinator.async_open_roof()
|
|
|
|
async def async_close_cover(self, **kwargs) -> None:
|
|
await self.coordinator.async_close_roof()
|
|
|
|
async def async_stop_cover(self, **kwargs) -> None:
|
|
await self.coordinator.async_stop_roof()
|