1 """Sensor platform for La Marzocco espresso machines."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from pylamarzocco.const
import BoilerType, MachineModel, PhysicalKey
7 from pylamarzocco.lm_machine
import LaMarzoccoMachine
12 SensorEntityDescription,
19 from .coordinator
import LaMarzoccoConfigEntry
20 from .entity
import LaMarzoccoEntity, LaMarzoccoEntityDescription
23 @dataclass(frozen=True, kw_only=True)
25 LaMarzoccoEntityDescription, SensorEntityDescription
27 """Description of a La Marzocco sensor."""
29 value_fn: Callable[[LaMarzoccoMachine], float | int]
32 ENTITIES: tuple[LaMarzoccoSensorEntityDescription, ...] = (
34 key=
"drink_stats_coffee",
35 translation_key=
"drink_stats_coffee",
36 native_unit_of_measurement=
"drinks",
37 state_class=SensorStateClass.TOTAL_INCREASING,
38 value_fn=
lambda device: device.statistics.drink_stats.get(PhysicalKey.A, 0),
39 available_fn=
lambda device: len(device.statistics.drink_stats) > 0,
40 entity_category=EntityCategory.DIAGNOSTIC,
43 key=
"drink_stats_flushing",
44 translation_key=
"drink_stats_flushing",
45 native_unit_of_measurement=
"drinks",
46 state_class=SensorStateClass.TOTAL_INCREASING,
47 value_fn=
lambda device: device.statistics.total_flushes,
48 available_fn=
lambda device: len(device.statistics.drink_stats) > 0,
49 entity_category=EntityCategory.DIAGNOSTIC,
53 translation_key=
"shot_timer",
54 native_unit_of_measurement=UnitOfTime.SECONDS,
55 state_class=SensorStateClass.MEASUREMENT,
56 device_class=SensorDeviceClass.DURATION,
57 value_fn=
lambda device: device.config.brew_active_duration,
58 available_fn=
lambda device: device.websocket_connected,
59 entity_category=EntityCategory.DIAGNOSTIC,
60 supported_fn=
lambda coordinator: coordinator.local_connection_configured,
63 key=
"current_temp_coffee",
64 translation_key=
"current_temp_coffee",
65 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
66 suggested_display_precision=1,
67 state_class=SensorStateClass.MEASUREMENT,
68 device_class=SensorDeviceClass.TEMPERATURE,
69 value_fn=
lambda device: device.config.boilers[
71 ].current_temperature,
74 key=
"current_temp_steam",
75 translation_key=
"current_temp_steam",
76 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
77 suggested_display_precision=1,
78 state_class=SensorStateClass.MEASUREMENT,
79 device_class=SensorDeviceClass.TEMPERATURE,
80 value_fn=
lambda device: device.config.boilers[
82 ].current_temperature,
83 supported_fn=
lambda coordinator: coordinator.device.model
84 != MachineModel.LINEA_MINI,
91 entry: LaMarzoccoConfigEntry,
92 async_add_entities: AddEntitiesCallback,
94 """Set up sensor entities."""
95 coordinator = entry.runtime_data
99 for description
in ENTITIES
100 if description.supported_fn(coordinator)
105 """Sensor representing espresso machine temperature data."""
107 entity_description: LaMarzoccoSensorEntityDescription
111 """State of the sensor."""
int|float native_value(self)
None async_setup_entry(HomeAssistant hass, LaMarzoccoConfigEntry entry, AddEntitiesCallback async_add_entities)