Skip to content

Commit

Permalink
Fix persistent notification count on server restart (#21405)
Browse files Browse the repository at this point in the history
* Fix persistent notification count on server restart
  • Loading branch information
karwosts authored Jul 18, 2024
1 parent d997cfc commit e63d82d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/components/ha-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {

private _editStyleLoaded = false;

private _unsubPersistentNotifications: UnsubscribeFunc | undefined;

@storage({
key: "sidebarPanelOrder",
state: true,
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit e63d82d

Please sign in to comment.