diff --git a/.coveragerc b/.coveragerc index f340202cdb8..b716874c679 100644 --- a/.coveragerc +++ b/.coveragerc @@ -170,6 +170,7 @@ omit = homeassistant/components/devolo_home_control/__init__.py homeassistant/components/devolo_home_control/binary_sensor.py homeassistant/components/devolo_home_control/const.py + homeassistant/components/devolo_home_control/cover.py homeassistant/components/devolo_home_control/devolo_device.py homeassistant/components/devolo_home_control/devolo_multi_level_switch.py homeassistant/components/devolo_home_control/light.py diff --git a/homeassistant/components/devolo_home_control/const.py b/homeassistant/components/devolo_home_control/const.py index 60923235916..b98346539d0 100644 --- a/homeassistant/components/devolo_home_control/const.py +++ b/homeassistant/components/devolo_home_control/const.py @@ -3,6 +3,6 @@ DOMAIN = "devolo_home_control" DEFAULT_MYDEVOLO = "https://www.mydevolo.com" DEFAULT_MPRM = "https://homecontrol.mydevolo.com" -PLATFORMS = ["binary_sensor", "light", "sensor", "switch"] +PLATFORMS = ["binary_sensor", "cover", "light", "sensor", "switch"] CONF_MYDEVOLO = "mydevolo_url" CONF_HOMECONTROL = "home_control_url" diff --git a/homeassistant/components/devolo_home_control/cover.py b/homeassistant/components/devolo_home_control/cover.py new file mode 100644 index 00000000000..7dae0c605ca --- /dev/null +++ b/homeassistant/components/devolo_home_control/cover.py @@ -0,0 +1,99 @@ +"""Platform for cover integration.""" +import logging + +from homeassistant.components.cover import ( + DEVICE_CLASS_BLIND, + SUPPORT_CLOSE, + SUPPORT_OPEN, + SUPPORT_SET_POSITION, + CoverEntity, +) +from homeassistant.config_entries import ConfigEntry +from homeassistant.helpers.typing import HomeAssistantType + +from .const import DOMAIN +from .devolo_device import DevoloDeviceEntity + +_LOGGER = logging.getLogger(__name__) + + +async def async_setup_entry( + hass: HomeAssistantType, entry: ConfigEntry, async_add_entities +) -> None: + """Get all cover devices and setup them via config entry.""" + entities = [] + + for device in hass.data[DOMAIN]["homecontrol"].multi_level_switch_devices: + for multi_level_switch in device.multi_level_switch_property: + if multi_level_switch.startswith("devolo.Blinds"): + entities.append( + DevoloCoverDeviceEntity( + homecontrol=hass.data[DOMAIN]["homecontrol"], + device_instance=device, + element_uid=multi_level_switch, + ) + ) + + async_add_entities(entities, False) + + +class DevoloCoverDeviceEntity(DevoloDeviceEntity, CoverEntity): + """Representation of a cover device within devolo Home Control.""" + + def __init__(self, homecontrol, device_instance, element_uid): + """Initialize a devolo blinds device.""" + super().__init__( + homecontrol=homecontrol, + device_instance=device_instance, + element_uid=element_uid, + name=device_instance.itemName, + sync=self._sync, + ) + + self._multi_level_switch_property = device_instance.multi_level_switch_property.get( + element_uid + ) + + self._position = self._multi_level_switch_property.value + + @property + def current_cover_position(self): + """Return the current position. 0 is closed. 100 is open.""" + return self._position + + @property + def device_class(self): + """Return the class of the device.""" + return DEVICE_CLASS_BLIND + + @property + def is_closed(self): + """Return if the blind is closed or not.""" + return not bool(self._position) + + @property + def supported_features(self): + """Flag supported features.""" + return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION + + def open_cover(self, **kwargs): + """Open the blind.""" + self._multi_level_switch_property.set(100) + + def close_cover(self, **kwargs): + """Close the blind.""" + self._multi_level_switch_property.set(0) + + def set_cover_position(self, **kwargs): + """Set the blind to the given position.""" + self._multi_level_switch_property.set(kwargs["position"]) + + def _sync(self, message=None): + """Update the binary sensor state.""" + if message[0] == self._unique_id: + self._position = message[1] + elif message[0].startswith("hdm"): + self._available = self._device_instance.is_online() + else: + _LOGGER.debug("Not valid message received: %s", message) + self.schedule_update_ha_state() diff --git a/homeassistant/components/devolo_home_control/switch.py b/homeassistant/components/devolo_home_control/switch.py index d14b6c059de..4ba212af379 100644 --- a/homeassistant/components/devolo_home_control/switch.py +++ b/homeassistant/components/devolo_home_control/switch.py @@ -19,7 +19,8 @@ async def async_setup_entry( entities = [] for device in devices: for binary_switch in device.binary_switch_property: - # Exclude the binary switch which have also a multi_level_switches here, because they are implemented as light devices now. + # Exclude the binary switch which also has multi_level_switches here, + # because those are implemented as light entities now. if not hasattr(device, "multi_level_switch_property"): entities.append( DevoloSwitch(