Get persistent_notifications for lovelace from websocket.#1649
Get persistent_notifications for lovelace from websocket.#1649balloob merged 3 commits intohome-assistant:masterfrom
Conversation
src/panels/lovelace/hui-root.js
Outdated
| _hassChanged(hass) { | ||
| if (!this.$.view.lastChild) return; | ||
| this.$.view.lastChild.hass = hass; | ||
| this._updateNotifications(); |
There was a problem hiding this comment.
This is very expensive. This will now query the websocket backend whenever hass changes, which is A LOT. We should cache the websocket response in a different variable and only update that on the persistent_notifications_updated event.
There was a problem hiding this comment.
Oh yeah, that was a bad idea
src/panels/lovelace/hui-root.js
Outdated
|
|
||
| async connectedCallback() { | ||
| super.connectedCallback(); | ||
| this._fetchPersistentNotifications(); |
There was a problem hiding this comment.
Collections will also fetch again after a reconnect.
There was a problem hiding this comment.
The return value of a collection is still an unSub function that should be called when the component disconnects.
There was a problem hiding this comment.
👍 Do we need to change the backend so that it sends the updated data with the event?
There was a problem hiding this comment.
No, then you need to get granular events like state_changed and only include the changed pieces.
There was a problem hiding this comment.
So do something like this in subscribeUpdates:
const fetchNotifications = conn => conn.sendMessagePromise({
type: 'persistent_notification/get'
});
const subscribeUpdates = (conn, store) =>
conn.subscribeEvents(
event => fetchNotifications(conn).then(notif => store.setState(notif, true)),
'persistent_notifications_updated'
);
export const subscribeNotifications = (conn, onChange) =>
createCollection(
'_ntf',
fetchNotifications,
subscribeUpdates,
conn,
onChange
);There was a problem hiding this comment.
👍 Will do. Later I can add more fine-grained events so we can update the collection without having to fetch the whole set
There was a problem hiding this comment.
I honestly think that it would be overkill. It should be such small data sets.
src/panels/lovelace/hui-root.js
Outdated
| value: [] | ||
| }, | ||
|
|
||
| notifications: { |
| 'configurator' | ||
| ]; | ||
|
|
||
| export default function computeNotifications(states) { |
There was a problem hiding this comment.
Now that it's only 1 domain, it's faster to do === instead of includes
|
We can merge this once we are no longer needing to do frontend updates for the beta. |
Frontend changes for home-assistant/core#16503
Lovelace will now use websocket connection and events to fetch/update persistent_notifications