mirror of
https://github.com/home-assistant/core
synced 2024-08-28 03:36:46 +02:00
54 lines
1.6 KiB
Python
54 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 .const import DOMAIN
|
|
from .entity import PoolSenseEntity
|
|
|
|
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|
BinarySensorEntityDescription(
|
|
key="pH Status",
|
|
translation_key="ph_status",
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
),
|
|
BinarySensorEntityDescription(
|
|
key="Chlorine Status",
|
|
translation_key="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) -> bool:
|
|
"""Return true if the binary sensor is on."""
|
|
return self.coordinator.data[self.entity_description.key] == "red"
|