From 429dfd5b50e814b9f0faff2889c1fb8907f664a0 Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 9 May 2022 21:41:49 -0400 Subject: [PATCH] removed $smType for conditions and trigger --- .../AutomationEditor/AutoInfoBox.tsx | 2 +- .../AutomationEditor/index.stories.tsx | 33 ++-- .../ConditionEditor.stories.tsx | 60 +++---- .../ConditionEditor/ConditionNode.tsx | 47 ++--- .../ConditionEditor/editorRender.tsx | 158 +++++----------- .../ConditionEditor/index.stories.tsx | 80 +++------ .../ConditionEditor/nestedUpdater.ts | 26 ++- .../components/ConditionEditor/viewRender.tsx | 2 +- .../src/components/DAGFlow/index.stories.tsx | 85 +++------ webapp/src/components/DAGFlow/index.tsx | 3 +- .../components/DAGFlow/sequenceConvertor.ts | 5 +- webapp/src/components/DAGFlow/updater.test.ts | 5 +- webapp/src/components/DAGFlow/updater.ts | 2 +- .../components/Inputs/InputList.stories.tsx | 2 +- webapp/src/components/Inputs/InputList.tsx | 5 +- .../MultiNodeEditors/index.stories.tsx | 18 +- .../src/components/MultiNodeEditors/index.tsx | 5 +- .../OptionManager/ConditionLogic.tsx | 7 +- .../NodeEditor/OptionManager/OptionManager.ts | 27 ++- .../OptionManager/TriggerDevice.tsx | 1 - .../NodeEditor/OptionManager/TriggerEvent.tsx | 1 - .../NodeEditor/OptionManager/TriggerHA.tsx | 3 +- .../NodeEditor/OptionManager/TriggerMQTT.tsx | 1 - .../OptionManager/TriggerNumericState.tsx | 1 - .../NodeEditor/OptionManager/TriggerState.tsx | 1 - .../OptionManager/TriggerTemplate.tsx | 1 - .../NodeEditor/OptionManager/TriggerTime.tsx | 1 - .../OptionManager/TriggerTimePattern.tsx | 1 - .../OptionManager/TriggerWebhook.tsx | 1 - .../NodeEditor/OptionManager/TriggerZone.tsx | 3 +- .../NodeEditor/OptionManager/index.ts | 80 +++------ webapp/src/components/NodeEditor/constants.ts | 12 +- .../components/NodeEditor/index.stories.tsx | 37 ++-- webapp/src/components/NodeEditor/index.tsx | 2 +- webapp/src/types/automations/conditions.ts | 37 ++-- webapp/src/types/automations/triggers.ts | 1 - webapp/src/utils/automations.ts | 54 ++++++ webapp/src/utils/defaults.ts | 23 ++- webapp/src/utils/formatting.test.ts | 97 ++++------ webapp/src/utils/formatting.ts | 170 +++++------------- webapp/src/utils/mocks.ts | 33 ++-- 41 files changed, 410 insertions(+), 723 deletions(-) create mode 100644 webapp/src/utils/automations.ts diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx index 9061db6..16cbe49 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx @@ -1,6 +1,6 @@ import "./AutoInfoBox.css"; import { AutomationMetadata } from "types/automations"; -import InputList from "components/Inputs/InputList"; +import { InputList } from "components/Inputs/InputList"; import InputText from "components/Inputs/InputText"; import InputTextArea from "components/Inputs/InputTextArea"; import { FC, useRef, useState } from 'react'; diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index df20f1f..8bb2c10 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -60,39 +60,28 @@ Simple.args = { }, trigger: [ { - "$smType": undefined, "platform": "numeric_state", "entity_id": "test", }, { - "$smType": undefined, "platform": "homeassistant", "event": "start", } ], sequence: [ { - $smType: "condition", condition: 'and', - condition_data: { - conditions: [ - { - $smType: 'condition', - condition: 'numeric_state', - condition_data: { - entity_id: 'sensor.temperature_kitchen', - below: '15', - } - }, - { - $smType: "condition", - condition: 'template', - condition_data: { - value_template: 'states(switch.kitchen_light) == "on"' - } - } - ] - } + conditions: [ + { + condition: 'numeric_state', + entity_id: 'sensor.temperature_kitchen', + below: '15', + }, + { + condition: 'template', + value_template: 'states(switch.kitchen_light) == "on"' + } + ] }, { $smType: "action", diff --git a/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx b/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx index 502b81a..c7e1d61 100644 --- a/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx +++ b/webapp/src/components/ConditionEditor/ConditionEditor.stories.tsx @@ -12,48 +12,32 @@ export default { export const Basic: ComponentStory = args => { const [state, setState] = useState({ - "$smType": "condition", "condition": "or", - "condition_data": { - "conditions": [ - { - "$smType": "condition", - "condition": "and", - "condition_data": { - "conditions": [ - { - "$smType": "condition", - "condition": "numeric_state", - "condition_data": { - "entity_id": [ - "sensor.kitchen_humidity" - ], - "conditions": [], - "above": "40" - } - }, - { - "$smType": "condition", - "condition": "template", - "condition_data": { - "value_template": "states('switch.kitchen') == 'on'" - } - } - ] - } - }, - { - "$smType": "condition", - "condition": "numeric_state", - "condition_data": { + "conditions": [ + { + "condition": "and", + "conditions": [ + { + "condition": "numeric_state", "entity_id": [ - "sensor.kitchen_temperature" + "sensor.kitchen_humidity" ], - "above": "51" + "above": "40" + }, + { + "condition": "template", + "value_template": "states('switch.kitchen') == 'on'" } - } - ] - } + ] + }, + { + "condition": "numeric_state", + "entity_id": [ + "sensor.kitchen_temperature" + ], + "above": "51" + } + ] }) return (
diff --git a/webapp/src/components/ConditionEditor/ConditionNode.tsx b/webapp/src/components/ConditionEditor/ConditionNode.tsx index 43dd9f4..e7cf52e 100644 --- a/webapp/src/components/ConditionEditor/ConditionNode.tsx +++ b/webapp/src/components/ConditionEditor/ConditionNode.tsx @@ -3,7 +3,7 @@ import { FC, useState, useEffect } from 'react'; import { getConditionDefaultValues } from "utils/defaults"; import { AutomationCondition } from "types/automations/conditions"; import { CheckMarkIcon, PencilIcon } from "components/Icons"; -import InputList from "components/Inputs/InputList"; +import { InputList } from "components/Inputs/InputList"; import InputYaml from "components/Inputs/InputYaml"; import { getEditor } from "./editorRender"; import { useStyles } from "./style"; @@ -51,17 +51,10 @@ export const ConditionNode: FC<{ ) { onUpdate({ ...condition, - $smType: 'condition', - condition_data: { - ...condition.condition_data, - conditions: condition.condition_data.conditions.concat({ - $smType: 'condition', - condition: 'or', - condition_data: { - conditions: [] - } - }) - } + conditions: condition.conditions.concat({ + condition: 'or', + conditions: [] + }) }) } } @@ -69,20 +62,10 @@ export const ConditionNode: FC<{ let childrenConditions: JSX.Element; if (effectiveDM) { const Viewer = getViewer(condition); - childrenConditions = { - onUpdate({ - ...data, - $smType: 'condition', - }) - }} /> + childrenConditions = } else { const Editor = getEditor(condition); - childrenConditions = { - onUpdate({ - ...data, - $smType: 'condition', - }) - }} /> + childrenConditions = } // styles let hasChildren = false; @@ -115,13 +98,10 @@ export const ConditionNode: FC<{ 'trigger', 'zone', ]} - onChange={n => onUpdate({ - $smType: 'condition', + onChange={(n: any) => onUpdate({ + ...getConditionDefaultValues(n), + ...condition, condition: n, - condition_data: { - ...getConditionDefaultValues(n), - ...condition.condition_data, - } } as any)} /> {effectiveDM &&