From b656ddc1f05666f89352acc2b1970ddacda022ce Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 30 Apr 2025 14:51:22 +0200 Subject: [PATCH 1/5] Add DHCP Browser entry point to network (#25235) * Add DHCP Browser entry point to network * lint --- .../config/network/ha-config-network-dhcp.ts | 66 +++++++++++++++++++ .../network/ha-config-section-network.ts | 7 ++ src/translations/en.json | 3 + 3 files changed, 76 insertions(+) create mode 100644 src/panels/config/network/ha-config-network-dhcp.ts diff --git a/src/panels/config/network/ha-config-network-dhcp.ts b/src/panels/config/network/ha-config-network-dhcp.ts new file mode 100644 index 0000000000..ef70d11903 --- /dev/null +++ b/src/panels/config/network/ha-config-network-dhcp.ts @@ -0,0 +1,66 @@ +import "@material/mwc-button/mwc-button"; +import type { CSSResultGroup } from "lit"; +import { css, html, LitElement } from "lit"; +import { customElement, property } from "lit/decorators"; +import "../../../components/ha-button"; +import "../../../components/ha-card"; +import { haStyle } from "../../../resources/styles"; +import type { HomeAssistant } from "../../../types"; + +@customElement("ha-config-network-dhcp") +class ConfigNetworkDHCP extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + protected render() { + return html` + +
+

+ ${this.hass.localize("ui.panel.config.network.discovery.dhcp_info")} +

+
+ +
+ `; + } + + static get styles(): CSSResultGroup { + return [ + haStyle, + css` + ha-settings-row { + padding: 0; + } + + .card-actions { + display: flex; + flex-direction: row-reverse; + justify-content: space-between; + align-items: center; + } + `, // row-reverse so we tab first to "save" + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-config-network-dhcp": ConfigNetworkDHCP; + } +} diff --git a/src/panels/config/network/ha-config-section-network.ts b/src/panels/config/network/ha-config-section-network.ts index 4b5f6a2808..c9a3df311d 100644 --- a/src/panels/config/network/ha-config-section-network.ts +++ b/src/panels/config/network/ha-config-section-network.ts @@ -5,6 +5,7 @@ import { isComponentLoaded } from "../../../common/config/is_component_loaded"; import "../../../layouts/hass-subpage"; import type { HomeAssistant, Route } from "../../../types"; import "./ha-config-network"; +import "./ha-config-network-dhcp"; import "./ha-config-network-ssdp"; import "./ha-config-network-zeroconf"; import "./ha-config-url-form"; @@ -37,6 +38,11 @@ class HaConfigSectionNetwork extends LitElement { : ""} + ${isComponentLoaded(this.hass, "dhcp") + ? html`` + : ""} ${isComponentLoaded(this.hass, "ssdp") ? html` Date: Wed, 30 Apr 2025 15:57:16 +0300 Subject: [PATCH 2/5] Allow pasting more automation config formats (#25239) --- .../automation/manual-automation-editor.ts | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/src/panels/config/automation/manual-automation-editor.ts b/src/panels/config/automation/manual-automation-editor.ts index a064b65a8d..57583f0505 100644 --- a/src/panels/config/automation/manual-automation-editor.ts +++ b/src/panels/config/automation/manual-automation-editor.ts @@ -27,7 +27,7 @@ import type { Trigger, } from "../../../data/automation"; import { normalizeAutomationConfig } from "../../../data/automation"; -import type { Action } from "../../../data/script"; +import { getActionType, type Action } from "../../../data/script"; import { haStyle } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; import { documentationUrl } from "../../../util/documentation-url"; @@ -312,10 +312,59 @@ export class HaManualAutomationEditor extends LitElement { const loaded: any = load(paste); if (loaded) { - let normalized: AutomationConfig | undefined; + let config = loaded; + + if ("automation" in config) { + config = config.automation; + if (Array.isArray(config)) { + config = config[0]; + } + } + + if (Array.isArray(config)) { + if (config.length === 1) { + config = config[0]; + } else { + const newConfig: AutomationConfig = { + triggers: [], + conditions: [], + actions: [], + }; + let found = false; + config.forEach((cfg: any) => { + if ("trigger" in cfg) { + found = true; + (newConfig.triggers as Trigger[]).push(cfg); + } + if ("condition" in cfg) { + found = true; + (newConfig.conditions as Condition[]).push(cfg); + } + if (getActionType(cfg) !== "unknown") { + found = true; + (newConfig.actions as Action[]).push(cfg); + } + }); + if (found) { + config = newConfig; + } + } + } + + if ("trigger" in config) { + config = { triggers: [config] }; + } + if ("condition" in config) { + config = { conditions: [config] }; + } + if (getActionType(config) !== "unknown") { + config = { actions: [config] }; + } + + let normalized: AutomationConfig; try { - normalized = normalizeAutomationConfig(loaded); + normalized = normalizeAutomationConfig(config); } catch (_err: any) { return; } From 50e39de9740fdf901e14a9c3ec0a84b5266fb943 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 30 Apr 2025 16:15:10 +0300 Subject: [PATCH 3/5] Allow pasting more script config (#25240) * Allow pasting more script config * Update manual-script-editor.ts --- .../config/script/manual-script-editor.ts | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/panels/config/script/manual-script-editor.ts b/src/panels/config/script/manual-script-editor.ts index d15c41a49f..457a6f7303 100644 --- a/src/panels/config/script/manual-script-editor.ts +++ b/src/panels/config/script/manual-script-editor.ts @@ -24,7 +24,11 @@ import "../../../components/ha-card"; import "../../../components/ha-icon-button"; import "../../../components/ha-markdown"; import type { Action, Fields, ScriptConfig } from "../../../data/script"; -import { MODES, normalizeScriptConfig } from "../../../data/script"; +import { + getActionType, + MODES, + normalizeScriptConfig, +} from "../../../data/script"; import { haStyle } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; import { documentationUrl } from "../../../util/documentation-url"; @@ -236,10 +240,31 @@ export class HaManualScriptEditor extends LitElement { const loaded: any = load(paste); if (loaded) { + let config = loaded; + + if ("script" in config) { + config = config.script; + if (Object.keys(config).length) { + config = config[Object.keys(config)[0]]; + } + } + + if (Array.isArray(config)) { + if (config.length === 1) { + config = config[0]; + } else { + config = { sequence: config }; + } + } + + if (!["sequence", "unknown"].includes(getActionType(config))) { + config = { sequence: [config] }; + } + let normalized: ScriptConfig | undefined; try { - normalized = normalizeScriptConfig(loaded); + normalized = normalizeScriptConfig(config); } catch (_err: any) { return; } From 2e4ce71d0604164334fb46c83d41d5896f60ff7b Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 30 Apr 2025 17:02:53 +0300 Subject: [PATCH 4/5] Improve trigger condition check on paste (#25241) --- src/data/automation.ts | 19 +++++++++++++++++++ .../automation/manual-automation-editor.ts | 14 +++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/data/automation.ts b/src/data/automation.ts index 7308e51e34..1e57fde2ff 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -492,6 +492,25 @@ export const getAutomationEditorInitData = () => { return data; }; +export const isTrigger = (config: unknown): boolean => { + if (!config || typeof config !== "object") { + return false; + } + const trigger = config as Record; + return ( + ("trigger" in trigger && typeof trigger.trigger === "string") || + ("platform" in trigger && typeof trigger.platform === "string") + ); +}; + +export const isCondition = (config: unknown): boolean => { + if (!config || typeof config !== "object") { + return false; + } + const condition = config as Record; + return "condition" in condition && typeof condition.condition === "string"; +}; + export const subscribeTrigger = ( hass: HomeAssistant, onChange: (result: { diff --git a/src/panels/config/automation/manual-automation-editor.ts b/src/panels/config/automation/manual-automation-editor.ts index 57583f0505..8e0ae2209f 100644 --- a/src/panels/config/automation/manual-automation-editor.ts +++ b/src/panels/config/automation/manual-automation-editor.ts @@ -26,7 +26,11 @@ import type { ManualAutomationConfig, Trigger, } from "../../../data/automation"; -import { normalizeAutomationConfig } from "../../../data/automation"; +import { + isCondition, + isTrigger, + normalizeAutomationConfig, +} from "../../../data/automation"; import { getActionType, type Action } from "../../../data/script"; import { haStyle } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; @@ -332,11 +336,11 @@ export class HaManualAutomationEditor extends LitElement { }; let found = false; config.forEach((cfg: any) => { - if ("trigger" in cfg) { + if (isTrigger(cfg)) { found = true; (newConfig.triggers as Trigger[]).push(cfg); } - if ("condition" in cfg) { + if (isCondition(cfg)) { found = true; (newConfig.conditions as Condition[]).push(cfg); } @@ -351,10 +355,10 @@ export class HaManualAutomationEditor extends LitElement { } } - if ("trigger" in config) { + if (isTrigger(config)) { config = { triggers: [config] }; } - if ("condition" in config) { + if (isCondition(config)) { config = { conditions: [config] }; } if (getActionType(config) !== "unknown") { From e5f41ceb3e5a0d95880193ea59a25fcd41596544 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 30 Apr 2025 16:08:42 +0200 Subject: [PATCH 5/5] Bumped version to 20250430.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 169b86dbe8..bb4fba543b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "home-assistant-frontend" -version = "20250430.0" +version = "20250430.1" license = "Apache-2.0" license-files = ["LICENSE*"] description = "The Home Assistant frontend"