added scene support

This commit is contained in:
ari committed 2022-08-06 22:43:56 -04:00
1 parent 754cc2ef98
commit 6b21734041
6 files changed
+52 -12

No files matched your search

@@ -0,0 +1,21 @@
import InputText from "components/Inputs/Base/InputText";
import { SceneAction } from "types/automations/actions";
import { OptionManager } from "./OptionManager";
export const ActionSceneState: OptionManager<SceneAction> = {
defaultState: () => ({
scene: "",
}),
isReady: () => true,
Component: ({ state, setState }) => {
return (
<>
<InputText
label="Scene"
value={state.scene ?? ""}
onChange={(d) => setState({ ...state, scene: d })}
/>
</>
);
},
};
@@ -22,6 +22,7 @@ import { ActionStopState } from "./ActionStop";
import { ActionParallelState } from "./ActionParallel";
import { TriggerSunState } from "./TriggerSun";
import { TriggerCalendarState } from "./TriggerCalendar";
import { ActionSceneState } from "./ActionScene";
export const getOptionManager = <T extends AutomationNodeTypes>(
nodeType: T,
@@ -41,6 +42,8 @@ export const getOptionManager = <T extends AutomationNodeTypes>(
return ActionCallServiceState;
case "wait":
return ActionWaitState;
case "scene":
return ActionSceneState;
case "stop":
return ActionStopState;
case "delay":
+13 -12
View File
@@ -4,24 +4,25 @@ const subtypeDescMap: Partial<Record<AutomationNodeSubtype, string>> = {
choose: "create conditional if/else statements",
parallel: "run multiple nodes at the same time",
stop: "stop the automation with a status code",
scene: "activate a scene.",
wait: "wait based on a condition",
repeat: "repeat a sequence until or while some conditions are met",
device: "device related actions",
service: "call a service",
event: "Fires when an event is being received.",
homeassistant: "Fires when Home Assistant starts up or shuts down.",
mqtt: "Fires when a specific message is received on given MQTT topic.",
sun: "Fires when the sun is setting or rising.",
event: "fires when an event is being received.",
homeassistant: "fires when Home Assistant starts up or shuts down.",
mqtt: "fires when a specific message is received on given MQTT topic.",
sun: "fires when the sun is setting or rising.",
numeric_state:
"Fires when the numeric value of an entity's state or attribute changes.",
state: "Fires when an entity's state or attribute changes",
template: "Evaluate a custom template",
time: "Specify a certain time to run",
"fires when the numeric value of an entity's state or attribute changes.",
state: "fires when an entity's state or attribute changes",
template: "evaluate a custom template",
time: "specify a certain time to run",
webhook:
"Webhook trigger fires when a web request is made to the webhook endpoint",
zone: "Specify when an entity enters or leaves a zone",
tag: "Fires when a tag is scanned.",
calendar: "Fires when a Calendar event starts or ends.",
"webhook trigger fires when a web request is made to the webhook endpoint",
zone: "specify when an entity enters or leaves a zone",
tag: "fires when a tag is scanned.",
calendar: "fires when a Calendar event starts or ends.",
};
export const getNodeSubTypeDescription = (
+3
View File
@@ -28,6 +28,7 @@ export type DelayAction = st.Infer<typeof v.DelayAction>;
export type FireEventAction = st.Infer<typeof v.FireEventAction>;
export type DeviceAction = st.Infer<typeof v.DeviceAction>;
export type StopAction = st.Infer<typeof v.StopAction>;
export type SceneAction = st.Infer<typeof v.SceneAction>;
export type ChooseAction = OriginalChooseAction | IfElseAction;
export type OriginalChooseAction = AutomationActionNodeBase<{
choose: Array<{
@@ -58,6 +59,7 @@ export type ActionTypeMapping = {
stop: StopAction;
choose: ChooseAction;
parallel: ParallelAction;
scene: SceneAction;
};
export type AutomationAction =
| ServiceAction
@@ -68,5 +70,6 @@ export type AutomationAction =
| StopAction
| ChooseAction
| ParallelAction
| SceneAction
| DelayAction;
export type ActionType = keyof ActionTypeMapping;
+7
View File
@@ -79,6 +79,13 @@ export const StopAction = st.assign(
})
);
export const SceneAction = st.assign(
AutomationActionNodeBase,
st.type({
scene: st.string(),
})
);
export const OriginalChooseAction = st.intersection([
AutomationActionNodeBase,
st.type({
+5
View File
@@ -50,6 +50,7 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T) => {
"stop",
"choose",
"parallel",
"scene",
] as AutomationNodeSubtype<"action">[];
case "condition":
return [
@@ -145,6 +146,8 @@ export const getNodeSubType = <
return "stop" as any;
} else if ("parallel" in node) {
return "parallel" as any;
} else if ("scene" in node) {
return "scene" as any;
} else if (!ignoreInvalid) {
throw new Error("Invalid node type!");
}
@@ -164,6 +167,7 @@ export const TriggerValidators: Record<TriggerType, any> = {
webhook: v.triggers.AutomationTriggerWebhook,
zone: v.triggers.AutomationTriggerZone,
sun: v.triggers.AutomationTriggerSun,
calendar: v.triggers.AutomationTriggerCalendar,
};
export const ActionValidators: Record<ActionType, any> = {
@@ -174,6 +178,7 @@ export const ActionValidators: Record<ActionType, any> = {
repeat: v.actions.RepeatAction,
service: v.actions.ServiceAction,
stop: v.actions.StopAction,
scene: v.actions.SceneAction,
wait: st.union([v.actions.DelayAction, v.actions.WaitAction]),
};