palazzem / ha-econnect-alarm

Home Assistant integration that provides a full-fledged Alarm Panel to control your Elmo/IESS alarm systems.
BSD 3-Clause "New" or "Revised" License
10 stars 5 forks source link

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

Closed palazzem closed 8 months ago

palazzem commented 8 months ago

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:

Extra Notes (optional):

n/a

Checklist