delay fixes

This commit is contained in:
ari committed 2022-06-12 22:23:30 -04:00
1 parent 5207c48f8d
commit d824a93695
5 files changed
+13 -7

No files matched your search

@@ -7,13 +7,12 @@ import { InputTime } from "components/Inputs/InputTime";
import { useState } from "react";
import { DelayAction, WaitAction } from "types/automations/actions";
import { OptionManager, updateActionData } from './OptionManager';
import { getNodeSubType } from 'utils/automations';
import InputYaml from "components/Inputs/InputYaml";
type ThisAction = WaitAction | DelayAction;
type Option = 'delay' | 'template' | 'trigger'
const getCurrentOption = (node: ThisAction): Option => {
if (getNodeSubType(node) === 'delay') {
if ('delay' in node) {
return 'delay'
} else {
return 'template'
@@ -40,6 +40,8 @@ export const getOptionManager = <T extends AutomationNodeTypes>(
return ActionCallServiceState;
case "wait":
return ActionWaitState;
case "delay":
return ActionWaitState;
}
}
if (nodeType === 'condition') {
+1 -1
View File
@@ -28,6 +28,7 @@ export type AutomationAction =
| ServiceAction
| RepeatAction
| WaitAction
| DelayAction
| FireEventAction
| DeviceAction
| ChooseAction
@@ -36,7 +37,6 @@ export type ActionType =
| 'service'
| 'repeat'
| 'wait'
| 'delay'
| 'event'
| 'device'
| 'choose'
+6 -4
View File
@@ -5,6 +5,7 @@ import { MiniFailure } from "types/validators/helper";
import { getFailures } from '../types/validators/helper';
import { ActionType } from "types/automations/actions";
import { ConditionType } from "types/automations/conditions";
import * as st from 'superstruct';
export const getNodeTypeAndValidate = (node: AutomationNode, allowedTypes: AutomationNodeTypes[]) => {
const nodeType = getNodeType(node);
@@ -31,7 +32,6 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T): Auto
"service",
"repeat",
"wait",
"delay",
"device",
"choose",
] as any
@@ -113,7 +113,7 @@ export const getNodeSubType = <T extends AutomationNodeTypes>(
} else if ('choose' in node) {
return 'choose' as any
} else if ('delay' in node) {
return 'delay' as any
return 'wait' as any
} else {
throw new Error("Invalid node type!")
}
@@ -140,8 +140,10 @@ const ActionValidators: Record<ActionType, any> = {
"event": v.actions.FireEventAction,
"repeat": v.actions.RepeatAction,
"service": v.actions.ServiceAction,
"wait": v.actions.WaitAction,
"delay": v.actions.DelayAction,
"wait": st.union([
v.actions.DelayAction,
v.actions.WaitAction
]),
}
const ConditionValidators: Record<ConditionType, any> = {
+3
View File
@@ -107,6 +107,9 @@ export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(
if ('repeat' in node) {
return 'Repeat ' + node.repeat.count
}
if ('delay' in node) {
return `Wait for ${convertTimeToString(node.delay)}`
}
if ('wait_template' in node) {
let out = 'Wait on ' + node.wait_template;
if (node.timeout) {