mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 05:47:20 +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;
|
||||
}
|
||||
|
||||
export interface WaitForTriggerActionParts extends BaseAction {
|
||||
milliseconds?: number;
|
||||
seconds?: number;
|
||||
minutes?: number;
|
||||
hours?: number;
|
||||
days?: number;
|
||||
}
|
||||
|
||||
export interface WaitForTriggerAction extends BaseAction {
|
||||
wait_for_trigger: Trigger | Trigger[];
|
||||
timeout?: number;
|
||||
timeout?: number | Partial<WaitForTriggerActionParts> | string;
|
||||
continue_on_timeout?: boolean;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,9 @@ import { WaitForTriggerAction } from "../../../../../data/script";
|
||||
import { HomeAssistant } from "../../../../../types";
|
||||
import "../../trigger/ha-automation-trigger";
|
||||
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")
|
||||
export class HaWaitForTriggerAction
|
||||
@ -22,17 +25,18 @@ export class HaWaitForTriggerAction
|
||||
}
|
||||
|
||||
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`
|
||||
<ha-textfield
|
||||
<ha-duration-input
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.automation.editor.actions.type.wait_for_trigger.timeout"
|
||||
)}
|
||||
.name=${"timeout"}
|
||||
.value=${timeout || ""}
|
||||
@change=${this._valueChanged}
|
||||
></ha-textfield>
|
||||
.data=${timeData}
|
||||
enableMillisecond
|
||||
@value-changed=${this._timeoutChanged}
|
||||
></ha-duration-input>
|
||||
<ha-formfield
|
||||
.label=${this.hass.localize(
|
||||
"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) {
|
||||
fireEvent(this, "value-changed", {
|
||||
value: { ...this.action, continue_on_timeout: ev.target.checked },
|
||||
@ -64,7 +79,7 @@ export class HaWaitForTriggerAction
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
ha-textfield {
|
||||
ha-duration-input {
|
||||
display: block;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user