mirror of
https://github.com/home-assistant/core.git
synced 2025-08-07 14:45:09 +02:00
Add binary sensors
This commit is contained in:
@@ -20,6 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
133
homeassistant/components/renson/binary_sensor.py
Normal file
133
homeassistant/components/renson/binary_sensor.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
"""Binary sensors for renson."""
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from renson_endura_delta.field_enum import (
|
||||||
|
AIR_QUALITY_CONTROL_FIELD,
|
||||||
|
BREEZE_ENABLE_FIELD,
|
||||||
|
BREEZE_MET_FIELD,
|
||||||
|
CO2_CONTROL_FIELD,
|
||||||
|
FROST_PROTECTION_FIELD,
|
||||||
|
HUMIDITY_CONTROL_FIELD,
|
||||||
|
PREHEATER_FIELD,
|
||||||
|
DataType,
|
||||||
|
FieldEnum,
|
||||||
|
)
|
||||||
|
from renson_endura_delta.renson import RensonVentilation
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
BinarySensorEntity,
|
||||||
|
BinarySensorEntityDescription,
|
||||||
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import EntityCategory
|
||||||
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import RensonCoordinator
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .entity import RensonEntity
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class RensonBinarySensorEntityDescriptionMixin:
|
||||||
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
|
field: FieldEnum
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class RensonBinarySensorEntityDescription(
|
||||||
|
BinarySensorEntityDescription, RensonBinarySensorEntityDescriptionMixin
|
||||||
|
):
|
||||||
|
"""Description of binary sensor."""
|
||||||
|
|
||||||
|
|
||||||
|
BINARY_SENSORS: tuple[RensonBinarySensorEntityDescription, ...] = (
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
name="Frost protection active",
|
||||||
|
key="FROST_PROTECTION_FIELD",
|
||||||
|
field=FROST_PROTECTION_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="BREEZE_ENABLE_FIELD",
|
||||||
|
name="Breeze",
|
||||||
|
field=BREEZE_ENABLE_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="BREEZE_MET_FIELD",
|
||||||
|
name="Breeze conditions met",
|
||||||
|
field=BREEZE_MET_FIELD,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="HUMIDITY_CONTROL_FIELD",
|
||||||
|
name="Humidity control",
|
||||||
|
field=HUMIDITY_CONTROL_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="AIR_QUALITY_CONTROL_FIELD",
|
||||||
|
name="Air quality control",
|
||||||
|
field=AIR_QUALITY_CONTROL_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="CO2_CONTROL_FIELD",
|
||||||
|
name="CO2 control",
|
||||||
|
field=CO2_CONTROL_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="PREHEATER_FIELD",
|
||||||
|
name="Preheater",
|
||||||
|
field=PREHEATER_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RensonBinarySensor(RensonEntity, BinarySensorEntity):
|
||||||
|
"""Get a sensor data from the Renson API and store it in the state of the class."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
description: RensonBinarySensorEntityDescription,
|
||||||
|
api: RensonVentilation,
|
||||||
|
coordinator: RensonCoordinator,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize class."""
|
||||||
|
super().__init__(description.key, api, coordinator)
|
||||||
|
|
||||||
|
self.field = description.field
|
||||||
|
self.entity_description = description
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
"""Handle updated data from the coordinator."""
|
||||||
|
all_data = self.coordinator.data
|
||||||
|
|
||||||
|
value = self.api.get_field_value(all_data, self.field.name)
|
||||||
|
|
||||||
|
self._attr_is_on = self.api.parse_value(value, DataType.BOOLEAN)
|
||||||
|
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Call the Renson integration to setup."""
|
||||||
|
|
||||||
|
api: RensonVentilation = hass.data[DOMAIN][config_entry.entry_id].api
|
||||||
|
coordinator: RensonCoordinator = hass.data[DOMAIN][
|
||||||
|
config_entry.entry_id
|
||||||
|
].coordinator
|
||||||
|
|
||||||
|
entities: list = []
|
||||||
|
for description in BINARY_SENSORS:
|
||||||
|
entities.append(RensonBinarySensor(description, api, coordinator))
|
||||||
|
|
||||||
|
async_add_entities(entities)
|
Reference in New Issue
Block a user