From 1eee03c8bdb6c0815b2eaecd8b68013f15bf9917 Mon Sep 17 00:00:00 2001 From: Raymond Julin Date: Sun, 9 Aug 2020 23:34:14 +0200 Subject: [PATCH] Safeguard against a JS error when a non-existant entity is used --- package.json | 1 - src/filterEntity.js | 3 +++ src/index.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0428ad4..7216b8a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "@babel/core": "^7.10.3", "@babel/register": "^7.10.3", "@rollup/plugin-commonjs": "^13.0.0", - "@ava/babel-preset-stage-4": "^4.0.0", "ava": "^3.9.0", "husky": "^4.2.5", "prettier": "^1.18.2", diff --git a/src/filterEntity.js b/src/filterEntity.js index 48a0eba..448bf77 100644 --- a/src/filterEntity.js +++ b/src/filterEntity.js @@ -38,6 +38,9 @@ function compareValue(expect, real) { // And the entire HASS state tree // this function will determine if the passed entity passes filtering rules or not function filterEntity(config, allStates) { + if (!allStates.hasOwnProperty(config.entity)) { + return false; + } if (config.when) { const { state: expect, entity = config.entity, attributes } = typeof config.when === "string" ? { state: config.when } : config.when; diff --git a/src/index.js b/src/index.js index de320f0..c28a088 100644 --- a/src/index.js +++ b/src/index.js @@ -97,7 +97,7 @@ class BannerCard extends LitElement { this._hass = hass; // Parse new state values for _entities_ - this.entityValues = this.entities + this.entityValues = (this.entities || []) .filter(conf => filterEntity(conf, hass.states)) .map(conf => this.parseEntity(conf)); }