11import "@home-assistant/webawesome/dist/components/divider/divider" ;
22import { ResizeController } from "@lit-labs/observers/resize-controller" ;
33import { mdiChevronDown , mdiPlus , mdiRefresh } from "@mdi/js" ;
4- import type { CSSResultGroup , PropertyValues , TemplateResult } from "lit" ;
4+ import type { UnsubscribeFunc } from "home-assistant-js-websocket" ;
5+ import type { CSSResultGroup , TemplateResult } from "lit" ;
56import { LitElement , css , html , nothing } from "lit" ;
67import { customElement , property , state } from "lit/decorators" ;
78import { storage } from "../../common/decorators/storage" ;
@@ -16,19 +17,23 @@ import "../../components/ha-icon-button";
1617import "../../components/ha-list" ;
1718import "../../components/ha-list-item" ;
1819import "../../components/ha-menu-button" ;
20+ import "../../components/ha-spinner" ;
1921import "../../components/ha-state-icon" ;
2022import "../../components/ha-svg-icon" ;
2123import "../../components/ha-two-pane-top-app-bar-fixed" ;
2224import type { Calendar , CalendarEvent } from "../../data/calendar" ;
2325import { fetchCalendarEvents , getCalendars } from "../../data/calendar" ;
26+ import type { EntityRegistryEntry } from "../../data/entity/entity_registry" ;
27+ import { subscribeEntityRegistry } from "../../data/entity/entity_registry" ;
2428import { fetchIntegrationManifest } from "../../data/integration" ;
2529import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow" ;
30+ import { SubscribeMixin } from "../../mixins/subscribe-mixin" ;
2631import { haStyle } from "../../resources/styles" ;
2732import type { CalendarViewChanged , HomeAssistant } from "../../types" ;
2833import "./ha-full-calendar" ;
2934
3035@customElement ( "ha-panel-calendar" )
31- class PanelCalendar extends LitElement {
36+ class PanelCalendar extends SubscribeMixin ( LitElement ) {
3237 @property ( { attribute : false } ) public hass ! : HomeAssistant ;
3338
3439 @property ( { type : Boolean , reflect : true } ) public narrow = false ;
@@ -41,6 +46,8 @@ class PanelCalendar extends LitElement {
4146
4247 @state ( ) private _error ?: string = undefined ;
4348
49+ @state ( ) private _entityRegistry ?: EntityRegistryEntry [ ] ;
50+
4451 @state ( )
4552 @storage ( {
4653 key : "deSelectedCalendars" ,
@@ -77,14 +84,46 @@ class PanelCalendar extends LitElement {
7784 this . mobile = ev . matches ;
7885 } ;
7986
80- public willUpdate ( changedProps : PropertyValues ) : void {
81- super . willUpdate ( changedProps ) ;
82- if ( ! this . hasUpdated ) {
83- this . _calendars = getCalendars ( this . hass , this ) ;
84- }
87+ public hassSubscribe ( ) : UnsubscribeFunc [ ] {
88+ return [
89+ subscribeEntityRegistry ( this . hass . connection ! , ( entities ) => {
90+ this . _entityRegistry = entities ;
91+ // Refresh calendars when entity registry updates (includes color changes)
92+ this . _calendars = getCalendars ( this . hass , this , this . _entityRegistry ) ;
93+ // Refetch events if view dates are available (handles both initial load and color updates)
94+ if ( this . _start && this . _end ) {
95+ this . _fetchEvents (
96+ this . _start ,
97+ this . _end ,
98+ this . _selectedCalendars
99+ ) . then ( ( result ) => {
100+ this . _events = result . events ;
101+ this . _handleErrors ( result . errors ) ;
102+ } ) ;
103+ }
104+ } ) ,
105+ ] ;
85106 }
86107
87108 protected render ( ) : TemplateResult {
109+ if ( ! this . _entityRegistry ) {
110+ return html `
111+ <ha- two- pane-to p- app- bar- fixed .narrow = ${ this . narrow } >
112+ <ha- menu- butto n
113+ slot= "navigationIcon"
114+ .hass = ${ this . hass }
115+ .narrow = ${ this . narrow }
116+ > </ ha- menu- butto n>
117+ <div slot= "title" >
118+ ${ this . hass . localize ( "ui.components.calendar.my_calendars" ) }
119+ </ div>
120+ <div class= "loading" >
121+ <ha- spinner> </ ha- spinner>
122+ </ div>
123+ </ ha- two- pane-to p- app- bar- fixed>
124+ ` ;
125+ }
126+
88127 const calendarItems = this . _calendars . map (
89128 ( selCal ) => html `
90129 <ha- dropdown- item
@@ -220,7 +259,7 @@ class PanelCalendar extends LitElement {
220259 manifest : await fetchIntegrationManifest ( this . hass , "local_calendar" ) ,
221260 dialogClosedCallback : ( { flowFinished } ) => {
222261 if ( flowFinished ) {
223- this . _calendars = getCalendars ( this . hass , this ) ;
262+ this . _calendars = getCalendars ( this . hass , this , this . _entityRegistry ) ;
224263 }
225264 } ,
226265 } ) ;
@@ -301,6 +340,13 @@ class PanelCalendar extends LitElement {
301340 : host ([mobile ]) {
302341 padding-left : unset;
303342 }
343+ .loading {
344+ display : flex;
345+ align-items : center;
346+ justify-content : center;
347+ padding : var (--ha-space-8 );
348+ min-height : 400px ;
349+ }
304350 ` ,
305351 ] ;
306352 }
0 commit comments