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

fix(entity): retry all calls while refreshing the access token if expired #164

Closed palazzem closed 4 months ago

palazzem commented 4 months ago

Related Issues

Proposed Changes:

This change retries all decorated function call or services after obtaining a new refreshed token, if necessary. These decorators have been applied to all calls made by the Alarm Panel and Services.

The set state decorator now handles all exceptions so that, in case of unexpected failure, the previous state is always reverted.

Testing:

  1. Enable a long delay (e.g. 3600s)
  2. Wait for 5 minutes (token expiration)
  3. Run any action from the panel or call an arm/disarm service

Extra Notes (optional):

This change doesn't have unit tests, hence why the code coverage decreased. While this is very sub-optimal for the code quality and reliability, we're working on the underlying implementation refactoring as the retry mechanism must be moved in econnect-python. This is necessary otherwise all library users have to implement the refresh token management, increasing heavily the code duplication.

As soon as this part is migrated, this code can be removed.

Checklist

coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9158415390

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
custom_components/econnect_metronet/decorators.py 19 40 47.5%
<!-- Total: 29 50 58.0% -->
Totals Coverage Status
Change from base Build 9111312503: -2.1%
Covered Lines: 701
Relevant Lines: 769

💛 - Coveralls
palazzem commented 4 months ago

We temporarily accept the code coverage reduction until this code is moved in the underlying econnect-python library. See https://github.com/palazzem/econnect-python/issues/152.