From f1b99cad1c05f1f9df042b5b92c44c42f71ff166 Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 5 Aug 2022 22:22:28 -0400 Subject: [PATCH] trigger automation in metadata --- .../AutomationManager/ListBoxGroup/index.tsx | 2 ++ .../components/AutomationManager/Loaded/index.tsx | 1 + .../components/AutomationManager/Loaded/state.ts | 1 + .../AutomationManager/MetadataBox/index.css | 13 +++++++++++++ .../AutomationManager/MetadataBox/index.tsx | 3 +++ .../AutomationManager/Sidebar/index.stories.tsx | 1 + .../components/AutomationManager/Sidebar/index.tsx | 1 + .../components/AutomationManager/index.stories.tsx | 1 + webapp/src/components/AutomationManager/index.tsx | 3 +++ webapp/src/routes/automation.tsx | 10 ++++++++++ webapp/yarn.lock | 10 ---------- 11 files changed, 36 insertions(+), 10 deletions(-) diff --git a/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx b/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx index dffaafb..d7b24e8 100644 --- a/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx +++ b/webapp/src/components/AutomationManager/ListBoxGroup/index.tsx @@ -16,6 +16,7 @@ export type ListBoxGroupProps = AutomationManagerItem & { ) => void; onAutomationDelete: (aid: string, eid: string) => void; onSelect: (aid: string) => void; + onRun: (eid: string) => void; initialOpenState?: boolean; tagsDB: TagDB; }; @@ -70,6 +71,7 @@ export const ListBoxGroup: FC = ({ } isSelected={auto.flags.isSelected} onSelect={() => events.onSelect(auto.id)} + onRun={() => events.onRun(auto.entityId)} onDescriptionUpdate={(description) => events.onAutomationUpdate( { diff --git a/webapp/src/components/AutomationManager/Loaded/index.tsx b/webapp/src/components/AutomationManager/Loaded/index.tsx index f2665ff..d39dfa4 100644 --- a/webapp/src/components/AutomationManager/Loaded/index.tsx +++ b/webapp/src/components/AutomationManager/Loaded/index.tsx @@ -32,6 +32,7 @@ export const AutomationManagerLoaded: FC< state.setSelectedAutomationId(null); }} onAutomationUpdate={state.sideBarUpdateAutomation} + onRun={args.onAutomationRun} />
{state.currentAutomationId !== null ? ( diff --git a/webapp/src/components/AutomationManager/Loaded/state.ts b/webapp/src/components/AutomationManager/Loaded/state.ts index 653b780..62ffbfa 100644 --- a/webapp/src/components/AutomationManager/Loaded/state.ts +++ b/webapp/src/components/AutomationManager/Loaded/state.ts @@ -15,6 +15,7 @@ export type UseAutomationManagerStateArgs = { onAutomationAdd: (auto: AutomationData) => void; onAutomationUpdate: (aid: string, auto: AutomationData) => void; onAutomationStateChange: (eid: string, on: boolean) => void; + onAutomationRun: (eid: string) => void; }; export const useAutomationManagerState = ({ configAutomations, diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.css b/webapp/src/components/AutomationManager/MetadataBox/index.css index a055148..244f92c 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.css +++ b/webapp/src/components/AutomationManager/MetadataBox/index.css @@ -42,12 +42,25 @@ font-size: 0.9em; } +.automation-manager--metadatabox .buttons { + display: flex; + flex-direction: row; + gap: 0.25em; +} + .automation-manager--metadatabox .delete:hover { cursor: pointer; color: var(--mui-error-light); + color: var(--mui-error-contrastText); background-color: var(--mui-error-dark); } +.automation-manager--metadatabox .run:hover { + cursor: pointer; + color: var(--mui-success-contrastText); + background-color: var(--mui-success-dark); +} + .automation-manager--metadatabox .select:hover, .automation-manager--metadatabox.selected.automation-manager--metadatabox .select { cursor: pointer; diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.tsx b/webapp/src/components/AutomationManager/MetadataBox/index.tsx index 25bcc35..b8b166c 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.tsx +++ b/webapp/src/components/AutomationManager/MetadataBox/index.tsx @@ -7,6 +7,7 @@ import Alert from "@mui/material/Alert"; import DeleteForeverIcon from "@mui/icons-material/DeleteForever"; import SelectIcon from "@mui/icons-material/HighlightAltSharp"; +import RunIcon from "@mui/icons-material/RunCircleOutlined"; import { InputTextView } from "components/Inputs/InputTextView"; import { ButtonIcon } from "components/Icons/ButtonIcons"; @@ -17,6 +18,7 @@ import { TagDB } from "../TagDB"; export type MetadataBoxProps = AutomationManagerAuto & { onDelete: () => void; onSelect: () => void; + onRun: () => void; onStateUpdate: (s: "on" | "off") => void; onTitleUpdate: (t: string) => void; onDescriptionUpdate: (t: string) => void; @@ -80,6 +82,7 @@ export const MetadataBox: FC = (props) => { icon={} onClick={props.onSelect} /> + } onClick={props.onRun} /> } diff --git a/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx b/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx index 003de43..77b4795 100644 --- a/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx +++ b/webapp/src/components/AutomationManager/Sidebar/index.stories.tsx @@ -33,6 +33,7 @@ const story = makeStory({ selectedAutomationId={selectedAutomationId} tagsDB={useTagDB(automations, (a, t) => onTagUpdate(t, a))} automations={automations} + onRun={args.onRun} onSelectedAutomationId={(aid) => { args.onSelectedAutomationId(aid); setSelAutoId(aid); diff --git a/webapp/src/components/AutomationManager/Sidebar/index.tsx b/webapp/src/components/AutomationManager/Sidebar/index.tsx index 4d2b98e..c652d6c 100644 --- a/webapp/src/components/AutomationManager/Sidebar/index.tsx +++ b/webapp/src/components/AutomationManager/Sidebar/index.tsx @@ -31,6 +31,7 @@ export type AutomationManagerSidebarProps = { onAutomationDelete: (aid: string, eid: string) => void; onAutomationAdd: () => void; onSelectedAutomationId: (aid: string) => void; + onRun: (eid: string) => void; }; export const AutomationManagerSidebar: FC = ({ automations, diff --git a/webapp/src/components/AutomationManager/index.stories.tsx b/webapp/src/components/AutomationManager/index.stories.tsx index 4d7a992..eeb8bf8 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={() => {}} + triggerAutomation={() => {}} forceDeleteAutomation={() => {}} onAutomationStateChange={(eid, on) => { if (!haEntities.loading && !haEntities.error) { diff --git a/webapp/src/components/AutomationManager/index.tsx b/webapp/src/components/AutomationManager/index.tsx index 5a3a755..c1f6881 100644 --- a/webapp/src/components/AutomationManager/index.tsx +++ b/webapp/src/components/AutomationManager/index.tsx @@ -14,6 +14,7 @@ export type AutomationManagerProps = { onAutomationStateChange: (eid: string, on: boolean) => void; refreshAutomations: () => void; forceDeleteAutomation: (eid: string) => void; + triggerAutomation: (eid: string) => void; haEntities: HAEntitiesState; api: ApiService; }; @@ -24,6 +25,7 @@ export const AutomationManager: FC = ({ onAutomationStateChange, refreshAutomations, forceDeleteAutomation, + triggerAutomation, }) => { const snackbr = useSnackbar(); const [isSaving, setIsSaving] = useState(false); @@ -79,6 +81,7 @@ export const AutomationManager: FC = ({ { await api.updateAutomation({ diff --git a/webapp/src/routes/automation.tsx b/webapp/src/routes/automation.tsx index 7a4308c..a0ce084 100644 --- a/webapp/src/routes/automation.tsx +++ b/webapp/src/routes/automation.tsx @@ -11,6 +11,16 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => { ha.callService("automation", "reload")} + triggerAutomation={(entity_id) => + ha.callService( + "automation", + "trigger", + {}, + { + entity_id, + } + ) + } forceDeleteAutomation={(eid) => ha.callHA({ entity_id: eid, diff --git a/webapp/yarn.lock b/webapp/yarn.lock index 6734604..02cbfbd 100644 --- a/webapp/yarn.lock +++ b/webapp/yarn.lock @@ -10472,16 +10472,6 @@ jss@10.9.0, jss@^10.8.2: is-in-browser "^1.1.3" tiny-warning "^1.0.2" -jss@10.9.1: - version "10.9.1" - resolved "https://registry.yarnpkg.com/jss/-/jss-10.9.1.tgz#43d95a964f68f31074470da8de5167aed4586311" - integrity sha512-omDBQTYyIdYuHee1mkpqDyHw2NguCrURBU1izPPHmdtDK6SkP7P3buZt4ybHWOahTZ3+xd0C+zLPBBw7Hn3eYg== - dependencies: - "@babel/runtime" "^7.3.1" - csstype "^3.0.2" - is-in-browser "^1.1.3" - tiny-warning "^1.0.2" - jss@10.9.2: version "10.9.2" resolved "https://registry.yarnpkg.com/jss/-/jss-10.9.2.tgz#9379be1f195ef98011dfd31f9448251bd61b95a9"