1 """Number platform for IronOS integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from enum
import StrEnum
9 from pynecil
import CharSetting, CommunicationError, LiveDataResponse
14 NumberEntityDescription,
22 from .
import IronOSConfigEntry
23 from .const
import DOMAIN, MAX_TEMP, MIN_TEMP
24 from .entity
import IronOSBaseEntity
27 @dataclass(frozen=True, kw_only=True)
29 """Describes IronOS number entity."""
31 value_fn: Callable[[LiveDataResponse], float | int |
None]
32 max_value_fn: Callable[[LiveDataResponse], float | int]
37 """Number controls for Pinecil device."""
39 SETPOINT_TEMP =
"setpoint_temperature"
42 PINECIL_NUMBER_DESCRIPTIONS: tuple[IronOSNumberEntityDescription, ...] = (
44 key=PinecilNumber.SETPOINT_TEMP,
45 translation_key=PinecilNumber.SETPOINT_TEMP,
46 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
47 device_class=NumberDeviceClass.TEMPERATURE,
48 value_fn=
lambda data: data.setpoint_temp,
49 set_key=CharSetting.SETPOINT_TEMP,
51 native_min_value=MIN_TEMP,
53 max_value_fn=
lambda data:
min(data.max_tip_temp_ability
or MAX_TEMP, MAX_TEMP),
60 entry: IronOSConfigEntry,
61 async_add_entities: AddEntitiesCallback,
63 """Set up number entities from a config entry."""
64 coordinator = entry.runtime_data
68 for description
in PINECIL_NUMBER_DESCRIPTIONS
73 """Implementation of a IronOS number entity."""
75 entity_description: IronOSNumberEntityDescription
78 """Update the current value."""
80 await self.coordinator.device.write(self.
entity_descriptionentity_description.set_key, value)
81 except CommunicationError
as e:
83 translation_domain=DOMAIN,
84 translation_key=
"submit_setting_failed",
90 """Return sensor state."""
95 """Return sensor state."""
float|int|None native_value(self)
None async_set_native_value(self, float value)
float native_max_value(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, IronOSConfigEntry entry, AddEntitiesCallback async_add_entities)