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 &&