stop action
This commit is contained in:
1 parent
07ab4b9089
commit
8bf25547eb
7 files changed
+96
-39
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
import InputText from "components/Inputs/InputText";
|
||||||
|
import { StopAction } from "types/automations/actions";
|
||||||
|
import { OptionManager } from "./OptionManager";
|
||||||
|
|
||||||
|
export const ActionStopState: OptionManager<StopAction> = {
|
||||||
|
defaultState: () => ({
|
||||||
|
alias: "",
|
||||||
|
stop: "",
|
||||||
|
}),
|
||||||
|
isReady: () => true,
|
||||||
|
Component: ({ state, setState }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<InputText
|
||||||
|
label="Stop Reason"
|
||||||
|
value={state.stop ?? []}
|
||||||
|
onChange={(d) => setState({ ...state, stop: d })}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AutomationNodeTypes, AutomationNodeSubtype } from "types/automations"
|
import { AutomationNodeTypes, AutomationNodeSubtype } from "types/automations";
|
||||||
import { ActionChooseState } from "./ActionChoose";
|
import { ActionChooseState } from "./ActionChoose";
|
||||||
import { ActionDeviceState } from "./ActionDevice";
|
import { ActionDeviceState } from "./ActionDevice";
|
||||||
import { ActionCallServiceState } from "./ActionService";
|
import { ActionCallServiceState } from "./ActionService";
|
||||||
@@ -19,59 +19,60 @@ import { TriggerTimePattern } from "./TriggerTimePattern";
|
|||||||
import { TriggerWebhook } from "./TriggerWebhook";
|
import { TriggerWebhook } from "./TriggerWebhook";
|
||||||
import { TriggerZone } from "./TriggerZone";
|
import { TriggerZone } from "./TriggerZone";
|
||||||
import { TriggerDevice } from "./TriggerDevice";
|
import { TriggerDevice } from "./TriggerDevice";
|
||||||
|
import { ActionStopState } from "./ActionStop";
|
||||||
|
|
||||||
|
|
||||||
export const getOptionManager = <T extends AutomationNodeTypes>(
|
export const getOptionManager = <T extends AutomationNodeTypes>(
|
||||||
nodeType: T,
|
nodeType: T,
|
||||||
nodeSubtype: AutomationNodeSubtype<T>,
|
nodeSubtype: AutomationNodeSubtype<T>
|
||||||
): OptionManager<any> => {
|
): OptionManager<any> => {
|
||||||
if (nodeType === 'action') {
|
if (nodeType === "action") {
|
||||||
switch (nodeSubtype) {
|
switch (nodeSubtype) {
|
||||||
case "choose":
|
case "choose":
|
||||||
return ActionChooseState;
|
return ActionChooseState;
|
||||||
case "device":
|
case "device":
|
||||||
return ActionDeviceState;
|
return ActionDeviceState;
|
||||||
case 'event':
|
case "event":
|
||||||
return ActionEventState;
|
return ActionEventState;
|
||||||
case "repeat":
|
case "repeat":
|
||||||
return ActionRepeatState;
|
return ActionRepeatState;
|
||||||
case 'service':
|
case "service":
|
||||||
return ActionCallServiceState;
|
return ActionCallServiceState;
|
||||||
case "wait":
|
case "wait":
|
||||||
return ActionWaitState;
|
return ActionWaitState;
|
||||||
|
case "stop":
|
||||||
|
return ActionStopState;
|
||||||
case "delay":
|
case "delay":
|
||||||
return ActionWaitState;
|
return ActionWaitState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nodeType === 'condition') {
|
if (nodeType === "condition") {
|
||||||
return ConditionLogicState
|
return ConditionLogicState;
|
||||||
}
|
}
|
||||||
if (nodeType === "trigger") {
|
if (nodeType === "trigger") {
|
||||||
switch (nodeSubtype) {
|
switch (nodeSubtype) {
|
||||||
case "event":
|
case "event":
|
||||||
return TriggerEventState
|
return TriggerEventState;
|
||||||
case "homeassistant":
|
case "homeassistant":
|
||||||
return TriggerHAState
|
return TriggerHAState;
|
||||||
case "mqtt":
|
case "mqtt":
|
||||||
return TriggerMQTTState
|
return TriggerMQTTState;
|
||||||
case "numeric_state":
|
case "numeric_state":
|
||||||
return TriggerNumericState
|
return TriggerNumericState;
|
||||||
case "state":
|
case "state":
|
||||||
return TriggerState
|
return TriggerState;
|
||||||
case "template":
|
case "template":
|
||||||
return TriggerTemplate
|
return TriggerTemplate;
|
||||||
case 'time':
|
case "time":
|
||||||
return TriggerTime
|
return TriggerTime;
|
||||||
case 'time_pattern':
|
case "time_pattern":
|
||||||
return TriggerTimePattern
|
return TriggerTimePattern;
|
||||||
case 'webhook':
|
case "webhook":
|
||||||
return TriggerWebhook
|
return TriggerWebhook;
|
||||||
case "zone":
|
case "zone":
|
||||||
return TriggerZone
|
return TriggerZone;
|
||||||
case "device":
|
case "device":
|
||||||
return TriggerDevice
|
return TriggerDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Generic
|
return Generic;
|
||||||
}
|
};
|
||||||
@@ -20,6 +20,7 @@ export type WaitAction = st.Infer<typeof v.WaitAction>;
|
|||||||
export type DelayAction = st.Infer<typeof v.DelayAction>;
|
export type DelayAction = st.Infer<typeof v.DelayAction>;
|
||||||
export type FireEventAction = st.Infer<typeof v.FireEventAction>;
|
export type FireEventAction = st.Infer<typeof v.FireEventAction>;
|
||||||
export type DeviceAction = st.Infer<typeof v.DeviceAction>;
|
export type DeviceAction = st.Infer<typeof v.DeviceAction>;
|
||||||
|
export type StopAction = st.Infer<typeof v.StopAction>;
|
||||||
export type ChooseAction = AutomationActionNodeBase<{
|
export type ChooseAction = AutomationActionNodeBase<{
|
||||||
choose: Array<{
|
choose: Array<{
|
||||||
conditions: AutomationCondition[];
|
conditions: AutomationCondition[];
|
||||||
@@ -34,6 +35,7 @@ export type AutomationAction =
|
|||||||
| DelayAction
|
| DelayAction
|
||||||
| FireEventAction
|
| FireEventAction
|
||||||
| DeviceAction
|
| DeviceAction
|
||||||
|
| StopAction
|
||||||
| ChooseAction;
|
| ChooseAction;
|
||||||
export type ActionType =
|
export type ActionType =
|
||||||
| "service"
|
| "service"
|
||||||
@@ -41,4 +43,5 @@ export type ActionType =
|
|||||||
| "wait"
|
| "wait"
|
||||||
| "event"
|
| "event"
|
||||||
| "device"
|
| "device"
|
||||||
|
| "stop"
|
||||||
| "choose";
|
| "choose";
|
||||||
@@ -30,11 +30,10 @@ export type AutomationNode<N extends AutomationNodeTypes = any> =
|
|||||||
: N extends "condition"
|
: N extends "condition"
|
||||||
? AutomationCondition
|
? AutomationCondition
|
||||||
: never;
|
: never;
|
||||||
|
export type AutomationNodeSubTypeMapping = {
|
||||||
|
trigger: TriggerType;
|
||||||
|
action: ActionType;
|
||||||
|
condition: ConditionType;
|
||||||
|
};
|
||||||
export type AutomationNodeSubtype<T extends AutomationNodeTypes = any> =
|
export type AutomationNodeSubtype<T extends AutomationNodeTypes = any> =
|
||||||
T extends "trigger"
|
AutomationNodeSubTypeMapping[T];
|
||||||
? TriggerType
|
|
||||||
: T extends "action"
|
|
||||||
? ActionType
|
|
||||||
: T extends "condition"
|
|
||||||
? ConditionType
|
|
||||||
: never;
|
|
||||||
@@ -63,6 +63,13 @@ export const DeviceAction = st.assign(
|
|||||||
st.partial(AutomationDeviceState)
|
st.partial(AutomationDeviceState)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const StopAction = st.assign(
|
||||||
|
AutomationActionNodeBase,
|
||||||
|
st.type({
|
||||||
|
stop: st.string(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
export const ChooseAction = st.intersection([
|
export const ChooseAction = st.intersection([
|
||||||
AutomationActionNodeBase,
|
AutomationActionNodeBase,
|
||||||
st.type({
|
st.type({
|
||||||
|
|||||||
@@ -39,12 +39,17 @@ export const getNodeType = (node: AutomationNode): AutomationNodeTypes => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSubTypeList = <T extends AutomationNodeTypes>(
|
export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T) => {
|
||||||
nodeType: T
|
|
||||||
): AutomationNodeSubtype<T>[] => {
|
|
||||||
switch (nodeType) {
|
switch (nodeType) {
|
||||||
case "action":
|
case "action":
|
||||||
return ["service", "repeat", "wait", "device", "choose"] as any;
|
return [
|
||||||
|
"service",
|
||||||
|
"repeat",
|
||||||
|
"wait",
|
||||||
|
"device",
|
||||||
|
"stop",
|
||||||
|
"choose",
|
||||||
|
] as AutomationNodeSubtype<"action">[];
|
||||||
case "condition":
|
case "condition":
|
||||||
return [
|
return [
|
||||||
"or",
|
"or",
|
||||||
@@ -57,7 +62,7 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(
|
|||||||
"time",
|
"time",
|
||||||
"trigger",
|
"trigger",
|
||||||
"zone",
|
"zone",
|
||||||
] as any;
|
] as AutomationNodeSubtype<"condition">[];
|
||||||
case "trigger":
|
case "trigger":
|
||||||
return [
|
return [
|
||||||
"device",
|
"device",
|
||||||
@@ -72,7 +77,7 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(
|
|||||||
"tag",
|
"tag",
|
||||||
"template",
|
"template",
|
||||||
"webhook",
|
"webhook",
|
||||||
] as any;
|
] as AutomationNodeSubtype<"trigger">[];
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -125,6 +130,8 @@ export const getNodeSubType = <T extends AutomationNodeTypes>(
|
|||||||
return "choose" as any;
|
return "choose" as any;
|
||||||
} else if ("delay" in node) {
|
} else if ("delay" in node) {
|
||||||
return "wait" as any;
|
return "wait" as any;
|
||||||
|
} else if ("stop" in node) {
|
||||||
|
return "stop" as any;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Invalid node type!");
|
throw new Error("Invalid node type!");
|
||||||
}
|
}
|
||||||
@@ -151,6 +158,7 @@ export const ActionValidators: Record<ActionType, any> = {
|
|||||||
event: v.actions.FireEventAction,
|
event: v.actions.FireEventAction,
|
||||||
repeat: v.actions.RepeatAction,
|
repeat: v.actions.RepeatAction,
|
||||||
service: v.actions.ServiceAction,
|
service: v.actions.ServiceAction,
|
||||||
|
stop: v.actions.StopAction,
|
||||||
wait: st.union([v.actions.DelayAction, v.actions.WaitAction]),
|
wait: st.union([v.actions.DelayAction, v.actions.WaitAction]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
DayOfWeek,
|
DayOfWeek,
|
||||||
} from "types/automations/common";
|
} from "types/automations/common";
|
||||||
import { AutomationTriggerZone } from "types/automations/triggers";
|
import { AutomationTriggerZone } from "types/automations/triggers";
|
||||||
|
import StopIcon from "@mui/icons-material/PanToolOutlined";
|
||||||
export interface Namer {
|
export interface Namer {
|
||||||
getEntityName(entity_id: string | string[], maxEntities?: number): string;
|
getEntityName(entity_id: string | string[], maxEntities?: number): string;
|
||||||
getDeviceName(device_id: string): string;
|
getDeviceName(device_id: string): string;
|
||||||
@@ -171,6 +171,23 @@ export const getDescriptionFromAutomationNode = <
|
|||||||
}
|
}
|
||||||
return "Switch (choose)";
|
return "Switch (choose)";
|
||||||
}
|
}
|
||||||
|
if ("stop" in node) {
|
||||||
|
if (allowJs) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: "0.5em",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span>{node.stop}</span>
|
||||||
|
<StopIcon />
|
||||||
|
</div>
|
||||||
|
) as any;
|
||||||
|
}
|
||||||
|
return `Stopping due to ${node.stop}`;
|
||||||
|
}
|
||||||
return "n/a";
|
return "n/a";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user