diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc9f649 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +web/node_modules +web/.parcel-cache +web/dist +api/venv diff --git a/web/.vscode/launch.json b/web/.vscode/launch.json new file mode 100644 index 0000000..200d9e9 --- /dev/null +++ b/web/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "type": "node", + "name": "vscode-jest-tests", + "request": "launch", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "program": "${workspaceFolder}/node_modules/.bin/jest", + "cwd": "${workspaceFolder}", + "args": [ + "--runInBand", + "--watchAll=false" + ] + } + ] +} \ No newline at end of file diff --git a/web/.vscode/settings.json b/web/.vscode/settings.json index 55712c1..3e1a239 100644 --- a/web/.vscode/settings.json +++ b/web/.vscode/settings.json @@ -1,3 +1,4 @@ { - "typescript.tsdk": "node_modules/typescript/lib" + "typescript.tsdk": "node_modules/typescript/lib", + "jest.jestCommandLine": "node_modules/.bin/jest" } \ No newline at end of file diff --git a/web/src/automation/StateManager/ConditionLogic.tsx b/web/src/automation/StateManager/ConditionLogic.tsx index a825795..52d495b 100644 --- a/web/src/automation/StateManager/ConditionLogic.tsx +++ b/web/src/automation/StateManager/ConditionLogic.tsx @@ -21,7 +21,7 @@ export default class ConditionLogicState extends BaseState { return
this.setState({...state, alias})} /> return
this.setState({...state, alias})} /> { defaultState = () => ({ alias: "Unknown", }) - isReady(state: ServiceScript): boolean { + isReady(state: any): boolean { return true; } - renderOptionList(state: ServiceScript): JSX.Element { + renderOptionList(state: any): JSX.Element { return
this.setState({...state, alias})} />
diff --git a/web/src/automation/StateManager/ScriptChoose.tsx b/web/src/automation/StateManager/ScriptChoose.tsx index f065794..f06314c 100644 --- a/web/src/automation/StateManager/ScriptChoose.tsx +++ b/web/src/automation/StateManager/ScriptChoose.tsx @@ -19,7 +19,7 @@ export default class ScriptChooseState extends BaseState { return
this.setState({...state, alias})} /> { return
this.setState({...state, alias})} /> { return
this.setState({...state, alias})} /> { return
this.setState({...state, alias})} /> { return
this.setState({...state, alias})} /> { return
this.setState({...state, alias})} /> ; } @@ -28,7 +28,7 @@ export interface FireEventScript extends BaseScript { export interface DeviceScript extends BaseScript { type: string; device_id: string; - entity_id: string; + entity_id?: string; domain: string; } export interface ChooseScript extends BaseScript { diff --git a/web/src/automation/utils.spec.ts b/web/src/automation/utils.spec.ts new file mode 100644 index 0000000..127c9a4 --- /dev/null +++ b/web/src/automation/utils.spec.ts @@ -0,0 +1,138 @@ + +import {getDescriptionFromAutomationNode} from "./utils"; + +test('using alias as description', () => { + expect(getDescriptionFromAutomationNode({ + alias: "Start Music In Kitchen", + service: 'media_player.play_media', + target: { + entity_id: "media_player.kitchen_dot" + }, + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", + } + })).toEqual("Start Music In Kitchen") +}) + + +test('get service action description', () => { + expect(getDescriptionFromAutomationNode({ + service: 'media_player.play_media', + target: { + entity_id: "media_player.kitchen_dot" + }, + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", + } + })).toEqual("media_player.play_media") +}) + +test('get repeat action description', () => { + expect(getDescriptionFromAutomationNode({ + repeat: { + count: 10, + sequence: [] + } + })).toEqual("Repeat 10") +}) + + +test('get wait action description', () => { + expect(getDescriptionFromAutomationNode({ + wait_template: "states(switch.kitchen_light) == 'on'" + })).toEqual("Wait on states(switch.kitchen_light) == 'on'") + expect(getDescriptionFromAutomationNode({ + wait_template: "states(switch.kitchen_light) == 'on'", + timeout: '00:01:00' + })).toEqual("Wait on states(switch.kitchen_light) == 'on' for 00:01:00") +}) + +test('get fire event action description', () => { + expect(getDescriptionFromAutomationNode({ + event: 'test_event', + event_data: {}, + })).toEqual("Trigger test_event") +}) + +test('get device action description', () => { + expect(getDescriptionFromAutomationNode({ + device_id: "12310das01231", + domain: "zwave_js", + type: "set_value" + + })).toEqual("set_value on 12310das01231") +}) + +test('get choose action description', () => { + expect(getDescriptionFromAutomationNode({ + choose: [], + default: [], + })).toEqual("Choose") +}) + +test('get and/or/not condition description', () => { + expect(getDescriptionFromAutomationNode({ + condition: 'and', + conditions: [], + })).toEqual("Logic") + expect(getDescriptionFromAutomationNode({ + condition: 'or', + conditions: [], + })).toEqual("Logic") + expect(getDescriptionFromAutomationNode({ + condition: 'not', + conditions: [], + })).toEqual("Logic") +}) + +test('get Numeric State condition description', () => { + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + entity_id: 'sensor.temperature', + })).toEqual("sensor.temperature?>?<") + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + })).toEqual("Numeric State Condition") + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + entity_id: 'sensor.temperature', + above: 17, + })).toEqual("sensor.temperature > 17") + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + entity_id: 'sensor.temperature', + below: 5, + })).toEqual("sensor.temperature < 5") + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + entity_id: 'sensor.temperature', + above: 17, + below: 20, + })).toEqual("17 < sensor.temperature < 20") + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + entity_id: 'sensor.temperature', + above: 17, + below: 20, + value_template: "{{ float(state.state) + 2 }}" + })).toEqual("17 < sensor.temperature < 20") + expect(getDescriptionFromAutomationNode({ + condition: 'numeric_state', + entity_id: [ + "sensor.kitchen_temperature", + "sensor.living_room_temperature" + ], + above: 17, + below: 20, + value_template: "{{ float(state.state) + 2 }}" + })).toEqual("17 < ... < 20") +}) + +// test('get State condition description', () => { +// expect(getDescriptionFromAutomationNode({ +// condition: 'state', +// entity_id: 'sensor.temperature', +// })).toEqual("sensor.temperature?>?<") +// }) \ No newline at end of file diff --git a/web/src/automation/utils.ts b/web/src/automation/utils.ts index 0196633..ba7954c 100644 --- a/web/src/automation/utils.ts +++ b/web/src/automation/utils.ts @@ -1,27 +1,58 @@ import { AutomationNode, AutomationNodeType, NodeSubType } from "./types"; -export const getNameFromAction = (action: AutomationNode): string => { +export const getDescriptionFromAutomationNode = (action: AutomationNode): string => { if(typeof action === 'string') { return action; } if ('alias' in action && action.alias){ return action.alias; } + if ('condition' in action) { + if( + (action.condition === 'and') || + (action.condition === 'or') || + (action.condition === 'not') + ) { + return "Logic" + } else { + switch(action.condition) { + case "numeric_state": + if(action.entity_id) { + const center = typeof action.entity_id === 'string' ? action.entity_id : '...' + if(action.above) { + if(action.below) { + return `${action.above} < ${center} < ${action.below}` + } + return `${center} > ${action.above}` + } + if(action.below) { + return `${center} < ${action.below}` + } + return `${center}?>?<` + } + return "Numeric State Condition" + } + } + } if ('service' in action) { return action.service } if ('repeat' in action) { - return 'Repeat' + return 'Repeat ' + action.repeat.count; } if ('wait_template' in action) { - return 'Wait' + let out= 'Wait on ' + action.wait_template; + if (action.timeout) { + out += (' for ' + action.timeout) + } + return out; } if ('event' in action) { - return action.event + return `Trigger ${action.event}` } if ('type' in action) { - return 'Device ' +action.type + return `${action.type} on ${action.device_id}` } if ('choose' in action) { return 'Choose' diff --git a/web/src/components/AutomationDAG/DAGNode.tsx b/web/src/components/AutomationDAG/DAGNode.tsx index 0c0f9ce..5c89b61 100644 --- a/web/src/components/AutomationDAG/DAGNode.tsx +++ b/web/src/components/AutomationDAG/DAGNode.tsx @@ -9,7 +9,7 @@ export interface NodeProp extends Node { isOpen?: boolean; onXClick?: () => void; onOpenClick?: () => void; - topColor?: 'red' | 'green' | 'blue' | 'none'; + color?: Node['color']; } export default ({ loc: [x,y], @@ -19,10 +19,10 @@ export default ({ onXClick=() => {}, onOpenClick=() => {}, isOpen=false, - topColor='none', + color='none', }: NodeProp) =>
-
+
X
diff --git a/web/src/components/AutomationDAG/dagFuncs.spec.ts b/web/src/components/AutomationDAG/dagFuncs.spec.ts new file mode 100644 index 0000000..e43b6b5 --- /dev/null +++ b/web/src/components/AutomationDAG/dagFuncs.spec.ts @@ -0,0 +1,233 @@ + +import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants"; +import { DAG } from "./types"; +import {clip, computeDAG} from "./dagFuncs"; + +test('it clips overflowing values', () => { + expect(clip([GRAPH_WIDTH, GRAPH_HEIGHT])).toEqual([ + GRAPH_WIDTH-NODE_WIDTH, + GRAPH_HEIGHT-NODE_HEIGHT + ]) + expect(clip([-10, -10])).toEqual([ + 0, 0 + ]) + expect(clip([0, 0])).toEqual([ + 0, 0 + ]) +}) + +test('simple empty input dag', () => { + expect(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [], + condition: [], + action: [ + ], + })).toEqual({ + nodes: {}, + edges: [ + ], + }) +}) + +test('simple single node type input dag', () => { + expect(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [ + { + platform: 'time', + at: '10:00:00' + } + ], + condition: [ + { + condition: 'template', + value_template: 'states(switch.kitchen_light) == "on"' + } + ], + action: [ + { + alias: "Start Music In Kitchen", + service: 'media_player.play_media', + target: { + entity_id: "media_player.kitchen_dot" + }, + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", + } + } + ], + })).toEqual({ + nodes: { + "trigger.0": { + text: '', + // text: "At 10:00:00", + loc: [0,5], + color: 'green', + }, + "condition.0": { + loc: [NODE_WIDTH*1.5, 5], + text: '', + color: 'blue', + // text: 'states(switch.kitchen_light) == "on"' + }, + "action.0": { + loc: [NODE_WIDTH*3, 5], + text: '', + color: 'red', + // text: 'Start Music In Kitchen', + } + }, + edges: [ + { from: 'trigger.0', to: 'condition.0', direction: '1->2' }, + { from: 'condition.0', to: 'action.0', direction: '1->2' }, + ], + } as DAG) +}) + + +test('simple dag with no triggers', () => { + expect(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [ + ], + condition: [ + { + condition: 'template', + value_template: 'states(switch.kitchen_light) == "on"' + } + ], + action: [ + { + alias: "Start Music In Kitchen", + service: 'media_player.play_media', + target: { + entity_id: "media_player.kitchen_dot" + }, + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", + } + } + ], + })).toEqual({ + nodes: { + "condition.0": { + loc: [NODE_WIDTH*1.5, 5], + text: '', + color: 'blue', + // text: 'states(switch.kitchen_light) == "on"' + }, + "action.0": { + loc: [NODE_WIDTH*3, 5], + text: '', + color: 'red', + // text: 'Start Music In Kitchen', + } + }, + edges: [ + { from: 'condition.0', to: 'action.0', direction: '1->2' }, + ], + } as DAG) +}) + + +test('simple dag with no conditions', () => { + expect(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [ + { + platform: 'time', + at: '10:00:00' + } + ], + condition: [], + action: [ + { + alias: "Start Music In Kitchen", + service: 'media_player.play_media', + target: { + entity_id: "media_player.kitchen_dot" + }, + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", + } + } + ], + })).toEqual({ + nodes: { + "trigger.0": { + text: '', + // text: "At 10:00:00", + loc: [0,5], + color: 'green', + }, + "action.0": { + loc: [NODE_WIDTH*3, 5], + text: '', + color: 'red', + // text: 'Start Music In Kitchen', + } + }, + edges: [ + { from: 'trigger.0', to: 'action.0', direction: '1->2' }, + ], + } as DAG) +}) + + +test('simple dag with no actions', () => { + expect(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [ + { + platform: 'time', + at: '10:00:00' + } + ], + condition: [ + { + condition: 'template', + value_template: 'states(switch.kitchen_light) == "on"' + } + ], + action: [ + ], + })).toEqual({ + nodes: { + "trigger.0": { + text: '', + // text: "At 10:00:00", + loc: [0,5], + color: 'green', + }, + "condition.0": { + loc: [NODE_WIDTH*1.5, 5], + text: '', + color: 'blue', + // text: 'states(switch.kitchen_light) == "on"' + }, + }, + edges: [ + { from: 'trigger.0', to: 'condition.0', direction: '1->2' } + ], + } as DAG) +}) + diff --git a/web/src/components/AutomationDAG/dagFuncs.ts b/web/src/components/AutomationDAG/dagFuncs.ts new file mode 100644 index 0000000..6bc48c7 --- /dev/null +++ b/web/src/components/AutomationDAG/dagFuncs.ts @@ -0,0 +1,89 @@ + +import { Automation } from "../../automation/types"; +import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants"; +import {DAG, Node, Point, NormalizedDag} from "./types"; + + +export const clip = (p: Point) : Point => { + const [x,y] = p.map(c => Math.max(0, c)); + return [Math.min(GRAPH_WIDTH-NODE_WIDTH, x), Math.min(GRAPH_HEIGHT-NODE_HEIGHT, y)] +} +export const normalizeDAG = (dag: DAG): NormalizedDag => { + // let overflow: bo + const nodes = Object.keys(dag.nodes).map<[string, Node]>(nodeId => [nodeId, { + ...dag.nodes[nodeId], + loc: clip(dag.nodes[nodeId].loc), + }]).reduce((all, [nodeId, next]) => ({ + [nodeId]: next, + ...all, + }),{}); + return { + nodes, + edges: dag.edges, + } +} +export const computeDAG = (automation: Automation) : DAG => { + const nodes: DAG['nodes'] = {}; + const edges: DAG['edges'] = []; + + const triggerIds: string[] = []; + automation.trigger.forEach((t,i) => { + nodes[`trigger.${i}`] = { + loc: [0, 5+NODE_HEIGHT*i*1.5], + text: "", + color: 'green', + } + triggerIds.push(`trigger.${i}`); + }) + + let lastConditionId: string | undefined = undefined; + automation.condition.forEach((c,i) => { + const cid = `condition.${i}`; + nodes[cid] = { + loc: [NODE_WIDTH*1.5, 5+NODE_HEIGHT*i*1.5], + text: "", + color: 'blue', + } + lastConditionId = cid; + if (i === 0) { + triggerIds.forEach(tid => edges.push({ + from: tid, to: cid, direction: '1->2', + })); + } else { + edges.push({ + from: lastConditionId, to: cid, direction: '1->2', + }) + } + }); + if (!lastConditionId) { + if(triggerIds.length > 0) { + lastConditionId = triggerIds[triggerIds.length-1] + } + } + + const actionIds: string[] = []; + automation.action.forEach((c,i) => { + const aid = `action.${i}`; + nodes[aid] = { + loc: [NODE_WIDTH*3, 5+NODE_HEIGHT*i*1.5], + text: "", + color: 'red', + } + actionIds.push(aid); + if (i === 0) { + if (lastConditionId) { + edges.push({ + from: lastConditionId, to: aid, direction: '1->2', + }); + } + } else { + edges.push({ + from: `action.${i-1}`, to: aid, direction: '1->2', + }) + } + }) + + return { + nodes, edges + } +} \ No newline at end of file diff --git a/web/src/components/AutomationDAG/index.tsx b/web/src/components/AutomationDAG/index.tsx index f9efc61..7f9a3e2 100644 --- a/web/src/components/AutomationDAG/index.tsx +++ b/web/src/components/AutomationDAG/index.tsx @@ -3,26 +3,18 @@ import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_WIDTH } from "./constants"; import DAGEdge from "./DAGEdge"; import DAGNode from "./DAGNode"; import { DAG, Node } from "./types"; -import { normalizeDAG } from "./utils"; +import { normalizeDAG } from "./dagFuncs"; export interface Props extends DAG { - + onDelete: (nodeId: string) => void; + onOpenNode: (nodeId: string) => void; } export default function AutomationDAG({ + onDelete, + onOpenNode, ...dag }: Props) { // state - const [{nodes, edges}, _setDAG] = useState(normalizeDAG(dag)); - - // set state - const setDAG = (dag: DAG) => _setDAG(normalizeDAG(dag)); - const removeNode = (nodeId: string) => () => { - const newNodes = {...nodes} - delete newNodes[nodeId]; - _setDAG({ - nodes: newNodes, - edges: edges.filter(e => e.from !== nodeId && e.to !== nodeId), - }) - } + const {nodes, edges} = normalizeDAG(dag); // render return
{Object.keys(nodes).map((nodeId) => - + onDelete(nodeId)} + onOpenClick={() => onOpenNode(nodeId)} + /> )} diff --git a/web/src/components/AutomationDAG/types.ts b/web/src/components/AutomationDAG/types.ts index 00d5937..ff61f9a 100644 --- a/web/src/components/AutomationDAG/types.ts +++ b/web/src/components/AutomationDAG/types.ts @@ -4,6 +4,7 @@ export type Point = [number, number]; export interface Node { loc: Point; text: JSX.Element | string; + color?: 'red' | 'green' | 'blue' | 'none'; } export interface Edge { from: string; diff --git a/web/src/components/AutomationDAG/utils.spec.ts b/web/src/components/AutomationDAG/utils.spec.ts deleted file mode 100644 index e277ae7..0000000 --- a/web/src/components/AutomationDAG/utils.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ - -import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants"; -import {clip, computeDAG} from "./utils"; - -test('it clips overflowing values', () => { - expect(clip([GRAPH_WIDTH, GRAPH_HEIGHT])).toEqual([ - GRAPH_WIDTH-NODE_WIDTH, - GRAPH_HEIGHT-NODE_HEIGHT - ]) - expect(clip([-10, -10])).toEqual([ - 0, 0 - ]) - expect(clip([0, 0])).toEqual([ - 0, 0 - ]) -}) - -test('simple empty input dag', () => { - expect(computeDAG({ - id: "root", - alias: "root", - description: 'root', - mode: 'single', - trigger: [], - condition: [], - action: [ - ], - })).toEqual({ - nodes: {}, - edges: [ - ], - }) -}) \ No newline at end of file diff --git a/web/src/components/AutomationDAG/utils.ts b/web/src/components/AutomationDAG/utils.ts deleted file mode 100644 index 93a34f1..0000000 --- a/web/src/components/AutomationDAG/utils.ts +++ /dev/null @@ -1,58 +0,0 @@ - -import { Automation } from "../../automation/types"; -import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants"; -import {DAG, Node, Point, NormalizedDag} from "./types"; - - -export const clip = (p: Point) : Point => { - const [x,y] = p.map(c => Math.max(0, c)); - return [Math.min(GRAPH_WIDTH-NODE_WIDTH, x), Math.min(GRAPH_HEIGHT-NODE_HEIGHT, y)] -} -export const normalizeDAG = (dag: DAG): NormalizedDag => { - // let overflow: bo - const nodes = Object.keys(dag.nodes).map<[string, Node]>(nodeId => [nodeId, { - ...dag.nodes[nodeId], - loc: clip(dag.nodes[nodeId].loc), - }]).reduce((all, [nodeId, next]) => ({ - [nodeId]: next, - ...all, - }),{}); - // dag.edges.forEach(edge => { - // const n1 = nodes[edge.from]; - // const n2 = nodes[edge.to]; - // n2.loc[0] = Math.max(n2.loc[0], n1.loc[0] + 1.25*NODE_WIDTH) - // }) - - return { - nodes, - edges: dag.edges, - } -} -export const computeDAG = (automation: Automation) : DAG => { - const nodes: DAG['nodes'] = {}; - const edges: DAG['edges'] = []; - - automation.action - - // let currentNode: InputDagNode | null = rootNode; - // let currLoc: Point = [0,0]; - // let idPath = ''; - // // let - // while (currentNode) { - // const n = { - // text: currentNode.display, - // loc: currLoc, - // } - // if(idPath) { - // nodes[idPath + "." + currentNode.name] = n - // edges - // } else { - // nodes[currentNode.name] = n - // } - // currentNode = currentNode.next[0] - // } - - return { - nodes, edges - } -} \ No newline at end of file diff --git a/web/src/components/AutomationEditor/ScriptNode.tsx b/web/src/components/AutomationEditor/ScriptNode.tsx index 97a78ad..26172d1 100644 --- a/web/src/components/AutomationEditor/ScriptNode.tsx +++ b/web/src/components/AutomationEditor/ScriptNode.tsx @@ -1,6 +1,6 @@ import StateManager from "../../automation/StateManager"; import { AutomationAction } from "../../automation/types"; -import { determineNodeTypes, getNameFromAction } from "../../automation/utils"; +import { determineNodeTypes, getDescriptionFromAutomationNode } from "../../automation/utils"; import AutomationNode from "../AutomationNode"; @@ -15,7 +15,7 @@ export default function ScriptNode({ const [nodeType, nodeSubType] = determineNodeTypes(data); const stateManager = new StateManager(nodeType, nodeSubType, data); - return + return {stateManager.renderOptionList()} } \ No newline at end of file diff --git a/web/src/components/AutomationEditor/index.tsx b/web/src/components/AutomationEditor/index.tsx index 70656f9..3c16400 100644 --- a/web/src/components/AutomationEditor/index.tsx +++ b/web/src/components/AutomationEditor/index.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import * as types from "../../automation/types"; -import { getNameFromAction } from "../../automation/utils"; +import { getDescriptionFromAutomationNode } from "../../automation/utils"; import AutomationNode from "../AutomationNode"; import NewNodeModal from "./NewNodeModal"; import ScriptNode from "./ScriptNode"; diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 1fd34ed..6c8aa7c 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -1,40 +1,53 @@ +import { useState } from "react"; import AutomationDAG from "../components/AutomationDAG"; +import { DAG } from "../components/AutomationDAG/types"; +import { computeDAG } from "../components/AutomationDAG/dagFuncs"; // import AutomationEditor from "../components/AutomationEditor"; // import sample from "../sample/auto_01.yaml"; export function Home() { + const [dag, setDag] = useState(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [ + { + platform: 'time', + at: '10:00:00' + } + ], + condition: [ + { + condition: 'template', + value_template: 'states(switch.kitchen_light) == "on"' + } + ], + action: [ + { + alias: "Start Music In Kitchen", + service: 'media_player.play_media', + target: { + entity_id: "media_player.kitchen_dot" + }, + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", + } + } + ], +})) return (
2', - }, - { - from: "0", to: "2", - direction: '1->2', - }, - { - from: "2", to: "3", - direction: '1->2', - }, - { - from: "1", to: "4", - direction: '1->2', - }, - { - from: "0", to: "3", - direction: '1->2', - }, - ]} + {...dag} + onDelete={nodeId => { + const nodes = {...dag.nodes}; + delete nodes[nodeId]; + const edges = dag.edges.filter(e => (e.from !== nodeId) && (e.to !== nodeId)); + setDag({nodes, edges}); + }} + onOpenNode={nodeId => console.log({nodeId})} /> {/*