Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity icons not updating on state change #281

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% if installed %}

### Features
{% if version_installed.replace("v", "").replace(".","") | int < 10802 %}
- Fixed `Entity icons not updating on state change`
{% endif %}

{% if version_installed.replace("v", "").replace(".","") | int < 10800 %}
- Fixed `Changed loading of cards to await dependencies`
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "room-card",
"version": "1.08.01",
"version": "1.08.02",
"description": "Show entities in Home Assistant's Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
6 changes: 3 additions & 3 deletions room-card.js

Large diffs are not rendered by default.

Binary file modified room-card.js.gz
Binary file not shown.
51 changes: 29 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { checkConfig, entityStyles, renderEntitiesRow, renderInfoEntity, renderR
import { getEntityIds, parseConfig } from './util';
import { hideIfCard } from './hide';
import { style } from './styles';
import { RoomCardConfig, RoomCardLovelaceCardConfig } from './types/room-card-types';
import { HomeAssistantEntity, RoomCardConfig, RoomCardLovelaceCardConfig } from './types/room-card-types';
import * as packageJson from '../package.json';

console.info(
Expand All @@ -28,9 +28,7 @@ console.info(

@customElement('room-card')
export default class RoomCard extends LitElement {
private _hass?: HomeAssistant;
@property() monitoredStates?: HassEntities = {};
@property() config?: RoomCardConfig;
@property() _helpers: { createCardElement(config: LovelaceCardConfig): LovelaceCard }

getChildCustomCardTypes(cards: RoomCardLovelaceCardConfig[], target: Set<string>) {
Expand All @@ -50,20 +48,6 @@ export default class RoomCard extends LitElement {
await Promise.all(Array.from(distinctTypes).map(type => customElements.whenDefined(type)));
}

async setConfig(config: RoomCardConfig) {
checkConfig(config);
const entityIds = getEntityIds(config);
this.config = { ...config, entityIds: entityIds };

await this.waitForDependentComponents(config);

/* istanbul ignore next */
/* eslint-disable @typescript-eslint/no-explicit-any */
if ((window as any).loadCardHelpers) {
this._helpers = await (window as any).loadCardHelpers();
}
}

protected shouldUpdate(changedProps: PropertyValues): boolean {
const result = this.monitoredStates !== undefined
&& this.config !== undefined
Expand All @@ -81,7 +65,7 @@ export default class RoomCard extends LitElement {
for (const entityId of this.config.entityIds) {
if (entityId in hass.states) {
const monitoredEntity = this.monitoredStates && this.monitoredStates[entityId];

/* istanbul ignore next */
if (!this.monitoredStates || monitoredEntity?.last_updated < hass.states[entityId].last_updated ||
monitoredEntity?.last_changed < hass.states[entityId].last_changed) {
Expand All @@ -99,11 +83,34 @@ export default class RoomCard extends LitElement {
}
}

@property()
get hass() { return this._hass; }
@property() _hass?: HomeAssistant;
@property() config?: RoomCardConfig;

private stateObj: HomeAssistantEntity | undefined;

async setConfig(config: RoomCardConfig) {

checkConfig(config);

this.config = { ...config, entityIds: getEntityIds(config) };

await this.waitForDependentComponents(config);

/* istanbul ignore next */
/* eslint-disable @typescript-eslint/no-explicit-any */
if ((window as any).loadCardHelpers) {
this._helpers = await (window as any).loadCardHelpers();
}
}

set hass(hass: HomeAssistant) {
this.updateMonitoredStates(hass);
this._hass = hass;

if (hass && this.config) {
this.updateMonitoredStates(hass);

this.config.hass = hass;
}
}

static get styles(): CSSResult {
Expand Down Expand Up @@ -148,7 +155,7 @@ export default class RoomCard extends LitElement {
hideIfCard(config, hass) ||
(config.show_states && !config.show_states.includes(hass.states[config.entity].state))
) {
return;
return null;
}

let element: LovelaceCard;
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ describe('Testing index file class RoomCard', () => {

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

expect(result).toBeUndefined();
expect(result).toBeDefined();
}),
test('Calling createCardElement with config.show_states true', () => {
hass.states['light.test_entity'].state = 'test';
Expand Down
Loading