fix: Improve Home trait discovery process.#580
fix: Improve Home trait discovery process.#580allenporter merged 3 commits intoPython-roborock:mainfrom
Conversation
e504a08 to
c5cf8c2
Compare
This updates the Home trait to allow the current map to be refreshed even if initial discovery fails. The caller can invoke discovery at startup, but then after just invoke refresh and the right thing should happen. We now track discovery explicitly and only persist the cache when we have completed discovery to avoid persisting an incomplete view of all available maps.
e504a08 to
f6cd9a4
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the HomeTrait.refresh() behavior to handle scenarios where home discovery hasn't completed yet, particularly when the device is busy cleaning. The key improvement is allowing refresh to fall back to updating only the current map when full discovery cannot be performed.
- Modified
refresh()to attempt discovery when not completed, gracefully falling back to current map refresh when device is busy - Updated
_update_current_map()to conditionally update persistent cache based on discovery completion status - Removed obsolete test for error condition that no longer exists, added comprehensive test for refresh behavior during device busy state
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| roborock/devices/traits/v1/home.py | Added _discovery_completed flag to track discovery state; refactored refresh() to attempt discovery first and fall back to current map refresh; updated _update_current_map() to conditionally persist cache based on discovery status |
| tests/devices/traits/v1/test_home.py | Removed test for obsolete error condition; added verification of persistent cache updates in discovery test; expanded device busy test to cover refresh attempts during and after cleaning |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removed redundant assertion for home_map_info length.
| # then we'll fall through below to refresh the current map only. | ||
| try: | ||
| await self.discover_home() | ||
| return self |
There was a problem hiding this comment.
not against it but do we utilize anywhere the fact that this is returning self?
There was a problem hiding this comment.
Yes, agreed, we never use it and it only adds typing pain. I'll remove it in a followup PR.
This updates the Home trait to allow the current map to be refreshed even if initial discovery fails. The caller can invoke discovery at startup, but then after just invoke refresh and the right thing should happen.
We now track discovery explicitly and only persist the cache when we have completed discovery to avoid persisting an incomplete view of all available maps.