1 """Select platform for La Marzocco espresso machines."""
3 from collections.abc
import Callable, Coroutine
4 from dataclasses
import dataclass
7 from pylamarzocco.const
import MachineModel, PrebrewMode, SmartStandbyMode, SteamLevel
8 from pylamarzocco.exceptions
import RequestNotSuccessful
9 from pylamarzocco.lm_machine
import LaMarzoccoMachine
10 from pylamarzocco.models
import LaMarzoccoMachineConfig
18 from .const
import DOMAIN
19 from .coordinator
import LaMarzoccoConfigEntry
20 from .entity
import LaMarzoccoEntity, LaMarzoccoEntityDescription
24 STEAM_LEVEL_HA_TO_LM = {
25 "1": SteamLevel.LEVEL_1,
26 "2": SteamLevel.LEVEL_2,
27 "3": SteamLevel.LEVEL_3,
30 STEAM_LEVEL_LM_TO_HA = {value: key
for key, value
in STEAM_LEVEL_HA_TO_LM.items()}
32 PREBREW_MODE_HA_TO_LM = {
33 "disabled": PrebrewMode.DISABLED,
34 "prebrew": PrebrewMode.PREBREW,
35 "preinfusion": PrebrewMode.PREINFUSION,
38 PREBREW_MODE_LM_TO_HA = {value: key
for key, value
in PREBREW_MODE_HA_TO_LM.items()}
40 STANDBY_MODE_HA_TO_LM = {
41 "power_on": SmartStandbyMode.POWER_ON,
42 "last_brewing": SmartStandbyMode.LAST_BREWING,
45 STANDBY_MODE_LM_TO_HA = {value: key
for key, value
in STANDBY_MODE_HA_TO_LM.items()}
48 @dataclass(frozen=True, kw_only=True)
50 LaMarzoccoEntityDescription,
51 SelectEntityDescription,
53 """Description of a La Marzocco select entity."""
55 current_option_fn: Callable[[LaMarzoccoMachineConfig], str]
56 select_option_fn: Callable[[LaMarzoccoMachine, str], Coroutine[Any, Any, bool]]
59 ENTITIES: tuple[LaMarzoccoSelectEntityDescription, ...] = (
61 key=
"steam_temp_select",
62 translation_key=
"steam_temp_select",
63 options=[
"1",
"2",
"3"],
64 select_option_fn=
lambda machine, option: machine.set_steam_level(
65 STEAM_LEVEL_HA_TO_LM[option]
67 current_option_fn=
lambda config: STEAM_LEVEL_LM_TO_HA[config.steam_level],
68 supported_fn=
lambda coordinator: coordinator.device.model
69 == MachineModel.LINEA_MICRA,
72 key=
"prebrew_infusion_select",
73 translation_key=
"prebrew_infusion_select",
74 entity_category=EntityCategory.CONFIG,
75 options=[
"disabled",
"prebrew",
"preinfusion"],
76 select_option_fn=
lambda machine, option: machine.set_prebrew_mode(
77 PREBREW_MODE_HA_TO_LM[option]
79 current_option_fn=
lambda config: PREBREW_MODE_LM_TO_HA[config.prebrew_mode],
80 supported_fn=
lambda coordinator: coordinator.device.model
83 MachineModel.LINEA_MICRA,
84 MachineModel.LINEA_MINI,
88 key=
"smart_standby_mode",
89 translation_key=
"smart_standby_mode",
90 entity_category=EntityCategory.CONFIG,
91 options=[
"power_on",
"last_brewing"],
92 select_option_fn=
lambda machine, option: machine.set_smart_standby(
93 enabled=machine.config.smart_standby.enabled,
94 mode=STANDBY_MODE_HA_TO_LM[option],
95 minutes=machine.config.smart_standby.minutes,
97 current_option_fn=
lambda config: STANDBY_MODE_LM_TO_HA[
98 config.smart_standby.mode
106 entry: LaMarzoccoConfigEntry,
107 async_add_entities: AddEntitiesCallback,
109 """Set up select entities."""
110 coordinator = entry.runtime_data
114 for description
in ENTITIES
115 if description.supported_fn(coordinator)
120 """La Marzocco select entity."""
122 entity_description: LaMarzoccoSelectEntityDescription
126 """Return the current selected option."""
128 self.
entity_descriptionentity_description.current_option_fn(self.coordinator.device.config)
132 """Change the selected option."""
136 self.coordinator.device, option
138 except RequestNotSuccessful
as exc:
140 translation_domain=DOMAIN,
141 translation_key=
"select_option_error",
142 translation_placeholders={
None async_select_option(self, str option)
str|None current_option(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, LaMarzoccoConfigEntry entry, AddEntitiesCallback async_add_entities)