Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """Support for ZHA AnalogOutput cluster."""
2 
3 from __future__ import annotations
4 
5 import functools
6 import logging
7 
8 from homeassistant.components.number import RestoreNumber
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.dispatcher import async_dispatcher_connect
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 from homeassistant.helpers.typing import UndefinedType
15 
16 from .entity import ZHAEntity
17 from .helpers import (
18  SIGNAL_ADD_ENTITIES,
19  async_add_entities as zha_async_add_entities,
20  convert_zha_error_to_ha_error,
21  get_zha_data,
22 )
23 
24 _LOGGER = logging.getLogger(__name__)
25 
26 
28  hass: HomeAssistant,
29  config_entry: ConfigEntry,
30  async_add_entities: AddEntitiesCallback,
31 ) -> None:
32  """Set up the Zigbee Home Automation Analog Output from config entry."""
33  zha_data = get_zha_data(hass)
34  entities_to_create = zha_data.platforms[Platform.NUMBER]
35 
37  hass,
38  SIGNAL_ADD_ENTITIES,
39  functools.partial(
40  zha_async_add_entities, async_add_entities, ZhaNumber, entities_to_create
41  ),
42  )
43  config_entry.async_on_unload(unsub)
44 
45 
47  """Representation of a ZHA Number entity."""
48 
49  @property
50  def name(self) -> str | UndefinedType | None:
51  """Return the name of the number entity."""
52  if (description := self.entity_data.entity.description) is None:
53  return super().name
54 
55  # The name of this entity is reported by the device itself.
56  # For backwards compatibility, we keep the same format as before. This
57  # should probably be changed in the future to omit the prefix.
58  return f"{super().name} {description}"
59 
60  @property
61  def native_value(self) -> float | None:
62  """Return the current value."""
63  return self.entity_data.entity.native_value
64 
65  @property
66  def native_min_value(self) -> float:
67  """Return the minimum value."""
68  return self.entity_data.entity.native_min_value
69 
70  @property
71  def native_max_value(self) -> float:
72  """Return the maximum value."""
73  return self.entity_data.entity.native_max_value
74 
75  @property
76  def native_step(self) -> float | None:
77  """Return the value step."""
78  return self.entity_data.entity.native_step
79 
80  @property
81  def native_unit_of_measurement(self) -> str | None:
82  """Return the unit the value is expressed in."""
83  return self.entity_data.entity.native_unit_of_measurement
84 
85  @convert_zha_error_to_ha_error
86  async def async_set_native_value(self, value: float) -> None:
87  """Update the current value from HA."""
88  await self.entity_data.entity.async_set_native_value(value=value)
89  self.async_write_ha_stateasync_write_ha_state()
None async_set_native_value(self, float value)
Definition: number.py:86
str|UndefinedType|None name(self)
Definition: number.py:50
HAZHAData get_zha_data(HomeAssistant hass)
Definition: helpers.py:1020
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: number.py:31
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103