From 175034bbcc8143ab9b137f4fa3a818245a339c60 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Fri, 24 Dec 2021 11:10:19 -0500 Subject: [PATCH] mocks + defaults --- webapp/src/utils/defaults.ts | 12 +++++++ webapp/src/utils/mocks.ts | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 webapp/src/utils/mocks.ts diff --git a/webapp/src/utils/defaults.ts b/webapp/src/utils/defaults.ts index 5293898..71c8ef2 100644 --- a/webapp/src/utils/defaults.ts +++ b/webapp/src/utils/defaults.ts @@ -1,4 +1,5 @@ import { AutomationCondition, LogicCondition, NumericCondition, StateCondition, TemplateCondition, TimeCondition, TriggerCondition, ZoneCondition } from "types/automations/conditions"; +import { AutomationData } from 'types/automations'; export const getConditionDefaultValues = (condition: AutomationCondition['condition']): AutomationCondition['condition_data'] => { @@ -39,3 +40,14 @@ export const getConditionDefaultValues = (condition: AutomationCondition['condit } throw new Error("NOT IMPLEMENTED!") } + +export const defaultAutomation = (id: string): AutomationData => ({ + metadata: { + id, + alias: "New Automation", + description: "", + mode: "single", + }, + trigger: [], + sequence: [], +}) diff --git a/webapp/src/utils/mocks.ts b/webapp/src/utils/mocks.ts new file mode 100644 index 0000000..b4b6eb4 --- /dev/null +++ b/webapp/src/utils/mocks.ts @@ -0,0 +1,66 @@ +import { AutomationData } from 'types/automations'; + + +export const createMockAuto = (): AutomationData => ({ + metadata: { + id: "random", + alias: "Random", + description: "Example Metadata", + trigger_variables: { + 'wowo': '!' + }, + mode: 'single', + }, + 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"' + } + } + ] + } + }, + { + $smType: "action", + action: "service", + action_data: { + 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", + } + } + } + ] +})