diff --git a/lint-staged.config.js b/lint-staged.config.js index 5359a96eee..a1bd97c88d 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -2,7 +2,7 @@ export default { "*.?(c|m){js,ts}": [ "eslint --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --fix", "prettier --cache --write", - "lit-analyzer", + "lit-analyzer --quiet", ], "*.{json,css,md,markdown,html,y?aml}": "prettier --cache --write", "translations/*/*.json": (files) => diff --git a/src/common/entity/attribute_icon_path.ts b/src/common/entity/attribute_icon_path.ts index aa42803887..f3855a5232 100644 --- a/src/common/entity/attribute_icon_path.ts +++ b/src/common/entity/attribute_icon_path.ts @@ -1,4 +1,5 @@ /** Return an icon representing a attribute. */ +import { mdiCircleMedium, mdiCreation } from "@mdi/js"; import { HassEntity } from "home-assistant-js-websocket"; import { computeFanModeIcon, @@ -6,6 +7,7 @@ import { computePresetModeIcon, computeSwingModeIcon, } from "../../data/climate"; +import { computeHumidiferModeIcon } from "../../data/humidifier"; import { computeDomain } from "./compute_domain"; const iconGenerators: Record string>> = { @@ -15,6 +17,15 @@ const iconGenerators: Record string>> = { preset_mode: computePresetModeIcon, swing_mode: computeSwingModeIcon, }, + humidifier: { + mode: computeHumidiferModeIcon, + }, + light: { + effect: () => mdiCreation, + }, + fan: { + preset_mode: () => mdiCircleMedium, + }, }; export const attributeIconPath = ( diff --git a/src/components/ha-control-select.ts b/src/components/ha-control-select.ts index 91c740d0e5..4cacb34fd2 100644 --- a/src/components/ha-control-select.ts +++ b/src/components/ha-control-select.ts @@ -5,6 +5,7 @@ import { LitElement, nothing, PropertyValues, + TemplateResult, } from "lit"; import { customElement, property, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; @@ -17,7 +18,7 @@ import "./ha-svg-icon"; export type ControlSelectOption = { value: string; label?: string; - icon?: string; + icon?: TemplateResult; path?: string; }; @@ -25,7 +26,7 @@ export type ControlSelectOption = { export class HaControlSelect extends LitElement { @property({ type: Boolean, reflect: true }) disabled = false; - @property() public options?: ControlSelectOption[]; + @property({ attribute: false }) public options?: ControlSelectOption[]; @property() public value?: string; @@ -183,9 +184,7 @@ export class HaControlSelect extends LitElement {
${option.path ? html`` - : option.icon - ? html` ` - : nothing} + : option.icon || nothing} ${option.label && !this.hideLabel ? html`${option.label}` : nothing} diff --git a/src/dialogs/more-info/controls/more-info-fan.ts b/src/dialogs/more-info/controls/more-info-fan.ts index b5f39cb05b..31eac2ca5d 100644 --- a/src/dialogs/more-info/controls/more-info-fan.ts +++ b/src/dialogs/more-info/controls/more-info-fan.ts @@ -14,6 +14,7 @@ import { stopPropagation } from "../../../common/dom/stop_propagation"; import { stateActive } from "../../../common/entity/state_active"; import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-control-select-menu"; +import "../../../components/ha-attribute-icon"; import "../../../components/ha-list-item"; import "../../../components/ha-outlined-icon-button"; import { UNAVAILABLE } from "../../../data/entity"; @@ -187,10 +188,30 @@ class MoreInfoFan extends LitElement { @selected=${this._handlePresetMode} @closed=${stopPropagation} > - + ${this.stateObj.attributes.preset_mode + ? html`` + : html` + + `} ${this.stateObj.attributes.preset_modes?.map( (mode) => html` - + + ${this.hass.formatEntityAttributeValue( this.stateObj!, "preset_mode", diff --git a/src/dialogs/more-info/controls/more-info-humidifier.ts b/src/dialogs/more-info/controls/more-info-humidifier.ts index 367a9fe364..d9ae9ca08c 100644 --- a/src/dialogs/more-info/controls/more-info-humidifier.ts +++ b/src/dialogs/more-info/controls/more-info-humidifier.ts @@ -12,11 +12,11 @@ import { stopPropagation } from "../../../common/dom/stop_propagation"; import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-control-select-menu"; import "../../../components/ha-list-item"; +import "../../../components/ha-attribute-icon"; import { UNAVAILABLE } from "../../../data/entity"; import { HumidifierEntity, HumidifierEntityFeature, - computeHumidiferModeIcon, } from "../../../data/humidifier"; import "../../../state-control/humidifier/ha-state-control-humidifier-humidity"; import { HomeAssistant } from "../../../types"; @@ -109,14 +109,28 @@ class MoreInfoHumidifier extends LitElement { @selected=${this._handleModeChanged} @closed=${stopPropagation} > - + ${stateObj.attributes.mode + ? html`` + : html``} ${stateObj.attributes.available_modes!.map( (mode) => html` - + .hass=${this.hass} + .stateObj=${stateObj} + attribute="mode" + .attributeValue=${mode} + > ${this.hass.formatEntityAttributeValue( stateObj!, "mode", diff --git a/src/dialogs/more-info/controls/more-info-light.ts b/src/dialogs/more-info/controls/more-info-light.ts index 663c88dfbb..6054f0b695 100644 --- a/src/dialogs/more-info/controls/more-info-light.ts +++ b/src/dialogs/more-info/controls/more-info-light.ts @@ -19,6 +19,7 @@ import { customElement, property, state } from "lit/decorators"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-attributes"; +import "../../../components/ha-attribute-icon"; import "../../../components/ha-control-select-menu"; import "../../../components/ha-icon-button-group"; import "../../../components/ha-icon-button-toggle"; @@ -271,10 +272,28 @@ class MoreInfoLight extends LitElement { @selected=${this._handleEffect} @closed=${stopPropagation} > - + ${this.stateObj.attributes.effect + ? html`` + : html``} ${this.stateObj.attributes.effect_list?.map( (mode) => html` - + + ${this.hass.formatEntityAttributeValue( this.stateObj!, "effect", diff --git a/src/panels/lovelace/card-features/hui-climate-fan-modes-card-feature.ts b/src/panels/lovelace/card-features/hui-climate-fan-modes-card-feature.ts index bfdf039b94..78de1e6a4d 100644 --- a/src/panels/lovelace/card-features/hui-climate-fan-modes-card-feature.ts +++ b/src/panels/lovelace/card-features/hui-climate-fan-modes-card-feature.ts @@ -5,15 +5,12 @@ import { customElement, property, query, state } from "lit/decorators"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { computeDomain } from "../../../common/entity/compute_domain"; import { supportsFeature } from "../../../common/entity/supports-feature"; +import "../../../components/ha-attribute-icon"; import "../../../components/ha-control-select"; import type { ControlSelectOption } from "../../../components/ha-control-select"; import "../../../components/ha-control-select-menu"; import type { HaControlSelectMenu } from "../../../components/ha-control-select-menu"; -import { - ClimateEntity, - ClimateEntityFeature, - computeFanModeIcon, -} from "../../../data/climate"; +import { ClimateEntity, ClimateEntityFeature } from "../../../data/climate"; import { UNAVAILABLE } from "../../../data/entity"; import { HomeAssistant } from "../../../types"; import { LovelaceCardFeature, LovelaceCardFeatureEditor } from "../types"; @@ -136,7 +133,13 @@ class HuiClimateFanModesCardFeature "fan_mode", mode ), - path: computeFanModeIcon(mode), + icon: html``, })); if (this._config.style === "icons") { @@ -171,12 +174,19 @@ class HuiClimateFanModesCardFeature @selected=${this._valueChanged} @closed=${stopPropagation} > - + ${this._currentFanMode + ? html`` + : html` `} ${options.map( (option) => html` - - ${option.label} + ${option.icon}${option.label} ` )} diff --git a/src/panels/lovelace/card-features/hui-climate-hvac-modes-card-feature.ts b/src/panels/lovelace/card-features/hui-climate-hvac-modes-card-feature.ts index 4477359e1d..d01d6e43df 100644 --- a/src/panels/lovelace/card-features/hui-climate-hvac-modes-card-feature.ts +++ b/src/panels/lovelace/card-features/hui-climate-hvac-modes-card-feature.ts @@ -6,14 +6,14 @@ import { styleMap } from "lit/directives/style-map"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { computeDomain } from "../../../common/entity/compute_domain"; import { stateColorCss } from "../../../common/entity/state_color"; +import "../../../components/ha-attribute-icon"; import "../../../components/ha-control-select"; -import "../../../components/ha-control-select-menu"; import type { ControlSelectOption } from "../../../components/ha-control-select"; +import "../../../components/ha-control-select-menu"; import type { HaControlSelectMenu } from "../../../components/ha-control-select-menu"; import { ClimateEntity, compareClimateHvacModes, - computeHvacModeIcon, HvacMode, } from "../../../data/climate"; import { UNAVAILABLE } from "../../../data/entity"; @@ -130,7 +130,13 @@ class HuiClimateHvacModesCardFeature .map((mode) => ({ value: mode, label: this.hass!.formatEntityState(this.stateObj!, mode), - path: computeHvacModeIcon(mode), + icon: html``, })); if (this._config.style === "dropdown") { @@ -147,15 +153,22 @@ class HuiClimateHvacModesCardFeature @selected=${this._valueChanged} @closed=${stopPropagation} > - + ${this._currentHvacMode + ? html`` + : html``} ${options.map( (option) => html` - - ${option.label} + ${option.icon}${option.label} ` )} diff --git a/src/panels/lovelace/card-features/hui-climate-preset-modes-card-feature.ts b/src/panels/lovelace/card-features/hui-climate-preset-modes-card-feature.ts index 2067a17739..410f8ce942 100644 --- a/src/panels/lovelace/card-features/hui-climate-preset-modes-card-feature.ts +++ b/src/panels/lovelace/card-features/hui-climate-preset-modes-card-feature.ts @@ -5,15 +5,12 @@ import { customElement, property, query, state } from "lit/decorators"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { computeDomain } from "../../../common/entity/compute_domain"; import { supportsFeature } from "../../../common/entity/supports-feature"; +import "../../../components/ha-attribute-icon"; import "../../../components/ha-control-select"; import type { ControlSelectOption } from "../../../components/ha-control-select"; import "../../../components/ha-control-select-menu"; import type { HaControlSelectMenu } from "../../../components/ha-control-select-menu"; -import { - ClimateEntity, - ClimateEntityFeature, - computePresetModeIcon, -} from "../../../data/climate"; +import { ClimateEntity, ClimateEntityFeature } from "../../../data/climate"; import { UNAVAILABLE } from "../../../data/entity"; import { HomeAssistant } from "../../../types"; import { LovelaceCardFeature, LovelaceCardFeatureEditor } from "../types"; @@ -138,7 +135,13 @@ class HuiClimatePresetModesCardFeature "preset_mode", mode ), - path: computePresetModeIcon(mode), + icon: html``, })); if (this._config.style === "icons") { @@ -176,12 +179,21 @@ class HuiClimatePresetModesCardFeature @selected=${this._valueChanged} @closed=${stopPropagation} > - + ${this._currentPresetMode + ? html`` + : html` + + `} ${options.map( (option) => html` - - ${option.label} + ${option.icon}${option.label} ` )} diff --git a/src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts b/src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts index a3e4c845aa..94a366712a 100644 --- a/src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts +++ b/src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts @@ -5,16 +5,16 @@ import { customElement, property, query, state } from "lit/decorators"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { computeDomain } from "../../../common/entity/compute_domain"; import { supportsFeature } from "../../../common/entity/supports-feature"; +import "../../../components/ha-attribute-icon"; import "../../../components/ha-control-select"; import type { ControlSelectOption } from "../../../components/ha-control-select"; import "../../../components/ha-control-select-menu"; import type { HaControlSelectMenu } from "../../../components/ha-control-select-menu"; -import { - HumidifierEntityFeature, - HumidifierEntity, - computeHumidiferModeIcon, -} from "../../../data/humidifier"; import { UNAVAILABLE } from "../../../data/entity"; +import { + HumidifierEntity, + HumidifierEntityFeature, +} from "../../../data/humidifier"; import { HomeAssistant } from "../../../types"; import { LovelaceCardFeature, LovelaceCardFeatureEditor } from "../types"; import { HumidifierModesCardFeatureConfig } from "./types"; @@ -136,7 +136,13 @@ class HuiHumidifierModesCardFeature "mode", mode ), - path: computeHumidiferModeIcon(mode), + icon: html``, })); if (this._config.style === "icons") { @@ -168,12 +174,22 @@ class HuiHumidifierModesCardFeature @selected=${this._valueChanged} @closed=${stopPropagation} > - + ${this._currentMode + ? html`` + : html``} ${options.map( (option) => html` - - ${option.label} + ${option.icon}${option.label} ` )}