1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00
ha-core/homeassistant/components/flipr/binary_sensor.py
epenet fbabad1d1d
Add binary_sensor setup type hints [a-f] (#63268)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-03 13:10:41 +01:00

54 lines
1.6 KiB
Python

"""Support for Flipr binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
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: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""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"
)