Skip to content

Refactor ONVIF#35222

Merged
balloob merged 3 commits intohome-assistant:devfrom
hunterjm:onvif-device
May 6, 2020
Merged

Refactor ONVIF#35222
balloob merged 3 commits intohome-assistant:devfrom
hunterjm:onvif-device

Conversation

@hunterjm
Copy link
Copy Markdown
Member

@hunterjm hunterjm commented May 5, 2020

Proposed change

The goals of this refactor are as follows:

  1. Abstract calls to the ONVIF web service into a centrally managed device class.
  2. Improve efficiency of the integration by removing unnecessary duplicate API calls to the device.
  3. Update config flow and entity initialization logic to add all compatible streams, but default disable lower resolution profiles. Main change is in how profile logic is handled.
  4. Fix the PTZ service and add additional validation based on what PTZ options are available on the specified profile.

There is no functionality change here other than fixing the PTZ service which was confirmed not working. This will, however, lead way for the next PR which will add support for creating sensors based on event notifications.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

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

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Comment thread homeassistant/components/onvif/__init__.py Outdated
Comment thread homeassistant/components/onvif/base.py Outdated
Comment thread homeassistant/components/onvif/device.py Outdated
Comment thread homeassistant/components/onvif/models.py Outdated
@balloob
Copy link
Copy Markdown
Member

balloob commented May 5, 2020

AMAZING 🎉 Few minor comments.

Copy link
Copy Markdown
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.

Some comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we planning to extract this to a library?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This already existed in the current camera class. The same type of logic exists in the generic camera integration as well.

I've currently abstracted most of the API calls to device.py with a few in config_flow.py for validation checks during setup. It wouldn't be too far of a stretch to create a Home Assistant specific ONVIF library that further abstracts the logic if requested, though I think that's beyond the scope of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it's out of scope for this PR. I'm interested in our plan for the future and what we consider ok or not ok.

Comment thread homeassistant/components/onvif/camera.py Outdated
Comment thread homeassistant/components/onvif/device.py Outdated
@MartinHjelmare MartinHjelmare changed the title ONVIF refactor Refactor ONVIF May 5, 2020
@hunterjm
Copy link
Copy Markdown
Member Author

hunterjm commented May 5, 2020

@dshokouhi identified some issues with my PTZ move_type support detection. I'm getting a PTZ camera delivered today to do some additional testing. Will address PR comments along with that update hopefully later tonight.

The service still works if called with a supported type, but the warnings for unsupported operations don't work.

@hunterjm
Copy link
Copy Markdown
Member Author

hunterjm commented May 6, 2020

Most PR comments addressed with a few follow-ups.

The PTZ support is fine. The Amcrest camera being used says it supports the RelativeMove PTZ move type, but just fails silently. It's more of a device conformance issue at that point.

Copy link
Copy Markdown
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!

@balloob balloob merged commit 19734e7 into home-assistant:dev May 6, 2020
@hunterjm hunterjm deleted the onvif-device branch May 6, 2020 17:34
@chron0
Copy link
Copy Markdown

chron0 commented May 7, 2020

Still struggling to get PTZ working. I've tested the camera with https://github.com/agsh/onvif and PTZ is working with it so I can offer another probably flaky test subject from the h.view camera family. Looking forward to see it released so I can test it as well.

@hunterjm
Copy link
Copy Markdown
Member Author

hunterjm commented May 8, 2020

Please don’t comment on merged PRs. Feel free to hit up #cameras on discord though, as I am looking for some more testers. @ me there

@lock lock Bot locked and limited conversation to collaborators May 21, 2020
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