1 """Support for esphome numbers."""
3 from __future__
import annotations
5 from functools
import partial
7 from aioesphomeapi
import (
10 NumberMode
as EsphomeNumberMode,
20 convert_api_error_ha_error,
21 esphome_float_state_property,
22 platform_async_setup_entry,
24 from .enum_mapper
import EsphomeEnumMapper
26 NUMBER_MODES: EsphomeEnumMapper[EsphomeNumberMode, NumberMode] =
EsphomeEnumMapper(
28 EsphomeNumberMode.AUTO: NumberMode.AUTO,
29 EsphomeNumberMode.BOX: NumberMode.BOX,
30 EsphomeNumberMode.SLIDER: NumberMode.SLIDER,
36 """A number implementation for esphome."""
40 """Set attrs from static info."""
44 NumberDeviceClass, static_info.device_class
51 if unit_of_measurement := static_info.unit_of_measurement:
53 if mode := static_info.mode:
54 self.
_attr_mode_attr_mode = NUMBER_MODES.from_esphome(mode)
59 @esphome_float_state_property
61 """Return the state of the entity."""
63 return None if state.missing_state
else state.state
65 @convert_api_error_ha_error
67 """Update the current value."""
68 self.
_client_client.number_command(self.
_key_key, value)
71 async_setup_entry = partial(
72 platform_async_setup_entry,
74 entity_type=EsphomeNumber,
75 state_type=NumberState,