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

Widgets: use received entity state changes for updating if possible #2089

Merged

Conversation

jpelgrom
Copy link
Member

Summary

Currently, any time an entity state change is received (via the websocket) all widgets data is refreshed and views are updated. While it works to keep the widgets 'live', it is very inefficient, especially if there are a lot of state changes and/or you have a lot of widgets.

This PR proposes a way to use the entity state changes the app already receives to update the widgets more efficiently, specifically:

  • Only update the widgets that are affected by the state change*
  • Re-use the received entity state instead of making a call to the REST API to get the entity state, if possible

*Right now that is just the entity state and media player widgets. The template widget is rendered on the server which might be affected by state changes in ways we don't know anything about, so just keep refreshing that as before.

Screenshots

No visible changes

Link to pull request in Documentation repository

Doesn't seem necessary

Any other notes

 - Add a function to widgets implementing the BaseWidgetProvider that is called whenever a new state change for an entity is received. Implemented it by refreshing all widgets (match existing behaviour).
 - Only refresh the entity and media widget if the state of the entity they're displaying is changed. For the template widget we don't know since it is rendered on the server so just keep refreshing on any state change (no change).
 - Allow passing in a suggested entity for updating the view to allow the widgets to re-use the received state update object, removing the need to make another API call if the view is requested as a result from a state update.
@jpelgrom jpelgrom changed the title Widgets: use received entity state changes for updating Widgets: use received entity state changes for updating if possible Dec 29, 2021
@JBassett JBassett merged commit 5711e0e into home-assistant:master Dec 30, 2021
@jpelgrom jpelgrom deleted the widgets-use-entity-state-changes branch December 30, 2021 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants