1 """Support for Roborock select."""
4 from collections.abc
import Callable
5 from dataclasses
import dataclass
7 from roborock.containers
import Status
8 from roborock.roborock_message
import RoborockDataProtocol
9 from roborock.roborock_typing
import RoborockCommand
16 from .
import RoborockConfigEntry
17 from .const
import MAP_SLEEP
18 from .coordinator
import RoborockDataUpdateCoordinator
19 from .entity
import RoborockCoordinatedEntityV1
22 @dataclass(frozen=True, kw_only=True)
24 """Class to describe a Roborock select entity."""
27 api_command: RoborockCommand
29 value_fn: Callable[[Status], str |
None]
31 options_lambda: Callable[[Status], list[str] |
None]
33 parameter_lambda: Callable[[str, Status], list[int]]
35 protocol_listener: RoborockDataProtocol |
None =
None
38 SELECT_DESCRIPTIONS: list[RoborockSelectDescription] = [
41 translation_key=
"mop_intensity",
42 api_command=RoborockCommand.SET_WATER_BOX_CUSTOM_MODE,
43 value_fn=
lambda data: data.water_box_mode_name,
44 entity_category=EntityCategory.CONFIG,
45 options_lambda=
lambda data: data.water_box_mode.keys()
46 if data.water_box_mode
is not None
48 parameter_lambda=
lambda key, status: [status.get_mop_intensity_code(key)],
49 protocol_listener=RoborockDataProtocol.WATER_BOX_MODE,
53 translation_key=
"mop_mode",
54 api_command=RoborockCommand.SET_MOP_MODE,
55 value_fn=
lambda data: data.mop_mode_name,
56 entity_category=EntityCategory.CONFIG,
57 options_lambda=
lambda data: data.mop_mode.keys()
58 if data.mop_mode
is not None
60 parameter_lambda=
lambda key, status: [status.get_mop_mode_code(key)],
67 config_entry: RoborockConfigEntry,
68 async_add_entities: AddEntitiesCallback,
70 """Set up Roborock select platform."""
74 for coordinator
in config_entry.runtime_data.v1
75 for description
in SELECT_DESCRIPTIONS
77 options := description.options_lambda(
78 coordinator.roborock_device_info.props.status
85 f
"selected_map_{coordinator.duid_slug}", coordinator
87 for coordinator
in config_entry.runtime_data.v1
92 """A class to let you set options on a Roborock vacuum where the potential options are fixed."""
94 entity_description: RoborockSelectDescription
98 coordinator: RoborockDataUpdateCoordinator,
99 entity_description: RoborockSelectDescription,
102 """Create a select entity."""
105 f
"{entity_description.key}_{coordinator.duid_slug}",
107 entity_description.protocol_listener,
112 """Set the option."""
120 """Get the current status of the select entity from device_status."""
125 """A class to let you set the selected map on Roborock vacuum."""
127 _attr_entity_category = EntityCategory.DIAGNOSTIC
128 _attr_translation_key =
"selected_map"
131 """Set the option."""
132 for map_id, map_
in self.coordinator.maps.items():
133 if map_.name == option:
135 RoborockCommand.LOAD_MULTI_MAP,
140 self.coordinator.current_map = map_id
143 await asyncio.sleep(MAP_SLEEP)
148 """Gets all of the names of rooms that we are currently aware of."""
149 return [roborock_map.name
for roborock_map
in self.coordinator.maps.values()]
153 """Get the current status of the select entity from device_status."""
155 (current_map := self.coordinator.current_map)
is not None
156 and current_map
in self.coordinator.maps
158 return self.coordinator.maps[current_map].name
Status _device_status(self)
dict send(self, RoborockCommand|str command, dict[str, Any]|list[Any]|int|None params=None)
dict send(self, RoborockCommand|str command, dict[str, Any]|list[Any]|int|None params=None)
None async_select_option(self, str option)
str|None current_option(self)
None __init__(self, RoborockDataUpdateCoordinator coordinator, RoborockSelectDescription entity_description, list[str] options)
str|None current_option(self)
None async_select_option(self, str option)
None async_setup_entry(HomeAssistant hass, RoborockConfigEntry config_entry, AddEntitiesCallback async_add_entities)