Initial support for parallel

This commit is contained in:
ari committed 2022-07-14 16:09:17 -04:00
1 parent 50f1d2a42d
commit d4e2e2f1e5
6 files changed
+50 -1

No files matched your search

@@ -0,0 +1,22 @@
import InputYaml from "components/Inputs/InputYaml";
import { ParallelAction } from "types/automations/actions";
import { OptionManager } from "./OptionManager";
export const ActionParallelState: OptionManager<ParallelAction> = {
defaultState: () => ({
alias: "",
parallel: [],
}),
isReady: () => true,
Component: ({ state, setState }) => {
return (
<>
<InputYaml
label="Actions"
value={state.parallel ?? []}
onChange={(parallel) => setState({ ...state, parallel })}
/>
</>
);
},
};
@@ -20,6 +20,7 @@ import { TriggerWebhook } from "./TriggerWebhook";
import { TriggerZone } from "./TriggerZone"; import { TriggerZone } from "./TriggerZone";
import { TriggerDevice } from "./TriggerDevice"; import { TriggerDevice } from "./TriggerDevice";
import { ActionStopState } from "./ActionStop"; import { ActionStopState } from "./ActionStop";
import { ActionParallelState } from "./ActionParallel";
export const getOptionManager = <T extends AutomationNodeTypes>( export const getOptionManager = <T extends AutomationNodeTypes>(
nodeType: T, nodeType: T,
@@ -43,6 +44,8 @@ export const getOptionManager = <T extends AutomationNodeTypes>(
return ActionStopState; return ActionStopState;
case "delay": case "delay":
return ActionWaitState; return ActionWaitState;
case "parallel":
return ActionParallelState;
} }
} }
if (nodeType === "condition") { if (nodeType === "condition") {
+11 -1
View File
@@ -28,7 +28,16 @@ export type ChooseAction = AutomationActionNodeBase<{
}>; }>;
default?: AutomationSequenceNode[]; default?: AutomationSequenceNode[];
}>; }>;
export type ParallelAction = AutomationActionNodeBase<{
parallel: Array<
| AutomationAction
| {
sequence: AutomationAction[];
}
>;
}>;
export type AutomationAction = export type AutomationAction =
| ParallelAction
| ServiceAction | ServiceAction
| RepeatAction | RepeatAction
| WaitAction | WaitAction
@@ -44,4 +53,5 @@ export type ActionType =
| "event" | "event"
| "device" | "device"
| "stop" | "stop"
| "choose"; | "choose"
| "parallel";
+7
View File
@@ -83,3 +83,10 @@ export const ChooseAction = st.intersection([
default: st.optional(st.array(st.object())), default: st.optional(st.array(st.object())),
}), }),
]); ]);
export const ParallelAction = st.intersection([
AutomationActionNodeBase,
st.type({
parallel: st.array(st.object()),
}),
]);
+4
View File
@@ -49,6 +49,7 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T) => {
"device", "device",
"stop", "stop",
"choose", "choose",
"parallel",
] as AutomationNodeSubtype<"action">[]; ] as AutomationNodeSubtype<"action">[];
case "condition": case "condition":
return [ return [
@@ -132,6 +133,8 @@ export const getNodeSubType = <T extends AutomationNodeTypes>(
return "wait" as any; return "wait" as any;
} else if ("stop" in node) { } else if ("stop" in node) {
return "stop" as any; return "stop" as any;
} else if ("parallel" in node) {
return "parallel" as any;
} else { } else {
throw new Error("Invalid node type!"); throw new Error("Invalid node type!");
} }
@@ -153,6 +156,7 @@ export const TriggerValidators: Record<TriggerType, any> = {
}; };
export const ActionValidators: Record<ActionType, any> = { export const ActionValidators: Record<ActionType, any> = {
parallel: v.actions.ParallelAction,
choose: v.actions.ChooseAction, choose: v.actions.ChooseAction,
device: v.actions.DeviceAction, device: v.actions.DeviceAction,
event: v.actions.FireEventAction, event: v.actions.FireEventAction,
+3
View File
@@ -188,6 +188,9 @@ export const getDescriptionFromAutomationNode = <
} }
return `Stopping due to ${node.stop}`; return `Stopping due to ${node.stop}`;
} }
if ("parallel" in node) {
return "Parallel";
}
return "n/a"; return "n/a";
}; };