Compare commits

...
11 Commits
Author SHA1 Message Date
ari 6b21734041 added scene support 2022-08-06 22:43:56 -04:00
ari 754cc2ef98 added more support for trigger types 2022-08-06 22:37:26 -04:00
ari 1cb40288b1 remove state for zone 2022-08-06 20:41:02 -04:00
ari 129ba28ff5 v0.5.3 2022-08-06 20:28:09 -04:00
Ari Sosnovsky 44e246f79b Update README.md 2022-08-06 20:22:34 -04:00
ari 8bcbcaa801 added a redirect 2022-08-06 20:03:10 -04:00
ari b479476833 fixed up invalid node issue 2022-08-06 15:29:41 -04:00
Przemysław Adam Sowa baa31ab649 Don't use network host mode in the example docker-compose.yaml (#128) 2022-08-06 14:20:27 -04:00
Ari Sosnovsky dc7c6273e4 Update README.md 2022-08-06 13:16:34 -04:00
Ari Sosnovsky 2942b6173b Update README.md 2022-08-05 23:41:46 -04:00
ari bcfc648011 controls 2022-08-05 23:35:47 -04:00
22 changed files with 320 additions and 84 deletions

No files matched your search

+12
View File
@@ -1,5 +1,17 @@
# Changelog ![GitHub release (latest by date)](https://img.shields.io/github/v/release/asosnovsky/Shortumation?label=&style=for-the-badge) # Changelog ![GitHub release (latest by date)](https://img.shields.io/github/v/release/asosnovsky/Shortumation?label=&style=for-the-badge)
## [0.5.3] - Bug Fixes
- Redirecting `/` to `/web` to resolve container install strangeness reported in https://github.com/asosnovsky/Shortumation/issues/125
- Fixed missing flag that caused the automation to explode in https://github.com/asosnovsky/Shortumation/issues/124
## [0.5.2] - Better Controls
- Add automation trigger
- Speed dial on the bottom
<img src="https://user-images.githubusercontent.com/7451445/183231968-9891bbb4-5c7c-4e05-b804-36978c809a5c.png" width="200px"/>
- Infinite undos <img src="https://user-images.githubusercontent.com/7451445/183231977-ed000017-2886-4a57-b5fb-c7e527bf3894.png" width="200px"/>
## [0.5.1] - Sidebar! ## [0.5.1] - Sidebar!
- completely redesigned the sidebar! - completely redesigned the sidebar!
+8 -4
View File
@@ -1,4 +1,4 @@
# Shortumation ![GitHub release (latest by date)](https://img.shields.io/github/v/release/asosnovsky/Shortumation?label=&style=platsic) # <img src="logo.png" height="40x"/> Shortumation ![GitHub release (latest by date)](https://img.shields.io/github/v/release/asosnovsky/Shortumation?label=&style=platsic)
[![Test](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml/badge.svg)](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [![Build](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml/badge.svg)](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml) [![Test](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml/badge.svg)](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [![Build](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml/badge.svg)](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml)
@@ -6,7 +6,9 @@
| ------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | | ------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| Version | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/asosnovsky/Shortumation?label=&style=for-the-badge) | ![Docker Image Version (latest semver)](https://img.shields.io/docker/v/asosnovsky/shortumation-amd64?&sort=date&label=&style=for-the-badge) | | Version | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/asosnovsky/Shortumation?label=&style=for-the-badge) | ![Docker Image Version (latest semver)](https://img.shields.io/docker/v/asosnovsky/shortumation-amd64?&sort=date&label=&style=for-the-badge) |
A [home-assistant addon](https://www.home-assistant.io/addons/) for a better UI for managing and writing your automations. We provide a way to visualize your automation using a visual-programming language that draws inspirations from [Node-Red](https://nodered.org/). A [home-assistant addon](https://www.home-assistant.io/addons/) for a better UI for managing and writing your automations. We provide a way to visualize your automation using a visual-programming language that draws inspirations from [Node-Red](https://nodered.org/).
<img src="./assets/comparisons.png">
## Features ## Features
@@ -46,12 +48,14 @@ Add the repository URL under **Supervisor → Add-on store → ⋮ → Manage ad
It should now appear in your `Add-on Store` and you should be able to install it! It should now appear in your `Add-on Store` and you should be able to install it!
**Please note that you may need to enable advance mode in your settings first!**
### Containerized or HA Core ### Containerized or HA Core
Please note that this way of using Shortumation is **not future proof**.
If this warning does not scare you or you still want to try things out, then take a look at the example [docker-compose.yaml](example/containerized/docker-compose.yaml), or read the [extended guide here](https://github.com/asosnovsky/Shortumation/wiki/Installation#containerized--ha-core). If this warning does not scare you or you still want to try things out, then take a look at the example [docker-compose.yaml](example/containerized/docker-compose.yaml), or read the [extended guide here](https://github.com/asosnovsky/Shortumation/wiki/Installation#containerized--ha-core).
In general, if you want to help provide this to more home-assistant fans please join on the conversation here https://github.com/asosnovsky/Shortumation/issues/102 or help contribute :)
## FAQ ## FAQ
**How is this different from Node-Red?** **How is this different from Node-Red?**
+11 -1
View File
@@ -1,6 +1,7 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from fastapi.responses import RedirectResponse
from src.automations.manager import AutomationManager from src.automations.manager import AutomationManager
from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER
@@ -10,7 +11,8 @@ from .routes import automations, details, ping, socket
def make_app(automation_mgr: AutomationManager) -> FastAPI: def make_app(automation_mgr: AutomationManager) -> FastAPI:
app = FastAPI() app = FastAPI()
if (ROOT_FOLDER / "web").exists(): has_web_folder = (ROOT_FOLDER / "web").exists()
if has_web_folder:
app.mount( app.mount(
f"{API_PREFIX}/web", f"{API_PREFIX}/web",
StaticFiles( StaticFiles(
@@ -19,6 +21,7 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
), ),
name="web", name="web",
) )
else: else:
print("WARN: could not find web folder") print("WARN: could not find web folder")
app.add_middleware( app.add_middleware(
@@ -36,4 +39,11 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details" details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details"
) )
app.include_router(socket.router, prefix=f"{API_PREFIX}/socket") app.include_router(socket.router, prefix=f"{API_PREFIX}/socket")
@app.get("/")
def get_index():
if has_web_folder:
return RedirectResponse("/web")
return RedirectResponse("/details")
return app return app
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

+1 -1
View File
@@ -1,5 +1,5 @@
name: Shortumation name: Shortumation
version: v0.5.1 version: v0.5.3
slug: shortumation slug: shortumation
image: asosnovsky/shortumation-{arch} image: asosnovsky/shortumation-{arch}
url: "https://github.com/asosnovsky/Shortumation" url: "https://github.com/asosnovsky/Shortumation"
+5 -2
View File
@@ -12,9 +12,12 @@ services:
shortumation: shortumation:
# make sure to replace the ARCH with whatever system you are running! # make sure to replace the ARCH with whatever system you are running!
image: "asosnovsky/shortumation-${ARCH:-amd64}:${SHORTUMATION_VERSION:-latest}" image: "asosnovsky/shortumation-${ARCH:-amd64}:${SHORTUMATION_VERSION:-latest}"
network_mode: host ports:
- 8000:8000
extra_hosts:
- "host.docker.internal:host-gateway"
volumes: volumes:
- ./config:/config - ./config:/config
environment: environment:
- SUPERVISOR_TOKEN=${SUPERVISOR_TOKEN} - SUPERVISOR_TOKEN=${SUPERVISOR_TOKEN}
- HASSIO_WS=ws://0.0.0.0:8123/api/websocket - HASSIO_WS=ws://host.docker.internal:8123/api/websocket
@@ -120,3 +120,54 @@ export const MissingAutoInConfig = make({
entitySource: {}, entitySource: {},
}, },
}); });
export const BadAutomation = make({
haProps: {
loading: false,
entities: {
[`automation.${auto1.metadata.id}`]: {
entity_id: `automation.${auto1.metadata.id}`,
attributes: {
id: "test",
},
context: { id: "", parent_id: null, user_id: null },
last_changed: "",
last_updated: "",
state: "on",
},
},
entitySource: {},
},
automations: [
{
tags: {},
metadata: {
id: "test",
mode: "single",
alias: "Light.Tank_Day",
description: "",
},
trigger: [
{
platform: "sun",
event: "sunrise",
offset: "30",
} as any,
{ whoAmI: "bad node is who" } as any,
],
condition: [{ whoAmI: "bad node is who" } as any],
sequence: [
{ scene: "scene.light_day" } as any,
{ whoAmI: "bad node is who" } as any,
{
service: "input_select.set_options",
target: {
entity_id: "input_select.tank_light_mode",
},
data: {
options: "day",
},
},
],
},
],
});
@@ -6,7 +6,7 @@ export const NODE_HEIGHT = 80 as const;
export const DEFAULT_DIMS: DAGDims = { export const DEFAULT_DIMS: DAGDims = {
collection: { collection: {
height: NODE_HEIGHT * 3, height: NODE_HEIGHT * 3,
width: NODE_WIDTH * 1.5, width: NODE_WIDTH * 2.5,
}, },
node: { node: {
height: NODE_HEIGHT, height: NODE_HEIGHT,
@@ -29,7 +29,7 @@ export const useDAGElementsState = () => {
}, },
getIsClosedActions(nodeId: string, node: AutomationNode) { getIsClosedActions(nodeId: string, node: AutomationNode) {
if (isSpecialNode(getNodeSubType(node))) { if (isSpecialNode(getNodeSubType(node, true))) {
return { return {
isClosed: this.get(nodeId).isClosed ?? false, isClosed: this.get(nodeId).isClosed ?? false,
setIsClosed: (v: boolean) => this.set(nodeId, "isClosed", v), setIsClosed: (v: boolean) => this.set(nodeId, "isClosed", v),
@@ -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 })}
/>
</>
);
},
};
@@ -0,0 +1,39 @@
import { OptionManager } from "./OptionManager";
import { AutomationTriggerCalendar } from "types/automations/triggers";
import { InputList } from "components/Inputs/InputList";
import InputText from "components/Inputs/Base/InputText";
export const TriggerCalendarState: OptionManager<AutomationTriggerCalendar> = {
defaultState: (): AutomationTriggerCalendar => ({
platform: "calendar",
event: "sunset",
}),
isReady: () => true,
Component: ({ state, setState }) => {
return (
<>
<InputList
label="Event Type"
current={state.event}
options={["start", "end"]}
onChange={(event) =>
setState({
...state,
event,
})
}
/>
<InputText
label="Offset"
value={state.offset ?? ""}
onChange={(s) =>
setState({
...state,
offset: !s ? undefined : s,
})
}
/>
</>
);
},
};
@@ -0,0 +1,39 @@
import { OptionManager } from "./OptionManager";
import { AutomationTriggerSun } from "types/automations/triggers";
import { InputList } from "components/Inputs/InputList";
import InputText from "components/Inputs/Base/InputText";
export const TriggerSunState: OptionManager<AutomationTriggerSun> = {
defaultState: (): AutomationTriggerSun => ({
platform: "sun",
event: "sunset",
}),
isReady: () => true,
Component: ({ state, setState }) => {
return (
<>
<InputList
label="Event Type"
current={state.event}
options={["sunset", "sunrise"]}
onChange={(event) =>
setState({
...state,
event,
})
}
/>
<InputText
label="Offset"
value={state.offset ?? ""}
onChange={(s) =>
setState({
...state,
offset: !s ? undefined : s,
})
}
/>
</>
);
},
};
@@ -8,7 +8,7 @@ export const TriggerWebhook: OptionManager<AutomationTriggerWebhook> = {
webhook_id: "", webhook_id: "",
}), }),
isReady: () => true, isReady: () => true,
renderOptionList: (state, setState) => { Component: ({ state, setState }) => {
return ( return (
<> <>
<InputText <InputText
@@ -21,6 +21,10 @@ export const TriggerWebhook: OptionManager<AutomationTriggerWebhook> = {
}) })
} }
/> />
<span>
You can run this automation by sending an HTTP POST request to
http://your-home-assistant-ip/api/webhook/{state.webhook_id}.
</span>
</> </>
); );
}, },
@@ -20,6 +20,9 @@ import { TriggerZone } from "./TriggerZone";
import { TriggerDevice } from "./TriggerDevice"; import { TriggerDevice } from "./TriggerDevice";
import { ActionStopState } from "./ActionStop"; import { ActionStopState } from "./ActionStop";
import { ActionParallelState } from "./ActionParallel"; import { ActionParallelState } from "./ActionParallel";
import { TriggerSunState } from "./TriggerSun";
import { TriggerCalendarState } from "./TriggerCalendar";
import { ActionSceneState } from "./ActionScene";
export const getOptionManager = <T extends AutomationNodeTypes>( export const getOptionManager = <T extends AutomationNodeTypes>(
nodeType: T, nodeType: T,
@@ -39,6 +42,8 @@ export const getOptionManager = <T extends AutomationNodeTypes>(
return ActionCallServiceState; return ActionCallServiceState;
case "wait": case "wait":
return ActionWaitState; return ActionWaitState;
case "scene":
return ActionSceneState;
case "stop": case "stop":
return ActionStopState; return ActionStopState;
case "delay": case "delay":
@@ -58,6 +63,10 @@ export const getOptionManager = <T extends AutomationNodeTypes>(
return TriggerHAState; return TriggerHAState;
case "mqtt": case "mqtt":
return TriggerMQTTState; return TriggerMQTTState;
case "sun":
return TriggerSunState;
case "calendar":
return TriggerCalendarState;
case "numeric_state": case "numeric_state":
return TriggerNumericState; return TriggerNumericState;
case "state": case "state":
@@ -1,57 +1,55 @@
import React from "react"; import React from "react";
import { ComponentMeta, ComponentStory } from "@storybook/react"; import { ComponentStory } from "@storybook/react";
import { NodeEditor } from "."; import { NodeEditor, NodeEditorProps } from ".";
import { AutomationCondition } from "types/automations/conditions"; import { AutomationCondition } from "types/automations/conditions";
import { Button } from "components/Inputs/Buttons/Button"; import { Button } from "components/Inputs/Buttons/Button";
import { useState } from "react"; import { useState } from "react";
import { Modal } from "components/Modal"; import { Modal } from "components/Modal";
import { Page } from "components/Page"; import { Page } from "components/Page";
import { makeStory } from "devUtils";
export default { const { componentMeta, make } = makeStory({
title: "NodeEditor", meta: {
component: NodeEditor, title: "NodeEditor",
parameters: { actions: { argTypesRegex: "^on.*" } }, args: {
args: { node: {
node: { data: {},
data: {}, service: "",
service: "", target: "",
target: "", },
}, },
}, },
} as ComponentMeta<typeof NodeEditor>; Component: (props: NodeEditorProps) => {
const [state, setState] = useState(props.node);
return (
<Page>
<NodeEditor
{...props}
node={state}
onSave={(s) => {
setState(s);
props.onSave && props.onSave(s);
}}
/>
</Page>
);
},
});
const Base: ComponentStory<typeof NodeEditor> = (props) => { export default componentMeta;
const [state, setState] = useState(props.node);
return ( export const Action = make({});
<Page> export const SingleOption = make({
<NodeEditor
{...props}
node={state}
onSave={(s) => {
setState(s);
props.onSave && props.onSave(s);
}}
/>
</Page>
);
};
export const Action = Base.bind({});
export const SingleOption = Action.bind({});
SingleOption.args = {
...SingleOption.args,
allowedTypes: ["action"], allowedTypes: ["action"],
}; });
export const Condition = Action.bind({}); export const Condition = make({
Condition.args = {
...Condition.args,
node: { node: {
condition: "and", condition: "and",
conditions: [ conditions: [
{ {
condition: "numeric_state", condition: "numeric_state",
entity_id: ["sensor.kitchen_humidity"], entity_id: ["sensor.kitchen_humidity"],
conditions: [],
above: "40", above: "40",
}, },
{ {
@@ -59,26 +57,22 @@ Condition.args = {
value_template: "states('switch.kitchen') == 'on'", value_template: "states('switch.kitchen') == 'on'",
}, },
], ],
} as AutomationCondition, },
}; });
export const UnSupported = Action.bind({}); export const UnSupported = make({
UnSupported.args = {
...UnSupported.args,
node: { node: {
condition: "bargs", condition: "bargs",
platform: "rouge", platform: "rouge",
} as any, } as any,
}; });
export const DeviceTriggerExample = Action.bind({}); export const DeviceTriggerExample = make({
DeviceTriggerExample.args = {
...DeviceTriggerExample.args,
node: { node: {
platform: "device", platform: "device",
device_id: "bd83b10cb1c7aa028c12dade5b4e87d5", device_id: "bd83b10cb1c7aa028c12dade5b4e87d5",
}, },
}; });
export const InAModal: ComponentStory<typeof NodeEditor> = (props) => { export const InAModal: ComponentStory<typeof NodeEditor> = (props) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
@@ -92,19 +86,15 @@ export const InAModal: ComponentStory<typeof NodeEditor> = (props) => {
); );
}; };
export const ServiceExample = Action.bind({}); export const ServiceExample = make({
ServiceExample.args = {
...ServiceExample.args,
node: { node: {
target: {}, target: {},
data: {}, data: {},
service: "", service: "",
}, },
}; });
export const ServiceWithDataExample = Action.bind({}); export const ServiceWithDataExample = make({
ServiceWithDataExample.args = {
...ServiceWithDataExample.args,
node: { node: {
target: { target: {
entity: "light.switch_baby", entity: "light.switch_baby",
@@ -114,37 +104,29 @@ ServiceWithDataExample.args = {
}, },
service: "light.turn_on", service: "light.turn_on",
}, },
}; });
export const DelayExample = Action.bind({}); export const DelayExample = make({
DelayExample.args = {
...DelayExample.args,
node: { node: {
wait_template: "", wait_template: "",
}, },
}; });
export const StateTriggerExample = Action.bind({}); export const StateTriggerExample = make({
StateTriggerExample.args = {
...StateTriggerExample.args,
node: { node: {
platform: "state", platform: "state",
entity_id: "binary_sensor.door_main", entity_id: "binary_sensor.door_main",
}, },
}; });
export const DeviceActionFilledExample = Action.bind({}); export const DeviceActionFilledExample = make({
DeviceActionFilledExample.args = {
...DeviceActionFilledExample.args,
node: { node: {
type: "toggle", type: "toggle",
device_id: "c9711be86b0301955f72380509285485", device_id: "c9711be86b0301955f72380509285485",
}, } as any,
}; });
export const NotifyPhoneViaDeviceAction = Action.bind({}); export const NotifyPhoneViaDeviceAction = make({
NotifyPhoneViaDeviceAction.args = {
...NotifyPhoneViaDeviceAction.args,
node: { node: {
device_id: "2a98db84af7526c7ec3cc7aebd1a9e1c", device_id: "2a98db84af7526c7ec3cc7aebd1a9e1c",
domain: "mobile_app", domain: "mobile_app",
@@ -152,4 +134,11 @@ NotifyPhoneViaDeviceAction.args = {
title: "Hassio Status", title: "Hassio Status",
message: "Hassio Is turning off...", message: "Hassio Is turning off...",
} as any, } as any,
}; });
export const Sun = make({
node: {
platform: "sun",
event: "sunset",
},
});
+15
View File
@@ -4,10 +4,25 @@ const subtypeDescMap: Partial<Record<AutomationNodeSubtype, string>> = {
choose: "create conditional if/else statements", choose: "create conditional if/else statements",
parallel: "run multiple nodes at the same time", parallel: "run multiple nodes at the same time",
stop: "stop the automation with a status code", stop: "stop the automation with a status code",
scene: "activate a scene.",
wait: "wait based on a condition", wait: "wait based on a condition",
repeat: "repeat a sequence until or while some conditions are met", repeat: "repeat a sequence until or while some conditions are met",
device: "device related actions", device: "device related actions",
service: "call a service", 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.",
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",
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.",
}; };
export const getNodeSubTypeDescription = ( 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 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 StopAction = st.Infer<typeof v.StopAction>;
export type SceneAction = st.Infer<typeof v.SceneAction>;
export type ChooseAction = OriginalChooseAction | IfElseAction; export type ChooseAction = OriginalChooseAction | IfElseAction;
export type OriginalChooseAction = AutomationActionNodeBase<{ export type OriginalChooseAction = AutomationActionNodeBase<{
choose: Array<{ choose: Array<{
@@ -58,6 +59,7 @@ export type ActionTypeMapping = {
stop: StopAction; stop: StopAction;
choose: ChooseAction; choose: ChooseAction;
parallel: ParallelAction; parallel: ParallelAction;
scene: SceneAction;
}; };
export type AutomationAction = export type AutomationAction =
| ServiceAction | ServiceAction
@@ -68,5 +70,6 @@ export type AutomationAction =
| StopAction | StopAction
| ChooseAction | ChooseAction
| ParallelAction | ParallelAction
| SceneAction
| DelayAction; | DelayAction;
export type ActionType = keyof ActionTypeMapping; export type ActionType = keyof ActionTypeMapping;
+9 -1
View File
@@ -26,6 +26,10 @@ export type AutomationTriggerZone = st.Infer<typeof v.AutomationTriggerZone>;
export type AutomationTriggerDevice = st.Infer< export type AutomationTriggerDevice = st.Infer<
typeof v.AutomationTriggerDevice typeof v.AutomationTriggerDevice
>; >;
export type AutomationTriggerSun = st.Infer<typeof v.AutomationTriggerSun>;
export type AutomationTriggerCalendar = st.Infer<
typeof v.AutomationTriggerCalendar
>;
export type ActionTriggerMapping = { export type ActionTriggerMapping = {
homeassistant: AutomationTriggerHA; homeassistant: AutomationTriggerHA;
@@ -39,6 +43,8 @@ export type ActionTriggerMapping = {
time: AutomationTriggerTime; time: AutomationTriggerTime;
webhook: AutomationTriggerWebhook; webhook: AutomationTriggerWebhook;
zone: AutomationTriggerZone; zone: AutomationTriggerZone;
sun: AutomationTriggerSun;
calendar: AutomationTriggerCalendar;
}; };
export type TriggerType = keyof ActionTriggerMapping; export type TriggerType = keyof ActionTriggerMapping;
@@ -54,4 +60,6 @@ export type AutomationTrigger =
| AutomationTriggerTime | AutomationTriggerTime
| AutomationTriggerWebhook | AutomationTriggerWebhook
| AutomationTriggerZone | AutomationTriggerZone
| AutomationTriggerDevice; | AutomationTriggerDevice
| AutomationTriggerSun
| AutomationTriggerCalendar;
+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([ export const OriginalChooseAction = st.intersection([
AutomationActionNodeBase, AutomationActionNodeBase,
st.type({ st.type({
+15
View File
@@ -96,6 +96,20 @@ export const AutomationTriggerZone = st.type({
event: st.enums(["enter", "leave"]), event: st.enums(["enter", "leave"]),
}); });
export const AutomationTriggerSun = st.type({
...AutomationTriggerBase,
platform: st.literal("sun"),
event: st.enums(["sunset", "sunrise"]),
offset: st.optional(st.string()),
});
export const AutomationTriggerCalendar = st.type({
...AutomationTriggerBase,
platform: st.literal("calendar"),
event: st.enums(["start", "end"]),
offset: st.optional(st.string()),
});
export const AutomationTriggerDevice = st.type({ export const AutomationTriggerDevice = st.type({
...AutomationTriggerBase, ...AutomationTriggerBase,
..._AutomationDeviceState, ..._AutomationDeviceState,
@@ -103,6 +117,7 @@ export const AutomationTriggerDevice = st.type({
}); });
export const AutomationTrigger = st.union([ export const AutomationTrigger = st.union([
AutomationTriggerSun,
AutomationTriggerEvent, AutomationTriggerEvent,
AutomationTriggerHA, AutomationTriggerHA,
AutomationTriggerMQTT, AutomationTriggerMQTT,
+8
View File
@@ -50,6 +50,7 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T) => {
"stop", "stop",
"choose", "choose",
"parallel", "parallel",
"scene",
] as AutomationNodeSubtype<"action">[]; ] as AutomationNodeSubtype<"action">[];
case "condition": case "condition":
return [ return [
@@ -73,6 +74,8 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T) => {
"zone", "zone",
"event", "event",
"homeassistant", "homeassistant",
"sun",
"calendar",
"mqtt", "mqtt",
"tag", "tag",
"template", "template",
@@ -143,6 +146,8 @@ export const getNodeSubType = <
return "stop" as any; return "stop" as any;
} else if ("parallel" in node) { } else if ("parallel" in node) {
return "parallel" as any; return "parallel" as any;
} else if ("scene" in node) {
return "scene" as any;
} else if (!ignoreInvalid) { } else if (!ignoreInvalid) {
throw new Error("Invalid node type!"); throw new Error("Invalid node type!");
} }
@@ -161,6 +166,8 @@ export const TriggerValidators: Record<TriggerType, any> = {
time: v.triggers.AutomationTriggerTime, time: v.triggers.AutomationTriggerTime,
webhook: v.triggers.AutomationTriggerWebhook, webhook: v.triggers.AutomationTriggerWebhook,
zone: v.triggers.AutomationTriggerZone, zone: v.triggers.AutomationTriggerZone,
sun: v.triggers.AutomationTriggerSun,
calendar: v.triggers.AutomationTriggerCalendar,
}; };
export const ActionValidators: Record<ActionType, any> = { export const ActionValidators: Record<ActionType, any> = {
@@ -171,6 +178,7 @@ export const ActionValidators: Record<ActionType, any> = {
repeat: v.actions.RepeatAction, repeat: v.actions.RepeatAction,
service: v.actions.ServiceAction, service: v.actions.ServiceAction,
stop: v.actions.StopAction, stop: v.actions.StopAction,
scene: v.actions.SceneAction,
wait: st.union([v.actions.DelayAction, v.actions.WaitAction]), wait: st.union([v.actions.DelayAction, v.actions.WaitAction]),
}; };
-1
View File
@@ -48,7 +48,6 @@ export const getConditionDefaultValues = (
condition, condition,
zone: "", zone: "",
entity_id: [], entity_id: [],
state: [],
} as ZoneCondition; } as ZoneCondition;
} else if (condition === "device") { } else if (condition === "device") {
return { return {