mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 23:57:06 +00:00
Add dock dryer control to Roborock (#138495)
* Add a dock dryer select * change import * Change name to match app
This commit is contained in:
parent
0b41d056d3
commit
f50325fc7d
@ -4,9 +4,9 @@ import asyncio
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from roborock.containers import Status
|
from roborock.code_mappings import RoborockDockDustCollectionModeCode
|
||||||
from roborock.roborock_message import RoborockDataProtocol
|
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.components.select import SelectEntity, SelectEntityDescription
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
@ -25,11 +25,11 @@ class RoborockSelectDescription(SelectEntityDescription):
|
|||||||
# The command that the select entity will send to the api.
|
# The command that the select entity will send to the api.
|
||||||
api_command: RoborockCommand
|
api_command: RoborockCommand
|
||||||
# Gets the current value of the select entity.
|
# 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.
|
# 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.
|
# 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
|
protocol_listener: RoborockDataProtocol | None = None
|
||||||
|
|
||||||
@ -39,24 +39,37 @@ SELECT_DESCRIPTIONS: list[RoborockSelectDescription] = [
|
|||||||
key="water_box_mode",
|
key="water_box_mode",
|
||||||
translation_key="mop_intensity",
|
translation_key="mop_intensity",
|
||||||
api_command=RoborockCommand.SET_WATER_BOX_CUSTOM_MODE,
|
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,
|
entity_category=EntityCategory.CONFIG,
|
||||||
options_lambda=lambda data: data.water_box_mode.keys()
|
options_lambda=lambda data: data.status.water_box_mode.keys()
|
||||||
if data.water_box_mode is not None
|
if data.status.water_box_mode is not None
|
||||||
else 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,
|
protocol_listener=RoborockDataProtocol.WATER_BOX_MODE,
|
||||||
),
|
),
|
||||||
RoborockSelectDescription(
|
RoborockSelectDescription(
|
||||||
key="mop_mode",
|
key="mop_mode",
|
||||||
translation_key="mop_mode",
|
translation_key="mop_mode",
|
||||||
api_command=RoborockCommand.SET_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,
|
entity_category=EntityCategory.CONFIG,
|
||||||
options_lambda=lambda data: data.mop_mode.keys()
|
options_lambda=lambda data: data.status.mop_mode.keys()
|
||||||
if data.mop_mode is not None
|
if data.status.mop_mode is not None
|
||||||
else 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
|
for description in SELECT_DESCRIPTIONS
|
||||||
if (
|
if (
|
||||||
options := description.options_lambda(
|
options := description.options_lambda(
|
||||||
coordinator.roborock_device_info.props.status
|
coordinator.roborock_device_info.props
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
is not None
|
is not None
|
||||||
@ -111,13 +124,13 @@ class RoborockSelectEntity(RoborockCoordinatedEntityV1, SelectEntity):
|
|||||||
"""Set the option."""
|
"""Set the option."""
|
||||||
await self.send(
|
await self.send(
|
||||||
self.entity_description.api_command,
|
self.entity_description.api_command,
|
||||||
self.entity_description.parameter_lambda(option, self._device_status),
|
self.entity_description.parameter_lambda(option, self.coordinator.data),
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_option(self) -> str | None:
|
def current_option(self) -> str | None:
|
||||||
"""Get the current status of the select entity from device_status."""
|
"""Get the current status of the select entity from device props."""
|
||||||
return self.entity_description.value_fn(self._device_status)
|
return self.entity_description.value_fn(self.coordinator.data)
|
||||||
|
|
||||||
|
|
||||||
class RoborockCurrentMapSelectEntity(RoborockCoordinatedEntityV1, SelectEntity):
|
class RoborockCurrentMapSelectEntity(RoborockCoordinatedEntityV1, SelectEntity):
|
||||||
|
@ -353,6 +353,15 @@
|
|||||||
},
|
},
|
||||||
"selected_map": {
|
"selected_map": {
|
||||||
"name": "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": {
|
"switch": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user