mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 12:26:35 +00:00
Use duration input for timeout in wait_for_trigger action (#13426)
* Use duration input for timeout in wait_for_trigger action * Specify event type
This commit is contained in:
parent
4b54cb4a35
commit
9ed0cb3011
@ -155,9 +155,17 @@ export interface WaitAction extends BaseAction {
|
|||||||
continue_on_timeout?: boolean;
|
continue_on_timeout?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WaitForTriggerActionParts extends BaseAction {
|
||||||
|
milliseconds?: number;
|
||||||
|
seconds?: number;
|
||||||
|
minutes?: number;
|
||||||
|
hours?: number;
|
||||||
|
days?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface WaitForTriggerAction extends BaseAction {
|
export interface WaitForTriggerAction extends BaseAction {
|
||||||
wait_for_trigger: Trigger | Trigger[];
|
wait_for_trigger: Trigger | Trigger[];
|
||||||
timeout?: number;
|
timeout?: number | Partial<WaitForTriggerActionParts> | string;
|
||||||
continue_on_timeout?: boolean;
|
continue_on_timeout?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ import { WaitForTriggerAction } from "../../../../../data/script";
|
|||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import "../../trigger/ha-automation-trigger";
|
import "../../trigger/ha-automation-trigger";
|
||||||
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
||||||
|
import "../../../../../components/ha-duration-input";
|
||||||
|
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
||||||
|
import { TimeChangedEvent } from "../../../../../components/ha-base-time-input";
|
||||||
|
|
||||||
@customElement("ha-automation-action-wait_for_trigger")
|
@customElement("ha-automation-action-wait_for_trigger")
|
||||||
export class HaWaitForTriggerAction
|
export class HaWaitForTriggerAction
|
||||||
@ -22,17 +25,18 @@ export class HaWaitForTriggerAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const { wait_for_trigger, continue_on_timeout, timeout } = this.action;
|
const { wait_for_trigger, continue_on_timeout } = this.action;
|
||||||
|
const timeData = createDurationData(this.action.timeout);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-textfield
|
<ha-duration-input
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.type.wait_for_trigger.timeout"
|
"ui.panel.config.automation.editor.actions.type.wait_for_trigger.timeout"
|
||||||
)}
|
)}
|
||||||
.name=${"timeout"}
|
.data=${timeData}
|
||||||
.value=${timeout || ""}
|
enableMillisecond
|
||||||
@change=${this._valueChanged}
|
@value-changed=${this._timeoutChanged}
|
||||||
></ha-textfield>
|
></ha-duration-input>
|
||||||
<ha-formfield
|
<ha-formfield
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.type.wait_for_trigger.continue_timeout"
|
"ui.panel.config.automation.editor.actions.type.wait_for_trigger.continue_timeout"
|
||||||
@ -52,6 +56,17 @@ export class HaWaitForTriggerAction
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _timeoutChanged(ev: CustomEvent<{ value: TimeChangedEvent }>): void {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const value = ev.detail.value;
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: { ...this.action, timeout: value },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private _continueChanged(ev) {
|
private _continueChanged(ev) {
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: { ...this.action, continue_on_timeout: ev.target.checked },
|
value: { ...this.action, continue_on_timeout: ev.target.checked },
|
||||||
@ -64,7 +79,7 @@ export class HaWaitForTriggerAction
|
|||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
ha-textfield {
|
ha-duration-input {
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user