+
+
+
+
+
+ `;
+ }
+
+ 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' ){