Some preparation work

This commit is contained in:
Thomas Lovén 2018-09-07 12:49:47 +02:00
parent 2c420a47e3
commit a1f3dbf1cd

View File

@ -30,10 +30,10 @@ class SliderEntityRow extends Polymer.Element {
hass="[[_hass]]" hass="[[_hass]]"
> >
<div class="flex"> <div class="flex">
<template is='dom-if' if='{{showTop}}'> <template is='dom-if' if='{{displayTop}}'>
${slider} ${slider}
</template> </template>
<template is='dom-if' if='{{!hideControl}}'> <template is='dom-if' if='{{displayToggle}}'>
<ha-entity-toggle <ha-entity-toggle
state-obj="[[stateObj]]" state-obj="[[stateObj]]"
hass="[[_hass]]" hass="[[_hass]]"
@ -41,7 +41,7 @@ class SliderEntityRow extends Polymer.Element {
</template> </template>
</div> </div>
</hui-generic-entity-row> </hui-generic-entity-row>
<template is='dom-if' if='{{showBottom}}'> <template is='dom-if' if='{{displayBottom}}'>
<div class="second-line"> <div class="second-line">
${slider} ${slider}
</div> </div>
@ -53,9 +53,10 @@ class SliderEntityRow extends Polymer.Element {
return { return {
_hass: Object, _hass: Object,
_config: Object, _config: Object,
hideControl: { type: Boolean, value: false }, hideToggle: { type: Boolean, value: false },
breakSlider: { type: Boolean, value: false }, breakSlider: { type: Boolean, value: false },
hideWhenOff: { type: Boolean, value: false }, hideWhenOff: { type: Boolean, value: false },
showValue: { type: Boolean, value: false },
isOn: { type: Boolean }, isOn: { type: Boolean },
stateObj: { type: Object, value: null }, stateObj: { type: Object, value: null },
min: { type: Number, value: 0 }, min: { type: Number, value: 0 },
@ -69,30 +70,43 @@ class SliderEntityRow extends Polymer.Element {
setConfig(config) setConfig(config)
{ {
this._config = config; this._config = config;
if('hide_control' in config && config.hide_control) this.hideToggle = config.hide_control || config.hide_toggle || false;
this.hideControl = true; this.breakSlider = config.break_slider || false;
if('break_slider' in config && config.break_slider) this.hideWhenOff = config.hide_when_off || false;
this.breakSlider = true; this.showValue = config.show_value || false;
if('hide_when_off' in config && config.hide_when_off)
this.hideWhenOff = true;
} }
updateSliders() updateSliders()
{ {
this.showTop = false; this.displayTop = false;
this.showBottom = false; this.displayBottom = false;
this.displayToggle = true;
this.displayStatus = false;
if(this.hideToggle) this.displayToggle = false;
if(this.showValue) {
this.displayToggle = false;
this.displayStatus = true;
}
if(!(this.stateObj.state === 'on' || this.stateObj.state === 'off')) {
this.displayToggle = false;
this.displayStatus = true;
}
if(this.stateObj.state === 'on' || !this.hideWhenOff) {
this.displayBottom = this.breakSlider;
this.displayTop = !this.breakSlider;
}
if(!(this.attribute in this.stateObj.attributes)) { if(!(this.attribute in this.stateObj.attributes)) {
if(!('supported_features' in this.stateObj.attributes) || if(!('supported_features' in this.stateObj.attributes) ||
!(this.stateObj.attributes['supported_features'] & 1)) { !(this.stateObj.attributes['supported_features'] & 1)) {
return; this.displayTop = this.displayBottom = false;
} }
} }
if(!(this.hideWhenOff && !this.isOn)) {
if(this.breakSlider)
this.showBottom = true;
else
this.showTop = true;
}
} }
set hass(hass) { set hass(hass) {