From afdb369e04e554cb462105a761ff17e7ae75bca5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 28 Jan 2021 09:24:18 -0600 Subject: [PATCH] Separate fan speeds into percentages and presets modes (#8216) --- src/data/fan.ts | 4 ++ .../more-info/controls/more-info-fan.js | 65 +++++++++++++++---- src/translations/en.json | 1 + 3 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 src/data/fan.ts diff --git a/src/data/fan.ts b/src/data/fan.ts new file mode 100644 index 0000000000..7fe1e8af52 --- /dev/null +++ b/src/data/fan.ts @@ -0,0 +1,4 @@ +export const SUPPORT_SET_SPEED = 1; +export const SUPPORT_OSCILLATE = 2; +export const SUPPORT_DIRECTION = 4; +export const SUPPORT_PRESET_MODE = 8; diff --git a/src/dialogs/more-info/controls/more-info-fan.js b/src/dialogs/more-info/controls/more-info-fan.js index fde009e367..a5b1b5df52 100644 --- a/src/dialogs/more-info/controls/more-info-fan.js +++ b/src/dialogs/more-info/controls/more-info-fan.js @@ -5,12 +5,15 @@ import { html } from "@polymer/polymer/lib/utils/html-tag"; /* eslint-plugin-disable lit */ import { PolymerElement } from "@polymer/polymer/polymer-element"; import { attributeClassNames } from "../../../common/entity/attribute_class_names"; +import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-attributes"; import "../../../components/ha-icon-button"; +import "../../../components/ha-labeled-slider"; import "../../../components/ha-paper-dropdown-menu"; import "../../../components/ha-switch"; import { EventsMixin } from "../../../mixins/events-mixin"; import LocalizeMixin from "../../../mixins/localize-mixin"; +import { SUPPORT_SET_SPEED } from "../../../data/fan"; /* * @appliesMixin EventsMixin @@ -20,13 +23,15 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { return html`
-
+
+ +
+ +
@@ -96,7 +113,7 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { `; } @@ -115,6 +132,10 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { oscillationToggleChecked: { type: Boolean, }, + + percentageSliderValue: { + type: Number, + }, }; } @@ -122,6 +143,7 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { if (newVal) { this.setProperties({ oscillationToggleChecked: newVal.attributes.oscillating, + percentageSliderValue: newVal.attributes.percentage, }); } @@ -135,19 +157,36 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) { computeClassNames(stateObj) { return ( "more-info-fan " + - attributeClassNames(stateObj, ["oscillating", "speed_list", "direction"]) + (supportsFeature(stateObj, SUPPORT_SET_SPEED) ? "has-percentage " : "") + + (stateObj.attributes.preset_modes && + stateObj.attributes.preset_modes.length + ? "has-preset_modes " + : "") + + attributeClassNames(stateObj, ["oscillating", "direction"]) ); } - speedChanged(ev) { - const oldVal = this.stateObj.attributes.speed; + presetModeChanged(ev) { + const oldVal = this.stateObj.attributes.preset_mode; const newVal = ev.detail.value; if (!newVal || oldVal === newVal) return; - this.hass.callService("fan", "turn_on", { + this.hass.callService("fan", "set_preset_mode", { entity_id: this.stateObj.entity_id, - speed: newVal, + preset_mode: newVal, + }); + } + + percentageChanged(ev) { + const oldVal = parseInt(this.stateObj.attributes.percentage, 10); + const newVal = ev.target.value; + + if (isNaN(newVal) || oldVal === newVal) return; + + this.hass.callService("fan", "set_percentage", { + entity_id: this.stateObj.entity_id, + percentage: newVal, }); } diff --git a/src/translations/en.json b/src/translations/en.json index efcab1801e..7f225af03c 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -157,6 +157,7 @@ }, "fan": { "speed": "Speed", + "preset_mode": "Preset Mode", "oscillate": "Oscillate", "direction": "Direction", "forward": "Forward",