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

Bump reolink-aio to 0.9.1 #118655

Merged
merged 11 commits into from
Jun 4, 2024
Merged

Conversation

starkillerOG
Copy link
Contributor

@starkillerOG starkillerOG commented Jun 2, 2024

Breaking change

Proposed change

Breaking changes:

Additions:

Bug fixes:

Optimizations:

Full Changelog: starkillerOG/reolink_aio@0.8.11...0.9.1

Due to a breaking change in reolink-aio regarding the structure of the cmd_list and the doorbell LED, some small adjustments are needed in the bump PR. The rest of the changes will be done in split out PRs to make Battery cameras fully compatible (and not drain their batteries).

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

To help with the load of incoming pull requests:

@starkillerOG
Copy link
Contributor Author

I would like to get this into the 2024.6.0 (beta) release because otherwise I will be blocked from doing version bumps of reolink-aio in the 2024.6.x release cycle. (Due to adjustments needed in HA code for reolink > 0.9 releases)

@starkillerOG starkillerOG requested a review from bdraco June 3, 2024 08:10
Comment on lines 149 to 152
self._update_cmd_list_count[cmd_key].setdefault(self._channel, 0)
self._update_cmd_list_count[cmd_key][self._channel] += 1
if self._channel not in self._host.update_cmd_list[cmd_key]:
self._host.update_cmd_list[cmd_key].append(self._channel)
Copy link
Member

@bdraco bdraco Jun 3, 2024

Choose a reason for hiding this comment

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

If you are going to do ref counting and channel is hashable it might make this a bit simpler to make update_cmd_list a defaultdict of dict and do

self._host.update_cmd[cmd_key][self._channel] += 1 and self._host.update_cmd[cmd_key][self._channel] -= 1 (and than delete the entry when it reaches 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion, I have implemented that now (I think).

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 now have two lists (update_cmd_list and update_cmd_list_count), I do that because I want to keep update_cmd_list as simple as possible since it is looked up many times for each update that happens every 1 minute.

Copy link
Member

Choose a reason for hiding this comment

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

Where does the lookup happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

In the future you should be able to optimize https://github.com/starkillerOG/reolink_aio/blob/714e87f05669c1b0889ba5c0718297ce6a06a10c/reolink_aio/api.py#L1546 a bit more by having all the commands in a set and than using intersection on the dict to find the supported commands

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is very instresting, will keep this in mind.
You are so good in runtime optimazations (I read the members discord and I am amazed by your work).

@starkillerOG
Copy link
Contributor Author

@bdraco I tested the code and it is working perfectly.
Very nice it is now cleaned up directly when the entities are removed.
That ensures no unneeded HTTP(S) requests are beeing made.

Comment on lines 94 to 96
self._host.update_cmd_list_count[cmd_key].setdefault("host", 0)
self._host.update_cmd_list_count[cmd_key]["host"] += 1
self._host.update_cmd_list.setdefault(cmd_key, [])
Copy link
Member

Choose a reason for hiding this comment

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

Do you need a seperate list and count. Can you use the same container where the value is the reference count, and the key is the cmd_key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well I also need the channel in there.
The upstream library needs to now which commands it needs to send to which channels.
(the library talks to a NVR which has multiple camera's connected using a build-in POE switch, so each channel is a seperate camera)

Currently the structure for the upstream library is:
{cmd_key: [channels]}
So for instance if only camera's on channel 2 and 5 support Zoom and those entities are enabled:
{"GetZoomFocus": [2, 5]}
For commands that talk to the NVR itself and not to a channel, for instance the hard drive status of the NVR, it looks like:
{"GetHddInfo": []}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The update_cmd_list_count looks like:
{"GetZoomFocus": {"Host": 6, 2: 3, 5: 3}}
and
{"GetHddInfo": {"Host": 1}}

But that added complexity of knowing how many entities are using the command is not needed in the upstream library (reolink-aio)

Copy link
Member

Choose a reason for hiding this comment

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

bdraco@272e28e

Maybe something like this

@starkillerOG starkillerOG changed the title Bump reolink-aio to 0.9.0 Bump reolink-aio to 0.9.1 Jun 3, 2024
Co-authored-by: J. Nick Koston <nick@koston.org>
@starkillerOG
Copy link
Contributor Author

@bdraco thank you very much for your code suggestion.
It is extremely ellegant!
I did not know defaultdict existed but it is wonderfull.
I am learning so much from you experianced people!

@starkillerOG starkillerOG merged commit cba0754 into home-assistant:dev Jun 4, 2024
34 checks passed
@starkillerOG starkillerOG deleted the reolink_bump090 branch June 4, 2024 06:00
frenck pushed a commit that referenced this pull request Jun 4, 2024
Co-authored-by: J. Nick Koston <nick@koston.org>
dgomes pushed a commit to dgomes/home-assistant that referenced this pull request Jun 4, 2024
Co-authored-by: J. Nick Koston <nick@koston.org>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 5, 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.

3 participants