Fix AttributeError in Roborock Empty Mode entity#159278
Conversation
|
Hey there @Lash-L, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an AttributeError that occurs when the Roborock dust collection mode's mode attribute is None. The bug would cause a crash when trying to access .name on a None value.
Key changes:
- Updated the
value_fnlambda in the dust collection mode select entity to safely handleNonevalues using the walrus operator - Added comprehensive test coverage for the None handling scenario with parameterized tests
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| homeassistant/components/roborock/select.py | Modified the dust_collection_mode value_fn to use walrus operator for None-safe access to mode.name, returning None when mode is None (which displays as "unknown" state) |
| tests/components/roborock/test_select.py | Added parameterized test test_dust_collection_mode_none to verify correct handling of None, smart, and light mode values with appropriate state expectations |
| value_fn=lambda api: ( | ||
| mode.name if (mode := api.dust_collection_mode.mode) is not None else None # type: ignore[union-attr] | ||
| ), |
There was a problem hiding this comment.
Small tweak - I think the policy for multiline lambdas is to have the whole thing wrapped in a brackets.
| 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
There was a problem hiding this comment.
But then again - maybe that's one for a follow-up PR as the chosen style is used accross the entity descriptions.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Proposed change
Fix AttributeError in Roborock Empty Mode entity.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: