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

Use DataUpdateCoordinator for mikrotik #72954

Merged
merged 10 commits into from Jun 29, 2022

Conversation

engrbm87
Copy link
Contributor

@engrbm87 engrbm87 commented Jun 3, 2022

Breaking change

Proposed change

Use DataUpdateCoordinator for mikrotik

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:

@engrbm87
Copy link
Contributor Author

Appreciate getting this merged if there are no other comments.

@bdraco
Copy link
Member

bdraco commented Jun 22, 2022

I'm a little worried about the performance impact here as DataUpdateCoordinator calls back all entities each update so you'll go from writing state for a single entity via the signal to writing state for every entity every time there is an update.

That might be a performance problem.

@engrbm87
Copy link
Contributor Author

I'm a little worried about the performance impact here as DataUpdateCoordinator calls back all entities each update so you'll go from writing state for a single entity via the signal to writing state for every entity every time there is an update.

That might be a performance problem.

Currently the signal is causing all entities to update. So by changing to the DataUpdateCoordinator we are not changing this.
To my understading all integration entities should update together. Is this something that we should look into for this integration?

@bdraco
Copy link
Member

bdraco commented Jun 22, 2022

Currently the signal is causing all entities to update.

That does seem to be the case. I read return f"mikrotik-update-{self.host}" as it was the device tracker and not hub itself.

So by changing to the DataUpdateCoordinator we are not changing this.

To my understading all integration entities should update together. Is this something that we should look into for this integration?

Do you have a way of knowing which ones actually changed so you could only signal the ones that have changed?

We use something like this to only signal/callback entities that have changes to avoid lots of state writes when there are many entities
https://github.com/home-assistant/core/blob/dev/homeassistant/components/august/subscriber.py
https://github.com/home-assistant/core/blob/dev/homeassistant/components/unifiprotect/data.py

@engrbm87
Copy link
Contributor Author

Let me look into it and see if it is possible.

@engrbm87
Copy link
Contributor Author

I tried checking other integrations that have device_tracker and I noticed that the signal dispatched causes all device trackers to update. I also want to highlight that the state of the device tracker (home / not_home) is determined by HA based on the detection_time option. Also the update includes attribute updates not just state so it is important that all enabled device_tracker entities get updated with each scan.

@bdraco bdraco self-requested a review June 23, 2022 23:13
@MartinHjelmare MartinHjelmare added this to By Code Owner in Dev Jun 26, 2022
Dev automation moved this from By Code Owner to Reviewer approved Jun 29, 2022
@bdraco bdraco added the smash Indicator this PR is close to finish for merging or closing label Jun 29, 2022
async def async_update(self):
"""Update Mikrotik devices information."""
await self.hass.async_add_executor_job(self._mk_data.update)
async_dispatcher_send(self.hass, self.signal_update)
await self.hass.async_add_executor_job(self._mk_data.update_devices)

async def async_setup(self):
Copy link
Member

Choose a reason for hiding this comment

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

In a future PR it would be good to move to into __init__.py since it makes it harder to see what is going on at startup with having it on the coordinator object

@bdraco bdraco merged commit 8905e6f into home-assistant:dev Jun 29, 2022
Dev automation moved this from Reviewer approved to Done Jun 29, 2022
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 comments in a new PR. Thanks!

homeassistant/components/mikrotik/hub.py Show resolved Hide resolved
homeassistant/components/mikrotik/hub.py Show resolved Hide resolved
tests/components/mikrotik/test_init.py Show resolved Hide resolved
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2022
@engrbm87 engrbm87 deleted the mikrotik-dataupdatecoordinator branch September 16, 2022 09:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants