diff --git a/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx b/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx index 337200d..2710b35 100644 --- a/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx +++ b/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx @@ -14,7 +14,7 @@ export type ListBoxGroupProps = AutomationManagerItem & { aid: string, eid: string ) => void; - onAutomationDelete: (aid: string) => void; + onAutomationDelete: (aid: string, eid: string) => void; onSelect: (aid: string) => void; initialOpenState?: boolean; tagsDB: TagDB; @@ -64,7 +64,9 @@ export const ListBoxGroup: FC = ({ key={`${i}-${auto.id}`} {...auto} tagsDB={tagsDB} - onDelete={() => events.onAutomationDelete(auto.id)} + onDelete={() => + events.onAutomationDelete(auto.id, auto.entityId) + } onSelect={() => events.onSelect(auto.id)} onDescriptionUpdate={(description) => events.onAutomationUpdate( diff --git a/webapp/src/components/AutomationManager/Loaded/index.tsx b/webapp/src/components/AutomationManager/Loaded/index.tsx index cb57885..f2665ff 100644 --- a/webapp/src/components/AutomationManager/Loaded/index.tsx +++ b/webapp/src/components/AutomationManager/Loaded/index.tsx @@ -11,7 +11,7 @@ import { import Alert from "@mui/material/Alert"; export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & { - onAutomationDelete: (aid: string) => void; + onAutomationDelete: (aid: string, eid: string) => void; }; export const AutomationManagerLoaded: FC< PropsWithChildren @@ -27,7 +27,10 @@ export const AutomationManagerLoaded: FC< selectedAutomationId={state.currentAutomationId} onSelectedAutomationId={state.setSelectedAutomationId} onAutomationAdd={() => state.addNew()} - onAutomationDelete={onAutomationDelete} + onAutomationDelete={(aid, eid) => { + onAutomationDelete(aid, eid); + state.setSelectedAutomationId(null); + }} onAutomationUpdate={state.sideBarUpdateAutomation} />
diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.tsx b/webapp/src/components/AutomationManager/MetadataBox/index.tsx index aacd2c7..25bcc35 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.tsx +++ b/webapp/src/components/AutomationManager/MetadataBox/index.tsx @@ -13,7 +13,6 @@ import { ButtonIcon } from "components/Icons/ButtonIcons"; import { AutomationManagerAuto } from "../types"; import { Tags } from "./Tags"; import { TagDB } from "../TagDB"; -import useWindowSize from "utils/useWindowSize"; export type MetadataBoxProps = AutomationManagerAuto & { onDelete: () => void; diff --git a/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx b/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx index 009de10..003de43 100644 --- a/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx +++ b/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx @@ -37,8 +37,8 @@ const story = makeStory({ args.onSelectedAutomationId(aid); setSelAutoId(aid); }} - onAutomationDelete={(aid) => { - args.onAutomationDelete(aid); + onAutomationDelete={(aid, eid) => { + args.onAutomationDelete(aid, eid); setAutomations(automations.filter(({ id }) => id !== aid)); }} onAutomationUpdate={(a, aid, eid) => { diff --git a/webapp/src/components/AutomationManager/Sidebar/index.tsx b/webapp/src/components/AutomationManager/Sidebar/index.tsx index 02d776a..9044288 100644 --- a/webapp/src/components/AutomationManager/Sidebar/index.tsx +++ b/webapp/src/components/AutomationManager/Sidebar/index.tsx @@ -28,7 +28,7 @@ export type AutomationManagerSidebarProps = { aid: string, eid: string ) => void; - onAutomationDelete: (aid: string) => void; + onAutomationDelete: (aid: string, eid: string) => void; onAutomationAdd: () => void; onSelectedAutomationId: (aid: string) => void; }; diff --git a/webapp/src/components/AutomationManager/index.stories.tsx b/webapp/src/components/AutomationManager/index.stories.tsx index 3724cc0..4d7a992 100644 --- a/webapp/src/components/AutomationManager/index.stories.tsx +++ b/webapp/src/components/AutomationManager/index.stories.tsx @@ -20,6 +20,7 @@ const { make, componentMeta } = makeStory({ api={useMockApiService(args.automations ?? [], !args.automations)} haEntities={useMockHAEntities(haEntities)} refreshAutomations={() => {}} + forceDeleteAutomation={() => {}} onAutomationStateChange={(eid, on) => { if (!haEntities.loading && !haEntities.error) { setHAE({ diff --git a/webapp/src/components/AutomationManager/index.tsx b/webapp/src/components/AutomationManager/index.tsx index ef26096..8312b2c 100644 --- a/webapp/src/components/AutomationManager/index.tsx +++ b/webapp/src/components/AutomationManager/index.tsx @@ -13,6 +13,7 @@ import { useSnackbar } from "notistack"; export type AutomationManagerProps = { onAutomationStateChange: (eid: string, on: boolean) => void; refreshAutomations: () => void; + forceDeleteAutomation: (eid: string) => void; haEntities: HAEntitiesState; api: ApiService; }; @@ -22,6 +23,7 @@ export const AutomationManager: FC = ({ haEntities, onAutomationStateChange, refreshAutomations, + forceDeleteAutomation, }) => { const snackbr = useSnackbar(); const [isSaving, setIsSaving] = useState(false); @@ -80,16 +82,23 @@ export const AutomationManager: FC = ({ }); refreshAutomations(); }} - onAutomationDelete={(aid) => { + onAutomationDelete={(aid, eid) => { const index = configAutomations.data.findIndex( ({ metadata }) => metadata.id === aid ); + let deleteSent = false; if (index >= 0) { api.removeAutomation({ index, }); - refreshAutomations(); - } else { + deleteSent = true; + } + const hassAuto = hassEntities[eid]; + if (hassAuto) { + forceDeleteAutomation(eid); + deleteSent = true; + } + if (!deleteSent) { snackbr.enqueueSnackbar( "Failed to delete automation, this may be resolved by a refresh or reboot of Home Assistant", { @@ -97,6 +106,7 @@ export const AutomationManager: FC = ({ } ); } + // refreshAutomations(); }} onAutomationUpdate={(aid, auto) => { const index = configAutomations.data.findIndex( diff --git a/webapp/src/components/Inputs/InputTextView.tsx b/webapp/src/components/Inputs/InputTextView.tsx index 5665c66..2d5c7f9 100644 --- a/webapp/src/components/Inputs/InputTextView.tsx +++ b/webapp/src/components/Inputs/InputTextView.tsx @@ -29,7 +29,7 @@ export const InputTextView: FC> = ( return (
!!props.disabled && setViewMode(false)} + onClick={() => !props.disabled && setViewMode(false)} > {!!props.value ? ( {props.value} diff --git a/webapp/src/routes/automation.tsx b/webapp/src/routes/automation.tsx index c73a73a..7a4308c 100644 --- a/webapp/src/routes/automation.tsx +++ b/webapp/src/routes/automation.tsx @@ -11,6 +11,12 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => { ha.callService("automation", "reload")} + forceDeleteAutomation={(eid) => + ha.callHA({ + entity_id: eid, + type: "config/entity_registry/remove", + }) + } onAutomationStateChange={(eid, on) => { ha.callService( "automation",