diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionScene.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionScene.tsx new file mode 100644 index 0000000..b48b887 --- /dev/null +++ b/webapp/src/components/NodeEditor/OptionManager/ActionScene.tsx @@ -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 = { + defaultState: () => ({ + scene: "", + }), + isReady: () => true, + Component: ({ state, setState }) => { + return ( + <> + setState({ ...state, scene: d })} + /> + + ); + }, +}; diff --git a/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts b/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts index b67abd4..bfa2be3 100644 --- a/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts +++ b/webapp/src/components/NodeEditor/OptionManager/getOptionManager.ts @@ -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 = ( nodeType: T, @@ -41,6 +42,8 @@ export const getOptionManager = ( return ActionCallServiceState; case "wait": return ActionWaitState; + case "scene": + return ActionSceneState; case "stop": return ActionStopState; case "delay": diff --git a/webapp/src/components/NodeEditor/utils.ts b/webapp/src/components/NodeEditor/utils.ts index 4589a7c..51f6675 100644 --- a/webapp/src/components/NodeEditor/utils.ts +++ b/webapp/src/components/NodeEditor/utils.ts @@ -4,24 +4,25 @@ const subtypeDescMap: Partial> = { 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 = ( diff --git a/webapp/src/types/automations/actions.ts b/webapp/src/types/automations/actions.ts index 178a1a5..4a18115 100644 --- a/webapp/src/types/automations/actions.ts +++ b/webapp/src/types/automations/actions.ts @@ -28,6 +28,7 @@ export type DelayAction = st.Infer; export type FireEventAction = st.Infer; export type DeviceAction = st.Infer; export type StopAction = st.Infer; +export type SceneAction = st.Infer; 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; diff --git a/webapp/src/types/validators/actions.ts b/webapp/src/types/validators/actions.ts index a18b253..5065ca8 100644 --- a/webapp/src/types/validators/actions.ts +++ b/webapp/src/types/validators/actions.ts @@ -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({ diff --git a/webapp/src/utils/automations.ts b/webapp/src/utils/automations.ts index 4e30341..257ed56 100644 --- a/webapp/src/utils/automations.ts +++ b/webapp/src/utils/automations.ts @@ -50,6 +50,7 @@ export const getSubTypeList = (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 = { webhook: v.triggers.AutomationTriggerWebhook, zone: v.triggers.AutomationTriggerZone, sun: v.triggers.AutomationTriggerSun, + calendar: v.triggers.AutomationTriggerCalendar, }; export const ActionValidators: Record = { @@ -174,6 +178,7 @@ export const ActionValidators: Record = { 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]), };