hass-core/homeassistant/components/flipr/binary_sensor.py
epenet 5538d5d59d
Use new DeviceClass enums in flipr (#61439)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-12-10 08:48:10 -05:00

46 lines
1.3 KiB
Python

"""Support for Flipr binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from . import FliprEntity
from .const import DOMAIN
BINARY_SENSORS_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="ph_status",
name="PH Status",
device_class=BinarySensorDeviceClass.PROBLEM,
),
BinarySensorEntityDescription(
key="chlorine_status",
name="Chlorine Status",
device_class=BinarySensorDeviceClass.PROBLEM,
),
)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""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):
"""Return true if the binary sensor is on in case of a Problem is detected."""
return (
self.coordinator.data[self.entity_description.key] == "TooLow"
or self.coordinator.data[self.entity_description.key] == "TooHigh"
)