fix: handle Web API unauthorized errors#825
Open
allenporter wants to merge 1 commit intoPython-roborock:mainfrom
Open
fix: handle Web API unauthorized errors#825allenporter wants to merge 1 commit intoPython-roborock:mainfrom
allenporter wants to merge 1 commit intoPython-roborock:mainfrom
Conversation
Lash-L
approved these changes
May 3, 2026
Collaborator
Lash-L
left a comment
There was a problem hiding this comment.
Looks good. Only side effect is that in a asyncio gathered situation the unauthorized hook may fire multiple times, but that isn't a problem with this implementation or a problem in general - we should just be mindful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves an issue where background Web API calls (like fetching map room names) can silently fail when credentials expire, causing Home Assistant to fall back to default values instead of triggering a reauthentication flow.
The
UserWebApiClienthas been updated to automatically catchRoborockInvalidCredentialsexceptions. Instead of allowing these to bubble up uncontrollably or get swallowed by trait-level exception handlers,UserWebApiClientnow accepts anunauthorized_hookwhich it invokes before propagating the exception. TheDeviceManagerpropagates this hook from thecreate_device_managerfactory down into theUserWebApiClientinstance.Fixes home-assistant/core#169639
Changes
roborock/web_api.py: UpdatedUserWebApiClientto acceptunauthorized_hookand wrappedget_home_data,get_routines,get_rooms, andexecute_routineto invoke it whenRoborockInvalidCredentialsis raised.roborock/devices/device_manager.py: Updatedcreate_web_api_wrapperto supply the hook to theUserWebApiClient.tests/: Addedtest_user_web_api_client_unauthorized_hooktotests/test_web_api.pyto cover the new hook behavior and ensured existingDeviceManagerreauth tests continue to pass.Testing
uv run pytest.DeviceManagerreauth propagation andUserWebApiClientlogic directly.