Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """Flame height number sensors."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 
8  NumberEntity,
9  NumberEntityDescription,
10  NumberMode,
11 )
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from .const import DOMAIN, LOGGER
17 from .coordinator import IntellifireDataUpdateCoordinator
18 from .entity import IntellifireEntity
19 
20 
22  hass: HomeAssistant,
23  entry: ConfigEntry,
24  async_add_entities: AddEntitiesCallback,
25 ) -> None:
26  """Set up the fans."""
27  coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
28 
29  description = NumberEntityDescription(
30  key="flame_control",
31  translation_key="flame_control",
32  )
33 
35  [
37  coordinator=coordinator, description=description
38  )
39  ]
40  )
41 
42 
43 @dataclass
45  """Flame height control entity."""
46 
47  _attr_native_max_value: float = 5
48  _attr_native_min_value: float = 1
49  _attr_native_step: float = 1
50  _attr_mode: NumberMode = NumberMode.SLIDER
51 
52  def __init__(
53  self,
54  coordinator: IntellifireDataUpdateCoordinator,
55  description: NumberEntityDescription,
56  ) -> None:
57  """Initialize Flame height Sensor."""
58  super().__init__(coordinator, description)
59 
60  @property
61  def native_value(self) -> float | None:
62  """Return the current Flame Height segment number value."""
63  # UI uses 1-5 for flame height, backing lib uses 0-4
64  return self.coordinator.read_api.data.flameheight + 1
65 
66  async def async_set_native_value(self, value: float) -> None:
67  """Slider change."""
68  value_to_send: int = int(value) - 1
69  LOGGER.debug(
70  "%s set flame height to %d with raw value %s",
71  self.namename,
72  value,
73  value_to_send,
74  )
75  await self.coordinator.control_api.set_flame_height(height=value_to_send)
76  await self.coordinator.async_refresh()
None __init__(self, IntellifireDataUpdateCoordinator coordinator, NumberEntityDescription description)
Definition: number.py:56
str|UndefinedType|None name(self)
Definition: entity.py:738
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: number.py:25