@@ -7,7 +7,7 @@ import { checkConfig, entityStyles, renderEntitiesRow, renderInfoEntity, renderR
77import { getEntityIds , parseConfig } from './util' ;
88import { hideIfCard } from './hide' ;
99import { style } from './styles' ;
10- import { RoomCardConfig , RoomCardLovelaceCardConfig } from './types/room-card-types' ;
10+ import { HomeAssistantEntity , RoomCardConfig , RoomCardLovelaceCardConfig } from './types/room-card-types' ;
1111import * as packageJson from '../package.json' ;
1212
1313console . info (
@@ -28,9 +28,7 @@ console.info(
2828
2929@customElement ( 'room-card' )
3030export default class RoomCard extends LitElement {
31- private _hass ?: HomeAssistant ;
3231 @property ( ) monitoredStates ?: HassEntities = { } ;
33- @property ( ) config ?: RoomCardConfig ;
3432 @property ( ) _helpers : { createCardElement ( config : LovelaceCardConfig ) : LovelaceCard }
3533
3634 getChildCustomCardTypes ( cards : RoomCardLovelaceCardConfig [ ] , target : Set < string > ) {
@@ -50,20 +48,6 @@ export default class RoomCard extends LitElement {
5048 await Promise . all ( Array . from ( distinctTypes ) . map ( type => customElements . whenDefined ( type ) ) ) ;
5149 }
5250
53- async setConfig ( config : RoomCardConfig ) {
54- checkConfig ( config ) ;
55- const entityIds = getEntityIds ( config ) ;
56- this . config = { ...config , entityIds : entityIds } ;
57-
58- await this . waitForDependentComponents ( config ) ;
59-
60- /* istanbul ignore next */
61- /* eslint-disable @typescript-eslint/no-explicit-any */
62- if ( ( window as any ) . loadCardHelpers ) {
63- this . _helpers = await ( window as any ) . loadCardHelpers ( ) ;
64- }
65- }
66-
6751 protected shouldUpdate ( changedProps : PropertyValues ) : boolean {
6852 const result = this . monitoredStates !== undefined
6953 && this . config !== undefined
@@ -81,7 +65,7 @@ export default class RoomCard extends LitElement {
8165 for ( const entityId of this . config . entityIds ) {
8266 if ( entityId in hass . states ) {
8367 const monitoredEntity = this . monitoredStates && this . monitoredStates [ entityId ] ;
84-
68+
8569 /* istanbul ignore next */
8670 if ( ! this . monitoredStates || monitoredEntity ?. last_updated < hass . states [ entityId ] . last_updated ||
8771 monitoredEntity ?. last_changed < hass . states [ entityId ] . last_changed ) {
@@ -99,11 +83,34 @@ export default class RoomCard extends LitElement {
9983 }
10084 }
10185
102- @property ( )
103- get hass ( ) { return this . _hass ; }
86+ @property ( ) _hass ?: HomeAssistant ;
87+ @property ( ) config ?: RoomCardConfig ;
88+
89+ private stateObj : HomeAssistantEntity | undefined ;
90+
91+ async setConfig ( config : RoomCardConfig ) {
92+
93+ checkConfig ( config ) ;
94+
95+ this . config = { ...config , entityIds : getEntityIds ( config ) } ;
96+
97+ await this . waitForDependentComponents ( config ) ;
98+
99+ /* istanbul ignore next */
100+ /* eslint-disable @typescript-eslint/no-explicit-any */
101+ if ( ( window as any ) . loadCardHelpers ) {
102+ this . _helpers = await ( window as any ) . loadCardHelpers ( ) ;
103+ }
104+ }
105+
104106 set hass ( hass : HomeAssistant ) {
105- this . updateMonitoredStates ( hass ) ;
106107 this . _hass = hass ;
108+
109+ if ( hass && this . config ) {
110+ this . updateMonitoredStates ( hass ) ;
111+
112+ this . config . hass = hass ;
113+ }
107114 }
108115
109116 static get styles ( ) : CSSResult {
@@ -148,7 +155,7 @@ export default class RoomCard extends LitElement {
148155 hideIfCard ( config , hass ) ||
149156 ( config . show_states && ! config . show_states . includes ( hass . states [ config . entity ] . state ) )
150157 ) {
151- return ;
158+ return null ;
152159 }
153160
154161 let element : LovelaceCard ;
0 commit comments