Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Added check to verify that the attribute exists in provided entityId. (
Browse files Browse the repository at this point in the history
…#10)

* Added check to verify that the attribute exists in provided entityId.
Added error detail to the innerHTML to notify user of the problem with attribute provided.
This previously would cause an error and would crash lovelace cards that this custom element was used in.

* Updated README.md and VERSION.

* Update README.md
  • Loading branch information
ccmacaluso authored and ludeeus committed Jul 18, 2019
1 parent 35212f8 commit af633ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2.0
0.3.0
9 changes: 7 additions & 2 deletions state-attribute-element.js
Expand Up @@ -11,8 +11,13 @@ class StateAttributeElement extends HTMLElement {
this.state = hass.states[entityId].attributes[attr][sub_attribute]
}
const card = document.createElement('state-attribute-element');
if (this.state.length != 0 || show_empty === true) {
this.innerHTML = `${prefix_string}${this.state}${suffix_string}`
if (this.state) {
if (this.state.length != 0 || show_empty === true) {
this.innerHTML = `${prefix_string}${this.state}${suffix_string}`
}
}
else {
this.innerHTML = 'Attribute: ' + attr + ' does not exist in entity: ' + entityId + '.'
}
}
setConfig(config) {
Expand Down

0 comments on commit af633ab

Please sign in to comment.