diff --git a/.coveragerc b/.coveragerc index 6bc69125c30..fb1869b2489 100644 --- a/.coveragerc +++ b/.coveragerc @@ -233,6 +233,7 @@ omit = homeassistant/components/duotecno/__init__.py homeassistant/components/duotecno/entity.py homeassistant/components/duotecno/switch.py + homeassistant/components/duotecno/cover.py homeassistant/components/dwd_weather_warnings/const.py homeassistant/components/dwd_weather_warnings/coordinator.py homeassistant/components/dwd_weather_warnings/sensor.py diff --git a/homeassistant/components/duotecno/__init__.py b/homeassistant/components/duotecno/__init__.py index a1cf1c907a6..668a38dae5b 100644 --- a/homeassistant/components/duotecno/__init__.py +++ b/homeassistant/components/duotecno/__init__.py @@ -11,7 +11,7 @@ from homeassistant.exceptions import ConfigEntryNotReady from .const import DOMAIN -PLATFORMS: list[Platform] = [Platform.SWITCH] +PLATFORMS: list[Platform] = [Platform.SWITCH, Platform.COVER] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/duotecno/cover.py b/homeassistant/components/duotecno/cover.py new file mode 100644 index 00000000000..13e3df8fc0a --- /dev/null +++ b/homeassistant/components/duotecno/cover.py @@ -0,0 +1,85 @@ +"""Support for Velbus covers.""" +from __future__ import annotations + +from typing import Any + +from duotecno.unit import DuoswitchUnit + +from homeassistant.components.cover import ( + CoverEntity, + CoverEntityFeature, +) +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import DOMAIN +from .entity import DuotecnoEntity + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up the duoswitch endities.""" + cntrl = hass.data[DOMAIN][entry.entry_id] + async_add_entities( + DuotecnoCover(channel) for channel in cntrl.get_units("DuoSwitchUnit") + ) + + +class DuotecnoCover(DuotecnoEntity, CoverEntity): + """Representation a Velbus cover.""" + + _unit: DuoswitchUnit + + def __init__(self, unit: DuoswitchUnit) -> None: + """Initialize the cover.""" + super().__init__(unit) + self._attr_supported_features = ( + CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP + ) + + @property + def is_closed(self) -> bool | None: + """Return if the cover is closed.""" + return self._unit.is_closed() + + @property + def is_opening(self) -> bool: + """Return if the cover is opening.""" + return self._unit.is_opening() + + @property + def is_closing(self) -> bool: + """Return if the cover is closing.""" + return self._unit.is_closing() + + async def async_open_cover(self, **kwargs: Any) -> None: + """Open the cover.""" + try: + await self._unit.open() + except OSError as err: + raise HomeAssistantError( + "Transmit for the open_cover packet failed" + ) from err + + async def async_close_cover(self, **kwargs: Any) -> None: + """Close the cover.""" + try: + await self._unit.close() + except OSError as err: + raise HomeAssistantError( + "Transmit for the close_cover packet failed" + ) from err + + async def async_stop_cover(self, **kwargs: Any) -> None: + """Stop the cover.""" + try: + await self._unit.stop() + except OSError as err: + raise HomeAssistantError( + "Transmit for the stop_cover packet failed" + ) from err