Add severity level to dialog automation mode
parent
3ce639946c
commit
62711e5c74
|
@ -13,6 +13,7 @@ import { createSearchParam } from "../common/url/search-params";
|
||||||
|
|
||||||
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
||||||
export const AUTOMATION_DEFAULT_MAX = 10;
|
export const AUTOMATION_DEFAULT_MAX = 10;
|
||||||
|
export const AUTOMATION_DEFAULT_MAX_EXCEEDED: AutomationConfigMaxExceeded = "warning";
|
||||||
|
|
||||||
export interface AutomationEntity extends HassEntityBase {
|
export interface AutomationEntity extends HassEntityBase {
|
||||||
attributes: HassEntityAttributeBase & {
|
attributes: HassEntityAttributeBase & {
|
||||||
|
@ -40,8 +41,11 @@ export interface ManualAutomationConfig {
|
||||||
action?: Action | Action[];
|
action?: Action | Action[];
|
||||||
mode?: (typeof MODES)[number];
|
mode?: (typeof MODES)[number];
|
||||||
max?: number;
|
max?: number;
|
||||||
max_exceeded?:
|
max_exceeded?: AutomationConfigMaxExceeded;
|
||||||
| "silent"
|
variables?: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AutomationConfigMaxExceeded = "silent"
|
||||||
| "critical"
|
| "critical"
|
||||||
| "fatal"
|
| "fatal"
|
||||||
| "error"
|
| "error"
|
||||||
|
@ -50,8 +54,7 @@ export interface ManualAutomationConfig {
|
||||||
| "info"
|
| "info"
|
||||||
| "debug"
|
| "debug"
|
||||||
| "notset";
|
| "notset";
|
||||||
variables?: Record<string, unknown>;
|
export const automationConfigMaxExceededOptions = ["silent", "critical", "fatal", "error", "warning", "info", "debug"];
|
||||||
}
|
|
||||||
|
|
||||||
export interface BlueprintAutomationConfig extends ManualAutomationConfig {
|
export interface BlueprintAutomationConfig extends ManualAutomationConfig {
|
||||||
use_blueprint: { path: string; input?: BlueprintInput };
|
use_blueprint: { path: string; input?: BlueprintInput };
|
||||||
|
|
|
@ -5,6 +5,7 @@ import type { CSSResultGroup } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
||||||
import "../../../../components/ha-dialog-header";
|
import "../../../../components/ha-dialog-header";
|
||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-icon-button";
|
||||||
import "../../../../components/ha-md-list-item";
|
import "../../../../components/ha-md-list-item";
|
||||||
|
@ -12,10 +13,15 @@ import "../../../../components/ha-md-list";
|
||||||
import "../../../../components/ha-radio";
|
import "../../../../components/ha-radio";
|
||||||
import "../../../../components/ha-textfield";
|
import "../../../../components/ha-textfield";
|
||||||
import "../../../../components/ha-dialog";
|
import "../../../../components/ha-dialog";
|
||||||
|
import "../../../../components/ha-select";
|
||||||
|
import "../../../../components/ha-list-item";
|
||||||
|
|
||||||
|
import type { AutomationConfigMaxExceeded } from "../../../../data/automation";
|
||||||
import {
|
import {
|
||||||
AUTOMATION_DEFAULT_MAX,
|
AUTOMATION_DEFAULT_MAX,
|
||||||
AUTOMATION_DEFAULT_MODE,
|
AUTOMATION_DEFAULT_MODE,
|
||||||
|
AUTOMATION_DEFAULT_MAX_EXCEEDED,
|
||||||
|
automationConfigMaxExceededOptions,
|
||||||
} from "../../../../data/automation";
|
} from "../../../../data/automation";
|
||||||
import { MODES, isMaxMode } from "../../../../data/script";
|
import { MODES, isMaxMode } from "../../../../data/script";
|
||||||
import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||||
|
@ -36,6 +42,11 @@ class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
|
|
||||||
@state() private _newMax?: number;
|
@state() private _newMax?: number;
|
||||||
|
|
||||||
|
@state() private _maxExceeded?: AutomationConfigMaxExceeded =
|
||||||
|
AUTOMATION_DEFAULT_MAX_EXCEEDED;
|
||||||
|
|
||||||
|
@state() private _newMaxExceeded?: AutomationConfigMaxExceeded;
|
||||||
|
|
||||||
public showDialog(params: AutomationModeDialog): void {
|
public showDialog(params: AutomationModeDialog): void {
|
||||||
this._opened = true;
|
this._opened = true;
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
@ -43,6 +54,8 @@ class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
this._newMax = isMaxMode(this._newMode)
|
this._newMax = isMaxMode(this._newMode)
|
||||||
? params.config.max || AUTOMATION_DEFAULT_MAX
|
? params.config.max || AUTOMATION_DEFAULT_MAX
|
||||||
: undefined;
|
: undefined;
|
||||||
|
this._maxExceeded =
|
||||||
|
params.config.max_exceeded || AUTOMATION_DEFAULT_MAX_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog() {
|
public closeDialog() {
|
||||||
|
@ -158,6 +171,25 @@ class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|
||||||
|
<div class="options">
|
||||||
|
<ha-select
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.max_exceeded"
|
||||||
|
)}
|
||||||
|
.value=${this._maxExceeded}
|
||||||
|
name="max_exceeded"
|
||||||
|
@selected=${this._valueChanged}
|
||||||
|
@closed=${stopPropagation}
|
||||||
|
naturalMenuWidth
|
||||||
|
>
|
||||||
|
${automationConfigMaxExceededOptions.map(
|
||||||
|
(option) => html`
|
||||||
|
<ha-list-item .value=${option}>${option}</ha-list-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</ha-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
||||||
${this.hass.localize("ui.common.cancel")}
|
${this.hass.localize("ui.common.cancel")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
|
@ -183,6 +215,8 @@ class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
const target = ev.target as any;
|
const target = ev.target as any;
|
||||||
if (target.name === "max") {
|
if (target.name === "max") {
|
||||||
this._newMax = Number(target.value);
|
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,
|
...this._params.config,
|
||||||
mode: this._newMode,
|
mode: this._newMode,
|
||||||
max: this._newMax,
|
max: this._newMax,
|
||||||
|
max_exceeded: this._newMaxExceeded,
|
||||||
});
|
});
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
@ -212,6 +247,9 @@ class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
ha-dialog-header a {
|
ha-dialog-header a {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
ha-select {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -3707,6 +3707,7 @@
|
||||||
"queued": "Queue length",
|
"queued": "Queue length",
|
||||||
"parallel": "Max number of parallel runs"
|
"parallel": "Max number of parallel runs"
|
||||||
},
|
},
|
||||||
|
"max_exceeded": "Max exceeded severity level",
|
||||||
"edit_yaml": "Edit in YAML",
|
"edit_yaml": "Edit in YAML",
|
||||||
"edit_ui": "Edit in visual editor",
|
"edit_ui": "Edit in visual editor",
|
||||||
"copy_to_clipboard": "Copy to clipboard",
|
"copy_to_clipboard": "Copy to clipboard",
|
||||||
|
|
Loading…
Reference in New Issue