Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """Platform to control a Renson ventilation unit."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from renson_endura_delta.field_enum import FILTER_PRESET_FIELD, DataType
8 from renson_endura_delta.renson import RensonVentilation
9 
11  NumberDeviceClass,
12  NumberEntity,
13  NumberEntityDescription,
14 )
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.const import EntityCategory, UnitOfTime
17 from homeassistant.core import HomeAssistant, callback
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 
20 from .const import DOMAIN
21 from .coordinator import RensonCoordinator
22 from .entity import RensonEntity
23 
24 _LOGGER = logging.getLogger(__name__)
25 
26 
27 RENSON_NUMBER_DESCRIPTION = NumberEntityDescription(
28  key="filter_change",
29  translation_key="filter_change",
30  native_step=1,
31  native_min_value=0,
32  native_max_value=360,
33  entity_category=EntityCategory.CONFIG,
34  has_entity_name=True,
35  device_class=NumberDeviceClass.DURATION,
36  native_unit_of_measurement=UnitOfTime.DAYS,
37 )
38 
39 
41  hass: HomeAssistant,
42  config_entry: ConfigEntry,
43  async_add_entities: AddEntitiesCallback,
44 ) -> None:
45  """Set up the Renson number platform."""
46 
47  api: RensonVentilation = hass.data[DOMAIN][config_entry.entry_id].api
48  coordinator: RensonCoordinator = hass.data[DOMAIN][
49  config_entry.entry_id
50  ].coordinator
51 
52  async_add_entities([RensonNumber(RENSON_NUMBER_DESCRIPTION, api, coordinator)])
53 
54 
56  """Representation of the Renson number platform."""
57 
58  def __init__(
59  self,
60  description: NumberEntityDescription,
61  api: RensonVentilation,
62  coordinator: RensonCoordinator,
63  ) -> None:
64  """Initialize the Renson number."""
65  super().__init__(description.key, api, coordinator)
66 
67  self.entity_descriptionentity_description = description
68 
69  @callback
70  def _handle_coordinator_update(self) -> None:
71  """Handle updated data from the coordinator."""
72  self._attr_native_value_attr_native_value = self.apiapiapi.parse_value(
73  self.apiapiapi.get_field_value(self.coordinator.data, FILTER_PRESET_FIELD.name),
74  DataType.NUMERIC,
75  )
76 
78 
79  async def async_set_native_value(self, value: float) -> None:
80  """Update the current value."""
81 
82  await self.hasshasshass.async_add_executor_job(self.apiapiapi.set_filter_days, value)
83 
84  await self.coordinator.async_request_refresh()
None async_set_native_value(self, float value)
Definition: number.py:79
None __init__(self, NumberEntityDescription description, RensonVentilation api, RensonCoordinator coordinator)
Definition: number.py:63
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: number.py:44