From 8a44adb447636927a03110b336924e6420093f6e Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Mon, 25 Sep 2023 13:34:39 +0200 Subject: [PATCH] Add binary sensors for duotecno (#100844) * Add binary sensors for duotecno * Add comments --- .coveragerc | 1 + homeassistant/components/duotecno/__init__.py | 1 + .../components/duotecno/binary_sensor.py | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 homeassistant/components/duotecno/binary_sensor.py diff --git a/.coveragerc b/.coveragerc index c72c570feab..7a016dac370 100644 --- a/.coveragerc +++ b/.coveragerc @@ -247,6 +247,7 @@ omit = homeassistant/components/duotecno/cover.py homeassistant/components/duotecno/light.py homeassistant/components/duotecno/climate.py + homeassistant/components/duotecno/binary_sensor.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 bc7d519aa9c..d9d890c28f3 100644 --- a/homeassistant/components/duotecno/__init__.py +++ b/homeassistant/components/duotecno/__init__.py @@ -16,6 +16,7 @@ PLATFORMS: list[Platform] = [ Platform.COVER, Platform.LIGHT, Platform.CLIMATE, + Platform.BINARY_SENSOR, ] diff --git a/homeassistant/components/duotecno/binary_sensor.py b/homeassistant/components/duotecno/binary_sensor.py new file mode 100644 index 00000000000..a1638ce4055 --- /dev/null +++ b/homeassistant/components/duotecno/binary_sensor.py @@ -0,0 +1,34 @@ +"""Support for Duotecno binary sensors.""" + +from duotecno.unit import ControlUnit + +from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +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 Duotecno binary sensor on config_entry.""" + cntrl = hass.data[DOMAIN][entry.entry_id] + async_add_entities( + DuotecnoBinarySensor(channel) for channel in cntrl.get_units("ControlUnit") + ) + + +class DuotecnoBinarySensor(DuotecnoEntity, BinarySensorEntity): + """Representation of a DuotecnoBinarySensor.""" + + _unit: ControlUnit + + @property + def is_on(self) -> bool: + """Return true if the binary sensor is on.""" + return self._unit.is_on()