From f434658a0e2faf779f85e73c461143704250cedd Mon Sep 17 00:00:00 2001 From: Steven Rollason <2099542+gadgetchnnel@users.noreply.github.com> Date: Fri, 19 Apr 2019 09:25:00 +0100 Subject: [PATCH] Allow override of name in config --- lovelace-text-input-row.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lovelace-text-input-row.js b/lovelace-text-input-row.js index 0d5a779..dd66601 100644 --- a/lovelace-text-input-row.js +++ b/lovelace-text-input-row.js @@ -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]; @@ -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);