mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Renson binary sensors (#94490)
* Add binary sensors * Add Renson services * Add fan to Renson * Revert "Add fan to Renson" This reverts commit 8e7c09671ebf0a53ce0bb633d5209a3add2856b6. * Revert "Add Renson services" This reverts commit d862976c81404623eccd64275f412dc9cdb2c1c4. * Add binary sensor to coveragerc file * Update homeassistant/components/renson/binary_sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * Update homeassistant/components/renson/binary_sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * Changed hard coded names to use translation * Code cleaning * Use super()._handle_coordinator_update() --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
80d2309896
commit
9e8d89c4f5
@ -1006,6 +1006,7 @@ omit =
|
|||||||
homeassistant/components/renson/const.py
|
homeassistant/components/renson/const.py
|
||||||
homeassistant/components/renson/entity.py
|
homeassistant/components/renson/entity.py
|
||||||
homeassistant/components/renson/sensor.py
|
homeassistant/components/renson/sensor.py
|
||||||
|
homeassistant/components/renson/binary_sensor.py
|
||||||
homeassistant/components/raspyrfm/*
|
homeassistant/components/raspyrfm/*
|
||||||
homeassistant/components/recollect_waste/sensor.py
|
homeassistant/components/recollect_waste/sensor.py
|
||||||
homeassistant/components/recorder/repack.py
|
homeassistant/components/recorder/repack.py
|
||||||
|
@ -20,6 +20,7 @@ from .const import DOMAIN
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
136
homeassistant/components/renson/binary_sensor.py
Normal file
136
homeassistant/components/renson/binary_sensor.py
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
"""Binary sensors for renson."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
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(
|
||||||
|
translation_key="frost_protection_active",
|
||||||
|
key="FROST_PROTECTION_FIELD",
|
||||||
|
field=FROST_PROTECTION_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="BREEZE_ENABLE_FIELD",
|
||||||
|
translation_key="breeze",
|
||||||
|
field=BREEZE_ENABLE_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="BREEZE_MET_FIELD",
|
||||||
|
translation_key="breeze_conditions_met",
|
||||||
|
field=BREEZE_MET_FIELD,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="HUMIDITY_CONTROL_FIELD",
|
||||||
|
translation_key="humidity_control",
|
||||||
|
field=HUMIDITY_CONTROL_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="AIR_QUALITY_CONTROL_FIELD",
|
||||||
|
translation_key="air_quality_control",
|
||||||
|
field=AIR_QUALITY_CONTROL_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="CO2_CONTROL_FIELD",
|
||||||
|
translation_key="co2_control",
|
||||||
|
field=CO2_CONTROL_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
RensonBinarySensorEntityDescription(
|
||||||
|
key="PREHEATER_FIELD",
|
||||||
|
translation_key="preheater",
|
||||||
|
field=PREHEATER_FIELD,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
RensonBinarySensor(description, api, coordinator)
|
||||||
|
for description in BINARY_SENSORS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RensonBinarySensor(RensonEntity, BinarySensorEntity):
|
||||||
|
"""Get sensor data from the Renson API and store it in the state of the class."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
super()._handle_coordinator_update()
|
@ -13,6 +13,29 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
|
"binary_sensor": {
|
||||||
|
"frost_protection_active": {
|
||||||
|
"name": "Frost protection active"
|
||||||
|
},
|
||||||
|
"breeze": {
|
||||||
|
"name": "Breeze"
|
||||||
|
},
|
||||||
|
"breeze_conditions_met": {
|
||||||
|
"name": "Breeze conditions met"
|
||||||
|
},
|
||||||
|
"humidity_control": {
|
||||||
|
"name": "Humidity control"
|
||||||
|
},
|
||||||
|
"air_quality_control": {
|
||||||
|
"name": "Air quality control"
|
||||||
|
},
|
||||||
|
"co2_control": {
|
||||||
|
"name": "CO2 control"
|
||||||
|
},
|
||||||
|
"preheater": {
|
||||||
|
"name": "Preheater"
|
||||||
|
}
|
||||||
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"co2_quality_category": {
|
"co2_quality_category": {
|
||||||
"name": "CO2 quality category",
|
"name": "CO2 quality category",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user