Skip to content

Commit 69d8eeb

Browse files
authored
Revert changes to persistent notification in sidebar (#25984)
1 parent 3b7d286 commit 69d8eeb

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/components/ha-sidebar.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
mdiTooltipAccount,
1515
mdiViewDashboard,
1616
} from "@mdi/js";
17+
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
1718
import type { CSSResultGroup, PropertyValues } from "lit";
1819
import { LitElement, css, html, nothing } from "lit";
1920
import {
@@ -205,6 +206,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
205206

206207
private _recentKeydownActiveUntil = 0;
207208

209+
private _unsubPersistentNotifications: UnsubscribeFunc | undefined;
210+
208211
@query(".tooltip") private _tooltip!: HTMLDivElement;
209212

210213
public hassSubscribe() {
@@ -227,9 +230,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {
227230
}
228231
}
229232
),
230-
subscribeNotifications(this.hass.connection, (notifications) => {
231-
this._notifications = notifications;
232-
}),
233233
...(this.hass.user?.is_admin
234234
? [
235235
subscribeRepairsIssueRegistry(this.hass.connection!, (repairs) => {
@@ -300,6 +300,23 @@ class HaSidebar extends SubscribeMixin(LitElement) {
300300
);
301301
}
302302

303+
protected firstUpdated(changedProps: PropertyValues) {
304+
super.firstUpdated(changedProps);
305+
this._subscribePersistentNotifications();
306+
}
307+
308+
private _subscribePersistentNotifications(): void {
309+
if (this._unsubPersistentNotifications) {
310+
this._unsubPersistentNotifications();
311+
}
312+
this._unsubPersistentNotifications = subscribeNotifications(
313+
this.hass.connection,
314+
(notifications) => {
315+
this._notifications = notifications;
316+
}
317+
);
318+
}
319+
303320
protected updated(changedProps) {
304321
super.updated(changedProps);
305322
if (changedProps.has("alwaysExpand")) {
@@ -311,6 +328,14 @@ class HaSidebar extends SubscribeMixin(LitElement) {
311328

312329
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
313330

331+
if (
332+
this.hass &&
333+
oldHass?.connected === false &&
334+
this.hass.connected === true
335+
) {
336+
this._subscribePersistentNotifications();
337+
}
338+
314339
this._calculateCounts();
315340

316341
if (!SUPPORT_SCROLL_IF_NEEDED) {

0 commit comments

Comments
 (0)