8000 Automatically add newly added devices for UniFi Protect by AngellusMortis · Pull Request #73879 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Automatically add newly added devices for UniFi Protect #73879

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

Merged
merged 1 commit into from
Jun 27, 2022
Merged

Automatically add newly added devices for UniFi Protect #73879

merged 1 commit into from
Jun 27, 2022

Conversation

AngellusMortis
Copy link
Contributor
@AngellusMortis AngellusMortis commented Jun 23, 2022

Proposed change

Automatically adds any new devices that are newly adopted within UniFi Protect.

This is primarily done by listening for a "Device Adopted" event and then initiating a dispatch to process the newly added device for all of the supported platforms. The only except to this is camera entities. When a Camera is adopted, it has no camera channels initially, so camera entities cannot be initialized. It adds the device ID to a list and wait until an update event comes in for that device with the camera channels and then sends another dispatch.

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

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

The integration reached or maintains the following Integration Quality Scale:

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

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @briis, @bdraco, mind taking a look at this pull request as it has been labeled with an integration (unifiprotect) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@bdraco
Copy link
Member
bdraco commented Jun 23, 2022

Now I have to go find a new device to test with :)

@bdraco
Copy link
Member
bdraco commented Jun 23, 2022

Existing functionality testing looks good.

Still looking for a device I can wipe and re-adopt. If I can't find one that works I'll factory reset a camera later today when I'm back at the house and don't need to worry about one actually recording

@bdraco
Copy link
Member
bdraco commented Jun 23, 2022
2022-06-23 21:01:02 ERROR (MainThread) [pyunifiprotect.websocket] Error processing websocket message
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/websocket.py", line 69, in _process_message
    sub(msg)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/api.py", line 587, in _process_ws_message
    processed_message = self.bootstrap.process_ws_packet(
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 462, in process_ws_packet
    return self._process_device_update(packet, action, data, ignore_stats)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 389, in _process_device_update
    obj = obj.update_from_dict(deepcopy(data))
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/devices.py", line 827, in update_from_dict
    return super().update_from_dict(data)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 493, in update_from_dict
    setattr(self, key, convert_unifi_data(data[key], self.__fields__[key]))
  File "/usr/local/lib/python3.9/site-packages/pydantic/main.py", line 370, in __setattr__
    raise ValidationError([error_], self.__class__)
pydantic.error_wrappers.ValidationError: 1 validation error for Camera
type
  none is not an allowed value (type=type_error.none.not_allowed)

2022-06-23 21:00:29 ERROR (MainThread) [pyunifiprotect.websocket] Error processing websocket message
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/websocket.py", line 69, in _process_message
    sub(msg)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/api.py", line 587, in _process_ws_message
    processed_message = self.bootstrap.process_ws_packet(
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 462, in process_ws_packet
    return self._process_device_update(packet, action, data, ignore_stats)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 389, in _process_device_update
    obj = obj.update_from_dict(deepcopy(data))
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/devices.py", line 827, in update_from_dict
    return super().update_from_dict(data)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 493, in update_from_dict
    setattr(self, key, convert_unifi_data(data[key], self.__fields__[key]))
  File "/usr/local/lib/python3.9/site-packages/pydantic/main.py", line 370, in __setattr__
    raise ValidationError([error_], self.__class__)
pydantic.error_wrappers.ValidationError: 1 validation error for Camera
anonymous_device_id
  none is not an allowed value (type=type_error.none.not_allowed)
2022-06-23 21:00:03 ERROR (MainThread) [pyunifiprotect.websocket] Error processing websocket message
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/websocket.py", line 69, in _process_message
    sub(msg)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/api.py", line 587, in _process_ws_message
    processed_message = self.bootstrap.process_ws_packet(
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 462, in process_ws_packet
    return self._process_device_update(packet, action, data, ignore_stats)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 389, in _process_device_update
    obj = obj.update_from_dict(deepcopy(data))
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/devices.py", line 827, in update_from_dict
    return super().update_from_dict(data)
  File "/usr/local/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 493, in update_from_dict
    setattr(self, key, convert_unifi_data(data[key], self.__fields__[key]))
  File "/usr/local/lib/python3.9/site-packages/pydantic/main.py", line 370, in __setattr__
    raise ValidationError([error_], self.__class__)
pydantic.error_wrappers.ValidationError: 1 validation error for Camera
anonymous_device_id
  none is not an allowed value (type=type_error.none.not_allowed)

It works but there are errors
Screen Shot 2022-06-23 at 16 01 50
Screen Shot 2022-06-23 at 16 02 07

@bdraco
Copy link
Member
bdraco commented Jun 27, 2022

No more tracebacks in the log, but it looks like motion gets added twice.

2022-06-27 11:33:18 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform unifiprotect does not generate unique IDs. ID 74ACB9001038_motion already exists - ignoring binary_sensor.g4_bullet_detections_motion
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_is_dark
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_ssh_enabled
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_overlay_show_name
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_overlay_show_date
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_overlay_show_logo
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_overlay_show_bitrate
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.unifiprotect entity: binary_sensor.g4_bullet_detections_motion
2022-06-27 11:33:18 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform unifiprotect does not generate unique IDs. ID 74ACB9001038_motion already exists - ignoring binary_sensor.g4_bullet_detections_motion
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_oldest_recording
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_storage_used
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_disk_write_rate
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_recording_mode
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_received_data
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_transferred_data
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_uptime
2022-06-27 11:33:18 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.unifiprotect entity: sensor.g4_bullet_last_motion_detected
2022-06-27 11:33:22 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.unifiprotect entity: camera.g4_bullet_high

@bdraco
Copy link
Member
bdraco commented Jun 27, 2022

The unique id conflict is a regression introduced in #73768 and unrelated to this PR

@bdraco bdraco merged commit b9c636b into home-assistant:dev Jun 27, 2022
@bdraco bdraco deleted the adopted-devices branch June 27, 2022 21:03
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.

Please address the comment in a new PR. Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 2022
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.

4 participants
0