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 Reolink proxy for playback #133916

Merged
merged 17 commits into from
Jan 3, 2025
Merged

Conversation

starkillerOG
Copy link
Contributor

@starkillerOG starkillerOG commented Dec 23, 2024

Breaking change

Proposed change

Instead of directly supplying the local URL to the playback file (mp4), proxy the mp4 through HomeAssistant.
This ensures playback is also possible when not on the local network since the playback file URL is a local URL using the IP of the camera on the local network.

This also solves the issues with invalid SSL certificates, since the clients will now see the SSL certificate of HomeAssistant instead of the problamatic Reolink camera self-signed SSL certificates. When requesting the mp4 we ignore the SSL check properly.

For the Home Hub the Download command instead of Playback command will be used, restoring the ability to playback video files, which broke with the most recent Home Hub firmware.

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:

@starkillerOG
Copy link
Contributor Author

starkillerOG commented Dec 23, 2024

Already tested this code and it works.
However I still need to write the tests.

@starkillerOG
Copy link
Contributor Author

starkillerOG commented Dec 29, 2024

This now needs a version bump of reolink-aio, see PR: #134286

@starkillerOG
Copy link
Contributor Author

A alternative to this PR would be to use hass-web-proxy-lib from @dermotduffy for the person reviewing this PR, I would like to get your opinion on what's the best approach?

@starkillerOG
Copy link
Contributor Author

starkillerOG commented Dec 31, 2024

I have split out the changes to the switch tests in this PR: #134339

@edenhaus
Copy link
Contributor

edenhaus commented Jan 2, 2025

A alternative to this PR would be to use hass-web-proxy-lib from @dermotduffy for the person reviewing this PR, I would like to get your opinion on what's the best approach?

Can we create a generic solution that can be used by all integrations that want to proxy something through HA?
For example, add the proxing support to media_source or extend https://www.home-assistant.io/integrations/proxy/ so all can benefit and not only integrations using media_source

homeassistant/components/reolink/views.py Outdated Show resolved Hide resolved
homeassistant/components/reolink/views.py Show resolved Hide resolved
host.api.nvr_name,
)

reolink_response.release()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be in a finally block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is nessesary.
I dont even know if the release() is actually needed, I think aiohttp will clean it up by itself.
But since it is a rather large payload (few Mb) I think it is nice to release it as soon as possible to free resources.

homeassistant/components/reolink/util.py Outdated Show resolved Hide resolved
@dermotduffy
Copy link
Contributor

Can we create a generic solution that can be used by all integrations that want to proxy something through HA?

Just to clarify: The external library already offers this, since any integration (core or custom) could use that library to proxy anything (media or not). It would certainly be better if something like this was "baked in", though.

For example, add the proxing support to media_source or extend https://www.home-assistant.io/integrations/proxy/ so all can benefit and not only integrations using media_source

I can imagine many ways something like this could run into "principled disagreements" (e.g. "Home Assistant shouldn't proxy anything", "Home Assistant shouldn't offer unauthenticated proxying", "Home Assistant should insist on valid certificates when it proxies", etc), that would ideally be settled before development time is spent towards adding this functionality to Core.

Since I wrote the external library, perhaps I should start an architecture discussion on offering this solution "baked in"?

This might let us discuss the general, without blocking this Reolink specific work from @starkillerOG .

@starkillerOG
Copy link
Contributor Author

I agree @dermotduffy

@starkillerOG
Copy link
Contributor Author

@edenhaus all review feedback has been processed.

Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @starkillerOG 👍

@edenhaus edenhaus added this to the 2025.1.0 milestone Jan 3, 2025
@edenhaus edenhaus merged commit 8a2f8dc into home-assistant:dev Jan 3, 2025
34 checks passed
frenck pushed a commit that referenced this pull request Jan 3, 2025
@maniacaris
Copy link

@starkillerOG - Thank you for your work on this. This PR sought to address an issue I encountered for the first time today, so I was happy to see this.

I just upgraded my instance to 2025.1.0 to test this out, but it doesn't seem to be working for me. I am attempting to play media from a PoE Doorbell that is saving recordings to a local SD card and I typically access my HA instance via an NGINX reverse proxy using SSL. My doorbell is on a separate VLAN from my HA instance, but my HA instance is allowed to access the camera VLAN.

Prior to the update, I was able to view clips in the media browser if I accessed my HA instance directly via its LAN IP/port, but playback did not work when accessing HA externally through my reverse proxy. I (perhaps incorrectly) attributed the discrepancy to the issues mentioned in this PR. After the update to 2025.1.0, playback does not work at all. I tested several different browsers and cleared cache. I also took a look at the network log in Chrome dev tools and did see 404 errors when I try to play a recording.

Is there some new configuration needed to make this work or a specific combination of settings that allows it to work? Please let me know if there's any information that might steer me in the right direction. I'm happy to open an issue for this as well if you'd prefer.

@starkillerOG starkillerOG deleted the reolink_proxy branch January 4, 2025 08:26
cereal2nd pushed a commit to cereal2nd/home-assistant that referenced this pull request Jan 4, 2025
@starkillerOG
Copy link
Contributor Author

@maniacaris you are right, I checked and indeed this PR introduced a small bug wich now broke playback.
It was introduced last minute in this commit: 46424e8

A fix is here: #134652. This also gives a explanation of what is happening.

Should be fixed tommorow with HA 2025.1.1

@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2025
@starkillerOG
Copy link
Contributor Author

@maniacaris HA 2025.1.1 is now available, could you let me know if playback now fully works for you?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.