sync'd up
This commit is contained in:
1 parent
7cb1a5d907
commit
a391eae7c5
19 files changed
+320
-170
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { useEffect, useState } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { AutomationData, BareAutomationData } from "types/automations";
|
||||
import { defaultAutomation } from "utils/defaults";
|
||||
import { TagDB } from "../TagDB";
|
||||
import { AutomationManagerAuto } from "../types";
|
||||
@@ -12,7 +12,9 @@ export const useAutomationDB = (
|
||||
) => {
|
||||
const autoMap = genMapping(haEntities, configAutomations, tagsDB);
|
||||
const [newAuto, setNewAuto] =
|
||||
useState<null | [AutomationManagerAuto, AutomationData]>(null);
|
||||
useState<
|
||||
null | [AutomationManagerAuto, AutomationData | BareAutomationData]
|
||||
>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (newAuto && autoMap[newAuto[0].id]) {
|
||||
@@ -30,7 +32,9 @@ export const useAutomationDB = (
|
||||
},
|
||||
getAutomationData(
|
||||
autoId: string
|
||||
): null | [AutomationManagerAuto, AutomationData | null] {
|
||||
):
|
||||
| null
|
||||
| [AutomationManagerAuto, AutomationData | BareAutomationData | null] {
|
||||
if (newAuto && newAuto[0].id === autoId) {
|
||||
return newAuto;
|
||||
}
|
||||
@@ -54,9 +58,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,
|
||||
source_file: "n/a",
|
||||
source_file_type: "n/a",
|
||||
configuration_key: "n/a",
|
||||
},
|
||||
auto,
|
||||
]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { useState } from "react";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { AutomationData, BareAutomationData } from "types/automations";
|
||||
import { useTagDB } from "../TagDB";
|
||||
import { useAutomationDB } from "./automationDB";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
@@ -12,7 +12,7 @@ export type UseAutomationManagerStateArgs = {
|
||||
configAutomations: AutomationData[];
|
||||
hassEntities: HassEntities;
|
||||
onUpdateTags: (aid: string, tags: Record<string, string>) => void;
|
||||
onAutomationAdd: (auto: AutomationData) => void;
|
||||
onAutomationAdd: (auto: BareAutomationData) => void;
|
||||
onAutomationUpdate: (auto: AutomationData) => void;
|
||||
onAutomationStateChange: (eid: string, on: boolean) => void;
|
||||
onAutomationRun: (eid: string) => void;
|
||||
@@ -68,7 +68,7 @@ export const useAutomationManagerState = ({
|
||||
get tagsDB() {
|
||||
return tagsDB;
|
||||
},
|
||||
get currentAutomation(): AutomationData | null {
|
||||
get currentAutomation(): AutomationData | BareAutomationData | null {
|
||||
return currentAutomation === null ? null : currentAutomation[1];
|
||||
},
|
||||
get currentAutomationIsNew() {
|
||||
@@ -95,11 +95,11 @@ export const useAutomationManagerState = ({
|
||||
const auto = automationDB.addNew();
|
||||
methods.setSelectedAutomationId(auto.id, true);
|
||||
},
|
||||
editorUpdateAutomation(auto: AutomationData) {
|
||||
editorUpdateAutomation(auto: AutomationData | BareAutomationData) {
|
||||
if (methods.currentAutomationIsNew) {
|
||||
onAutomationAdd(auto);
|
||||
} else if (methods.currentAutomationId) {
|
||||
onAutomationUpdate(auto);
|
||||
onAutomationUpdate(auto as AutomationData);
|
||||
}
|
||||
},
|
||||
sideBarUpdateAutomation(
|
||||
@@ -108,7 +108,13 @@ export const useAutomationManagerState = ({
|
||||
eid: string
|
||||
) {
|
||||
const previousAuto = automationDB.getAutomationData(aid);
|
||||
if (previousAuto && previousAuto[1]) {
|
||||
if (
|
||||
previousAuto &&
|
||||
previousAuto[1] &&
|
||||
"configuration_key" in previousAuto[1] &&
|
||||
"source_file" in previousAuto[1] &&
|
||||
"source_file_type" in previousAuto[1]
|
||||
) {
|
||||
const previousAutoState = previousAuto[1];
|
||||
if (
|
||||
previousAutoState.alias !== a.title ||
|
||||
|
||||
Reference in new issue
Block a user