1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-01 19:57:08 +01:00
Files
core/homeassistant/components/vallox/binary_sensor.py
T
2026-04-30 21:14:48 +02:00

68 lines
2.0 KiB
Python

"""Support for Vallox ventilation unit binary sensors."""
from dataclasses import dataclass
from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.const import CONF_NAME, EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .coordinator import ValloxConfigEntry, ValloxDataUpdateCoordinator
from .entity import ValloxEntity
class ValloxBinarySensorEntity(ValloxEntity, BinarySensorEntity):
"""Representation of a Vallox binary sensor."""
entity_description: ValloxBinarySensorEntityDescription
_attr_entity_category = EntityCategory.DIAGNOSTIC
def __init__(
self,
name: str,
coordinator: ValloxDataUpdateCoordinator,
description: ValloxBinarySensorEntityDescription,
) -> None:
"""Initialize the Vallox binary sensor."""
super().__init__(name, coordinator)
self.entity_description = description
self._attr_unique_id = f"{self._device_uuid}-{description.key}"
@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
return self.coordinator.data.get(self.entity_description.metric_key) == 1
@dataclass(frozen=True, kw_only=True)
class ValloxBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Describes Vallox binary sensor entity."""
metric_key: str
BINARY_SENSOR_ENTITIES: tuple[ValloxBinarySensorEntityDescription, ...] = (
ValloxBinarySensorEntityDescription(
key="post_heater",
translation_key="post_heater",
metric_key="A_CYC_IO_HEATER",
),
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ValloxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the sensors."""
async_add_entities(
ValloxBinarySensorEntity(entry.data[CONF_NAME], entry.runtime_data, description)
for description in BINARY_SENSOR_ENTITIES
)