Skip to content

fix: handle Web API unauthorized errors#825

Open
allenporter wants to merge 1 commit intoPython-roborock:mainfrom
allenporter:web-api-unauthorized-hook
Open

fix: handle Web API unauthorized errors#825
allenporter wants to merge 1 commit intoPython-roborock:mainfrom
allenporter:web-api-unauthorized-hook

Conversation

@allenporter
Copy link
Copy Markdown
Contributor

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 UserWebApiClient has been updated to automatically catch RoborockInvalidCredentials exceptions. Instead of allowing these to bubble up uncontrollably or get swallowed by trait-level exception handlers, UserWebApiClient now accepts an unauthorized_hook which it invokes before propagating the exception. The DeviceManager propagates this hook from the create_device_manager factory down into the UserWebApiClient instance.

Fixes home-assistant/core#169639

Changes

  • roborock/web_api.py: Updated UserWebApiClient to accept unauthorized_hook and wrapped get_home_data, get_routines, get_rooms, and execute_routine to invoke it when RoborockInvalidCredentials is raised.
  • roborock/devices/device_manager.py: Updated create_web_api_wrapper to supply the hook to the UserWebApiClient.
  • tests/: Added test_user_web_api_client_unauthorized_hook to tests/test_web_api.py to cover the new hook behavior and ensured existing DeviceManager reauth tests continue to pass.

Testing

  • Verified full unit test suite passes cleanly via uv run pytest.
  • Tested the DeviceManager reauth propagation and UserWebApiClient logic directly.

Copilot AI review requested due to automatic review settings May 3, 2026 19:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Collaborator

@Lash-L Lash-L left a comment

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roborock - Segment / Room names are not correct

3 participants