Skip to content

User camera unique id in go2rtc if available#168603

Merged
edenhaus merged 5 commits into
devfrom
edenhaus/go2rtc-unique-id
Apr 28, 2026
Merged

User camera unique id in go2rtc if available#168603
edenhaus merged 5 commits into
devfrom
edenhaus/go2rtc-unique-id

Conversation

@edenhaus
Copy link
Copy Markdown
Member

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

  • 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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings April 20, 2026 09:29
@edenhaus edenhaus requested a review from a team as a code owner April 20, 2026 09:29
@home-assistant
Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of go2rtc can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign go2rtc Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
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 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 prefer camera.unique_id and 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.

Comment thread homeassistant/components/go2rtc/util.py Outdated
Comment thread tests/components/go2rtc/test_init.py Outdated
Copy link
Copy Markdown
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 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 prefer camera.unique_id and 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.

Comment thread tests/components/go2rtc/test_init.py
Comment thread tests/components/go2rtc/test_init.py
Comment thread homeassistant/components/go2rtc/util.py
@MartinHjelmare MartinHjelmare marked this pull request as draft April 22, 2026 19:26
Comment thread homeassistant/components/go2rtc/util.py Outdated
Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 08:50
@edenhaus edenhaus marked this pull request as ready for review April 24, 2026 08:53
Copy link
Copy Markdown
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 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.

Comment thread tests/components/go2rtc/conftest.py Outdated
Comment thread tests/components/go2rtc/test_init.py
@edenhaus edenhaus merged commit b47b7fa into dev Apr 28, 2026
33 checks passed
@edenhaus edenhaus deleted the edenhaus/go2rtc-unique-id branch April 28, 2026 11:39
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 29, 2026
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.

5 participants