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