Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/roborock/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class RoborockSelectDescription(SelectEntityDescription):
key="dust_collection_mode",
translation_key="dust_collection_mode",
api_command=RoborockCommand.SET_DUST_COLLECTION_MODE,
value_fn=lambda api: api.dust_collection_mode.mode.name, # type: ignore[union-attr]
value_fn=lambda api: (
mode.name if (mode := api.dust_collection_mode.mode) is not None else None # type: ignore[union-attr]
),
Comment on lines +76 to +78

@epenet epenet Dec 17, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small tweak - I think the policy for multiline lambdas is to have the whole thing wrapped in a brackets.

Suggested change
value_fn=lambda api: (
mode.name if (mode := api.dust_collection_mode.mode) is not None else None # type: ignore[union-attr]
),
value_fn=(
lambda api: mode.name
if (mode := api.dust_collection_mode.mode) is not None # type: ignore[union-attr]
else None
),

Also
None if val is None else val
is shorter than
val if val is not None else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then again - maybe that's one for a follow-up PR as the chosen style is used accross the entity descriptions.

entity_category=EntityCategory.CONFIG,
options_lambda=lambda api: (
RoborockDockDustCollectionModeCode.keys()
Expand Down
28 changes: 28 additions & 0 deletions tests/components/roborock/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from roborock import RoborockCommand
from roborock.data.v1 import RoborockDockDustCollectionModeCode
from roborock.exceptions import RoborockException

from homeassistant.components.roborock import DOMAIN
Expand Down Expand Up @@ -154,3 +155,30 @@ async def test_selected_map_without_name(
select_entity = hass.states.get("select.roborock_s7_maxv_selected_map")
assert select_entity
assert select_entity.state == "Map 0"


@pytest.mark.parametrize(
("dust_collection_mode", "expected_state"),
[
(None, "unknown"),
(RoborockDockDustCollectionModeCode.smart, "smart"),
(RoborockDockDustCollectionModeCode.light, "light"),
],
)
async def test_dust_collection_mode_none(
hass: HomeAssistant,
mock_roborock_entry: MockConfigEntry,
fake_vacuum: FakeDevice,
dust_collection_mode: RoborockDockDustCollectionModeCode | None,
expected_state: str,
) -> None:
"""Test that maps without a name are given a placeholder name."""
Comment thread
epenet marked this conversation as resolved.
Outdated
assert fake_vacuum.v1_properties
assert fake_vacuum.v1_properties.dust_collection_mode
fake_vacuum.v1_properties.dust_collection_mode.mode = dust_collection_mode

await async_setup_component(hass, DOMAIN, {})

select_entity = hass.states.get("select.roborock_s7_maxv_dock_empty_mode")
assert select_entity
assert select_entity.state == expected_state
Loading