Skip to content
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

Add go2rtc and extend camera integration for better WebRTC support #124410

Merged
merged 34 commits into from
Oct 3, 2024

Conversation

edenhaus
Copy link
Contributor

@edenhaus edenhaus commented Aug 22, 2024

Breaking change

Proposed change

  • Extend the camera integration
    • Allow registering ICE servers, which any WebRTC camera will use
    • Added a new function to return WebRTCClientConfiguration to the frontend (Integration can overwrite it partly)
    • Refactor registering a WebRTC proxy: Previously, only rstp_to_webrtc proxy could be registered. Now, any WebRTC proxy supporting any protocol can be registered
    • Added ws endpoint to fetch WebRTC client config
  • Add go2rtc integration. Will automatically use provided binary if HA is running inside docker. Otherwise, a host will be asked
  • Add go2rtc binary to docker image

Library: https://github.com/home-assistant-libs/python-go2rtc-client

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

  • 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.

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

Hey there @allenporter, mind taking a look at this pull request as it has been labeled with an integration (rtsp_to_webrtc) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of rtsp_to_webrtc 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 rtsp_to_webrtc 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.

@home-assistant
Copy link

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

Code owner commands

Code owners of camera 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 camera 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.

@allenporter
Copy link
Contributor

My impression is that https://www.home-assistant.io/integrations/rtsp_to_webrtc/ already supports go2rtc because go2rtc exports the same API as RTSPToWebRTC for backwards compatibility/forking. However, i don't think the documentation is updated. rtsp_to_webrtc also works with RTSPtoWeb and detects the type of server involved.

Can we either or both (1) Improve usability for of rtsp_to_webrtc by improving documentation or making a virtual integration etc so that the same integration is used but with a different brand/name/icon (2) add any functionality missing to the rtsp to webrtc client library needed for go2rtc? though i'm not actually sure what functionality is missing

@allenporter
Copy link
Contributor

A couple other considerations:
(1) downloading a go binary is not something home assistant core should support like the custom component does We would instead guide users to install an add-on I believe -- and there are ways to improve discovery for that?
(2) The name webrtc is one we avoided for rtsp_to_webrtc in home-assistant/architecture#658 discussion and so i'm not positive that name should be used here either.
(3) I am supportive of adding new websocket endpoints for stun settings. There was some previous discussion here home-assistant/architecture#1040 and I agree with making this available through the existing registration mechanism (I nudged sdb9696 over discord chat towards the approach you have built here).

@edenhaus
Copy link
Contributor Author

(1) downloading a go binary is not something home assistant core should support like the custom component does We would instead guide users to install an add-on I believe -- and there are ways to improve discovery for that?

The go binary will be installed and shipped with the docker image. The code was only copied from the current custom component and is handy to test everything

I just opened the PR to make testing the code on multiple machines easier. The PR is far from completed
About improvements to rtsp_to_webrtc, I currently create a POC for WebRTC but of course, we can improve both later

@edenhaus edenhaus changed the title Add WebRTC WIP: Add WebRTC Aug 22, 2024
@allenporter
Copy link
Contributor

OK my point was that my impression was rtsp_to_webrtc already works with go2rtc, RTSPtoWebRTC, and RTSPtoWeb so i'm questioning if we need both. For example the current client is adaptive supporting two different protocols and decides which one to do so if you want more functionality it could support a 3rd type.

@edenhaus edenhaus changed the title WIP: Add go2rtc Add go2rtc and extend camera integration for better WebRTC support Oct 1, 2024
@edenhaus edenhaus marked this pull request as ready for review October 1, 2024 07:38
@edenhaus edenhaus requested review from allenporter, a team and Kane610 as code owners October 1, 2024 07:38
Copy link
Member

@bemble bemble left a comment

Choose a reason for hiding this comment

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

We should be able to registrer a list of ice servers.

homeassistant/components/camera/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/camera/webrtc.py Show resolved Hide resolved
homeassistant/components/camera/__init__.py Outdated Show resolved Hide resolved
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

I didn't look at the tests yet.

Dockerfile Outdated Show resolved Hide resolved
homeassistant/components/camera/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/camera/helper.py Outdated Show resolved Hide resolved
homeassistant/components/camera/webrtc.py Show resolved Hide resolved
homeassistant/components/go2rtc/config_flow.py Outdated Show resolved Hide resolved
script/hassfest/docker.py Outdated Show resolved Hide resolved
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Tests are missing for go2rtc init module.

tests/components/camera/test_webrtc.py Outdated Show resolved Hide resolved
tests/components/camera/test_webrtc.py Outdated Show resolved Hide resolved
tests/components/camera/test_webrtc.py Outdated Show resolved Hide resolved
tests/components/camera/test_webrtc.py Outdated Show resolved Hide resolved
tests/components/camera/conftest.py Outdated Show resolved Hide resolved
homeassistant/components/camera/webrtc.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft October 2, 2024 14:39
@home-assistant
Copy link

home-assistant bot commented Oct 2, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

edenhaus and others added 3 commits October 2, 2024 17:49
@edenhaus
Copy link
Contributor Author

edenhaus commented Oct 2, 2024

Test coverage is now 100%

$ pytest tests/components/go2rtc --cov homeassistant/components/go2rtc --cov-report term-missing
Test session starts (platform: linux, Python 3.12.3, pytest 8.3.3, pytest-sugar 1.0.0)
rootdir: /workspaces/core
configfile: pyproject.toml
plugins: aiohttp-1.0.5, picked-0.5.0, requests-mock-1.12.1, respx-0.21.1, cov-5.0.0, sugar-1.0.0, anyio-4.4.0, syrupy-4.7.1, timeout-2.3.1, socket-0.7.0, github-actions-annotate-failures-0.2.0, xdist-3.6.1, unordered-0.6.1, mock-3.14.0, asyncio-0.24.0, typeguard-4.3.0, pytest_freezer-0.4.8, rerunfailures-14.0
asyncio: mode=Mode.AUTO, default_loop_scope=function
collected 10 items                                                                                                                                                                 

 tests/components/go2rtc/test_config_flow.py ✓✓✓✓✓✓                                                                                                                   60% ██████    
 tests/components/go2rtc/test_init.py ✓✓                                                                                                                              80% ████████  
 tests/components/go2rtc/test_server.py ✓✓                                                                                                                           100% ██████████

---------- coverage: platform linux, python 3.12.3-final-0 -----------
Name                                             Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------
homeassistant/components/go2rtc/__init__.py         34      0   100%
homeassistant/components/go2rtc/config_flow.py      41      0   100%
homeassistant/components/go2rtc/const.py             2      0   100%
homeassistant/components/go2rtc/server.py           34      0   100%
------------------------------------------------------------------------------
TOTAL                                              111      0   100%


Results (1.68s):
      10 passed

@edenhaus edenhaus marked this pull request as ready for review October 2, 2024 18:21
tests/components/go2rtc/conftest.py Outdated Show resolved Hide resolved
tests/components/go2rtc/conftest.py Outdated Show resolved Hide resolved
tests/components/go2rtc/test_init.py Outdated Show resolved Hide resolved
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good!

@bramkragten bramkragten merged commit 04860ae into dev Oct 3, 2024
40 checks passed
@bramkragten bramkragten deleted the edenhaus-webrtc branch October 3, 2024 07:20
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2024
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.

7 participants