@@ -14,6 +14,7 @@ import {
14
14
mdiTooltipAccount ,
15
15
mdiViewDashboard ,
16
16
} from "@mdi/js" ;
17
+ import type { UnsubscribeFunc } from "home-assistant-js-websocket" ;
17
18
import type { CSSResultGroup , PropertyValues } from "lit" ;
18
19
import { LitElement , css , html , nothing } from "lit" ;
19
20
import {
@@ -205,6 +206,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
205
206
206
207
private _recentKeydownActiveUntil = 0 ;
207
208
209
+ private _unsubPersistentNotifications : UnsubscribeFunc | undefined ;
210
+
208
211
@query ( ".tooltip" ) private _tooltip ! : HTMLDivElement ;
209
212
210
213
public hassSubscribe ( ) {
@@ -227,9 +230,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {
227
230
}
228
231
}
229
232
) ,
230
- subscribeNotifications ( this . hass . connection , ( notifications ) => {
231
- this . _notifications = notifications ;
232
- } ) ,
233
233
...( this . hass . user ?. is_admin
234
234
? [
235
235
subscribeRepairsIssueRegistry ( this . hass . connection ! , ( repairs ) => {
@@ -300,6 +300,23 @@ class HaSidebar extends SubscribeMixin(LitElement) {
300
300
) ;
301
301
}
302
302
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
+
303
320
protected updated ( changedProps ) {
304
321
super . updated ( changedProps ) ;
305
322
if ( changedProps . has ( "alwaysExpand" ) ) {
@@ -311,6 +328,14 @@ class HaSidebar extends SubscribeMixin(LitElement) {
311
328
312
329
const oldHass = changedProps . get ( "hass" ) as HomeAssistant | undefined ;
313
330
331
+ if (
332
+ this . hass &&
333
+ oldHass ?. connected === false &&
334
+ this . hass . connected === true
335
+ ) {
336
+ this . _subscribePersistentNotifications ( ) ;
337
+ }
338
+
314
339
this . _calculateCounts ( ) ;
315
340
316
341
if ( ! SUPPORT_SCROLL_IF_NEEDED ) {
0 commit comments