Skip to content

Commit

Permalink
Safeguard against a JS error when a non-existant entity is used
Browse files Browse the repository at this point in the history
  • Loading branch information
nervetattoo committed Aug 9, 2020
1 parent c9e16e0 commit 1eee03c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/filterEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 1eee03c

Please sign in to comment.