mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Add binary sensor platform to Aseko (#66643)
This commit is contained in:
parent
470936a63a
commit
19d8b8a6ff
@ -77,6 +77,7 @@ omit =
|
|||||||
homeassistant/components/aruba/device_tracker.py
|
homeassistant/components/aruba/device_tracker.py
|
||||||
homeassistant/components/arwn/sensor.py
|
homeassistant/components/arwn/sensor.py
|
||||||
homeassistant/components/aseko_pool_live/__init__.py
|
homeassistant/components/aseko_pool_live/__init__.py
|
||||||
|
homeassistant/components/aseko_pool_live/binary_sensor.py
|
||||||
homeassistant/components/aseko_pool_live/entity.py
|
homeassistant/components/aseko_pool_live/entity.py
|
||||||
homeassistant/components/aseko_pool_live/sensor.py
|
homeassistant/components/aseko_pool_live/sensor.py
|
||||||
homeassistant/components/asterisk_cdr/mailbox.py
|
homeassistant/components/asterisk_cdr/mailbox.py
|
||||||
|
@ -17,7 +17,7 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORMS: list[str] = [Platform.SENSOR]
|
PLATFORMS: list[str] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
95
homeassistant/components/aseko_pool_live/binary_sensor.py
Normal file
95
homeassistant/components/aseko_pool_live/binary_sensor.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
"""Support for Aseko Pool Live binary sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from aioaseko import Unit
|
||||||
|
|
||||||
|
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 AsekoDataUpdateCoordinator
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .entity import AsekoEntity
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class AsekoBinarySensorDescriptionMixin:
|
||||||
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
|
value_fn: Callable[[Unit], bool]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class AsekoBinarySensorEntityDescription(
|
||||||
|
BinarySensorEntityDescription, AsekoBinarySensorDescriptionMixin
|
||||||
|
):
|
||||||
|
"""Describes a Aseko binary sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
|
UNIT_BINARY_SENSORS: tuple[AsekoBinarySensorEntityDescription, ...] = (
|
||||||
|
AsekoBinarySensorEntityDescription(
|
||||||
|
key="water_flow",
|
||||||
|
name="Water Flow",
|
||||||
|
icon="mdi:waves-arrow-right",
|
||||||
|
value_fn=lambda unit: unit.water_flow,
|
||||||
|
),
|
||||||
|
AsekoBinarySensorEntityDescription(
|
||||||
|
key="has_alarm",
|
||||||
|
name="Alarm",
|
||||||
|
value_fn=lambda unit: unit.has_alarm,
|
||||||
|
device_class=BinarySensorDeviceClass.SAFETY,
|
||||||
|
),
|
||||||
|
AsekoBinarySensorEntityDescription(
|
||||||
|
key="has_error",
|
||||||
|
name="Error",
|
||||||
|
value_fn=lambda unit: unit.has_error,
|
||||||
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up the Aseko Pool Live binary sensors."""
|
||||||
|
data: list[tuple[Unit, AsekoDataUpdateCoordinator]] = hass.data[DOMAIN][
|
||||||
|
config_entry.entry_id
|
||||||
|
]
|
||||||
|
entities: list[BinarySensorEntity] = []
|
||||||
|
for unit, coordinator in data:
|
||||||
|
for description in UNIT_BINARY_SENSORS:
|
||||||
|
entities.append(AsekoUnitBinarySensorEntity(unit, coordinator, description))
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class AsekoUnitBinarySensorEntity(AsekoEntity, BinarySensorEntity):
|
||||||
|
"""Representation of a unit water flow binary sensor entity."""
|
||||||
|
|
||||||
|
entity_description: AsekoBinarySensorEntityDescription
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
unit: Unit,
|
||||||
|
coordinator: AsekoDataUpdateCoordinator,
|
||||||
|
entity_description: AsekoBinarySensorEntityDescription,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the unit binary sensor."""
|
||||||
|
super().__init__(unit, coordinator)
|
||||||
|
self.entity_description = entity_description
|
||||||
|
self._attr_name = f"{self._device_name} {entity_description.name}"
|
||||||
|
self._attr_unique_id = f"{self._unit.serial_number}_{entity_description.key}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
return self.entity_description.value_fn(self._unit)
|
Loading…
x
Reference in New Issue
Block a user