2021-09-07 07:52:42 +00:00
|
|
|
"""Support for Flipr binary sensors."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-10 13:48:10 +00:00
|
|
|
BinarySensorDeviceClass,
|
2021-09-07 07:52:42 +00:00
|
|
|
BinarySensorEntity,
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
)
|
2022-01-03 12:10:41 +00:00
|
|
|
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
|
2023-09-16 09:55:49 +00:00
|
|
|
from .entity import FliprEntity
|
2021-09-07 07:52:42 +00:00
|
|
|
|
|
|
|
BINARY_SENSORS_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="ph_status",
|
2023-06-27 11:20:30 +00:00
|
|
|
translation_key="ph_status",
|
2021-12-10 13:48:10 +00:00
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
2021-09-07 07:52:42 +00:00
|
|
|
),
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key="chlorine_status",
|
2023-06-27 11:20:30 +00:00
|
|
|
translation_key="chlorine_status",
|
2021-12-10 13:48:10 +00:00
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
2021-09-07 07:52:42 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-03 12:10:41 +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
|
2022-11-16 08:42:31 +00:00
|
|
|
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
|
|
|
)
|