diff --git a/.coveragerc b/.coveragerc index f394a1729bf..b0f3baf33cc 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1094,6 +1094,7 @@ omit = homeassistant/components/todoist/const.py homeassistant/components/tof/sensor.py homeassistant/components/tolo/__init__.py + homeassistant/components/tolo/binary_sensor.py homeassistant/components/tolo/button.py homeassistant/components/tolo/climate.py homeassistant/components/tolo/light.py diff --git a/homeassistant/components/tolo/__init__.py b/homeassistant/components/tolo/__init__.py index 02fece7b3b9..3776c4bd61c 100644 --- a/homeassistant/components/tolo/__init__.py +++ b/homeassistant/components/tolo/__init__.py @@ -22,7 +22,7 @@ from homeassistant.helpers.update_coordinator import ( from .const import DEFAULT_RETRY_COUNT, DEFAULT_RETRY_TIMEOUT, DOMAIN -PLATFORMS = ["button", "climate", "light", "select", "sensor"] +PLATFORMS = ["binary_sensor", "button", "climate", "light", "select", "sensor"] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/tolo/binary_sensor.py b/homeassistant/components/tolo/binary_sensor.py new file mode 100644 index 00000000000..777e2f16942 --- /dev/null +++ b/homeassistant/components/tolo/binary_sensor.py @@ -0,0 +1,72 @@ +"""TOLO Sauna binary sensors.""" + +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_OPENING, + BinarySensorEntity, +) +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import ToloSaunaCoordinatorEntity, ToloSaunaUpdateCoordinator +from .const import DOMAIN + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up binary sensors for TOLO Sauna.""" + coordinator = hass.data[DOMAIN][entry.entry_id] + async_add_entities( + [ + ToloFlowInBinarySensor(coordinator, entry), + ToloFlowOutBinarySensor(coordinator, entry), + ] + ) + + +class ToloFlowInBinarySensor(ToloSaunaCoordinatorEntity, BinarySensorEntity): + """Water In Valve Sensor.""" + + _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_name = "Water In Valve" + _attr_device_class = DEVICE_CLASS_OPENING + _attr_icon = "mdi:water-plus-outline" + + def __init__( + self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry + ) -> None: + """Initialize TOLO Water In Valve entity.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{entry.entry_id}_flow_in" + + @property + def is_on(self) -> bool: + """Return if flow in valve is open.""" + return self.coordinator.data.status.flow_in + + +class ToloFlowOutBinarySensor(ToloSaunaCoordinatorEntity, BinarySensorEntity): + """Water Out Valve Sensor.""" + + _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_name = "Water Out Valve" + _attr_device_class = DEVICE_CLASS_OPENING + _attr_icon = "mdi:water-minus-outline" + + def __init__( + self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry + ) -> None: + """Initialize TOLO Water Out Valve entity.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{entry.entry_id}_flow_out" + + @property + def is_on(self) -> bool: + """Return if flow out valve is open.""" + return self.coordinator.data.status.flow_out