-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Add subscribe preview feature endpoint to labs #157976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a WebSocket subscription endpoint (labs/subscribe) that allows users (including non-admin users) to subscribe to updates for specific lab preview features. This enables real-time notifications when a preview feature is enabled or disabled, which is particularly useful for features like snowflakes that should be visible to all users, not just administrators.
Key changes:
- Added
websocket_subscribe_featureendpoint that accepts domain and preview_feature parameters - Subscription filters events to only notify about the specific subscribed feature
- Unlike other labs endpoints, this does not require admin privileges by design
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/components/labs/websocket_api.py |
Implements the new websocket_subscribe_feature WebSocket command with proper event filtering and error handling for non-existent features |
tests/components/labs/test_websocket_api.py |
Adds comprehensive test coverage including successful subscription, event updates, non-existent feature errors, non-admin access verification, and proper event filtering |
| preview_feature_id = f"{domain}.{preview_feature_key}" | ||
|
|
||
| if preview_feature_id not in labs_data.preview_features: | ||
| connection.send_error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I look at this code, I think that async_is_preview_feature_enabled should also have a check whether the lab feature exists at all and if it does not exist, we should throw an exception. This way we save people the trouble of dealing with typos and wondering why their code isn’t working. A similar issue that you’re trying to guard against on the frontend also shows up in Python code. Since this is a new API, it might be worth considering before more people start using it and we end up too scared to introduce changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that would in another PR, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would make sense as a separate PR and discussion. My comment here was just a general observation while looking at how the current API would be used to implement the feature you’re adding. This missing check stood out as a piece that might be worth addressing separately.
frenck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed change
Add subscribe preview feature endpoint to labs.
This will allow non-admin user to fetch dedicated feature (for example, showing snowflakes for non-admin users)
For now, it returns the full feature object but we can also consider to only return the enabled boolean.
Type of change
Additional information
Checklist
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: