Make the element more well behaved

This commit is contained in:
Thomas Lovén 2019-02-14 12:11:01 +01:00
parent ba8f5049de
commit cde2a9bc93

View File

@ -1,6 +1,8 @@
class SliderEntityRow extends Polymer.Element {
static get template() {
if(!this._hass || !this._config)
return Polymer.html``;
const style = Polymer.html`
<style>
.flex {
@ -157,6 +159,14 @@ class SliderEntityRow extends Polymer.Element {
this.min = config.min || 0;
this.max = config.max || 100;
this.step = config.step || 5;
if(this._hass && this._config) {
this.stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
if(this.stateObj) {
this.value = this.controller.get(this.stateObj);
this.displaySlider = this.controller.supported(this.stateObj);
}
}
}
statusString(stateObj) {
@ -167,12 +177,15 @@ class SliderEntityRow extends Polymer.Element {
set hass(hass) {
this._hass = hass;
if(hass && this._config) {
this.stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
if(this.stateObj) {
this.value = this.controller.get(this.stateObj);
this.displaySlider = this.controller.supported(this.stateObj);
}
}
}
selectedValue(ev) {
this.controller.set(this.stateObj, parseInt(this.value, 10));