- refactor for multi-config suport done
- added better errror captures
This commit is contained in:
1 parent
55ea1e23a4
commit
c67d1bd32f
32 files changed
+991
-835
No files matched your search
@@ -46,10 +46,10 @@ export const useAutomationDB = (
|
||||
const auto = defaultAutomation(String(Date.now()));
|
||||
setNewAuto([
|
||||
{
|
||||
id: auto.metadata.id,
|
||||
id: auto.id,
|
||||
entityId: "",
|
||||
title: auto.metadata.alias ?? "",
|
||||
description: auto.metadata.description ?? "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: "unregistered",
|
||||
tags: {},
|
||||
issue: "New Automation",
|
||||
@@ -70,7 +70,7 @@ const genMapping = (
|
||||
const configData: Record<string, AutomationData> = configAutomations.reduce(
|
||||
(all, n) => ({
|
||||
...all,
|
||||
[n.metadata.id]: n,
|
||||
[n.id]: n,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
@@ -91,8 +91,8 @@ const genMapping = (
|
||||
|
||||
if (configData[autoId]) {
|
||||
found = configData[entityData.attributes.id];
|
||||
title = found.metadata.alias ?? title;
|
||||
description = found.metadata.description ?? description;
|
||||
title = found.alias ?? title;
|
||||
description = found.description ?? description;
|
||||
delete configData[autoId];
|
||||
} else {
|
||||
issue = "failed to find this automation in '/config' folder";
|
||||
@@ -113,14 +113,14 @@ const genMapping = (
|
||||
});
|
||||
|
||||
Object.values(configData).forEach((auto) => {
|
||||
automatioinMap[auto.metadata.id] = [
|
||||
automatioinMap[auto.id] = [
|
||||
{
|
||||
id: auto.metadata.id,
|
||||
id: auto.id,
|
||||
entityId: "",
|
||||
title: auto.metadata.alias ?? "",
|
||||
description: auto.metadata.description ?? "",
|
||||
title: auto.alias ?? "",
|
||||
description: auto.description ?? "",
|
||||
state: "unregistered",
|
||||
tags: tagsDB.getTags(auto.metadata.id),
|
||||
tags: tagsDB.getTags(auto.id),
|
||||
issue:
|
||||
"homeassistant did not load this automation, try to manually reload automations or restart homeassistant.",
|
||||
},
|
||||
|
||||
@@ -13,7 +13,7 @@ export type UseAutomationManagerStateArgs = {
|
||||
hassEntities: HassEntities;
|
||||
onUpdateTags: (aid: string, tags: Record<string, string>) => void;
|
||||
onAutomationAdd: (auto: AutomationData) => void;
|
||||
onAutomationUpdate: (aid: string, auto: AutomationData) => void;
|
||||
onAutomationUpdate: (auto: AutomationData) => void;
|
||||
onAutomationStateChange: (eid: string, on: boolean) => void;
|
||||
onAutomationRun: (eid: string) => void;
|
||||
};
|
||||
@@ -30,10 +30,12 @@ export const useAutomationManagerState = ({
|
||||
const snackbr = useSnackbar();
|
||||
const cookies = useAMSCookies();
|
||||
const tagsDB = useTagDB(
|
||||
configAutomations.map(({ metadata: { id }, tags }) => ({
|
||||
id,
|
||||
tags,
|
||||
})),
|
||||
configAutomations
|
||||
.filter((a) => typeof a === "object")
|
||||
.map(({ id, tags = {} }) => ({
|
||||
id,
|
||||
tags,
|
||||
})),
|
||||
onUpdateTags
|
||||
);
|
||||
const automationDB = useAutomationDB(hassEntities, configAutomations, tagsDB);
|
||||
@@ -91,13 +93,13 @@ export const useAutomationManagerState = ({
|
||||
}
|
||||
}
|
||||
const auto = automationDB.addNew();
|
||||
methods.setSelectedAutomationId(auto.metadata.id, true);
|
||||
methods.setSelectedAutomationId(auto.id, true);
|
||||
},
|
||||
editorUpdateAutomation(auto: AutomationData) {
|
||||
if (methods.currentAutomationIsNew) {
|
||||
onAutomationAdd(auto);
|
||||
} else if (methods.currentAutomationId) {
|
||||
onAutomationUpdate(methods.currentAutomationId, auto);
|
||||
onAutomationUpdate(auto);
|
||||
}
|
||||
},
|
||||
sideBarUpdateAutomation(
|
||||
@@ -109,16 +111,13 @@ export const useAutomationManagerState = ({
|
||||
if (previousAuto && previousAuto[1]) {
|
||||
const previousAutoState = previousAuto[1];
|
||||
if (
|
||||
previousAutoState.metadata.alias !== a.title ||
|
||||
previousAutoState.metadata.description !== a.description
|
||||
previousAutoState.alias !== a.title ||
|
||||
previousAutoState.description !== a.description
|
||||
) {
|
||||
onAutomationUpdate(aid, {
|
||||
onAutomationUpdate({
|
||||
...previousAutoState,
|
||||
metadata: {
|
||||
...previousAutoState.metadata,
|
||||
alias: a.title,
|
||||
description: a.description,
|
||||
},
|
||||
alias: a.title,
|
||||
description: a.description,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user