@@ -153,13 +153,12 @@ class RadioBrowserCard extends HTMLElement {
153153 if ( ! result || ! result . value ) return ;
154154
155155 const data = result . value ;
156- const localFavs = localStorage . getItem ( 'radio_favorites' ) ;
157- const localCustom = localStorage . getItem ( 'radio_custom_stations' ) ;
158- const hasLocalData = ( localFavs && JSON . parse ( localFavs ) . length > 0 ) ||
159- ( localCustom && JSON . parse ( localCustom ) . length > 0 ) ;
156+ const hasLocalFavs = this . _favorites && this . _favorites . length > 0 ;
157+ const hasLocalCustom = this . _customStations && this . _customStations . length > 0 ;
158+ const hasServerData = ( data . favorites ?. length > 0 || data . custom_stations ?. length > 0 ) ;
160159
161- // Only restore if localStorage is empty (cache was cleared) and server has data
162- if ( ! hasLocalData && ( data . favorites ?. length > 0 || data . custom_stations ?. length > 0 ) ) {
160+ // Only restore if local data is empty (cache was cleared) and server has data
161+ if ( ! hasLocalFavs && ! hasLocalCustom && hasServerData ) {
163162 console . log ( 'Cache cleared detected - restoring from HA server backup...' ) ;
164163 if ( data . favorites ?. length > 0 ) {
165164 this . _favorites = data . favorites ;
@@ -170,7 +169,14 @@ class RadioBrowserCard extends HTMLElement {
170169 localStorage . setItem ( 'radio_custom_stations' , JSON . stringify ( data . custom_stations ) ) ;
171170 }
172171 console . log ( `Restored: ${ data . favorites ?. length || 0 } favorites, ${ data . custom_stations ?. length || 0 } custom stations` ) ;
173- this . updatePlaylist ( ) ;
172+
173+ // Force re-render to show restored data (playlist DOM may already exist)
174+ if ( this . shadowRoot . querySelector ( '.playlist-items' ) ) {
175+ this . updatePlaylist ( ) ;
176+ } else {
177+ // DOM not ready yet, re-render the whole card
178+ this . render ( ) ;
179+ }
174180 }
175181 } catch ( e ) {
176182 console . log ( 'Auto-restore from HA server not available:' , e ) ;
0 commit comments