From 7fdf824e97bb972e9214b2c7ac868b35a5a9d33d Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Thu, 10 Jul 2025 12:33:33 -0700 Subject: [PATCH] Revert changes to persistent notification in sidebar (#25984) --- src/components/ha-sidebar.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/ha-sidebar.ts b/src/components/ha-sidebar.ts index 8ccaad0d95..d097a57ce0 100644 --- a/src/components/ha-sidebar.ts +++ b/src/components/ha-sidebar.ts @@ -14,6 +14,7 @@ import { mdiTooltipAccount, mdiViewDashboard, } from "@mdi/js"; +import type { UnsubscribeFunc } from "home-assistant-js-websocket"; import type { CSSResultGroup, PropertyValues } from "lit"; import { LitElement, css, html, nothing } from "lit"; import { @@ -205,6 +206,8 @@ class HaSidebar extends SubscribeMixin(LitElement) { private _recentKeydownActiveUntil = 0; + private _unsubPersistentNotifications: UnsubscribeFunc | undefined; + @query(".tooltip") private _tooltip!: HTMLDivElement; public hassSubscribe() { @@ -227,9 +230,6 @@ class HaSidebar extends SubscribeMixin(LitElement) { } } ), - subscribeNotifications(this.hass.connection, (notifications) => { - this._notifications = notifications; - }), ...(this.hass.user?.is_admin ? [ subscribeRepairsIssueRegistry(this.hass.connection!, (repairs) => { @@ -300,6 +300,23 @@ class HaSidebar extends SubscribeMixin(LitElement) { ); } + protected firstUpdated(changedProps: PropertyValues) { + super.firstUpdated(changedProps); + this._subscribePersistentNotifications(); + } + + private _subscribePersistentNotifications(): void { + if (this._unsubPersistentNotifications) { + this._unsubPersistentNotifications(); + } + this._unsubPersistentNotifications = subscribeNotifications( + this.hass.connection, + (notifications) => { + this._notifications = notifications; + } + ); + } + protected updated(changedProps) { super.updated(changedProps); if (changedProps.has("alwaysExpand")) { @@ -311,6 +328,14 @@ class HaSidebar extends SubscribeMixin(LitElement) { const oldHass = changedProps.get("hass") as HomeAssistant | undefined; + if ( + this.hass && + oldHass?.connected === false && + this.hass.connected === true + ) { + this._subscribePersistentNotifications(); + } + this._calculateCounts(); if (!SUPPORT_SCROLL_IF_NEEDED) {