From 134d1978f8fedb2bf4b8e38580d144c34b592d8b Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 14 Aug 2023 09:29:04 +0200 Subject: [PATCH] Use new select component for direction for more info fan (#17540) --- .../more-info/controls/more-info-fan.ts | 165 +++++++++--------- 1 file changed, 81 insertions(+), 84 deletions(-) diff --git a/src/dialogs/more-info/controls/more-info-fan.ts b/src/dialogs/more-info/controls/more-info-fan.ts index 57a4dd81dd..96a3826cb5 100644 --- a/src/dialogs/more-info/controls/more-info-fan.ts +++ b/src/dialogs/more-info/controls/more-info-fan.ts @@ -1,19 +1,14 @@ import { - mdiCreation, mdiFan, mdiFanOff, mdiPower, mdiRotateLeft, mdiRotateRight, + mdiTuneVariant, } from "@mdi/js"; import { CSSResultGroup, LitElement, PropertyValues, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { stopPropagation } from "../../../common/dom/stop_propagation"; -import { - computeAttributeNameDisplay, - computeAttributeValueDisplay, -} from "../../../common/entity/compute_attribute_display"; -import { computeStateDisplay } from "../../../common/entity/compute_state_display"; import { stateActive } from "../../../common/entity/state_active"; import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-attributes"; @@ -65,17 +60,15 @@ class MoreInfoFan extends LitElement { }); }; - _setReverseDirection() { - this.hass.callService("fan", "set_direction", { - entity_id: this.stateObj!.entity_id, - direction: "reverse", - }); - } + _handleDirection(ev) { + const newVal = ev.target.value; + const oldVal = this.stateObj?.attributes.direction; + + if (!newVal || oldVal === newVal) return; - _setForwardDirection() { this.hass.callService("fan", "set_direction", { entity_id: this.stateObj!.entity_id, - direction: "forward", + direction: newVal, }); } @@ -93,7 +86,7 @@ class MoreInfoFan extends LitElement { } _handleOscillating(ev) { - const newVal = ev.target.value === "yes"; + const newVal = ev.target.value === "on"; this.hass.callService("fan", "oscillate", { entity_id: this.stateObj!.entity_id, @@ -113,12 +106,8 @@ class MoreInfoFan extends LitElement { const forcedState = liveValue != null ? (liveValue ? "on" : "off") : undefined; - const stateDisplay = computeStateDisplay( - this.hass.localize, + const stateDisplay = this.hass.formatEntityState( this.stateObj!, - this.hass.locale, - this.hass.config, - this.hass.entities, forcedState ); @@ -186,49 +175,21 @@ class MoreInfoFan extends LitElement { .iconPathOff=${mdiFanOff} > `} - ${supportSpeedPercentage || supportsDirection - ? html`
- ${supportSpeedPercentage - ? html` - - - - ` - : nothing} - ${supportsDirection - ? html` - - - - - - - ` - : nothing} -
` + ${supportSpeedPercentage + ? html` +
+ ${supportSpeedPercentage + ? html` + + + + ` + : nothing} +
+ ` : nothing}
@@ -236,10 +197,8 @@ class MoreInfoFan extends LitElement { ${supportsPresetMode && this.stateObj.attributes.preset_modes ? html` - + ${this.stateObj.attributes.preset_modes?.map( (mode) => html` - - ${computeAttributeValueDisplay( - this.hass.localize, + + ${this.hass.formatEntityAttributeValue( this.stateObj!, - this.hass.locale, - this.hass.config, - this.hass.entities, "preset_mode", mode )} @@ -270,16 +225,58 @@ class MoreInfoFan extends LitElement { ` : nothing} + ${supportsDirection + ? html` + + + + + ${this.hass.formatEntityAttributeValue( + this.stateObj, + "direction", + "forward" + )} + + + + ${this.hass.formatEntityAttributeValue( + this.stateObj, + "direction", + "reverse" + )} + + + ` + : nothing} ${supportsOscillate ? html` - + - ${this.hass.localize("ui.common.yes")} + ${this.hass.localize("state.default.on")} - + - ${this.hass.localize("ui.common.no")} + ${this.hass.localize("state.default.off")} `