hass-core/homeassistant/components/poolsense/binary_sensor.py
epenet 545b10a711
Add binary_sensor setup type hints [o-r] (#63270)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-01-03 11:35:02 +01:00

53 lines
1.6 KiB
Python

"""Support for PoolSense binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PoolSenseEntity
from .const import DOMAIN
BINARY_SENSOR_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 to the shared sensor module."""
coordinator = hass.data[DOMAIN][config_entry.entry_id]
entities = [
PoolSenseBinarySensor(coordinator, config_entry.data[CONF_EMAIL], description)
for description in BINARY_SENSOR_TYPES
]
async_add_entities(entities, False)
class PoolSenseBinarySensor(PoolSenseEntity, BinarySensorEntity):
"""Representation of PoolSense binary sensors."""
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self.coordinator.data[self.entity_description.key] == "red"