From 62711e5c746d72cfa6433448cc4d12eaa20ab266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristof=20Mari=C3=ABn?= Date: Mon, 26 May 2025 11:10:56 -0700 Subject: [PATCH] Add severity level to dialog automation mode --- src/data/automation.ts | 23 ++++++----- .../dialog-automation-mode.ts | 38 +++++++++++++++++++ src/translations/en.json | 1 + 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/data/automation.ts b/src/data/automation.ts index 1e57fde2ff..ae987751db 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -13,6 +13,7 @@ import { createSearchParam } from "../common/url/search-params"; export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single"; export const AUTOMATION_DEFAULT_MAX = 10; +export const AUTOMATION_DEFAULT_MAX_EXCEEDED: AutomationConfigMaxExceeded = "warning"; export interface AutomationEntity extends HassEntityBase { attributes: HassEntityAttributeBase & { @@ -40,19 +41,21 @@ export interface ManualAutomationConfig { action?: Action | Action[]; mode?: (typeof MODES)[number]; max?: number; - max_exceeded?: - | "silent" - | "critical" - | "fatal" - | "error" - | "warning" - | "warn" - | "info" - | "debug" - | "notset"; + max_exceeded?: AutomationConfigMaxExceeded; variables?: Record; } +export type AutomationConfigMaxExceeded = "silent" + | "critical" + | "fatal" + | "error" + | "warning" + | "warn" + | "info" + | "debug" + | "notset"; +export const automationConfigMaxExceededOptions = ["silent", "critical", "fatal", "error", "warning", "info", "debug"]; + export interface BlueprintAutomationConfig extends ManualAutomationConfig { use_blueprint: { path: string; input?: BlueprintInput }; } diff --git a/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts b/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts index 8fcb7a5e75..e7a33d17d8 100644 --- a/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts +++ b/src/panels/config/automation/automation-mode-dialog/dialog-automation-mode.ts @@ -5,6 +5,7 @@ import type { CSSResultGroup } from "lit"; import { LitElement, css, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; +import { stopPropagation } from "../../../../common/dom/stop_propagation"; import "../../../../components/ha-dialog-header"; import "../../../../components/ha-icon-button"; import "../../../../components/ha-md-list-item"; @@ -12,10 +13,15 @@ import "../../../../components/ha-md-list"; import "../../../../components/ha-radio"; import "../../../../components/ha-textfield"; import "../../../../components/ha-dialog"; +import "../../../../components/ha-select"; +import "../../../../components/ha-list-item"; +import type { AutomationConfigMaxExceeded } from "../../../../data/automation"; import { AUTOMATION_DEFAULT_MAX, AUTOMATION_DEFAULT_MODE, + AUTOMATION_DEFAULT_MAX_EXCEEDED, + automationConfigMaxExceededOptions, } from "../../../../data/automation"; import { MODES, isMaxMode } from "../../../../data/script"; import type { HassDialog } from "../../../../dialogs/make-dialog-manager"; @@ -36,6 +42,11 @@ class DialogAutomationMode extends LitElement implements HassDialog { @state() private _newMax?: number; + @state() private _maxExceeded?: AutomationConfigMaxExceeded = + AUTOMATION_DEFAULT_MAX_EXCEEDED; + + @state() private _newMaxExceeded?: AutomationConfigMaxExceeded; + public showDialog(params: AutomationModeDialog): void { this._opened = true; this._params = params; @@ -43,6 +54,8 @@ class DialogAutomationMode extends LitElement implements HassDialog { this._newMax = isMaxMode(this._newMode) ? params.config.max || AUTOMATION_DEFAULT_MAX : undefined; + this._maxExceeded = + params.config.max_exceeded || AUTOMATION_DEFAULT_MAX_EXCEEDED; } public closeDialog() { @@ -158,6 +171,25 @@ class DialogAutomationMode extends LitElement implements HassDialog { ` : nothing} +
+ + ${automationConfigMaxExceededOptions.map( + (option) => html` + ${option} + ` + )} + +
+ ${this.hass.localize("ui.common.cancel")} @@ -183,6 +215,8 @@ class DialogAutomationMode extends LitElement implements HassDialog { const target = ev.target as any; if (target.name === "max") { this._newMax = Number(target.value); + } else if (target.name === "max_exceeded") { + this._newMaxExceeded = target.value; } } @@ -191,6 +225,7 @@ class DialogAutomationMode extends LitElement implements HassDialog { ...this._params.config, mode: this._newMode, max: this._newMax, + max_exceeded: this._newMaxExceeded, }); this.closeDialog(); } @@ -212,6 +247,9 @@ class DialogAutomationMode extends LitElement implements HassDialog { ha-dialog-header a { color: inherit; } + ha-select { + width: 100%; + } `, ]; } diff --git a/src/translations/en.json b/src/translations/en.json index 43ca921f43..936befa4a0 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3707,6 +3707,7 @@ "queued": "Queue length", "parallel": "Max number of parallel runs" }, + "max_exceeded": "Max exceeded severity level", "edit_yaml": "Edit in YAML", "edit_ui": "Edit in visual editor", "copy_to_clipboard": "Copy to clipboard",