commit 063cb5bbbfd0481454c469b16cbd00dbba9f1d34 Author: Thomas Lovén Date: Wed Aug 15 22:21:48 2018 +0200 Proof of concept diff --git a/README.md b/README.md new file mode 100644 index 0000000..53d0149 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +slider-entity-row +================= + + +Proof of concept + +No support given - if you don't know how to get this to work, that is probably a good thing for now. diff --git a/slider-entity-row.js b/slider-entity-row.js new file mode 100644 index 0000000..ad9820f --- /dev/null +++ b/slider-entity-row.js @@ -0,0 +1,82 @@ +class SliderEntityRowSlider extends Polymer.Element { + + static get template() { + return Polymer.html` + + + `; + } + + ready() { + super.ready(); + this.addEventListener('click', ev => ev.stopPropagation()); + } + + valueChanged(ev) { + const value = parseInt(this.value, 10); + const param = {entity_id: this.stateObj.entity_id }; + if(Number.isNaN(value)) return; + if(value === 0) { + this.hass.callService('light', 'turn_off', param); + } else { + param['brightness'] = value; + this.hass.callService('light', 'turn_on', param); + } + } + +} + +customElements.define('slider-entity-row-slider', SliderEntityRowSlider); + +class SliderEntityRow extends HTMLElement { + static get template() { + console.log("Template"); + } + + constructor() { + super(); + this.attachShadow({mode:'open'}); + this.base = document.createElement('hui-generic-entity-row'); + + this.slider = document.createElement('slider-entity-row-slider'); + this.toggle = document.createElement('ha-entity-toggle'); + + this.base.appendChild(this.slider); + this.base.appendChild(this.toggle); + this.shadowRoot.appendChild(this.base); + } + + setConfig(config) + { + this.base.config = config; + this.entity = config.entity; + console.log(this.base); + } + + set hass(hass) { + this.base.hass = hass; + this.toggle.hass = hass; + this.slider.hass = hass; + let stateObj = hass.states[this.entity]; + this.toggle.stateObj = stateObj; + this.slider.stateObj = stateObj; + this.slider.value = this.isOn(stateObj) ? stateObj.attributes['brightness']: 0; + } + + isOn(stateObj) { + return stateObj && stateObj.state === 'on'; + } + +} + +customElements.define('slider-entity-row', SliderEntityRow);