resizeable collection nodes
This commit is contained in:
1 parent
7483f2b65d
commit
1d7b6e96c1
4 files changed
+234
-39
No files matched your search
@@ -121,3 +121,156 @@ Conditions.args = {
|
||||
sequence: [],
|
||||
},
|
||||
};
|
||||
|
||||
export const FullAuto = Template.bind({});
|
||||
FullAuto.args = {
|
||||
...FullAuto.args,
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [
|
||||
{
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.temperature_kitchen",
|
||||
below: "15",
|
||||
},
|
||||
{
|
||||
condition: "template",
|
||||
value_template: 'states(switch.kitchen_light) == "on"',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.temperature_kitchen",
|
||||
below: "15",
|
||||
},
|
||||
],
|
||||
trigger: [
|
||||
{
|
||||
platform: "numeric_state",
|
||||
entity_id: "test",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
bad: "node",
|
||||
} as any,
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [
|
||||
{
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.temperature_kitchen",
|
||||
below: "15",
|
||||
},
|
||||
{
|
||||
condition: "template",
|
||||
value_template: 'states(switch.kitchen_light) == "on"',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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",
|
||||
},
|
||||
},
|
||||
{
|
||||
alias: "Bad Node",
|
||||
},
|
||||
{
|
||||
choose: [
|
||||
{
|
||||
conditions: [
|
||||
{
|
||||
condition: "state",
|
||||
entity_id: "lights.bathroom",
|
||||
state: "off",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
service: "light.turn_on",
|
||||
target: {
|
||||
entity_id: "lights.bathroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
{
|
||||
alias: "Turn off bedroom",
|
||||
service: "light.turn_off",
|
||||
target: {
|
||||
entity_id: "lights.bedroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
conditions: [
|
||||
{
|
||||
condition: "state",
|
||||
entity_id: "lights.bedroom",
|
||||
state: "off",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
alias: "Turn on bedroom",
|
||||
service: "light.turn_on",
|
||||
target: {
|
||||
entity_id: "lights.bedroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
{
|
||||
choose: [
|
||||
{
|
||||
conditions: [],
|
||||
sequence: [
|
||||
{
|
||||
choose: [],
|
||||
default: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: [
|
||||
{
|
||||
choose: [],
|
||||
default: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: [
|
||||
{
|
||||
service: "light.turn_off",
|
||||
target: {
|
||||
entity_id: "lights.bathroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -7,7 +7,10 @@ import {
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import * as distance from "./distance";
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { AutomationActionData } from "types/automations";
|
||||
import {
|
||||
AutomationActionData,
|
||||
AutomationSequenceNode,
|
||||
} from "types/automations";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { CollectionNodeMaker } from "../nodes/CollectionNode";
|
||||
|
||||
@@ -26,7 +29,7 @@ export const makeAutomationNodes = (
|
||||
nodeIndex: 0,
|
||||
});
|
||||
|
||||
const condOut = makeConditionNodes(automation.condition, {
|
||||
state = makeConditionNodes(automation.condition, {
|
||||
...args,
|
||||
elementData: state.elementData,
|
||||
position: distance.moveFromTo(
|
||||
@@ -40,7 +43,21 @@ export const makeAutomationNodes = (
|
||||
lastNodeId: state.lastNode.nodeId,
|
||||
});
|
||||
|
||||
return condOut.elementData;
|
||||
state = makeSequenceNodes(automation.sequence, {
|
||||
...args,
|
||||
elementData: state.elementData,
|
||||
position: distance.moveFromTo(
|
||||
"condition",
|
||||
"node",
|
||||
state.lastNode.pos,
|
||||
args.dims
|
||||
),
|
||||
nodeId: `${args.dims.flipped}-sequence`,
|
||||
nodeIndex: 2,
|
||||
lastNodeId: state.lastNode.nodeId,
|
||||
});
|
||||
|
||||
return state.elementData;
|
||||
};
|
||||
|
||||
export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
@@ -73,16 +90,7 @@ export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
|
||||
export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
nodes,
|
||||
{
|
||||
elementData,
|
||||
nodeId,
|
||||
stateUpdater,
|
||||
position,
|
||||
dims,
|
||||
namer,
|
||||
openModal,
|
||||
lastNodeId,
|
||||
}
|
||||
{ elementData, nodeId, stateUpdater, position, dims, namer, lastNodeId }
|
||||
) => {
|
||||
elementData.nodes.push(
|
||||
CollectionNodeMaker.makeElement({ id: nodeId, position }, dims, {
|
||||
@@ -103,6 +111,7 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
elementData.edges.push({
|
||||
source: lastNodeId,
|
||||
target: elementData.nodes[elementData.nodes.length - 1].id,
|
||||
animated: true,
|
||||
id: `${lastNodeId}->${
|
||||
elementData.nodes[elementData.nodes.length - 1].id
|
||||
}`,
|
||||
@@ -113,7 +122,21 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
lastNode: {
|
||||
nodeId,
|
||||
pos: elementData.nodes[elementData.nodes.length - 1].position,
|
||||
size: dims.trigger,
|
||||
size: dims.condition,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
nodes,
|
||||
{ nodeId, elementData, dims }
|
||||
) => {
|
||||
return {
|
||||
elementData,
|
||||
lastNode: {
|
||||
nodeId,
|
||||
pos: elementData.nodes[elementData.nodes.length - 1].position,
|
||||
size: dims.node,
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user