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

Implement coordinator class for Tradfri integration #64166

Merged

Conversation

ggravlingen
Copy link
Contributor

@ggravlingen ggravlingen commented Jan 15, 2022

Breaking change

Proposed change

This PR introduces a data coordinator class for the native Tradfri integration as discussed here.

The code works in my dev environment for the fan platform:

image

image

This PR will follow the following workflow:

  • Core code changes: introduction of the new coordinator.py file, refactoring of __init__.py, refactoring of fan.py and refactoring of the base_class.py file. Relevant changes to tests. I would like this to be fully aligned with HA-standards before I proceed with the other platforms.

Once that is done, the platforms, will be updated one by one:

  • Cover
  • Switch
  • Sensor
  • Light

To-do:

  • Fix tests
  • Add callback for hub available

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:

@ggravlingen
Copy link
Contributor Author

I have a few notes and questions:

  • I have temporarily disabled all platforms in the const-file. Will enable as we add updated code for all the platforms.
  • In this initial commit, all tests pass in test_fan.py and test_coordinator.py.
  • Could we move all setup fixtures with scope module to the conftest.py file? I've done it for the fan platform already.
  • I am a bit concerned regarding the functionality of light groups but as we have tests for them, we will make sure they work before the code merges.

@ggravlingen ggravlingen marked this pull request as ready for review January 15, 2022 16:24
homeassistant/components/tradfri/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/base_class.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/base_class.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/tradfri/fan.py Outdated Show resolved Hide resolved
tests/components/tradfri/conftest.py Outdated Show resolved Hide resolved
tests/components/tradfri/test_coordinator.py Outdated Show resolved Hide resolved
@ggravlingen
Copy link
Contributor Author

ggravlingen commented Jan 15, 2022

I've refactored the code to try to accomodate to the changes proposed in this review. I might have misunderstood something so apologies in advance if I haven't made all the requested changes.

ggravlingen and others added 2 commits January 16, 2022 10:42
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
@MartinHjelmare
Copy link
Member

Groups can be set as disabled by default and users can enable them if they want. We don't need a config option anymore for that. We can use the option to set default enabled state as a migration during a deprecation time. But let's change that in a separate PR.

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.

Great!

Let's wait with merging this until after we cut the beta tomorrow so we get some time to test this more in the dev branch before releasing it.

@MartinHjelmare MartinHjelmare marked this pull request as draft January 25, 2022 21:24
@ggravlingen
Copy link
Contributor Author

Great!

Let's wait with merging this until after we cut the beta tomorrow so we get some time to test this more in the dev branch before releasing it.

Good idea! Once merged, I'll add (in two separate PR's) sensors for the battery level of the cover platform, and air quality sensors from the fan platform.

Thank you for taking me through this PR! 🙇

@ggravlingen
Copy link
Contributor Author

Should I un-draft this or will you do it when the timing is right in regards to the beta?

@MartinHjelmare MartinHjelmare marked this pull request as ready for review January 27, 2022 10:12
@MartinHjelmare
Copy link
Member

We can merge now.

@MartinHjelmare MartinHjelmare merged commit 9d404b7 into home-assistant:dev Jan 27, 2022
@ggravlingen ggravlingen deleted the tradfri_implement_coordinator branch January 27, 2022 10:54
@ggravlingen
Copy link
Contributor Author

Thanks!

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