-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Fix AttributeError in Roborock Empty Mode entity #159278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
| 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.
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.
Co-authored-by: Copilot <[email protected]>
epenet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Co-authored-by: epenet <[email protected]> Co-authored-by: Copilot <[email protected]>
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: