User camera unique id in go2rtc if available#168603
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.
Pull request overview
This PR updates the go2rtc integration to use a stable camera identifier (preferring unique_id over entity_id) when naming/configuring streams, and adds tests for the new identifier behavior.
Changes:
- Add
get_camera_identifier()to prefercamera.unique_idand sanitize identifiers for go2rtc usage. - Update go2rtc provider logic and existing tests to use the new identifier when creating/listing streams and building ffmpeg chain sources.
- Add dedicated unit tests covering identifier preference and sanitization.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/go2rtc/util.py |
Adds get_camera_identifier() and identifier sanitization logic. |
homeassistant/components/go2rtc/__init__.py |
Switches go2rtc stream naming, websocket source, and snapshot requests to use the new identifier helper. |
tests/components/go2rtc/test_util.py |
Adds new unit tests for identifier preference and sanitization behavior. |
tests/components/go2rtc/test_init.py |
Updates assertions to expect the new identifier in stream configuration and ffmpeg chaining. |
tests/components/go2rtc/conftest.py |
Introduces a camera_unique_id fixture and passes it into the mock camera. |
tests/components/go2rtc/__init__.py |
Updates MockCamera to accept/set a unique_id. |
There was a problem hiding this comment.
Pull request overview
This PR updates the go2rtc integration to use a stable, URL-safe camera identifier derived from a camera’s unique_id (falling back to entity_id) so go2rtc stream/source names don’t change when users rename entities.
Changes:
- Add
get_camera_identifier()to prefercamera.unique_idand percent-encode unsafe characters. - Switch go2rtc stream setup, snapshot retrieval, and WebRTC source naming to use the new identifier.
- Update/extend go2rtc tests, including new unit tests for identifier sanitization.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/go2rtc/util.py |
Adds get_camera_identifier() and encoding rules for safe identifiers. |
homeassistant/components/go2rtc/__init__.py |
Replaces camera.entity_id with the new identifier for go2rtc stream/source operations. |
tests/components/go2rtc/test_util.py |
New test coverage for identifier selection + sanitization behavior. |
tests/components/go2rtc/test_init.py |
Updates expectations to use the identifier and attempts to parametrize unique_id vs None. |
tests/components/go2rtc/conftest.py |
Adds a camera_unique_id fixture and wires it into MockCamera creation. |
tests/components/go2rtc/__init__.py |
Updates MockCamera to accept/set a unique_id. |
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the go2rtc integration to prefer a stable, sanitized camera identifier (based on the camera’s unique ID when available) instead of relying on the entity_id.
Changes:
- Add
get_camera_identifier()to generate a go2rtc-safe identifier (with URL-style percent-encoding of unsafe characters). - Use the new identifier throughout the go2rtc WebRTC provider (streams add/list, ffmpeg stream name, snapshot source).
- Extend and add tests to validate identifier generation and integration behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/go2rtc/util.py |
Adds get_camera_identifier() helper and safe-character encoding logic. |
homeassistant/components/go2rtc/__init__.py |
Switches go2rtc stream/snapshot/WebRTC “source” identifiers from entity_id to the new helper. |
tests/components/go2rtc/test_util.py |
Adds unit tests covering identifier preference and sanitization behavior. |
tests/components/go2rtc/test_init.py |
Updates expectations to use the new identifier and adds parametrization for unique_id presence. |
tests/components/go2rtc/conftest.py |
Adds a camera_unique_id fixture and wires it into the test camera setup. |
tests/components/go2rtc/__init__.py |
Updates MockCamera to accept and expose a unique_id for testing. |
Breaking change
Proposed change
Prefer unique id over entity id, so we don't need to update the config if the user manually changes the entity id.
No migration is needed as the managed go2rtc is creating a new config file on each boot.
Unfortunately go2rtc is not validating the identifier but if passed in stream source some characters have special meaning.
To avoid strange issues we allow just a simple character set. All chars not in this set will be replaced by their hex representatives to still make sure we have a unique string.
Downside of using the unique id is that it's harder for a user to identify the camera in the go2rtc UI. This is acceptable as users should only use the go2rtc UI when debugging, which should be less frequent.
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: