diff --git a/dist/binary-control-button-row.js b/dist/binary-control-button-row.js index d59b116..00682df 100644 --- a/dist/binary-control-button-row.js +++ b/dist/binary-control-button-row.js @@ -6,12 +6,48 @@ window.customCards.push({ preview: false, }); -class CustomBinaryRow extends Polymer.Element { +const LitElement = customElements.get("ha-panel-lovelace") ? Object.getPrototypeOf(customElements.get("ha-panel-lovelace")) : Object.getPrototypeOf(customElements.get("hc-lovelace")); +const html = LitElement.prototype.html; +const css = LitElement.prototype.css; - static get template() { - return Polymer.html` - - - -
- - -
-
`; } - static get properties() { - return { - hass: { - type: Object, - observer: 'hassChanged' - }, - _config: Object, - _stateObj: Object, - _width: String, - _height: String, - _leftColor: String, - _leftText: String, - _leftName: String, - _leftState: Boolean, - _rightColor: String, - _rightText: String, - _rightName: String, - _rightState: Boolean, - } - } + render() { + return html` + +
+ + +
+
+ `; + } + + firstUpdated() { + super.firstUpdated(); + this.shadowRoot.getElementById('button-container').addEventListener('click', (ev) => ev.stopPropagation()); + } setConfig(config) { - this._config = config; + this._config = { ...this._config, ...config }; + } - this._config = { - customTheme: false, - reverseButtons: false, - width: '30px', - height: '30px', - isOnColor: '#43A047', - isOffColor: '#f44c09', - buttonInactiveColor: '#759aaa', - customOffText: 'OFF', - customOnText: 'ON', - ...config - }; + updated(changedProperties) { + if (changedProperties.has("hass")) { + this.hassChanged(); + } } hassChanged(hass) { - const config = this._config; - const stateObj = hass.states[config.entity]; + const stateObj = this.hass.states[config.entity]; const custTheme = config.customTheme; const revButtons = config.reverseButtons; const buttonWidth = config.width; @@ -155,41 +171,33 @@ class CustomBinaryRow extends Polymer.Element { let onname = 'on'; if (revButtons) { - this.setProperties({ - _stateObj: stateObj, - _rightState: stateObj.state === 'on', - _leftState: stateObj.state == 'off', - _width: buttonwidth, - _height: buttonheight, - _rightName: onname, - _leftName: offname, - _rightColor: oncolor, - _leftColor: offcolor, - _rightText: ontext, - _leftText: offtext, - }); + this._stateObj = stateObj; + this._rightState = stateObj.state === 'on'; + this._leftState = stateObj.state == 'off'; + this._width = buttonwidth; + this._height = buttonheight; + this._rightName = onname; + this._leftName = offname; + this._rightColor = oncolor; + this._leftColor = offcolor; + this._rightText = ontext; + this._leftText = offtext; } else { - this.setProperties({ - _stateObj: stateObj, - _leftState: stateObj.state === 'on', - _rightState: stateObj.state == 'off', - _width: buttonwidth, - _height: buttonheight, - _leftName: onname, - _rightName: offname, - _leftColor: oncolor, - _rightColor: offcolor, - _leftText: ontext, - _rightText: offtext, - }); + this._stateObj = stateObj; + this._leftState = stateObj.state === 'on'; + this._rightState = stateObj.state == 'off'; + this._width = buttonwidth; + this._height = buttonheight; + this._leftName = onname; + this._rightName = offname; + this._leftColor = oncolor; + this._rightColor = offcolor; + this._leftText = ontext; + this._rightText = offtext; } - } + } - stopPropagation(e) { - e.stopPropagation(); - } - setState(e) { const state = e.currentTarget.getAttribute('name'); if( state == 'off' ){