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

refactor: create AlarmCoordinator to separate HA functions from the fetching logic #74

Merged
merged 6 commits into from
Oct 12, 2023

Conversation

palazzem
Copy link
Owner

Related Issues

Proposed Changes:

This change refactors entirely how the DataUpdateCoordinator is exposed to the integration. Instead of writing the fetching logic inside the async_setup_entry as a standalone function, we moved the entire logic in a dedicated class that is easy to test. AlarmCoordinator is fully tested and a regression test is added to the test suite.

Furthermore, the integration now uses async_config_entry_first_refresh() to call the first update, so that if there are issues with the update, the integration will raise ConfigEntryNotReady exception, preventing the integration from loading. At that stage, the integration is flagged as "Failed to load", preventing logs spamming.

Testing:

  • Install the integration
  • It should work as usual as this is just a refactoring

Extra Notes (optional):

n/a

Checklist

  • Related issues and proposed changes are filled
  • Tests are defining the correct and expected behavior
  • Code is well-documented via docstrings

@palazzem palazzem added this to the 2.1.0 milestone Oct 11, 2023
@palazzem palazzem self-assigned this Oct 11, 2023
Copy link
Owner Author

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

Changes are required to improve the quality.

custom_components/econnect_metronet/__init__.py Outdated Show resolved Hide resolved
custom_components/econnect_metronet/coordinator.py Outdated Show resolved Hide resolved
custom_components/econnect_metronet/coordinator.py Outdated Show resolved Hide resolved
custom_components/econnect_metronet/coordinator.py Outdated Show resolved Hide resolved
custom_components/econnect_metronet/devices.py Outdated Show resolved Hide resolved
@palazzem palazzem force-pushed the palazzem/task-refactor-coordinator branch 2 times, most recently from 73b6ac1 to 14005af Compare October 12, 2023 13:23
@palazzem palazzem force-pushed the palazzem/task-refactor-coordinator branch from 14005af to 932c893 Compare October 12, 2023 13:23
@palazzem palazzem merged commit 83770d5 into main Oct 12, 2023
3 checks passed
@palazzem palazzem deleted the palazzem/task-refactor-coordinator branch October 12, 2023 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant