Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """Fully Kiosk Browser number entity."""
2 
3 from __future__ import annotations
4 
5 from contextlib import suppress
6 
7 from homeassistant.components.number import NumberEntity, NumberEntityDescription
8 from homeassistant.const import EntityCategory, UnitOfTime
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from . import FullyKioskConfigEntry
13 from .coordinator import FullyKioskDataUpdateCoordinator
14 from .entity import FullyKioskEntity
15 
16 ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
18  key="timeToScreensaverV2",
19  translation_key="screensaver_time",
20  native_max_value=9999,
21  native_step=1,
22  native_min_value=0,
23  native_unit_of_measurement=UnitOfTime.SECONDS,
24  entity_category=EntityCategory.CONFIG,
25  ),
27  key="screensaverBrightness",
28  translation_key="screensaver_brightness",
29  native_max_value=255,
30  native_step=1,
31  native_min_value=0,
32  entity_category=EntityCategory.CONFIG,
33  ),
35  key="timeToScreenOffV2",
36  translation_key="screen_off_time",
37  native_max_value=9999,
38  native_step=1,
39  native_min_value=0,
40  native_unit_of_measurement=UnitOfTime.SECONDS,
41  entity_category=EntityCategory.CONFIG,
42  ),
44  key="screenBrightness",
45  translation_key="screen_brightness",
46  native_max_value=255,
47  native_step=1,
48  native_min_value=0,
49  entity_category=EntityCategory.CONFIG,
50  ),
51 )
52 
53 
55  hass: HomeAssistant,
56  config_entry: FullyKioskConfigEntry,
57  async_add_entities: AddEntitiesCallback,
58 ) -> None:
59  """Set up the Fully Kiosk Browser number entities."""
60  coordinator = config_entry.runtime_data
61 
63  FullyNumberEntity(coordinator, entity)
64  for entity in ENTITY_TYPES
65  if entity.key in coordinator.data["settings"]
66  )
67 
68 
70  """Representation of a Fully Kiosk Browser entity."""
71 
72  def __init__(
73  self,
74  coordinator: FullyKioskDataUpdateCoordinator,
75  description: NumberEntityDescription,
76  ) -> None:
77  """Initialize the number entity."""
78  super().__init__(coordinator)
79  self.entity_descriptionentity_description = description
80  self._attr_unique_id_attr_unique_id = f"{coordinator.data['deviceID']}-{description.key}"
81 
82  @property
83  def native_value(self) -> int | None:
84  """Return the state of the number entity."""
85  if (
86  value := self.coordinator.data["settings"].get(self.entity_descriptionentity_description.key)
87  ) is None:
88  return None
89 
90  with suppress(ValueError):
91  return int(value)
92 
93  return None
94 
95  async def async_set_native_value(self, value: float) -> None:
96  """Set the value of the entity."""
97  await self.coordinator.fully.setConfigurationString(
98  self.entity_descriptionentity_description.key, int(value)
99  )
None __init__(self, FullyKioskDataUpdateCoordinator coordinator, NumberEntityDescription description)
Definition: number.py:76
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
None async_setup_entry(HomeAssistant hass, FullyKioskConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: number.py:58