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

Reolink ONVIF move read to primary callback #91478

Merged
merged 4 commits into from
Apr 17, 2023

Conversation

starkillerOG
Copy link
Contributor

@starkillerOG starkillerOG commented Apr 15, 2023

Breaking change

Proposed change

Reolink cameras receive motion/AI detection events using ONVIF push messages.
First ONVIF pushes would get lost due to a ConnectionResetError in the "old implementation" HA 2023.4.4 and lower
This bugfix PR #91070 resolved that issue by properly shielding and catching these errors and using polling once data was lost this is the "current implementation", no events are lost which is the most important, but polling is slower and is heavier on the cameras.
This "new implementation" moves the reading back to the primary callback and properly cathes cancellation and ConnectionResetErrors, but in my tests was able to retrieve the message data in 100% of the about 300 callbacks.

Comparing performance of the diffrent implementations for each about 300 ONVIF push motion/AI people events:
Old implementation: 69% push 0% polling 31% lost
Current implementation: 64% push 36% polling 0% lost
New implementation: 100% push 0% polling 0% lost

I am currently running the "new implementation" in my production enviroment and will update the percentages if posible polling callbacks ocur over a few days (once I run it that long).
Over more than a day with the "new implementation" in my production enviroment I got 4000+ ONVIF push motion/AI people events and still got 100% push 0% polling 0% lost.

I also tested this PR by adding await asyncio.sleep(5.0) in various places to trigger the cancellations and mallformed the ONVIF message, and then got polling callbacks, so the fallback for older camera's (or slow once) is still working.

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:

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 Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@bdraco bdraco added this to the 2023.4.5 milestone Apr 15, 2023
@bdraco
Copy link
Member

bdraco commented Apr 17, 2023

@starkillerOG Do your test stats still look good?

@starkillerOG
Copy link
Contributor Author

starkillerOG commented Apr 17, 2023

@bdraco Yes, over a day I got 4000+ ONVIF motion/AI events and still 100% push, 0% poll, 0% lost.
With the latest commit (read() instead of text()), I still got the same with about 350 ONVIF motion/AI events.

@bdraco
Copy link
Member

bdraco commented Apr 17, 2023

Awesome. It should use a bit less cpu time 👍

@bdraco bdraco merged commit 88bde2a into home-assistant:dev Apr 17, 2023
frenck pushed a commit that referenced this pull request Apr 17, 2023
* Move read to primary callback

* fix styling

* Do not raise on ConnectionResetError

* Split request.text() to .read() and decode("utf-8")
@frenck frenck mentioned this pull request Apr 17, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2023
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.

3 participants