Files
homeassistant-core/homeassistant/components/poolsense/binary_sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.5 KiB
Python
Raw Normal View History

2020-07-11 04:53:34 +02:00
"""Support for PoolSense binary sensors."""
2021-09-06 11:58:47 +02:00
from __future__ import annotations
2020-07-11 04:53:34 +02:00
from homeassistant.components.binary_sensor import (
2021-12-16 11:06:16 -05:00
BinarySensorDeviceClass,
2020-07-11 04:53:34 +02:00
BinarySensorEntity,
2021-09-06 11:58:47 +02:00
BinarySensorEntityDescription,
2020-07-11 04:53:34 +02:00
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2020-07-11 04:53:34 +02:00
2024-05-16 17:31:14 +02:00
from . import PoolSenseConfigEntry
from .entity import PoolSenseEntity
2020-07-11 04:53:34 +02:00
2021-09-06 11:58:47 +02:00
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="pH Status",
translation_key="ph_status",
2021-12-16 11:06:16 -05:00
device_class=BinarySensorDeviceClass.PROBLEM,
2021-09-06 11:58:47 +02:00
),
BinarySensorEntityDescription(
key="Chlorine Status",
translation_key="chlorine_status",
2021-12-16 11:06:16 -05:00
device_class=BinarySensorDeviceClass.PROBLEM,
2021-09-06 11:58:47 +02:00
),
)
2020-07-11 04:53:34 +02:00
async def async_setup_entry(
hass: HomeAssistant,
2024-05-16 17:31:14 +02:00
config_entry: PoolSenseConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
2020-07-11 04:53:34 +02:00
"""Defer sensor setup to the shared sensor module."""
2024-05-16 17:31:14 +02:00
coordinator = config_entry.runtime_data
2020-07-11 04:53:34 +02:00
async_add_entities(
PoolSenseBinarySensor(coordinator, description)
2021-09-06 11:58:47 +02:00
for description in BINARY_SENSOR_TYPES
)
2020-07-11 04:53:34 +02:00
class PoolSenseBinarySensor(PoolSenseEntity, BinarySensorEntity):
"""Representation of PoolSense binary sensors."""
@property
2023-09-27 10:14:51 +02:00
def is_on(self) -> bool:
2020-07-11 04:53:34 +02:00
"""Return true if the binary sensor is on."""
2021-09-06 11:58:47 +02:00
return self.coordinator.data[self.entity_description.key] == "red"