diff --git a/src/dialogs/more-info/controls/more-info-fan.ts b/src/dialogs/more-info/controls/more-info-fan.ts index ae841e996c..57a4dd81dd 100644 --- a/src/dialogs/more-info/controls/more-info-fan.ts +++ b/src/dialogs/more-info/controls/more-info-fan.ts @@ -6,7 +6,7 @@ import { mdiRotateLeft, mdiRotateRight, } from "@mdi/js"; -import { CSSResultGroup, html, LitElement, nothing, PropertyValues } from "lit"; +import { CSSResultGroup, LitElement, PropertyValues, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { @@ -17,15 +17,16 @@ import { computeStateDisplay } from "../../../common/entity/compute_state_displa import { stateActive } from "../../../common/entity/state_active"; import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-attributes"; -import "../../../components/ha-outlined-button"; +import "../../../components/ha-control-select-menu"; +import "../../../components/ha-list-item"; import "../../../components/ha-outlined-icon-button"; import { UNAVAILABLE } from "../../../data/entity"; import { - computeFanSpeedCount, - computeFanSpeedStateDisplay, + FAN_SPEED_COUNT_MAX_FOR_BUTTONS, FanEntity, FanEntityFeature, - FAN_SPEED_COUNT_MAX_FOR_BUTTONS, + computeFanSpeedCount, + computeFanSpeedStateDisplay, } from "../../../data/fan"; import { forwardHaptic } from "../../../data/haptics"; import { haOscillating } from "../../../data/icons/haOscillating"; @@ -78,20 +79,8 @@ class MoreInfoFan extends LitElement { }); } - _toggleOscillate() { - const oscillating = this.stateObj!.attributes.oscillating; - this.hass.callService("fan", "oscillate", { - entity_id: this.stateObj!.entity_id, - oscillating: !oscillating, - }); - } - _handlePresetMode(ev) { - ev.stopPropagation(); - ev.preventDefault(); - - const index = ev.detail.index; - const newVal = this.stateObj!.attributes.preset_modes![index]; + const newVal = ev.target.value; const oldVal = this._presetMode; if (!newVal || oldVal === newVal) return; @@ -103,6 +92,15 @@ class MoreInfoFan extends LitElement { }); } + _handleOscillating(ev) { + const newVal = ev.target.value === "yes"; + + this.hass.callService("fan", "oscillate", { + entity_id: this.stateObj!.entity_id, + oscillating: newVal, + }); + } + protected updated(changedProps: PropertyValues): void { if (changedProps.has("stateObj")) { this._presetMode = this.stateObj?.attributes.preset_mode; @@ -170,162 +168,147 @@ class MoreInfoFan extends LitElement { .stateOverride=${this._stateOverride} >
- ${ - supportsSpeed - ? html` - - - ` - : html` - - ` - } - ${ - supportSpeedPercentage || supportsDirection || supportsOscillate - ? html`
- ${supportSpeedPercentage - ? html` - - - - ` - : nothing} - ${supportsDirection - ? html` - - - - - - - ` - : nothing} - ${supportsOscillate - ? html` - - - - ` - : nothing} -
` - : nothing - } - ${ - supportsPresetMode && this.stateObj.attributes.preset_modes - ? html` - - + + ` + : html` + + `} + ${supportSpeedPercentage || supportsDirection + ? html`
+ ${supportSpeedPercentage + ? html` + - ${this._presetMode - ? computeAttributeValueDisplay( - this.hass.localize, - this.stateObj!, - this.hass.locale, - this.hass.config, - this.hass.entities, - "preset_mode", - this._presetMode - ) - : computeAttributeNameDisplay( - this.hass.localize, - this.stateObj, - this.hass.entities, - "preset_mode" - )} - - - ${this.stateObj.attributes.preset_modes?.map( - (mode) => html` - - ${computeAttributeValueDisplay( - this.hass.localize, - this.stateObj!, - this.hass.locale, - this.hass.config, - this.hass.entities, - "preset_mode", - mode - )} - - ` - )} - - ` - : nothing - } + + + ` + : nothing} + ${supportsDirection + ? html` + + + + + + + ` + : nothing} +
` + : nothing} +
+
+
+ ${supportsPresetMode && this.stateObj.attributes.preset_modes + ? html` + + + ${this.stateObj.attributes.preset_modes?.map( + (mode) => html` + + ${computeAttributeValueDisplay( + this.hass.localize, + this.stateObj!, + this.hass.locale, + this.hass.config, + this.hass.entities, + "preset_mode", + mode + )} + + ` + )} + + ` + : nothing} + ${supportsOscillate + ? html` + + + + + ${this.hass.localize("ui.common.yes")} + + + + ${this.hass.localize("ui.common.no")} + + + ` + : nothing}
-
`; }