diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx index 5bcb119..0cfb517 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx @@ -44,6 +44,9 @@ export const NoTags = make({ wowo: "!", }, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", }, }); @@ -60,5 +63,8 @@ export const SomeTags = make({ wowo: "!", }, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", }, }); diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index aa69933..ea0ebc2 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -53,6 +53,9 @@ Simple.args = { wowo: "!", }, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { platform: "numeric_state", @@ -102,6 +105,9 @@ EmptyStart.args = { id: "random", alias: "Random", description: "Example Metadata", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger_variables: { wowo: "!", }, @@ -131,6 +137,9 @@ BadAutomationInvalidTriggers.args = { id: "random", alias: "Random", description: "Example Metadata", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger_variables: { wowo: "!", }, @@ -169,6 +178,9 @@ RepeatExample.args = { alias: "Get out of baby room", description: "", mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { type: "opened", diff --git a/webapp/src/components/AutomationManager/ListBoxGroup/index.stories.tsx b/webapp/src/components/AutomationManager/ListBoxGroup/index.stories.tsx index 45a3133..3570ce9 100644 --- a/webapp/src/components/AutomationManager/ListBoxGroup/index.stories.tsx +++ b/webapp/src/components/AutomationManager/ListBoxGroup/index.stories.tsx @@ -26,6 +26,9 @@ const { make, componentMeta } = makeStory({ description: "Amazing automation!", tags: {}, state: "on", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", flags: { isSelected: false, isModified: false, @@ -37,6 +40,9 @@ const { make, componentMeta } = makeStory({ entityId: "automation.2", description: "Cool!", state: "on", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", flags: { isSelected: false, isModified: false, @@ -84,6 +90,9 @@ export const Nested = make({ description: "", title: "Automation #1", state: "on", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", flags: { isSelected: true, isModified: false, @@ -96,6 +105,9 @@ export const Nested = make({ description: "another one", title: "Automation #2", state: "off", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", flags: { isSelected: false, isModified: false, @@ -108,6 +120,9 @@ export const Nested = make({ description: "bad one", title: "Automation #3", state: "offing", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", flags: { isSelected: false, isModified: false, @@ -146,6 +161,9 @@ export const Nested = make({ isSelected: false, isModified: false, }, + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", state: "on", tags: { type: "good", diff --git a/webapp/src/components/AutomationManager/Loaded/automationDB.ts b/webapp/src/components/AutomationManager/Loaded/automationDB.ts index 5aea70a..c071ce7 100644 --- a/webapp/src/components/AutomationManager/Loaded/automationDB.ts +++ b/webapp/src/components/AutomationManager/Loaded/automationDB.ts @@ -54,6 +54,9 @@ export const useAutomationDB = ( tags: {}, issue: "New Automation", isNew: true, + source_file: auto.source_file, + source_file_type: auto.source_file_type, + configuration_key: auto.configuration_key, }, auto, ]); @@ -88,11 +91,16 @@ const genMapping = ( ? undefined : `recived invalid state "${entityData.state}, this could be because you have a lingering automation that was not cleared by homeassistant, try to reboot HA or manually clear this automation from HA Database."`; let found: AutomationData | null = null; - + let source_file = "n/a"; + let source_file_type = "n/a"; + let configuration_key = "n/a"; if (configData[autoId]) { found = configData[entityData.attributes.id]; title = found.alias ?? title; description = found.description ?? description; + source_file = found.source_file ?? source_file; + source_file_type = found.source_file_type ?? source_file_type; + configuration_key = found.configuration_key ?? configuration_key; delete configData[autoId]; } else { issue = "failed to find this automation in '/config' folder"; @@ -106,6 +114,9 @@ const genMapping = ( description, state: entityData.state, tags: tagsDB.getTags(autoId), + source_file, + source_file_type, + configuration_key, issue, }, found, @@ -121,6 +132,9 @@ const genMapping = ( description: auto.description ?? "", state: "unregistered", tags: tagsDB.getTags(auto.id), + source_file: auto.source_file, + source_file_type: auto.source_file_type, + configuration_key: auto.configuration_key, issue: "homeassistant did not load this automation, try to manually reload automations or restart homeassistant.", }, diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.css b/webapp/src/components/AutomationManager/MetadataBox/index.css index 244f92c..59e43cd 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.css +++ b/webapp/src/components/AutomationManager/MetadataBox/index.css @@ -84,4 +84,14 @@ font-size: 0.75em; user-select: none; max-width: 5em; +} + +.automation-manager--metadatabox .metadatabox--title--source { + margin-bottom: -0.5em; +} + + +.automation-manager--metadatabox .metadatabox--title--source .MuiChip-root { + font-size: 0.85em; + height: 2em; } \ No newline at end of file diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.tsx b/webapp/src/components/AutomationManager/MetadataBox/index.tsx index b8b166c..71a396d 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.tsx +++ b/webapp/src/components/AutomationManager/MetadataBox/index.tsx @@ -14,6 +14,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons"; import { AutomationManagerAuto } from "../types"; import { Tags } from "./Tags"; import { TagDB } from "../TagDB"; +import { Chip } from "@mui/material"; export type MetadataBoxProps = AutomationManagerAuto & { onDelete: () => void; @@ -53,6 +54,9 @@ export const MetadataBox: FC = (props) => { className="metadatabox--title" title={`ID=${props.id}, EntityID=${props.entityId}`} > + + + ((a) => ({ @@ -50,6 +53,9 @@ const bigList = bigMockAutoList.map((a) => ({ tags: a.tags, id: a.id, isSelected: false, + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", })); test("no grouping", () => { diff --git a/webapp/src/components/AutomationManager/index.stories.tsx b/webapp/src/components/AutomationManager/index.stories.tsx index 7ae308d..41c1c9b 100644 --- a/webapp/src/components/AutomationManager/index.stories.tsx +++ b/webapp/src/components/AutomationManager/index.stories.tsx @@ -154,6 +154,9 @@ export const BadAutomation = make({ mode: "single", alias: "Light.Tank_Day", description: "", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { platform: "sun", diff --git a/webapp/src/components/AutomationManager/index.tsx b/webapp/src/components/AutomationManager/index.tsx index f7639af..3c09206 100644 --- a/webapp/src/components/AutomationManager/index.tsx +++ b/webapp/src/components/AutomationManager/index.tsx @@ -60,7 +60,7 @@ export const AutomationManager: FC = ({ const invalidAutomations = configAutomationsValidated.filter( ({ failures }) => failures !== null ); - if (invalidAutomations.length > 0) { + if (invalidAutomations.length > 0 && !validationsShown.current) { validationsShown.current = true; confirm({ cancellationButtonProps: { @@ -102,7 +102,7 @@ export const AutomationManager: FC = ({ .catch(console.error); } } - }, [api.state.automations, validationsShown.current]); + }, [api.state.automations, confirm]); // handle bad states if (!haEntities.ready && haEntities.error) { diff --git a/webapp/src/components/AutomationManager/types.ts b/webapp/src/components/AutomationManager/types.ts index 3c0bc34..2025618 100644 --- a/webapp/src/components/AutomationManager/types.ts +++ b/webapp/src/components/AutomationManager/types.ts @@ -9,6 +9,9 @@ export type AutomationManagerAuto = AutomationManagerAutoUpdatable & { tags: Record; issue?: string; isNew?: boolean; + source_file: string; + source_file_type: string; + configuration_key: string; }; export type AutomationManagerAutoItem = AutomationManagerAuto & { flags: AutomationManagerItemFlags; diff --git a/webapp/src/types/validators/autmation.ts b/webapp/src/types/validators/autmation.ts index c7f1864..88c0ea2 100644 --- a/webapp/src/types/validators/autmation.ts +++ b/webapp/src/types/validators/autmation.ts @@ -8,8 +8,13 @@ export const AutomationData = st.object({ st.nullable(st.record(st.string(), st.string())) ), mode: st.enums(["single", "restart", "queued", "parallel"]), + tags: st.record(st.string(), st.string()), + + source_file: st.string(), + source_file_type: st.string(), + configuration_key: st.string(), + trigger: st.array(st.object()), condition: st.array(st.object()), action: st.array(st.object()), - tags: st.record(st.string(), st.string()), }); diff --git a/webapp/src/types/validators/metadata.ts b/webapp/src/types/validators/metadata.ts index 38c76fb..9763c09 100644 --- a/webapp/src/types/validators/metadata.ts +++ b/webapp/src/types/validators/metadata.ts @@ -1,10 +1,14 @@ -import * as st from 'superstruct' - +import * as st from "superstruct"; export const AutomationMetadata = st.object({ - id: st.string(), - alias: st.optional(st.string()), - description: st.optional(st.string()), - trigger_variables: st.optional(st.nullable(st.record(st.string(), st.string()))), - mode: st.enums(["single", "restart", "queued", "parallel"]), -}) \ No newline at end of file + id: st.string(), + alias: st.optional(st.string()), + description: st.optional(st.string()), + trigger_variables: st.optional( + st.nullable(st.record(st.string(), st.string())) + ), + mode: st.enums(["single", "restart", "queued", "parallel"]), + source_file: st.string(), + source_file_type: st.string(), + configuration_key: st.string(), +}); diff --git a/webapp/src/utils/defaults.ts b/webapp/src/utils/defaults.ts index 28b455a..0b60321 100644 --- a/webapp/src/utils/defaults.ts +++ b/webapp/src/utils/defaults.ts @@ -67,6 +67,9 @@ export const defaultAutomation = (id: string): AutomationData => ({ alias: "New Automation", description: "", mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", tags: {}, trigger: [], action: [], diff --git a/webapp/src/utils/mocks.ts b/webapp/src/utils/mocks.ts index 5e77117..cb70bef 100644 --- a/webapp/src/utils/mocks.ts +++ b/webapp/src/utils/mocks.ts @@ -16,6 +16,9 @@ export const createMockAuto = ({ mode: "single", tags, condition: [], + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { platform: "numeric_state", @@ -82,6 +85,9 @@ export const bigMockAutoList: AutomationData[] = [ description: "", trigger_variables: null, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { device_id: "asdasdasdas", @@ -231,6 +237,9 @@ export const bigMockAutoList: AutomationData[] = [ description: "", trigger_variables: null, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { platform: "device", @@ -271,6 +280,9 @@ export const bigMockAutoList: AutomationData[] = [ "Ensures that the climate is always in sync with the house settings", trigger_variables: null, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { platform: "state", @@ -403,6 +415,9 @@ export const bigMockAutoList: AutomationData[] = [ description: "Configures max/min light settings for the baby ", trigger_variables: null, mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", trigger: [ { platform: "time", @@ -463,6 +478,9 @@ export const bigMockAutoList: AutomationData[] = [ id: "alarmanlage_an", alias: "alarmanlage_an (Uhrzeit)", mode: "single", + source_file: "automation.yaml", + source_file_type: "list", + configuration_key: "automation", tags: {}, trigger: [ {