added supervisor token + snackbar for errors
This commit is contained in:
1 parent
e22f64dd51
commit
21fe64f4bf
9 files changed
+88
-21
No files matched your search
+1
-3
@@ -39,8 +39,6 @@ RUN /app/bin/build.sh /app /app/web-builder
|
||||
|
||||
# <--- Api Code -->
|
||||
COPY api/src /app/src
|
||||
COPY run.sh /app/run.sh
|
||||
RUN chmod +x /app/run.sh
|
||||
|
||||
# <--- Ports -->
|
||||
EXPOSE 8000
|
||||
@@ -50,5 +48,5 @@ LABEL \
|
||||
io.hass.type="addon" \
|
||||
io.hass.arch="armhf|aarch64|i386|amd64"
|
||||
|
||||
CMD [ "/app/run.sh" ]
|
||||
CMD [ "/app/bin/run.sh", "/app" ]
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
DC=docker-compose -f docker-compose.build.yaml -f docker-compose.test.yaml
|
||||
|
||||
build:
|
||||
$(DC) build
|
||||
$(DC) build\
|
||||
|
||||
push:
|
||||
$(DC) push
|
||||
|
||||
run:
|
||||
$(MAKE) build
|
||||
|
||||
@@ -16,6 +16,7 @@ init: false
|
||||
ingress: true
|
||||
ingress_port: 8000
|
||||
ingress_entry: "web/"
|
||||
homeassistant_api: true
|
||||
panel_icon: mdi:home-automation
|
||||
hassio_role: manager
|
||||
privileged:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
addon:
|
||||
image: "asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-latest}"
|
||||
image: "asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-edge}"
|
||||
build:
|
||||
context: "./"
|
||||
dockerfile: "./Dockerfile"
|
||||
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
api_location=${1}
|
||||
|
||||
pushd $api_location
|
||||
echo "--------------------"
|
||||
echo $BUILD_VERSION
|
||||
echo $SUPERVISOR_TOKEN
|
||||
echo $(python --version)
|
||||
echo "--------------------"
|
||||
python -m uvicorn src.app:app --host "0.0.0.0" --port 8000
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo $(python --version)
|
||||
python -m uvicorn src.app:app --host "0.0.0.0" --port 8000
|
||||
@@ -12,7 +12,6 @@ export const ActionDeviceState: OptionManager<DeviceAction> = {
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState, entities) => {
|
||||
console.log(entities.collection?.state)
|
||||
const update = updateActionData(state, setState);
|
||||
return <>
|
||||
<InputDevice
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import "./index.css";
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
||||
import { createRef, FC, ReactNode, useEffect, useRef } from 'react';
|
||||
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
|
||||
import { VersionBox } from "components/VersionBox";
|
||||
import { SnackbarProvider } from 'notistack';
|
||||
import { SnackbarKey, SnackbarProvider, useSnackbar } from 'notistack';
|
||||
import { Button } from "@mui/material";
|
||||
import { useHAConnection } from 'haService/connection';
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
@@ -10,19 +12,66 @@ const theme = createTheme({
|
||||
},
|
||||
});
|
||||
|
||||
export const InternalPage: FC<{
|
||||
children: ReactNode
|
||||
}> = ({ children }) => {
|
||||
const conn = useHAConnection();
|
||||
const theme = useTheme();
|
||||
const snackbar = useSnackbar();
|
||||
const snackbarKeyHAConKey = useRef<SnackbarKey | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (conn.status === 'error') {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Failed to connect to homeassistant due to "${JSON.stringify(conn.error)}"`, {
|
||||
"variant": "error",
|
||||
"persist": true,
|
||||
})
|
||||
} else if (conn.status === 'loading') {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Connecting to websocket...`, {
|
||||
"variant": "info",
|
||||
})
|
||||
} else if (conn.status === "loaded") {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||
}
|
||||
}
|
||||
}, [conn.status])
|
||||
|
||||
return <main className="page" style={{
|
||||
color: theme.palette.text.primary,
|
||||
background: theme.palette.background.default,
|
||||
}}>
|
||||
<VersionBox />
|
||||
{children}
|
||||
</main>
|
||||
}
|
||||
|
||||
export const Page: FC<{
|
||||
children: ReactNode
|
||||
}> = ({ children }) => {
|
||||
const notistackRef = createRef<any>();
|
||||
const onClickDismiss = (key: SnackbarKey) => () => {
|
||||
notistackRef.current.closeSnackbar(key);
|
||||
}
|
||||
return <ThemeProvider theme={theme}>
|
||||
<SnackbarProvider>
|
||||
<main className="page" style={{
|
||||
color: theme.palette.text.primary,
|
||||
background: theme.palette.background.default,
|
||||
}}>
|
||||
<VersionBox />
|
||||
<SnackbarProvider
|
||||
anchorOrigin={{
|
||||
"vertical": "bottom",
|
||||
"horizontal": "center"
|
||||
}}
|
||||
ref={notistackRef}
|
||||
action={key => <Button onClick={onClickDismiss(key)}>Dismiss</Button>}
|
||||
dense preventDuplicate
|
||||
>
|
||||
<InternalPage>
|
||||
{children}
|
||||
</main>
|
||||
</InternalPage>
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
|
||||
const HASS_URL = process.env.REACT_APP_HASS_URL as string;
|
||||
const HASS_TOKEN = process.env.REACT_APP_HASS_TOKEN;
|
||||
const HASS_SUPERVISOR_TOKEN = process.env.REACT_APP_SUPERVISOR_TOKEN as string;
|
||||
export type HAConnection = {
|
||||
status: 'loading'
|
||||
} | {
|
||||
@@ -51,6 +52,9 @@ const createAuth = async () => {
|
||||
if (HASS_TOKEN) {
|
||||
return createLongLivedTokenAuth(HASS_URL, HASS_TOKEN);
|
||||
}
|
||||
if (HASS_SUPERVISOR_TOKEN) {
|
||||
return await getAuth({ hassUrl: HASS_URL, authCode: HASS_SUPERVISOR_TOKEN });
|
||||
}
|
||||
try {
|
||||
auth = await getAuth();
|
||||
return auth
|
||||
@@ -79,7 +83,13 @@ async function startHAConnection() {
|
||||
} catch (error) {
|
||||
haConnection = {
|
||||
status: 'error',
|
||||
error: translateErrorCodes(error as any),
|
||||
error: {
|
||||
originalError: JSON.stringify(error),
|
||||
message: translateErrorCodes(error as any),
|
||||
hassToken: !HASS_TOKEN ? "no" : "yes",
|
||||
hasSuperToken: HASS_SUPERVISOR_TOKEN,
|
||||
url: HASS_URL,
|
||||
},
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user