Fix persistent notification count on server restart (#21405)

* Fix persistent notification count on server restart
This commit is contained in:
karwosts 2024-07-18 11:53:17 -07:00 committed by GitHub
parent d997cfcef0
commit e63d82d291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -210,6 +210,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
private _editStyleLoaded = false;
private _unsubPersistentNotifications: UnsubscribeFunc | undefined;
@storage({
key: "sidebarPanelOrder",
state: true,
@ -283,15 +285,26 @@ class HaSidebar extends SubscribeMixin(LitElement) {
hass.localize !== oldHass.localize ||
hass.locale !== oldHass.locale ||
hass.states !== oldHass.states ||
hass.defaultPanel !== oldHass.defaultPanel
hass.defaultPanel !== oldHass.defaultPanel ||
hass.connected !== oldHass.connected
);
}
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
subscribeNotifications(this.hass.connection, (notifications) => {
this._notifications = notifications;
});
this.subscribePersistentNotifications();
}
private subscribePersistentNotifications(): void {
if (this._unsubPersistentNotifications) {
this._unsubPersistentNotifications();
}
this._unsubPersistentNotifications = subscribeNotifications(
this.hass.connection,
(notifications) => {
this._notifications = notifications;
}
);
}
protected updated(changedProps) {
@ -306,6 +319,14 @@ class HaSidebar extends SubscribeMixin(LitElement) {
return;
}
if (
this.hass &&
changedProps.get("hass")?.connected === false &&
this.hass.connected === true
) {
this.subscribePersistentNotifications();
}
this._calculateCounts();
if (!SUPPORT_SCROLL_IF_NEEDED) {