2021-01-26 08:18:20 +00:00
|
|
|
"""Support for Rheem EcoNet water heaters."""
|
2024-03-08 13:15:26 +00:00
|
|
|
|
2021-09-03 20:34:51 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2025-01-28 10:45:24 +00:00
|
|
|
from pyeconet.equipment import Equipment, EquipmentType
|
2021-01-26 08:18:20 +00:00
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-10 07:57:31 +00:00
|
|
|
BinarySensorDeviceClass,
|
2021-01-26 08:18:20 +00:00
|
|
|
BinarySensorEntity,
|
2021-09-03 20:34:51 +00:00
|
|
|
BinarySensorEntityDescription,
|
2021-01-26 08:18:20 +00:00
|
|
|
)
|
2022-01-03 12:10:41 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-01-26 08:18:20 +00:00
|
|
|
|
2025-01-28 10:25:27 +00:00
|
|
|
from . import EconetConfigEntry
|
2024-09-16 13:25:30 +00:00
|
|
|
from .entity import EcoNetEntity
|
2021-01-26 08:18:20 +00:00
|
|
|
|
2021-09-03 20:34:51 +00:00
|
|
|
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="shutoff_valve_open",
|
|
|
|
name="shutoff_valve",
|
2021-12-10 07:57:31 +00:00
|
|
|
device_class=BinarySensorDeviceClass.OPENING,
|
2021-09-03 20:34:51 +00:00
|
|
|
),
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="running",
|
|
|
|
name="running",
|
2021-12-10 07:57:31 +00:00
|
|
|
device_class=BinarySensorDeviceClass.POWER,
|
2021-09-03 20:34:51 +00:00
|
|
|
),
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="screen_locked",
|
|
|
|
name="screen_locked",
|
2021-12-10 07:57:31 +00:00
|
|
|
device_class=BinarySensorDeviceClass.LOCK,
|
2021-09-03 20:34:51 +00:00
|
|
|
),
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="beep_enabled",
|
|
|
|
name="beep_enabled",
|
2021-12-10 07:57:31 +00:00
|
|
|
device_class=BinarySensorDeviceClass.SOUND,
|
2021-09-03 20:34:51 +00:00
|
|
|
),
|
|
|
|
)
|
2021-01-26 08:18:20 +00:00
|
|
|
|
|
|
|
|
2022-01-03 12:10:41 +00:00
|
|
|
async def async_setup_entry(
|
2025-01-28 10:25:27 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: EconetConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-03 12:10:41 +00:00
|
|
|
) -> None:
|
2021-01-26 08:18:20 +00:00
|
|
|
"""Set up EcoNet binary sensor based on a config entry."""
|
2025-01-28 10:25:27 +00:00
|
|
|
equipment = entry.runtime_data
|
2021-03-25 16:06:51 +00:00
|
|
|
all_equipment = equipment[EquipmentType.WATER_HEATER].copy()
|
|
|
|
all_equipment.extend(equipment[EquipmentType.THERMOSTAT].copy())
|
|
|
|
|
2021-09-03 20:34:51 +00:00
|
|
|
entities = [
|
|
|
|
EcoNetBinarySensor(_equip, description)
|
|
|
|
for _equip in all_equipment
|
|
|
|
for description in BINARY_SENSOR_TYPES
|
|
|
|
if getattr(_equip, description.key, None) is not None
|
|
|
|
]
|
|
|
|
|
|
|
|
async_add_entities(entities)
|
2021-01-26 08:18:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EcoNetBinarySensor(EcoNetEntity, BinarySensorEntity):
|
|
|
|
"""Define a Econet binary sensor."""
|
|
|
|
|
2023-02-06 10:37:25 +00:00
|
|
|
def __init__(
|
2025-01-28 10:45:24 +00:00
|
|
|
self, econet_device: Equipment, description: BinarySensorEntityDescription
|
2023-02-06 10:37:25 +00:00
|
|
|
) -> None:
|
2021-01-26 08:18:20 +00:00
|
|
|
"""Initialize."""
|
|
|
|
super().__init__(econet_device)
|
2021-09-03 20:34:51 +00:00
|
|
|
self.entity_description = description
|
2023-01-05 13:25:33 +00:00
|
|
|
self._attr_name = f"{econet_device.device_name}_{description.name}"
|
|
|
|
self._attr_unique_id = (
|
|
|
|
f"{econet_device.device_id}_{econet_device.device_name}_{description.name}"
|
|
|
|
)
|
2021-01-26 08:18:20 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the binary sensor is on."""
|
2021-09-03 20:34:51 +00:00
|
|
|
return getattr(self._econet, self.entity_description.key)
|