From e6a835a5f3c96eb9e896d6acd6be7fe508db6dd0 Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 8 Aug 2022 20:53:31 -0400 Subject: [PATCH] minor clean up --- webapp/src/types/automations/actions.ts | 13 +++-- webapp/src/types/automations/triggers.ts | 17 ++++--- webapp/src/types/validators/actions.ts | 60 ++++++++++++------------ 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/webapp/src/types/automations/actions.ts b/webapp/src/types/automations/actions.ts index 4a18115..3808da6 100644 --- a/webapp/src/types/automations/actions.ts +++ b/webapp/src/types/automations/actions.ts @@ -52,14 +52,17 @@ export type ParallelAction = AutomationActionNodeBase<{ }>; export type ActionTypeMapping = { service: ServiceAction; - repeat: RepeatAction; - wait: WaitAction | DelayAction; - event: FireEventAction; device: DeviceAction; - stop: StopAction; + + event: FireEventAction; + scene: SceneAction; + + repeat: RepeatAction; choose: ChooseAction; parallel: ParallelAction; - scene: SceneAction; + + wait: WaitAction | DelayAction; + stop: StopAction; }; export type AutomationAction = | ServiceAction diff --git a/webapp/src/types/automations/triggers.ts b/webapp/src/types/automations/triggers.ts index 63656ef..ca91e81 100644 --- a/webapp/src/types/automations/triggers.ts +++ b/webapp/src/types/automations/triggers.ts @@ -32,19 +32,22 @@ export type AutomationTriggerCalendar = st.Infer< >; export type ActionTriggerMapping = { - homeassistant: AutomationTriggerHA; device: AutomationTriggerDevice; + event: AutomationTriggerEvent; mqtt: AutomationTriggerMQTT; - numeric_state: AutomationTriggerNumericState; - state: AutomationTriggerState; + homeassistant: AutomationTriggerHA; tag: AutomationTriggerTag; - template: AutomationTriggerTemplate; - time: AutomationTriggerTime; - webhook: AutomationTriggerWebhook; - zone: AutomationTriggerZone; sun: AutomationTriggerSun; calendar: AutomationTriggerCalendar; + webhook: AutomationTriggerWebhook; + + numeric_state: AutomationTriggerNumericState; + state: AutomationTriggerState; + zone: AutomationTriggerZone; + + template: AutomationTriggerTemplate; + time: AutomationTriggerTime; }; export type TriggerType = keyof ActionTriggerMapping; diff --git a/webapp/src/types/validators/actions.ts b/webapp/src/types/validators/actions.ts index 5065ca8..a94bea2 100644 --- a/webapp/src/types/validators/actions.ts +++ b/webapp/src/types/validators/actions.ts @@ -13,15 +13,7 @@ export const AutomationActionNodeBase = st.type({ continue_on_error: st.optional(st.boolean()), }); -export const ServiceAction = st.intersection([ - AutomationActionNodeBase, - st.type({ - data: st.any(), - target: st.any(), - service: st.string(), - }), -]); - +// Flow Actions export const RepeatAction = st.intersection([ AutomationActionNodeBase, st.type({ @@ -59,19 +51,6 @@ export const DelayAction = st.intersection([ }), ]); -export const FireEventAction = st.intersection([ - AutomationActionNodeBase, - st.type({ - event: st.string(), - event_data: st.any(), - }), -]); - -export const DeviceAction = st.assign( - AutomationActionNodeBase, - st.partial(AutomationDeviceState) -); - export const StopAction = st.assign( AutomationActionNodeBase, st.type({ @@ -79,13 +58,6 @@ export const StopAction = st.assign( }) ); -export const SceneAction = st.assign( - AutomationActionNodeBase, - st.type({ - scene: st.string(), - }) -); - export const OriginalChooseAction = st.intersection([ AutomationActionNodeBase, st.type({ @@ -116,3 +88,33 @@ export const ParallelAction = st.intersection([ parallel: st.array(st.object()), }), ]); + +// Real Actions +export const ServiceAction = st.intersection([ + AutomationActionNodeBase, + st.type({ + data: st.any(), + target: st.any(), + service: st.string(), + }), +]); + +export const FireEventAction = st.intersection([ + AutomationActionNodeBase, + st.type({ + event: st.string(), + event_data: st.any(), + }), +]); + +export const DeviceAction = st.assign( + AutomationActionNodeBase, + st.partial(AutomationDeviceState) +); + +export const SceneAction = st.assign( + AutomationActionNodeBase, + st.type({ + scene: st.string(), + }) +);