Start reauth when roborock notices the MQTT session is unauthorized#159719
Conversation
This is invoked when the background thread notices the MQTT session is no longer valid.
|
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 adds a callback mechanism to handle MQTT session unauthorized events in the Roborock integration. When the device manager's background thread detects that the MQTT session is no longer valid, it triggers a reauth flow to prompt users to update their credentials.
Key changes:
- Adds
mqtt_session_unauthorized_hookcallback parameter to device manager initialization - Implements reauth flow trigger when MQTT authorization fails in background operations
- Adds test coverage for the new unauthorized hook callback functionality
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/roborock/__init__.py |
Adds lambda callback to create_device_manager that triggers reauth flow when MQTT session becomes unauthorized |
tests/components/roborock/test_init.py |
Adds test to verify the MQTT unauthorized hook correctly initiates the reauth flow |
| "mqtt_session_unauthorized_hook" | ||
| ) | ||
| assert mqtt_session_unauthorized_hook | ||
| mqtt_session_unauthorized_hook() |
There was a problem hiding this comment.
After calling the mqtt_session_unauthorized_hook, you need to call await hass.async_block_till_done() to allow the async task created by async_start_reauth to complete. The async_start_reauth method creates a task via hass.async_create_task, and without waiting for pending tasks to complete, the reauth flow may not be fully initialized when you check for it.
Add await hass.async_block_till_done() after line 125 and before checking for flows.
| mqtt_session_unauthorized_hook() | |
| mqtt_session_unauthorized_hook() | |
| await hass.async_block_till_done() |
Proposed change
Start reauth when roborock notices the MQTT session is unauthorized
The integration registers a callback with the Roborock Device Manager which is invoked when the
background thread notices the MQTT session is no longer valid. This is needed since we no longer block on an MQTT connection on startup since we prefer local device connection, but still need a way to notice the session has gone bad.
Type of change
Additional information
[code:135] Not authorized#159444Checklist
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: