Skip to content

Implement external state restoration#58

Merged
puddly merged 37 commits into
zigpy:devfrom
puddly:puddly/lighting-state-restoration-fixes
Jul 5, 2024
Merged

Implement external state restoration#58
puddly merged 37 commits into
zigpy:devfrom
puddly:puddly/lighting-state-restoration-fixes

Conversation

@puddly

@puddly puddly commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

A few platforms in ZHA uses instance attributes and complex logic to derive their state, relying on Home Assistant to persist it and restore it after startup:

  • I've exposed necessary information for some platforms (light and cover) for Home Assistant to store this information as extra state attributes, allowing it to be restore properly. I believe this was actually a bug in the past.
  • Other platforms could be converted to use the ZCL attribute cache, such as binary_sensor and lock. These effectively perform operations that change a ZCL attribute so the attribute cache can be used to maintain state.
  • Others rely on directly computing state from other information and unfortunately will have to be directly restored (siren).

In the future, we need to explore a way to store this extra state. I think zigpy can provide a hook. Alternatively, we can invert the storage logic and have ZHA implement a database driver for zigpy.

@codecov

codecov Bot commented Jul 1, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.25%. Comparing base (6794a64) to head (b8d5c57).
Report is 1 commits behind head on dev.

Files Patch % Lines
zha/application/platforms/number/__init__.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #58      +/-   ##
==========================================
+ Coverage   95.00%   95.25%   +0.25%     
==========================================
  Files          61       61              
  Lines        9306     9335      +29     
==========================================
+ Hits         8841     8892      +51     
+ Misses        465      443      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread zha/zigbee/cluster_handlers/lighting.py
@puddly puddly changed the title Persist lighting color mode Implement external state restoration Jul 3, 2024
Comment thread zha/application/platforms/light/__init__.py Outdated
Comment thread zha/application/platforms/light/__init__.py Outdated
Comment thread zha/application/platforms/light/__init__.py Outdated
Comment thread zha/application/platforms/light/__init__.py Outdated
Comment thread zha/application/platforms/light/__init__.py Outdated
@puddly

puddly commented Jul 3, 2024

Copy link
Copy Markdown
Contributor Author

I've foregone using the ZCL cache and instead just implement restore_external_state_attributes for the required entities. This makes this PR much simpler.

Comment thread zha/application/platforms/number/__init__.py Outdated

@TheJulianJES TheJulianJES left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also looks good IMO

@puddly puddly merged commit 8abf678 into zigpy:dev Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants