-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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>
- Loading branch information
1 parent
f1d2868
commit ee67c97
Showing
5 changed files
with
110 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
Platform.FAN, | ||
Platform.NUMBER, | ||
Platform.SENSOR, | ||
Platform.TIME, | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |