| 
 | 1 | +import { mdiWaterBoiler } from "@mdi/js";  | 
1 | 2 | import type { PropertyValues, TemplateResult } from "lit";  | 
2 | 3 | import { html, LitElement } from "lit";  | 
3 |  | -import { customElement, property, state } from "lit/decorators";  | 
 | 4 | +import { customElement, property, query, state } from "lit/decorators";  | 
4 | 5 | import { styleMap } from "lit/directives/style-map";  | 
 | 6 | +import { stopPropagation } from "../../../common/dom/stop_propagation";  | 
5 | 7 | import { computeDomain } from "../../../common/entity/compute_domain";  | 
6 | 8 | import { stateColorCss } from "../../../common/entity/state_color";  | 
7 |  | -import "../../../components/ha-control-button";  | 
8 |  | -import "../../../components/ha-control-button-group";  | 
9 | 9 | import "../../../components/ha-control-select";  | 
10 | 10 | import type { ControlSelectOption } from "../../../components/ha-control-select";  | 
11 |  | -import "../../../components/ha-control-slider";  | 
12 |  | -import { UNAVAILABLE } from "../../../data/entity";  | 
 | 11 | +import "../../../components/ha-control-select-menu";  | 
 | 12 | +import type { HaControlSelectMenu } from "../../../components/ha-control-select-menu";  | 
 | 13 | +import "../../../components/ha-list-item";  | 
13 | 14 | import type {  | 
14 | 15 |   OperationMode,  | 
15 | 16 |   WaterHeaterEntity,  | 
16 | 17 | } from "../../../data/water_heater";  | 
17 | 18 | import {  | 
18 |  | -  compareWaterHeaterOperationMode,  | 
19 | 19 |   computeOperationModeIcon,  | 
 | 20 | +  compareWaterHeaterOperationMode,  | 
20 | 21 | } from "../../../data/water_heater";  | 
 | 22 | +import { UNAVAILABLE } from "../../../data/entity";  | 
21 | 23 | import type { HomeAssistant } from "../../../types";  | 
22 | 24 | import type { LovelaceCardFeature, LovelaceCardFeatureEditor } from "../types";  | 
23 | 25 | import { cardFeatureStyles } from "./common/card-feature-styles";  | 
24 | 26 | import { filterModes } from "./common/filter-modes";  | 
25 | 27 | import type {  | 
26 |  | -  LovelaceCardFeatureContext,  | 
27 | 28 |   WaterHeaterOperationModesCardFeatureConfig,  | 
 | 29 | +  LovelaceCardFeatureContext,  | 
28 | 30 | } from "./types";  | 
29 | 31 | 
 
  | 
30 | 32 | export const supportsWaterHeaterOperationModesCardFeature = (  | 
@@ -52,6 +54,9 @@ class HuiWaterHeaterOperationModeCardFeature  | 
52 | 54 | 
 
  | 
53 | 55 |   @state() _currentOperationMode?: OperationMode;  | 
54 | 56 | 
 
  | 
 | 57 | +  @query("ha-control-select-menu", true)  | 
 | 58 | +  private _haSelect?: HaControlSelectMenu;  | 
 | 59 | + | 
55 | 60 |   private get _stateObj() {  | 
56 | 61 |     if (!this.hass || !this.context || !this.context.entity_id) {  | 
57 | 62 |       return undefined;  | 
@@ -97,8 +102,23 @@ class HuiWaterHeaterOperationModeCardFeature  | 
97 | 102 |     }  | 
98 | 103 |   }  | 
99 | 104 | 
 
  | 
 | 105 | +  protected updated(changedProps: PropertyValues) {  | 
 | 106 | +    super.updated(changedProps);  | 
 | 107 | +    if (this._haSelect && changedProps.has("hass")) {  | 
 | 108 | +      const oldHass = changedProps.get("hass") as HomeAssistant | undefined;  | 
 | 109 | +      if (  | 
 | 110 | +        this.hass &&  | 
 | 111 | +        this.hass.formatEntityAttributeValue !==  | 
 | 112 | +          oldHass?.formatEntityAttributeValue  | 
 | 113 | +      ) {  | 
 | 114 | +        this._haSelect.layoutOptions();  | 
 | 115 | +      }  | 
 | 116 | +    }  | 
 | 117 | +  }  | 
 | 118 | + | 
100 | 119 |   private async _valueChanged(ev: CustomEvent) {  | 
101 |  | -    const mode = (ev.detail as any).value as OperationMode;  | 
 | 120 | +    const mode =  | 
 | 121 | +      (ev.detail as any).value ?? ((ev.target as any).value as OperationMode);  | 
102 | 122 | 
 
  | 
103 | 123 |     if (mode === this._stateObj!.state) return;  | 
104 | 124 | 
 
  | 
@@ -143,9 +163,48 @@ class HuiWaterHeaterOperationModeCardFeature  | 
143 | 163 |     ).map<ControlSelectOption>((mode) => ({  | 
144 | 164 |       value: mode,  | 
145 | 165 |       label: this.hass!.formatEntityState(this._stateObj!, mode),  | 
146 |  | -      path: computeOperationModeIcon(mode as OperationMode),  | 
 | 166 | +      icon: html`  | 
 | 167 | +        <ha-svg-icon  | 
 | 168 | +          slot="graphic"  | 
 | 169 | +          .path=${computeOperationModeIcon(mode as OperationMode)}  | 
 | 170 | +        ></ha-svg-icon>  | 
 | 171 | +      `,  | 
147 | 172 |     }));  | 
148 | 173 | 
 
  | 
 | 174 | +    if (this._config.style === "dropdown") {  | 
 | 175 | +      return html`  | 
 | 176 | +        <ha-control-select-menu  | 
 | 177 | +          show-arrow  | 
 | 178 | +          hide-label  | 
 | 179 | +          .label=${this.hass.localize("ui.card.water_heater.mode")}  | 
 | 180 | +          .value=${this._currentOperationMode}  | 
 | 181 | +          .disabled=${this._stateObj.state === UNAVAILABLE}  | 
 | 182 | +          fixedMenuPosition  | 
 | 183 | +          naturalMenuWidth  | 
 | 184 | +          @selected=${this._valueChanged}  | 
 | 185 | +          @closed=${stopPropagation}  | 
 | 186 | +        >  | 
 | 187 | +          ${this._currentOperationMode  | 
 | 188 | +            ? html`  | 
 | 189 | +                <ha-svg-icon  | 
 | 190 | +                  slot="icon"  | 
 | 191 | +                  .path=${computeOperationModeIcon(this._currentOperationMode)}  | 
 | 192 | +                ></ha-svg-icon>  | 
 | 193 | +              `  | 
 | 194 | +            : html`  | 
 | 195 | +                <ha-svg-icon slot="icon" .path=${mdiWaterBoiler}></ha-svg-icon>  | 
 | 196 | +              `}  | 
 | 197 | +          ${options.map(  | 
 | 198 | +            (option) => html`  | 
 | 199 | +              <ha-list-item .value=${option.value} graphic="icon">  | 
 | 200 | +                ${option.icon}${option.label}  | 
 | 201 | +              </ha-list-item>  | 
 | 202 | +            `  | 
 | 203 | +          )}  | 
 | 204 | +        </ha-control-select-menu>  | 
 | 205 | +      `;  | 
 | 206 | +    }  | 
 | 207 | + | 
149 | 208 |     return html`  | 
150 | 209 |       <ha-control-select  | 
151 | 210 |         .options=${options}  | 
 | 
0 commit comments