From 6d36b0e28ce9630002aff206725f54cda084ddca Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Fri, 8 Dec 2023 11:58:08 +0100 Subject: [PATCH 1/5] Hide climate mode control on default dashboard if there is only one hvac mode (#18964) Hide hvac mode on default dashboard if there is only one hvac mode --- .../lovelace/common/generate-lovelace-config.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index 02e0f970baf8..2b5437a93dff 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -143,12 +143,15 @@ export const computeCards = ( const cardConfig: ThermostatCardConfig = { type: "thermostat", entity: entityId, - features: [ - { - type: "climate-hvac-modes", - hvac_modes: states[entityId]?.attributes?.hvac_modes, - }, - ], + features: + (states[entityId]?.attributes?.hvac_modes?.length ?? 0) > 1 + ? [ + { + type: "climate-hvac-modes", + hvac_modes: states[entityId]?.attributes?.hvac_modes, + }, + ] + : undefined, }; cards.push(cardConfig); } else if (domain === "humidifier") { From c9e69633875ed9ebc44f2ae18f83cd479f45074c Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:35:57 +0100 Subject: [PATCH 2/5] Fix todo url (#18954) * Fix todo url * Move searchParams * Update src/panels/todo/ha-panel-todo.ts * check if saved entity exists --------- Co-authored-by: Bram Kragten --- src/panels/todo/ha-panel-todo.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/panels/todo/ha-panel-todo.ts b/src/panels/todo/ha-panel-todo.ts index 345df4010cb6..ba03971c12e8 100644 --- a/src/panels/todo/ha-panel-todo.ts +++ b/src/panels/todo/ha-panel-todo.ts @@ -46,7 +46,10 @@ import { HuiErrorCard } from "../lovelace/cards/hui-error-card"; import { createCardElement } from "../lovelace/create-element/create-card-element"; import { LovelaceCard } from "../lovelace/types"; import { navigate } from "../../common/navigate"; -import { createSearchParam } from "../../common/url/search-params"; +import { + createSearchParam, + extractSearchParam, +} from "../../common/url/search-params"; import { constructUrlCurrentPath } from "../../common/url/construct-url"; @customElement("ha-panel-todo") @@ -105,18 +108,21 @@ class PanelTodo extends LitElement { if (!this.hasUpdated) { this.hass.loadFragmentTranslation("lovelace"); - } - if (!this.hasUpdated && !this._entityId) { - this._entityId = getTodoLists(this.hass)[0]?.entity_id; - } else if (!this.hasUpdated) { - this._setupTodoElement(); + const urlEntityId = extractSearchParam("entity_id"); + if (urlEntityId) { + this._entityId = urlEntityId; + } else { + if (this._entityId && !(this._entityId in this.hass.states)) { + this._entityId = undefined; + } + if (!this._entityId) { + this._entityId = getTodoLists(this.hass)[0]?.entity_id; + } + } } - } - protected updated(changedProperties: PropertyValues): void { - super.updated(changedProperties); - if (changedProperties.has("_entityId")) { + if (changedProperties.has("_entityId") || !this.hasUpdated) { this._setupTodoElement(); } From 8d2d45ae4edcc36ddbb17b2ec4876f7ea6073bb0 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Fri, 8 Dec 2023 13:43:59 +0100 Subject: [PATCH 3/5] Add dropdown style to hvac_modes feature (#18963) --- .../hui-climate-hvac-modes-card-feature.ts | 65 ++++++++++++++++++- src/panels/lovelace/card-features/types.ts | 1 + ...-climate-hvac-modes-card-feature-editor.ts | 41 ++++++++++-- src/translations/en.json | 7 +- 4 files changed, 105 insertions(+), 9 deletions(-) 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 5b1303938576..4477359e1d77 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 @@ -1,11 +1,15 @@ +import { mdiThermostat } from "@mdi/js"; import { HassEntity } from "home-assistant-js-websocket"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; -import { customElement, property, state } from "lit/decorators"; +import { customElement, property, query, state } from "lit/decorators"; 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-control-select"; +import "../../../components/ha-control-select-menu"; import type { ControlSelectOption } from "../../../components/ha-control-select"; +import type { HaControlSelectMenu } from "../../../components/ha-control-select-menu"; import { ClimateEntity, compareClimateHvacModes, @@ -35,6 +39,9 @@ class HuiClimateHvacModesCardFeature @state() _currentHvacMode?: HvacMode; + @query("ha-control-select-menu", true) + private _haSelect?: HaControlSelectMenu; + static getStubConfig( _, stateObj?: HassEntity @@ -66,8 +73,23 @@ class HuiClimateHvacModesCardFeature } } + protected updated(changedProps: PropertyValues) { + super.updated(changedProps); + if (this._haSelect && changedProps.has("hass")) { + const oldHass = changedProps.get("hass") as HomeAssistant | undefined; + if ( + this.hass && + this.hass.formatEntityAttributeValue !== + oldHass?.formatEntityAttributeValue + ) { + this._haSelect.layoutOptions(); + } + } + } + private async _valueChanged(ev: CustomEvent) { - const mode = (ev.detail as any).value as HvacMode; + const mode = + (ev.detail as any).value ?? ((ev.target as any).value as HvacMode); if (mode === this.stateObj!.state) return; @@ -111,6 +133,37 @@ class HuiClimateHvacModesCardFeature path: computeHvacModeIcon(mode), })); + if (this._config.style === "dropdown") { + return html` +
+ + + ${options.map( + (option) => html` + + + ${option.label} + + ` + )} + +
+ `; + } + return html`
+ ( + localize: LocalizeFunc, + formatEntityState: FormatEntityStateFunc, + stateObj?: HassEntity + ) => [ + { + name: "style", + selector: { + select: { + multiple: false, + mode: "list", + options: ["dropdown", "icons"].map((mode) => ({ + value: mode, + label: localize( + `ui.panel.lovelace.editor.features.types.climate-preset-modes.style_list.${mode}` + ), + })), + }, + }, + }, { name: "hvac_modes", selector: { @@ -59,12 +79,22 @@ export class HuiClimateHvacModesCardFeatureEditor ? this.hass.states[this.context?.entity_id] : undefined; - const schema = this._schema(this.hass.formatEntityState, stateObj); + const data: ClimateHvacModesCardFeatureConfig = { + style: "icons", + hvac_modes: [], + ...this._config, + }; + + const schema = this._schema( + this.hass.localize, + this.hass.formatEntityState, + stateObj + ); return html` { switch (schema.name) { case "hvac_modes": + case "style": return this.hass!.localize( `ui.panel.lovelace.editor.features.types.climate-hvac-modes.${schema.name}` ); default: - return this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ); + return ""; } }; } diff --git a/src/translations/en.json b/src/translations/en.json index 41ed918e2319..af46f7f13413 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -5280,7 +5280,12 @@ }, "climate-hvac-modes": { "label": "Climate HVAC modes", - "hvac_modes": "HVAC modes" + "hvac_modes": "HVAC modes", + "style": "[%key:ui::panel::lovelace::editor::features::types::climate-preset-modes::style%]", + "style_list": { + "dropdown": "[%key:ui::panel::lovelace::editor::features::types::climate-preset-modes::style_list::dropdown%]", + "icons": "[%key:ui::panel::lovelace::editor::features::types::climate-preset-modes::style_list::icons%]" + } }, "climate-preset-modes": { "label": "Climate preset modes", From 3ada2f3279c6c759f6bad20a57445d31adab34cf Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 8 Dec 2023 14:38:01 +0100 Subject: [PATCH 4/5] Fix label when there is no target (#18969) --- .../climate/ha-state-control-climate-humidity.ts | 6 ++++++ .../climate/ha-state-control-climate-temperature.ts | 11 +++++++---- .../ha-state-control-humidifier-humidity.ts | 4 +++- .../ha-state-control-water_heater-temperature.ts | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/state-control/climate/ha-state-control-climate-humidity.ts b/src/state-control/climate/ha-state-control-climate-humidity.ts index be27b7bdb629..9918db1044c5 100644 --- a/src/state-control/climate/ha-state-control-climate-humidity.ts +++ b/src/state-control/climate/ha-state-control-climate-humidity.ts @@ -97,6 +97,12 @@ export class HaStateControlClimateHumidity extends LitElement { `; } + if (!this._targetHumidity) { + return html` +

${this.hass.formatEntityState(this.stateObj)}

+ `; + } + return html`

${this.hass.localize("ui.card.climate.humidity_target")} diff --git a/src/state-control/climate/ha-state-control-climate-temperature.ts b/src/state-control/climate/ha-state-control-climate-temperature.ts index 755b0ce6ab37..0975b1bd9944 100644 --- a/src/state-control/climate/ha-state-control-climate-temperature.ts +++ b/src/state-control/climate/ha-state-control-climate-temperature.ts @@ -164,14 +164,17 @@ export class HaStateControlClimateTemperature extends LitElement { } if ( - !supportsFeature( + (!supportsFeature( this.stateObj, ClimateEntityFeature.TARGET_TEMPERATURE - ) && - !supportsFeature( + ) || + this._targetTemperature.value === null) && + (!supportsFeature( this.stateObj, ClimateEntityFeature.TARGET_TEMPERATURE_RANGE - ) + ) || + this._targetTemperature.low === null || + this._targetTemperature.high === null) ) { return html`

${this.hass.formatEntityState(this.stateObj)}

diff --git a/src/state-control/humidifier/ha-state-control-humidifier-humidity.ts b/src/state-control/humidifier/ha-state-control-humidifier-humidity.ts index 9f9bf9260514..648753ab6611 100644 --- a/src/state-control/humidifier/ha-state-control-humidifier-humidity.ts +++ b/src/state-control/humidifier/ha-state-control-humidifier-humidity.ts @@ -110,7 +110,9 @@ export class HaStateControlHumidifierHumidity extends LitElement {

${action && action !== "off" && action !== "idle" ? actionLabel - : this.hass.localize("ui.card.humidifier.target")} + : this._targetHumidity + ? this.hass.localize("ui.card.humidifier.target") + : this.hass.formatEntityState(this.stateObj)}

`; } diff --git a/src/state-control/water_heater/ha-state-control-water_heater-temperature.ts b/src/state-control/water_heater/ha-state-control-water_heater-temperature.ts index bbcd5cdaad1c..4e5249961865 100644 --- a/src/state-control/water_heater/ha-state-control-water_heater-temperature.ts +++ b/src/state-control/water_heater/ha-state-control-water_heater-temperature.ts @@ -107,7 +107,8 @@ export class HaStateControlWaterHeaterTemperature extends LitElement { !supportsFeature( this.stateObj, WaterHeaterEntityFeature.TARGET_TEMPERATURE - ) + ) || + !this._targetTemperature ) { return html`

${this.hass.formatEntityState(this.stateObj)}

From fcb9e13a8463f8a5b1917865ff265db3ee6125d4 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Fri, 8 Dec 2023 14:49:04 +0100 Subject: [PATCH 5/5] Bumped version to 20231208.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6267bdc101e0..afea7e45d6b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "home-assistant-frontend" -version = "20231208.1" +version = "20231208.2" license = {text = "Apache-2.0"} description = "The Home Assistant frontend" readme = "README.md"