1 """Number platform for La Marzocco espresso machines."""
3 from collections.abc
import Callable, Coroutine
4 from dataclasses
import dataclass
7 from pylamarzocco.const
import (
14 from pylamarzocco.exceptions
import RequestNotSuccessful
15 from pylamarzocco.lm_machine
import LaMarzoccoMachine
16 from pylamarzocco.models
import LaMarzoccoMachineConfig
21 NumberEntityDescription,
34 from .const
import DOMAIN
35 from .coordinator
import LaMarzoccoConfigEntry, LaMarzoccoUpdateCoordinator
36 from .entity
import LaMarzoccoEntity, LaMarzoccoEntityDescription
41 @dataclass(frozen=True, kw_only=True)
43 LaMarzoccoEntityDescription,
44 NumberEntityDescription,
46 """Description of a La Marzocco number entity."""
48 native_value_fn: Callable[[LaMarzoccoMachineConfig], float | int]
49 set_value_fn: Callable[[LaMarzoccoMachine, float | int], Coroutine[Any, Any, bool]]
52 @dataclass(frozen=True, kw_only=True)
54 LaMarzoccoEntityDescription,
55 NumberEntityDescription,
57 """Description of an La Marzocco number entity with keys."""
59 native_value_fn: Callable[[LaMarzoccoMachineConfig, PhysicalKey], float | int]
60 set_value_fn: Callable[
61 [LaMarzoccoMachine, float | int, PhysicalKey], Coroutine[Any, Any, bool]
65 ENTITIES: tuple[LaMarzoccoNumberEntityDescription, ...] = (
68 translation_key=
"coffee_temp",
69 device_class=NumberDeviceClass.TEMPERATURE,
70 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
71 native_step=PRECISION_TENTHS,
74 set_value_fn=
lambda machine, temp: machine.set_temp(BoilerType.COFFEE, temp),
75 native_value_fn=
lambda config: config.boilers[
81 translation_key=
"steam_temp",
82 device_class=NumberDeviceClass.TEMPERATURE,
83 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
84 native_step=PRECISION_WHOLE,
87 set_value_fn=
lambda machine, temp: machine.set_temp(BoilerType.STEAM, temp),
88 native_value_fn=
lambda config: config.boilers[
91 supported_fn=
lambda coordinator: coordinator.device.model
98 key=
"tea_water_duration",
99 translation_key=
"tea_water_duration",
100 device_class=NumberDeviceClass.DURATION,
101 native_unit_of_measurement=UnitOfTime.SECONDS,
102 native_step=PRECISION_WHOLE,
105 set_value_fn=
lambda machine, value: machine.set_dose_tea_water(
int(value)),
106 native_value_fn=
lambda config: config.dose_hot_water,
107 supported_fn=
lambda coordinator: coordinator.device.model
114 key=
"smart_standby_time",
115 translation_key=
"smart_standby_time",
116 device_class=NumberDeviceClass.DURATION,
117 native_unit_of_measurement=UnitOfTime.MINUTES,
120 native_max_value=240,
121 entity_category=EntityCategory.CONFIG,
122 set_value_fn=
lambda machine, value: machine.set_smart_standby(
123 enabled=machine.config.smart_standby.enabled,
124 mode=machine.config.smart_standby.mode,
127 native_value_fn=
lambda config: config.smart_standby.minutes,
132 KEY_ENTITIES: tuple[LaMarzoccoKeyNumberEntityDescription, ...] = (
135 translation_key=
"prebrew_off",
136 device_class=NumberDeviceClass.DURATION,
137 native_unit_of_measurement=UnitOfTime.SECONDS,
138 native_step=PRECISION_TENTHS,
141 entity_category=EntityCategory.CONFIG,
142 set_value_fn=
lambda machine, value, key: machine.set_prebrew_time(
143 prebrew_off_time=value, key=key
145 native_value_fn=
lambda config, key: config.prebrew_configuration[key].off_time,
146 available_fn=
lambda device: len(device.config.prebrew_configuration) > 0
147 and device.config.prebrew_mode == PrebrewMode.PREBREW,
148 supported_fn=
lambda coordinator: coordinator.device.model
149 != MachineModel.GS3_MP,
153 translation_key=
"prebrew_on",
154 device_class=NumberDeviceClass.DURATION,
155 native_unit_of_measurement=UnitOfTime.SECONDS,
156 native_step=PRECISION_TENTHS,
159 entity_category=EntityCategory.CONFIG,
160 set_value_fn=
lambda machine, value, key: machine.set_prebrew_time(
161 prebrew_on_time=value, key=key
163 native_value_fn=
lambda config, key: config.prebrew_configuration[key].off_time,
164 available_fn=
lambda device: len(device.config.prebrew_configuration) > 0
165 and device.config.prebrew_mode == PrebrewMode.PREBREW,
166 supported_fn=
lambda coordinator: coordinator.device.model
167 != MachineModel.GS3_MP,
170 key=
"preinfusion_off",
171 translation_key=
"preinfusion_off",
172 device_class=NumberDeviceClass.DURATION,
173 native_unit_of_measurement=UnitOfTime.SECONDS,
174 native_step=PRECISION_TENTHS,
177 entity_category=EntityCategory.CONFIG,
178 set_value_fn=
lambda machine, value, key: machine.set_preinfusion_time(
179 preinfusion_time=value, key=key
181 native_value_fn=
lambda config, key: config.prebrew_configuration[
184 available_fn=
lambda device: len(device.config.prebrew_configuration) > 0
185 and device.config.prebrew_mode == PrebrewMode.PREINFUSION,
186 supported_fn=
lambda coordinator: coordinator.device.model
187 != MachineModel.GS3_MP,
191 translation_key=
"dose",
192 native_unit_of_measurement=
"ticks",
193 native_step=PRECISION_WHOLE,
195 native_max_value=999,
196 entity_category=EntityCategory.CONFIG,
197 set_value_fn=
lambda machine, ticks, key: machine.set_dose(
198 dose=
int(ticks), key=key
200 native_value_fn=
lambda config, key: config.doses[key],
201 supported_fn=
lambda coordinator: coordinator.device.model
202 == MachineModel.GS3_AV,
209 entry: LaMarzoccoConfigEntry,
210 async_add_entities: AddEntitiesCallback,
212 """Set up number entities."""
213 coordinator = entry.runtime_data
214 entities: list[NumberEntity] = [
216 for description
in ENTITIES
217 if description.supported_fn(coordinator)
220 for description
in KEY_ENTITIES:
221 if description.supported_fn(coordinator):
222 num_keys = KEYS_PER_MODEL[MachineModel(coordinator.device.model)]
225 for key
in range(
min(num_keys, 1), num_keys + 1)
231 """La Marzocco number entity."""
233 entity_description: LaMarzoccoNumberEntityDescription
237 """Return the current value."""
238 return self.
entity_descriptionentity_description.native_value_fn(self.coordinator.device.config)
245 self.coordinator.device, value
247 except RequestNotSuccessful
as exc:
249 translation_domain=DOMAIN,
250 translation_key=
"number_exception",
251 translation_placeholders={
260 """Number representing espresso machine with key support."""
262 entity_description: LaMarzoccoKeyNumberEntityDescription
266 coordinator: LaMarzoccoUpdateCoordinator,
267 description: LaMarzoccoKeyNumberEntityDescription,
270 """Initialize the entity."""
271 super().
__init__(coordinator, description)
274 if pyhsical_key == 0:
285 """Return the current value."""
287 self.coordinator.device.config, PhysicalKey(self.
pyhsical_keypyhsical_key)
295 self.coordinator.device, value, PhysicalKey(self.
pyhsical_keypyhsical_key)
297 except RequestNotSuccessful
as exc:
299 translation_domain=DOMAIN,
300 translation_key=
"number_exception_key",
301 translation_placeholders={
_attr_translation_placeholders
_attr_entity_registry_enabled_default
None __init__(self, LaMarzoccoUpdateCoordinator coordinator, LaMarzoccoKeyNumberEntityDescription description, int pyhsical_key)
None async_set_native_value(self, float value)
None async_set_native_value(self, float value)
float|None native_value(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, LaMarzoccoConfigEntry entry, AddEntitiesCallback async_add_entities)