-
Selected node code
-
-
-
-
+
+
+
Selected node code
+
+
+
Path:
+
+
+
+
+
+
+
+
Condition A
+
Condition B
+
Condition C
+
+
+
Trace
+
+
+
-
+
Full script code
-
+
-
+
diff --git a/package-lock.json b/package-lock.json
index 13109e2..f16003d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -70,6 +70,11 @@
"resolved": "https://registry.npmjs.org/@vanillawc/wc-codemirror/-/wc-codemirror-1.8.10.tgz",
"integrity": "sha512-UKMD/UOpF1uRl29nlwvwQqSMBqsl+uDWYlGx82wIYbIBJkeqPrSo1Ez1rGi9jc1CL7/XwUr7u+l/kTwZAEkrEg=="
},
+ "argparse": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
+ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
+ },
"async": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
@@ -238,6 +243,14 @@
"integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=",
"dev": true
},
+ "js-yaml": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz",
+ "integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==",
+ "requires": {
+ "argparse": "^2.0.1"
+ }
+ },
"lit-element": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/lit-element/-/lit-element-2.3.1.tgz",
diff --git a/package.json b/package.json
index faf1ef4..93b115d 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
"dependencies": {
"@mdi/js": "^5.5.55",
"@vanillawc/wc-codemirror": "^1.8.10",
+ "js-yaml": "^4.0.0",
"lit-element": "^2.3.1"
}
}
diff --git a/src/demo-config.js b/src/demo-config.js
index 27b812d..6c99e47 100644
--- a/src/demo-config.js
+++ b/src/demo-config.js
@@ -1,107 +1,90 @@
-export const demoConfig = [
- {
- condition: "state",
- entity_id: "binary_sensor.dark_outside",
- state: "on",
- },
- {
- choose: [
- {
- conditions: [
- {
- condition: "state",
- entity_id: "binary_sensor.door_open",
- state: "on",
- },
- ],
- sequence: [
- {
- service: "light.turn_on",
- entity_id: "light.outdoors",
- }
- ],
- },
- {
- conditions: [
- {
- condition: "state",
- entity_id: "input_select.time_of_day",
- state: "night",
- },
- ],
- sequence: [
- {
- service: "light.turn_off",
- entity_id: "light.outdoors",
- }
- ],
- },
- ],
- default: [
- ],
- },
-]
+export const demoTrace = {
+ "trigger/2": {},
+ "condition/0": {},
+ "condition/1": {},
+ "condition/2": {},
+ "action/0": {},
+ "action/1": { result: true },
+ "action/2": {},
+ "action/3": {},
+ "action/4": {},
+ "action/5": { repeats: 1 },
+ "action/5/sequence/0": {},
+ "action/5/sequence/1": {},
+ "action/6": {},
+ "action/6/": {},
+ "action/6/choose/2": {},
+ "action/6/choose/2/sequence/0": {},
+ "action/6/choose/2/sequence/1": {},
+};
-export const demoConfig2 = [
- { service: "light.turn_on",
- data: {
- entity_id: "group.bedroom",
- brightness: 100,
+export const demoConfig = {
+ trigger: ["trigger1", "trigger2", "trigger3"],
+ condition: ["a", "b", "c"],
+ action: [
+ {
+ service: "light.turn_on",
+ data: {
+ entity_id: "group.bedroom",
+ brightness: 100,
+ },
},
- },
- { condition: "state",
- entity_id: "device_tracker.paulus",
- state: "home",
- },
- { delay: "01:00",
- },
- { wait_template: "{{ is_state(media_player.floor', 'stop') }}",
- },
- { event: "LOGBOOK_ENTRY",
- event_data: {
- name: "Paulus",
- message: "is waking up",
+ {
+ condition: "state",
entity_id: "device_tracker.paulus",
- domain: "light",
+ state: "home",
},
- },
- { repeat: {
- count: "5",
- sequence: [
- { delay: 2
- },
- { service: "light.toggle",
- data: {
- entity_id: "light.bed_light",
+ {
+ delay: "01:00",
+ },
+ {
+ wait_template: "{{ is_state(media_player.floor', 'stop') }}",
+ },
+ {
+ event: "LOGBOOK_ENTRY",
+ event_data: {
+ name: "Paulus",
+ message: "is waking up",
+ entity_id: "device_tracker.paulus",
+ domain: "light",
+ },
+ },
+ {
+ repeat: {
+ count: "5",
+ sequence: [
+ {
+ delay: 2,
},
+ {
+ service: "light.toggle",
+ data: {
+ entity_id: "light.bed_light",
+ },
+ },
+ ],
+ },
+ },
+ {
+ choose: [
+ {
+ conditions: [],
+ sequence: [
+ { service: "test" },
+ { service: "test" },
+ { service: "test" },
+ ],
+ },
+ {
+ conditions: [],
+ sequence: [{ service: "test" }],
+ },
+ {
+ conditions: [],
+ sequence: [{ service: "test" }, { service: "test" }],
},
],
+ default: [{ service: "test" }, { service: "test" }, { service: "test" }],
},
- },
- { choose: [
- { conditions: [],
- sequence: [
- { service: "test"},
- { service: "test"},
- { service: "test"},
- ],
- },
- { conditions: [],
- sequence: [
- { service: "test"},
- ],
- },
- { conditions: [],
- sequence: [
- { service: "test"},
- { service: "test"},
- ],
- },
- ],
- default: [
- { service: "test"},
- { service: "test"},
- { service: "test"},
- ],
- },
-];
+ ],
+};
diff --git a/src/hat-graph/hat-graph-node.ts b/src/hat-graph/hat-graph-node.ts
index 5a01e69..bf8606f 100644
--- a/src/hat-graph/hat-graph-node.ts
+++ b/src/hat-graph/hat-graph-node.ts
@@ -1,29 +1,35 @@
import { css, LitElement, property, svg } from "lit-element";
-const NODE_SIZE = 24;
-const VERTICAL_SPACING = 10;
+const NODE_SIZE = 30;
+const SPACING = 10;
export class HatGraphNode extends LitElement {
- @property() iconPath?;
- @property({ reflect: true }) marked?;
- @property({ reflect: true }) selected?;
- @property({ reflect: true }) disabled?;
+ @property() iconPath?: string;
+ @property({ reflect: true, type: Boolean }) marked?: boolean;
+ @property({ reflect: true, type: Boolean }) selected?: boolean;
+ @property({ reflect: true, type: Boolean }) disabled?: boolean;
+ @property({ reflect: true, type: Boolean }) graphstart?: boolean;
+ @property({ reflect: true, type: Boolean }) nofocus?: boolean;
connectedCallback() {
super.connectedCallback();
- if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
- this.addEventListener("focusin", () => this.setAttribute("selected", ""));
- this.addEventListener("focusout", () => this.removeAttribute("selected"));
+ if (!this.hasAttribute("tabindex") && !this.nofocus)
+ this.setAttribute("tabindex", "0");
}
updated() {
const svg = this.shadowRoot.querySelector("svg");
const bbox = svg.getBBox();
- svg.setAttribute("width", `${bbox.width + 2}px`);
- svg.setAttribute("height", `${bbox.height + 1}px`);
+ const extra_height = this.graphstart ? 2 : 1;
+ const extra_width = SPACING;
+ svg.setAttribute("width", `${bbox.width + extra_width}px`);
+ svg.setAttribute("height", `${bbox.height + extra_height}px`);
svg.setAttribute(
"viewBox",
- `${bbox.x - 1} ${bbox.y} ${bbox.width + 2} ${bbox.height + 1}`
+ `${Math.ceil(bbox.x - extra_width / 2)}
+ ${Math.ceil(bbox.y - extra_height / 2)}
+ ${bbox.width + extra_width}
+ ${bbox.height + extra_height}`
);
}
@@ -31,17 +37,21 @@ export class HatGraphNode extends LitElement {
return svg`