From f40698a6954389ed590e0f83420d83da337e0449 Mon Sep 17 00:00:00 2001 From: karwosts Date: Mon, 15 Jul 2024 16:59:31 -0700 Subject: [PATCH 1/2] Fix persistent notification count on server restart --- src/components/ha-sidebar.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/components/ha-sidebar.ts b/src/components/ha-sidebar.ts index da4b698616ce..df18e060cd1d 100644 --- a/src/components/ha-sidebar.ts +++ b/src/components/ha-sidebar.ts @@ -210,6 +210,8 @@ class HaSidebar extends SubscribeMixin(LitElement) { private _editStyleLoaded = false; + private _unsubPersistentNotifications; + @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) { From a2dc60d009e57b58793a41fef2a34c93e5540053 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:14:56 -0700 Subject: [PATCH 2/2] Update src/components/ha-sidebar.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/components/ha-sidebar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ha-sidebar.ts b/src/components/ha-sidebar.ts index df18e060cd1d..bd705917aa6e 100644 --- a/src/components/ha-sidebar.ts +++ b/src/components/ha-sidebar.ts @@ -210,7 +210,7 @@ class HaSidebar extends SubscribeMixin(LitElement) { private _editStyleLoaded = false; - private _unsubPersistentNotifications; + private _unsubPersistentNotifications: UnsubscribeFunc | undefined; @storage({ key: "sidebarPanelOrder",