Skip to content

Commit

Permalink
Allow override of name in config
Browse files Browse the repository at this point in the history
  • Loading branch information
gadgetchnnel authored Apr 19, 2019
1 parent 3ebaf1b commit f434658
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lovelace-text-input-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ class TextInputRow extends Polymer.Element {
this._hass.callService('input_text', 'set_value', param);
}

computeObjectId(entityId) {
return entityId.substr(entityId.indexOf(".") + 1);
}

computeStateName(stateObj){
return stateObj.attributes.friendly_name === undefined
? this.computeObjectId(stateObj.entity_id).replace(/_/g, " ")
: stateObj.attributes.friendly_name || "";
}

set hass(hass) {
this._hass = hass;
this.stateObj = hass.states[this._config.entity];
Expand All @@ -44,11 +54,9 @@ class TextInputRow extends Polymer.Element {
this.maxlength = this.stateObj.attributes.max;
this.pattern = this.stateObj.attributes.pattern;
this.mode = this.minlength = this.stateObj.attributes.mode;
this.label = this.stateObj.attributes.friendly_name;
this.label = this._config.name ? this._config.name : this.computeStateName(this.stateObj);
}
}


}

customElements.define('text-input-row', TextInputRow);

0 comments on commit f434658

Please sign in to comment.