Files
homeassistant-core/homeassistant/components/econet/binary_sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.4 KiB
Python
Raw Normal View History

2021-01-26 03:18:20 -05:00
"""Support for Rheem EcoNet water heaters."""
2021-09-03 22:34:51 +02:00
from __future__ import annotations
2021-01-26 03:18:20 -05:00
from pyeconet.equipment import EquipmentType
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
2021-01-26 03:18:20 -05:00
BinarySensorEntity,
2021-09-03 22:34:51 +02:00
BinarySensorEntityDescription,
2021-01-26 03:18:20 -05:00
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2021-01-26 03:18:20 -05:00
from . import EcoNetEntity
from .const import DOMAIN, EQUIPMENT
2021-09-03 22:34:51 +02:00
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="shutoff_valve_open",
name="shutoff_valve",
device_class=BinarySensorDeviceClass.OPENING,
2021-09-03 22:34:51 +02:00
),
BinarySensorEntityDescription(
key="running",
name="running",
device_class=BinarySensorDeviceClass.POWER,
2021-09-03 22:34:51 +02:00
),
BinarySensorEntityDescription(
key="screen_locked",
name="screen_locked",
device_class=BinarySensorDeviceClass.LOCK,
2021-09-03 22:34:51 +02:00
),
BinarySensorEntityDescription(
key="beep_enabled",
name="beep_enabled",
device_class=BinarySensorDeviceClass.SOUND,
2021-09-03 22:34:51 +02:00
),
)
2021-01-26 03:18:20 -05:00
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
2021-01-26 03:18:20 -05:00
"""Set up EcoNet binary sensor based on a config entry."""
equipment = hass.data[DOMAIN][EQUIPMENT][entry.entry_id]
all_equipment = equipment[EquipmentType.WATER_HEATER].copy()
all_equipment.extend(equipment[EquipmentType.THERMOSTAT].copy())
2021-09-03 22:34:51 +02: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 03:18:20 -05:00
class EcoNetBinarySensor(EcoNetEntity, BinarySensorEntity):
"""Define a Econet binary sensor."""
def __init__(
self, econet_device, description: BinarySensorEntityDescription
) -> None:
2021-01-26 03:18:20 -05:00
"""Initialize."""
super().__init__(econet_device)
2021-09-03 22:34:51 +02:00
self.entity_description = description
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 03:18:20 -05:00
@property
def is_on(self):
"""Return true if the binary sensor is on."""
2021-09-03 22:34:51 +02:00
return getattr(self._econet, self.entity_description.key)