diff --git a/src/dialogs/more-info/controls/more-info-climate.js b/src/dialogs/more-info/controls/more-info-climate.js index d0c4d419af..3fb90fed61 100644 --- a/src/dialogs/more-info/controls/more-info-climate.js +++ b/src/dialogs/more-info/controls/more-info-climate.js @@ -200,14 +200,15 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { > @@ -224,13 +225,19 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { dynamic-align="" label="[[localize('ui.card.climate.fan_mode')]]" > - + @@ -244,13 +251,17 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { dynamic-align="" label="[[localize('ui.card.climate.swing_mode')]]" > - + @@ -297,23 +308,6 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { observer: "stateObjChanged", }, - operationIndex: { - type: Number, - value: -1, - observer: "handleOperationmodeChanged", - }, - - fanIndex: { - type: Number, - value: -1, - observer: "handleFanmodeChanged", - }, - - swingIndex: { - type: Number, - value: -1, - observer: "handleSwingmodeChanged", - }, awayToggleChecked: Boolean, auxToggleChecked: Boolean, onToggleChecked: Boolean, @@ -346,36 +340,6 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { } } - handleOperationListUpdate() { - // force polymer to recognize selected item change (to update actual label) - this.operationIndex = -1; - if (this.stateObj.attributes.operation_list) { - this.operationIndex = this.stateObj.attributes.operation_list.indexOf( - this.stateObj.attributes.operation_mode - ); - } - } - - handleSwingListUpdate() { - // force polymer to recognize selected item change (to update actual label) - this.swingIndex = -1; - if (this.stateObj.attributes.swing_list) { - this.swingIndex = this.stateObj.attributes.swing_list.indexOf( - this.stateObj.attributes.swing_mode - ); - } - } - - handleFanListUpdate() { - // force polymer to recognize selected item change (to update actual label) - this.fanIndex = -1; - if (this.stateObj.attributes.fan_list) { - this.fanIndex = this.stateObj.attributes.fan_list.indexOf( - this.stateObj.attributes.fan_mode - ); - } - } - computeTemperatureStepSize(hass, stateObj) { if (stateObj.attributes.target_temp_step) { return stateObj.attributes.target_temp_step; @@ -517,33 +481,27 @@ class MoreInfoClimate extends LocalizeMixin(EventsMixin(PolymerElement)) { this.callServiceHelper(newVal ? "turn_on" : "turn_off", {}); } - handleFanmodeChanged(fanIndex) { - // Selected Option will transition to '' before transitioning to new value - if (fanIndex === "" || fanIndex === -1) return; - const fanInput = this.stateObj.attributes.fan_list[fanIndex]; - if (fanInput === this.stateObj.attributes.fan_mode) return; - this.callServiceHelper("set_fan_mode", { fan_mode: fanInput }); + handleFanmodeChanged(ev) { + const oldVal = this.stateObj.attributes.fan_mode; + const newVal = ev.detail.value; + if (!newVal || oldVal === newVal) return; + this.callServiceHelper("set_fan_mode", { fan_mode: newVal }); } - handleOperationmodeChanged(operationIndex) { - // Selected Option will transition to '' before transitioning to new value - if (operationIndex === "" || operationIndex === -1) return; - const operationInput = this.stateObj.attributes.operation_list[ - operationIndex - ]; - if (operationInput === this.stateObj.attributes.operation_mode) return; - + handleOperationmodeChanged(ev) { + const oldVal = this.stateObj.attributes.operation_mode; + const newVal = ev.detail.value; + if (!newVal || oldVal === newVal) return; this.callServiceHelper("set_operation_mode", { - operation_mode: operationInput, + operation_mode: newVal, }); } - handleSwingmodeChanged(swingIndex) { - // Selected Option will transition to '' before transitioning to new value - if (swingIndex === "" || swingIndex === -1) return; - const swingInput = this.stateObj.attributes.swing_list[swingIndex]; - if (swingInput === this.stateObj.attributes.swing_mode) return; - this.callServiceHelper("set_swing_mode", { swing_mode: swingInput }); + handleSwingmodeChanged(ev) { + const oldVal = this.stateObj.attributes.swing_mode; + const newVal = ev.detail.value; + if (!newVal || oldVal === newVal) return; + this.callServiceHelper("set_swing_mode", { swing_mode: newVal }); } callServiceHelper(service, data) { diff --git a/src/dialogs/more-info/controls/more-info-fan.js b/src/dialogs/more-info/controls/more-info-fan.js index a57b702f9f..63837ea052 100644 --- a/src/dialogs/more-info/controls/more-info-fan.js +++ b/src/dialogs/more-info/controls/more-info-fan.js @@ -49,12 +49,17 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { dynamic-align="" label="[[localize('ui.card.fan.speed')]]" > - + @@ -108,12 +113,6 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { observer: "stateObjChanged", }, - speedIndex: { - type: Number, - value: -1, - observer: "speedChanged", - }, - oscillationToggleChecked: { type: Boolean, }, @@ -124,9 +123,6 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { if (newVal) { this.setProperties({ oscillationToggleChecked: newVal.attributes.oscillating, - speedIndex: newVal.attributes.speed_list - ? newVal.attributes.speed_list.indexOf(newVal.attributes.speed) - : -1, }); } @@ -144,17 +140,15 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { ); } - speedChanged(speedIndex) { - var speedInput; - // Selected Option will transition to '' before transitioning to new value - if (speedIndex === "" || speedIndex === -1) return; + speedChanged(ev) { + var oldVal = this.stateObj.attributes.speed; + var newVal = ev.detail.value; - speedInput = this.stateObj.attributes.speed_list[speedIndex]; - if (speedInput === this.stateObj.attributes.speed) return; + if (!newVal || oldVal === newVal) return; this.hass.callService("fan", "turn_on", { entity_id: this.stateObj.entity_id, - speed: speedInput, + speed: newVal, }); } diff --git a/src/dialogs/more-info/controls/more-info-media_player.js b/src/dialogs/more-info/controls/more-info-media_player.js index fd22c1a111..495cb33fbd 100644 --- a/src/dialogs/more-info/controls/more-info-media_player.js +++ b/src/dialogs/more-info/controls/more-info-media_player.js @@ -157,7 +157,8 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {