Add pending dataset visibility and cancellation to OTBR WebSocket API#168441
Add pending dataset visibility and cancellation to OTBR WebSocket API#168441raman325 wants to merge 6 commits intohome-assistant:devfrom
Conversation
When otbr/set_channel is called, a pending dataset with a delay timer is created on the OTBR. Previously, the frontend had no way to check if a channel migration was pending or to cancel it after the initial response. This adds two new WebSocket commands: - otbr/get_pending_dataset: returns the pending channel and remaining delay in seconds, or None if no migration is pending - otbr/delete_pending_dataset: cancels a pending channel migration Also adds OTBRData.delete_pending_dataset() wrapper in util.py. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hey there @home-assistant/core, 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
Adds WebSocket endpoints to expose and cancel a pending OTBR channel migration so the frontend can display scheduled migrations and allow cancellation.
Changes:
- Register
otbr/get_pending_datasetto return pending channel + remaining delay (orNone). - Register
otbr/delete_pending_datasetto cancel a pending dataset. - Add
OTBRData.delete_pending_dataset()wrapper and associated WebSocket API tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/otbr/websocket_api.py |
Adds and registers two new OTBR WebSocket commands for pending dataset visibility/cancellation. |
homeassistant/components/otbr/util.py |
Adds an OTBRData.delete_pending_dataset() helper wrapping the python-otbr-api call with existing error handling. |
tests/components/otbr/test_websocket_api.py |
Adds test coverage for the new WebSocket commands across success/none/malformed/error cases. |
The OTBR REST API may not support DELETE on /node/dataset/pending (returns 405). Fall back to creating a pending dataset with the current active dataset and delay=0, which immediately applies the current state and clears the pending migration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Upstream PR to add DELETE support to the OTBR REST API: openthread/ot-br-posix#3308. The fallback in this PR handles OTBR firmware that doesn't yet have that change. |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds OTBR WebSocket API support for observing and canceling pending Thread channel migrations, enabling the frontend to surface “pending change” status and provide a cancel action.
Changes:
- Add
otbr/get_pending_datasetWebSocket command to report pending channel and delay timer from the pending dataset TLVs. - Add
otbr/delete_pending_datasetWebSocket command backed by a newOTBRData.delete_pending_dataset()helper with DELETE + fallback behavior. - Add test coverage for the new WebSocket commands, including error and fallback scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/otbr/websocket_api.py |
Registers and implements the two new admin-only WebSocket commands. |
homeassistant/components/otbr/util.py |
Adds OTBRData.delete_pending_dataset() with DELETE + fallback logic. |
tests/components/otbr/test_websocket_api.py |
Adds tests validating pending dataset parsing and deletion/fallback behaviors. |
…nding - Only trigger delete_pending_dataset fallback on 405 (Method Not Allowed), re-raise other OTBRError and connectivity/timeout errors immediately - Remove @require_admin from get_pending_dataset so non-admin users can view pending migrations in the frontend - Add test for non-405 error raising instead of falling back Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
agners
left a comment
There was a problem hiding this comment.
Let's wait until we better understand what operations are safe when it comes to pending dataset cancellation from upstream maintainers before implementing this feature on our end.
| Tries DELETE first (spec-compliant). Falls back to creating a pending | ||
| dataset with the current active dataset and delay=0, which immediately | ||
| applies the current state and clears the pending migration. | ||
| """ |
There was a problem hiding this comment.
While I totally get why we'd want this, I'd like to better understand how the BR behave when it comes to cancelling pending dataset (see openthread/ot-br-posix#3308 (comment)).
Also not sure if this work around is a good idea. From what I understand the delay is really required to have the dataset propagate through the network. The 5 minutes we choose by default is a conservative high number which makes sure that even battery operated devices with long idle times get the new pending dataset (through the current channel) before we switch to the new channel.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Proposed change
The frontend exposes a "change channel" action which triggers a channel migration with a 5-minute delay on the OTBR. Once initiated, users have no way of knowing a channel change is in flight without checking the logs. These new WebSocket commands provide the backend support needed to improve the frontend UX so users can see when a channel migration is pending and how much time remains. As a bonus, we can also let users cancel a pending change if they made a mistake.
Changes:
otbr/get_pending_dataset— returns the pending target channel and remaining delay (in seconds), orNoneif no migration is pending. Available to all authenticated users so the frontend can display pending migration status.otbr/delete_pending_dataset(admin-only) — cancels a pending channel migration. Includes a fallback for OTBR firmware that doesn't supportDELETE /node/dataset/pending(405 only — other errors are raised immediately): creates a pending dataset with the current active dataset and delay=0, which immediately clears the pending migration.OTBRData.delete_pending_dataset()wrapper inutil.pywith DELETE + fallback logicTested against a live OTBR (official HA addon + ZBT-2).
Type of change
Additional information
Checklist
ruff format homeassistant tests)To help with the load of incoming pull requests: