mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Add time entity to Renson (#105031)
* Add time entity to Renson * Update homeassistant/components/renson/time.py Co-authored-by: Robert Resch <robert@resch.dev> * remove deleted sensors from strings.json * Fix Ruff issue * Fixed loading issue * Try to fix frozen error * Revert "Try to fix frozen error" This reverts commit 803104c2925e6d5acecc0a9d45170a0c85ee7f0e. * Try to fix frozen error * Revert "Try to fix frozen error" This reverts commit 8ba2dcce9444fadcf6bf79e86295f93359b6d7b8. * Update homeassistant/components/renson/time.py Co-authored-by: Robert Resch <robert@resch.dev> * Change import + api argument * use _attr_has_entity_name * Update homeassistant/components/renson/time.py Co-authored-by: Jan-Philipp Benecke <github@bnck.me> --------- Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Jan-Philipp Benecke <github@bnck.me>
This commit is contained in:
parent
f1d2868fd0
commit
ee67c97274
@ -1040,6 +1040,7 @@ omit =
|
||||
homeassistant/components/renson/fan.py
|
||||
homeassistant/components/renson/binary_sensor.py
|
||||
homeassistant/components/renson/number.py
|
||||
homeassistant/components/renson/time.py
|
||||
homeassistant/components/raspyrfm/*
|
||||
homeassistant/components/recollect_waste/sensor.py
|
||||
homeassistant/components/recorder/repack.py
|
||||
|
@ -19,6 +19,7 @@ PLATFORMS = [
|
||||
Platform.FAN,
|
||||
Platform.NUMBER,
|
||||
Platform.SENSOR,
|
||||
Platform.TIME,
|
||||
]
|
||||
|
||||
|
||||
|
@ -17,13 +17,11 @@ from renson_endura_delta.field_enum import (
|
||||
CURRENT_AIRFLOW_INGOING_FIELD,
|
||||
CURRENT_LEVEL_FIELD,
|
||||
DAY_POLLUTION_FIELD,
|
||||
DAYTIME_FIELD,
|
||||
FILTER_REMAIN_FIELD,
|
||||
HUMIDITY_FIELD,
|
||||
INDOOR_TEMP_FIELD,
|
||||
MANUAL_LEVEL_FIELD,
|
||||
NIGHT_POLLUTION_FIELD,
|
||||
NIGHTTIME_FIELD,
|
||||
OUTDOOR_TEMP_FIELD,
|
||||
FieldEnum,
|
||||
)
|
||||
@ -185,20 +183,6 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=["off", "level1", "level2", "level3", "level4", "breeze"],
|
||||
),
|
||||
RensonSensorEntityDescription(
|
||||
key="DAYTIME_FIELD",
|
||||
translation_key="start_day_time",
|
||||
field=DAYTIME_FIELD,
|
||||
raw_format=False,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
RensonSensorEntityDescription(
|
||||
key="NIGHTTIME_FIELD",
|
||||
translation_key="start_night_time",
|
||||
field=NIGHTTIME_FIELD,
|
||||
raw_format=False,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
RensonSensorEntityDescription(
|
||||
key="DAY_POLLUTION_FIELD",
|
||||
translation_key="day_pollution_level",
|
||||
|
@ -24,6 +24,14 @@
|
||||
"name": "Reset filter counter"
|
||||
}
|
||||
},
|
||||
"time": {
|
||||
"day_time": {
|
||||
"name": "Start time of the day"
|
||||
},
|
||||
"night_time": {
|
||||
"name": "Start time of the night"
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"filter_change": {
|
||||
"name": "Filter clean/replacement"
|
||||
@ -125,12 +133,6 @@
|
||||
"breeze": "[%key:component::renson::entity::sensor::ventilation_level::state::breeze%]"
|
||||
}
|
||||
},
|
||||
"start_day_time": {
|
||||
"name": "Start day time"
|
||||
},
|
||||
"start_night_time": {
|
||||
"name": "Start night time"
|
||||
},
|
||||
"day_pollution_level": {
|
||||
"name": "Day pollution level",
|
||||
"state": {
|
||||
|
100
homeassistant/components/renson/time.py
Normal file
100
homeassistant/components/renson/time.py
Normal file
@ -0,0 +1,100 @@
|
||||
"""Renson ventilation unit time."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, time
|
||||
|
||||
from renson_endura_delta.field_enum import DAYTIME_FIELD, NIGHTTIME_FIELD, FieldEnum
|
||||
from renson_endura_delta.renson import RensonVentilation
|
||||
|
||||
from homeassistant.components.time import TimeEntity, TimeEntityDescription
|
||||
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 RensonData
|
||||
from .const import DOMAIN
|
||||
from .coordinator import RensonCoordinator
|
||||
from .entity import RensonEntity
|
||||
|
||||
|
||||
@dataclass(kw_only=True, frozen=True)
|
||||
class RensonTimeEntityDescription(TimeEntityDescription):
|
||||
"""Class describing Renson time entity."""
|
||||
|
||||
action_fn: Callable[[RensonVentilation, str], None]
|
||||
field: FieldEnum
|
||||
|
||||
|
||||
ENTITY_DESCRIPTIONS: tuple[RensonTimeEntityDescription, ...] = (
|
||||
RensonTimeEntityDescription(
|
||||
key="day_time",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="day_time",
|
||||
action_fn=lambda api, time: api.set_day_time(time),
|
||||
field=DAYTIME_FIELD,
|
||||
),
|
||||
RensonTimeEntityDescription(
|
||||
key="night_time",
|
||||
translation_key="night_time",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
action_fn=lambda api, time: api.set_night_time(time),
|
||||
field=NIGHTTIME_FIELD,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renson time platform."""
|
||||
|
||||
data: RensonData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities = [
|
||||
RensonTime(description, data.coordinator) for description in ENTITY_DESCRIPTIONS
|
||||
]
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class RensonTime(RensonEntity, TimeEntity):
|
||||
"""Representation of a Renson time entity."""
|
||||
|
||||
entity_description: RensonTimeEntityDescription
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
description: RensonTimeEntityDescription,
|
||||
coordinator: RensonCoordinator,
|
||||
) -> None:
|
||||
"""Initialize class."""
|
||||
super().__init__(description.key, coordinator.api, coordinator)
|
||||
|
||||
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.entity_description.field.name)
|
||||
|
||||
self._attr_native_value = datetime.strptime(
|
||||
value,
|
||||
"%H:%M",
|
||||
).time()
|
||||
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
def set_value(self, value: time) -> None:
|
||||
"""Triggers the action."""
|
||||
|
||||
string_value = value.strftime("%H:%M")
|
||||
self.entity_description.action_fn(self.api, string_value)
|
Loading…
x
Reference in New Issue
Block a user