Skip to content

Commit cfa46bc

Browse files
Entity icons not updating on state change (#281)
1 parent 6ac62ab commit cfa46bc

7 files changed

Lines changed: 40 additions & 29 deletions

File tree

info.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{% if installed %}
22

33
### Features
4+
{% if version_installed.replace("v", "").replace(".","") | int < 10802 %}
5+
- Fixed `Entity icons not updating on state change`
6+
{% endif %}
7+
48
{% if version_installed.replace("v", "").replace(".","") | int < 10800 %}
59
- Fixed `Changed loading of cards to await dependencies`
610
{% endif %}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "room-card",
3-
"version": "1.08.01",
3+
"version": "1.08.02",
44
"description": "Show entities in Home Assistant's Lovelace UI",
55
"keywords": [
66
"home-assistant",

room-card.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

room-card.js.gz

3 Bytes
Binary file not shown.

src/index.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { checkConfig, entityStyles, renderEntitiesRow, renderInfoEntity, renderR
77
import { getEntityIds, parseConfig } from './util';
88
import { hideIfCard } from './hide';
99
import { style } from './styles';
10-
import { RoomCardConfig, RoomCardLovelaceCardConfig } from './types/room-card-types';
10+
import { HomeAssistantEntity, RoomCardConfig, RoomCardLovelaceCardConfig } from './types/room-card-types';
1111
import * as packageJson from '../package.json';
1212

1313
console.info(
@@ -28,9 +28,7 @@ console.info(
2828

2929
@customElement('room-card')
3030
export 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;

tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ describe('Testing index file class RoomCard', () => {
420420

421421
const result = roomcard.createCardElement(config, hass);
422422

423-
expect(result).toBeUndefined();
423+
expect(result).toBeDefined();
424424
}),
425425
test('Calling createCardElement with config.show_states true', () => {
426426
hass.states['light.test_entity'].state = 'test';

0 commit comments

Comments
 (0)