core/homeassistant/components/flipr/binary_sensor.py

54 lines
1.6 KiB
Python
Raw Normal View History

2021-09-07 07:52:42 +00:00
"""Support for Flipr binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
2021-09-07 07:52:42 +00:00
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2021-09-07 07:52:42 +00:00
from .const import DOMAIN
from .entity import FliprEntity
2021-09-07 07:52:42 +00:00
BINARY_SENSORS_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="ph_status",
translation_key="ph_status",
device_class=BinarySensorDeviceClass.PROBLEM,
2021-09-07 07:52:42 +00:00
),
BinarySensorEntityDescription(
key="chlorine_status",
translation_key="chlorine_status",
device_class=BinarySensorDeviceClass.PROBLEM,
2021-09-07 07:52:42 +00:00
),
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
2021-09-07 07:52:42 +00:00
"""Defer sensor setup of flipr binary sensors."""
coordinator = hass.data[DOMAIN][config_entry.entry_id]
async_add_entities(
FliprBinarySensor(coordinator, description)
for description in BINARY_SENSORS_TYPES
)
class FliprBinarySensor(FliprEntity, BinarySensorEntity):
"""Representation of Flipr binary sensors."""
@property
def is_on(self) -> bool:
2021-09-07 07:52:42 +00:00
"""Return true if the binary sensor is on in case of a Problem is detected."""
2023-07-23 20:00:26 +00:00
return self.coordinator.data[self.entity_description.key] in (
"TooLow",
"TooHigh",
2021-09-07 07:52:42 +00:00
)