Make the element more well behaved
This commit is contained in:
parent
ba8f5049de
commit
cde2a9bc93
@ -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,12 +177,15 @@ class SliderEntityRow extends Polymer.Element {
|
|||||||
|
|
||||||
set hass(hass) {
|
set hass(hass) {
|
||||||
this._hass = hass;
|
this._hass = hass;
|
||||||
|
|
||||||
|
if(hass && this._config) {
|
||||||
this.stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
|
this.stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
|
||||||
if(this.stateObj) {
|
if(this.stateObj) {
|
||||||
this.value = this.controller.get(this.stateObj);
|
this.value = this.controller.get(this.stateObj);
|
||||||
this.displaySlider = this.controller.supported(this.stateObj);
|
this.displaySlider = this.controller.supported(this.stateObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
selectedValue(ev) {
|
selectedValue(ev) {
|
||||||
this.controller.set(this.stateObj, parseInt(this.value, 10));
|
this.controller.set(this.stateObj, parseInt(this.value, 10));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user