Skip to content

Conversation

@piitaya
Copy link
Member

@piitaya piitaya commented Dec 4, 2025

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Dec 4, 2025

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (labs) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of labs can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign labs Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
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.

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_feature endpoint 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(
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

@piitaya piitaya added this to the 2025.12.1 milestone Dec 5, 2025
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @piitaya 👍

../Frenck

                       

Blogging my personal ramblings at frenck.dev

@frenck frenck merged commit 66bddeb into dev Dec 5, 2025
36 checks passed
@frenck frenck deleted the subscribe_single_labs_preview_feature branch December 5, 2025 15:36
@frenck frenck mentioned this pull request Dec 5, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants