Skip to content
Snippets Groups Projects
Unverified Commit f50325fc authored by Luke Lashley's avatar Luke Lashley Committed by GitHub
Browse files

Add dock dryer control to Roborock (#138495)

* Add a dock dryer select

* change import

* Change name to match app
parent 0b41d056
No related branches found
No related tags found
No related merge requests found
......@@ -4,9 +4,9 @@ import asyncio
from collections.abc import Callable
from dataclasses import dataclass
from roborock.containers import Status
from roborock.code_mappings import RoborockDockDustCollectionModeCode
from roborock.roborock_message import RoborockDataProtocol
from roborock.roborock_typing import RoborockCommand
from roborock.roborock_typing import DeviceProp, RoborockCommand
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.const import EntityCategory
......@@ -25,11 +25,11 @@ class RoborockSelectDescription(SelectEntityDescription):
# The command that the select entity will send to the api.
api_command: RoborockCommand
# Gets the current value of the select entity.
value_fn: Callable[[Status], str | None]
value_fn: Callable[[DeviceProp], str | None]
# Gets all options of the select entity.
options_lambda: Callable[[Status], list[str] | None]
options_lambda: Callable[[DeviceProp], list[str] | None]
# Takes the value from the select entity and converts it for the api.
parameter_lambda: Callable[[str, Status], list[int]]
parameter_lambda: Callable[[str, DeviceProp], list[int]]
protocol_listener: RoborockDataProtocol | None = None
......@@ -39,24 +39,37 @@ SELECT_DESCRIPTIONS: list[RoborockSelectDescription] = [
key="water_box_mode",
translation_key="mop_intensity",
api_command=RoborockCommand.SET_WATER_BOX_CUSTOM_MODE,
value_fn=lambda data: data.water_box_mode_name,
value_fn=lambda data: data.status.water_box_mode_name,
entity_category=EntityCategory.CONFIG,
options_lambda=lambda data: data.water_box_mode.keys()
if data.water_box_mode is not None
options_lambda=lambda data: data.status.water_box_mode.keys()
if data.status.water_box_mode is not None
else None,
parameter_lambda=lambda key, status: [status.get_mop_intensity_code(key)],
parameter_lambda=lambda key, prop: [prop.status.get_mop_intensity_code(key)],
protocol_listener=RoborockDataProtocol.WATER_BOX_MODE,
),
RoborockSelectDescription(
key="mop_mode",
translation_key="mop_mode",
api_command=RoborockCommand.SET_MOP_MODE,
value_fn=lambda data: data.mop_mode_name,
value_fn=lambda data: data.status.mop_mode_name,
entity_category=EntityCategory.CONFIG,
options_lambda=lambda data: data.mop_mode.keys()
if data.mop_mode is not None
options_lambda=lambda data: data.status.mop_mode.keys()
if data.status.mop_mode is not None
else None,
parameter_lambda=lambda key, status: [status.get_mop_mode_code(key)],
parameter_lambda=lambda key, prop: [prop.status.get_mop_mode_code(key)],
),
RoborockSelectDescription(
key="dust_collection_mode",
translation_key="dust_collection_mode",
api_command=RoborockCommand.SET_DUST_COLLECTION_MODE,
value_fn=lambda data: data.dust_collection_mode_name,
entity_category=EntityCategory.CONFIG,
options_lambda=lambda data: RoborockDockDustCollectionModeCode.keys()
if data.dust_collection_mode_name is not None
else None,
parameter_lambda=lambda key, _: [
RoborockDockDustCollectionModeCode.as_dict().get(key)
],
),
]
......@@ -74,7 +87,7 @@ async def async_setup_entry(
for description in SELECT_DESCRIPTIONS
if (
options := description.options_lambda(
coordinator.roborock_device_info.props.status
coordinator.roborock_device_info.props
)
)
is not None
......@@ -111,13 +124,13 @@ class RoborockSelectEntity(RoborockCoordinatedEntityV1, SelectEntity):
"""Set the option."""
await self.send(
self.entity_description.api_command,
self.entity_description.parameter_lambda(option, self._device_status),
self.entity_description.parameter_lambda(option, self.coordinator.data),
)
@property
def current_option(self) -> str | None:
"""Get the current status of the select entity from device_status."""
return self.entity_description.value_fn(self._device_status)
"""Get the current status of the select entity from device props."""
return self.entity_description.value_fn(self.coordinator.data)
class RoborockCurrentMapSelectEntity(RoborockCoordinatedEntityV1, SelectEntity):
......
......@@ -353,6 +353,15 @@
},
"selected_map": {
"name": "Selected map"
},
"dust_collection_mode": {
"name": "Empty mode",
"state": {
"smart": "Smart",
"light": "Light",
"balanced": "[%key:component::roborock::entity::vacuum::roborock::state_attributes::fan_speed::state::balanced%]",
"max": "[%key:component::roborock::entity::select::mop_intensity::state::max%]"
}
}
},
"switch": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment