From e2d4022bded07289d2808b4910bd4b41589585ac Mon Sep 17 00:00:00 2001 From: Ari Date: Thu, 25 Aug 2022 12:27:14 -0400 Subject: [PATCH] less annoying ha connection state --- .../src/components/AutomationManager/index.tsx | 2 +- webapp/src/components/Page/index.tsx | 6 ------ webapp/src/components/VersionBox/index.css | 17 ++++++++++++++++- webapp/src/components/VersionBox/index.tsx | 16 ++++++++++++---- webapp/src/haService/index.ts | 5 ++++- webapp/src/routes/automation.tsx | 2 +- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/webapp/src/components/AutomationManager/index.tsx b/webapp/src/components/AutomationManager/index.tsx index dfe72e8..5cb63aa 100644 --- a/webapp/src/components/AutomationManager/index.tsx +++ b/webapp/src/components/AutomationManager/index.tsx @@ -264,7 +264,7 @@ export const AutomationManager: FC = ({ } ); } - // refreshAutomations(); + refreshAutomations(); }} onAutomationUpdate={(auto) => wrapApiPromise( diff --git a/webapp/src/components/Page/index.tsx b/webapp/src/components/Page/index.tsx index 6d6d93d..c16c683 100644 --- a/webapp/src/components/Page/index.tsx +++ b/webapp/src/components/Page/index.tsx @@ -58,12 +58,6 @@ export const InternalPage: FC<{ if (snackbarKeyHAConKey.current) { snackbar.closeSnackbar(snackbarKeyHAConKey.current); } - snackbarKeyHAConKey.current = snackbar.enqueueSnackbar( - `Connected to HA!`, - { - variant: "success", - } - ); } }, [conn, snackbar]); diff --git a/webapp/src/components/VersionBox/index.css b/webapp/src/components/VersionBox/index.css index 50f2c23..2371a2c 100644 --- a/webapp/src/components/VersionBox/index.css +++ b/webapp/src/components/VersionBox/index.css @@ -1,6 +1,21 @@ .version-box { position: absolute; - bottom: 0; + bottom: -0.5em; right: 0; font-size: 0.5em; +} + +.version-box #circle { + color: var(--mui-primary-main); + height: 1em; + width: 1em; +} + +.version-box #circle.error { + color: var(--mui-error-main); +} + + +.version-box #circle.loaded { + color: var(--mui-success-light); } \ No newline at end of file diff --git a/webapp/src/components/VersionBox/index.tsx b/webapp/src/components/VersionBox/index.tsx index 509fb93..24bd57d 100644 --- a/webapp/src/components/VersionBox/index.tsx +++ b/webapp/src/components/VersionBox/index.tsx @@ -1,9 +1,17 @@ import "./index.css"; import { FC } from "react"; +import { useHAConnection } from "haService/connection"; export const VersionBox: FC = () => { - const version = process.env.REACT_APP_BUILD_VERSION ?? "n/a"; - return
- version: {version} + const ha = useHAConnection(); + const version = process.env.REACT_APP_BUILD_VERSION ?? "n/a"; + + return ( +
+ version: {version} / HA Connection{" "} + + 🟢 +
-} \ No newline at end of file + ); +}; diff --git a/webapp/src/haService/index.ts b/webapp/src/haService/index.ts index 0547ca0..6b1a075 100644 --- a/webapp/src/haService/index.ts +++ b/webapp/src/haService/index.ts @@ -229,6 +229,9 @@ export const useHA = () => { callService, callHA, deviceExtras: getDeviceExtraWsCalls(callHA), - reloadAutomations: () => callService("automation", "reload"), + reloadAutomations: () => + conn.status === "loaded" + ? callService("automation", "reload") + : Promise.resolve(), }; }; diff --git a/webapp/src/routes/automation.tsx b/webapp/src/routes/automation.tsx index e6689ff..e2dadee 100644 --- a/webapp/src/routes/automation.tsx +++ b/webapp/src/routes/automation.tsx @@ -8,7 +8,7 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => { return ( ha.callService("automation", "reload")} + refreshAutomations={() => ha.reloadAutomations()} triggerAutomation={(entity_id) => ha.callService( "automation",