Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc773154c6 |
No files matched your search
@@ -4,3 +4,10 @@ webapp/.storybook
|
|||||||
webapp/.vscode
|
webapp/.vscode
|
||||||
webapp/.env.local
|
webapp/.env.local
|
||||||
webapp/tmux.sh
|
webapp/tmux.sh
|
||||||
|
api/.env
|
||||||
|
api/.coverage
|
||||||
|
api/venv
|
||||||
|
api/build
|
||||||
|
api/.mypy_cache
|
||||||
|
api/.vscode
|
||||||
|
api/.coverage
|
||||||
+2
-1
@@ -10,8 +10,8 @@ ARG BUILD_VERSION
|
|||||||
|
|
||||||
# <--- Environment Variables -->
|
# <--- Environment Variables -->
|
||||||
ENV HASSIO_TOKEN ""
|
ENV HASSIO_TOKEN ""
|
||||||
ENV SUPERVISOR_TOKEN ""
|
|
||||||
ENV BUILD_VERSION $BUILD_VERSION
|
ENV BUILD_VERSION $BUILD_VERSION
|
||||||
|
ENV HASS_URL "http://supervisor/"
|
||||||
|
|
||||||
# <--- System Wide Dependencies -->
|
# <--- System Wide Dependencies -->
|
||||||
ENV LANG C.UTF-8
|
ENV LANG C.UTF-8
|
||||||
@@ -52,3 +52,4 @@ LABEL \
|
|||||||
ENTRYPOINT [ "/app/bin/run.sh" ]
|
ENTRYPOINT [ "/app/bin/run.sh" ]
|
||||||
CMD [ "/app" ]
|
CMD [ "/app" ]
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.source https://github.com/asosnovsky/Shortumation
|
||||||
@@ -43,5 +43,4 @@ clean:
|
|||||||
run-local:
|
run-local:
|
||||||
rm -f web
|
rm -f web
|
||||||
ln -s ../webapp/build web
|
ln -s ../webapp/build web
|
||||||
cd ../webapp && yarn build
|
|
||||||
USE_EXAMPLE_REPO=1 $(VENV_BIN)/uvicorn src.app:app --reload
|
USE_EXAMPLE_REPO=1 $(VENV_BIN)/uvicorn src.app:app --reload
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from src.env import BUILD_VERSION
|
from src.env import BUILD_VERSION, HASS_URL, HASSIO_TOKEN
|
||||||
from src.hass_config import HassConfig
|
from src.hass_config import HassConfig
|
||||||
|
|
||||||
|
|
||||||
@@ -10,9 +8,11 @@ def make_details_router(hass_config: HassConfig) -> APIRouter:
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
def read_ping():
|
def read_details():
|
||||||
return {
|
return {
|
||||||
"version": BUILD_VERSION,
|
"version": BUILD_VERSION,
|
||||||
|
"hassio_token": HASSIO_TOKEN,
|
||||||
|
"hass_url": HASS_URL,
|
||||||
"config": hass_config.get_configuration_path(),
|
"config": hass_config.get_configuration_path(),
|
||||||
"tags": hass_config.get_automation_tags_path(),
|
"tags": hass_config.get_automation_tags_path(),
|
||||||
"autos": hass_config.get_automation_path(),
|
"autos": hass_config.get_automation_path(),
|
||||||
|
|||||||
@@ -4,5 +4,7 @@ from decouple import Csv, config
|
|||||||
|
|
||||||
ROOT_FOLDER = Path(__file__).parent.parent.absolute()
|
ROOT_FOLDER = Path(__file__).parent.parent.absolute()
|
||||||
BUILD_VERSION = config("BUILD_VERSION", "0.0.0")
|
BUILD_VERSION = config("BUILD_VERSION", "0.0.0")
|
||||||
|
HASSIO_TOKEN = config("HASSIO_TOKEN", "")
|
||||||
|
HASS_URL = config("HASS_URL", "/")
|
||||||
LOG_LEVEL = config("LOG_LEVEL", "INFO")
|
LOG_LEVEL = config("LOG_LEVEL", "INFO")
|
||||||
ORIGIN = config("ORIGIN", cast=Csv(), default="*")
|
ORIGIN = config("ORIGIN", cast=Csv(), default="*")
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
name: Shortumation
|
name: Shortumation
|
||||||
version: v0.1.14
|
version: v0.1.14
|
||||||
slug: shortumation
|
slug: shortumation
|
||||||
image: asosnovsky/shortumation-{arch}
|
image: ghcr.io/asosnovsky/shortumation-{arch}
|
||||||
url: "https://github.com/asosnovsky/Shortumation"
|
url: "https://github.com/asosnovsky/Shortumation"
|
||||||
description: "A homeassitant addon which provides better UI for automations & scripts."
|
description: "A homeassitant addon which provides better UI for automations & scripts."
|
||||||
arch:
|
arch:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
addon:
|
addon:
|
||||||
image: "asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-edge}"
|
image: "ghcr.io/asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-edge}"
|
||||||
build:
|
build:
|
||||||
context: "./"
|
context: "./"
|
||||||
dockerfile: "./Dockerfile"
|
dockerfile: "./Dockerfile"
|
||||||
|
|||||||
@@ -3,5 +3,8 @@ services:
|
|||||||
addon:
|
addon:
|
||||||
volumes:
|
volumes:
|
||||||
- "./sample_config:/config"
|
- "./sample_config:/config"
|
||||||
|
- "./api/tests:/app/tests"
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
|
env_file:
|
||||||
|
- api/.env
|
||||||
@@ -5,8 +5,6 @@ api_location=${1}
|
|||||||
pushd $api_location
|
pushd $api_location
|
||||||
echo "--------------------"
|
echo "--------------------"
|
||||||
echo "BUILD_VERSION = "$BUILD_VERSION
|
echo "BUILD_VERSION = "$BUILD_VERSION
|
||||||
echo "HASSIO_TOKEN = "$HASSIO_TOKEN
|
|
||||||
echo "SUPERVISOR_TOKEN = "$SUPERVISOR_TOKEN
|
|
||||||
echo $(python --version)
|
echo $(python --version)
|
||||||
echo "--------------------"
|
echo "--------------------"
|
||||||
python -m uvicorn src.app:app --host "0.0.0.0" --port 8000
|
python -m uvicorn src.app:app --host "0.0.0.0" --port 8000
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
"@types/node": "^17.0.36",
|
"@types/node": "^17.0.36",
|
||||||
"@types/react": "^18.0.9",
|
"@types/react": "^18.0.9",
|
||||||
"@types/react-dom": "^18.0.5",
|
"@types/react-dom": "^18.0.5",
|
||||||
|
"@types/ws": "^8.5.3",
|
||||||
"@uiw/react-codemirror": "^4.7.0",
|
"@uiw/react-codemirror": "^4.7.0",
|
||||||
"autosuggest-highlight": "^3.2.1",
|
"autosuggest-highlight": "^3.2.1",
|
||||||
"home-assistant-js-websocket": "^7.1.0",
|
"home-assistant-js-websocket": "^7.1.0",
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
"theming": "^3.3.0",
|
"theming": "^3.3.0",
|
||||||
"typescript": "^4.1.2",
|
"typescript": "^4.1.2",
|
||||||
"web-vitals": "^2.1.4",
|
"web-vitals": "^2.1.4",
|
||||||
|
"ws": "^8.7.0",
|
||||||
"yarn": "^1.22.17"
|
"yarn": "^1.22.17"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -10,13 +10,16 @@ export const makeRemoteAPI = (baseURL: string): API => ({
|
|||||||
data = {}
|
data = {}
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
const reply = await fetch(baseURL + path, {
|
const payload: RequestInit = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data),
|
};
|
||||||
});
|
if (method !== 'GET') {
|
||||||
|
payload["body"] = JSON.stringify(data);
|
||||||
|
}
|
||||||
|
const reply = await fetch(baseURL + path, payload);
|
||||||
let response: APIResponse<any>;
|
let response: APIResponse<any>;
|
||||||
if (reply.status === 200) {
|
if (reply.status === 200) {
|
||||||
response = {
|
response = {
|
||||||
|
|||||||
@@ -5,13 +5,18 @@ import { useAPIService } from './core';
|
|||||||
import { useMockAPI } from "./mock";
|
import { useMockAPI } from "./mock";
|
||||||
|
|
||||||
const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i);
|
const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i);
|
||||||
|
const baseURL = process.env.NODE_ENV === 'development' ?
|
||||||
|
"http://localhost:8000" :
|
||||||
|
(!locationPrefixWeb ? '' : locationPrefixWeb[1]);
|
||||||
|
|
||||||
|
export const remoteDetailsAPI = makeRemoteAPI(
|
||||||
|
baseURL + "/details"
|
||||||
|
);
|
||||||
|
export const remoteAutoAPI = makeRemoteAPI(
|
||||||
|
baseURL + "/automations"
|
||||||
|
);
|
||||||
export const useConnectedApiService = () => useAPIService(
|
export const useConnectedApiService = () => useAPIService(
|
||||||
makeAutomationAPI(makeRemoteAPI(
|
makeAutomationAPI(remoteAutoAPI)
|
||||||
process.env.NODE_ENV === 'development' ?
|
|
||||||
"http://localhost:8000/automations" :
|
|
||||||
(!locationPrefixWeb ? '' : locationPrefixWeb[1]) + "/automations"
|
|
||||||
))
|
|
||||||
);
|
);
|
||||||
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
|
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
|
||||||
makeAutomationAPI(useMockAPI(initialAutos))
|
makeAutomationAPI(useMockAPI(initialAutos))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export interface ListParams {
|
|||||||
}
|
}
|
||||||
export type APIRequest<D> = {
|
export type APIRequest<D> = {
|
||||||
path: string;
|
path: string;
|
||||||
method?: "POST" | "DELETE",
|
method?: "POST" | "DELETE" | "GET",
|
||||||
data?: D;
|
data?: D;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export const AutoInfoBox: FC<Props> = ({
|
|||||||
<div className="automation-editor--info-box--tags">
|
<div className="automation-editor--info-box--tags">
|
||||||
<h1>Tags</h1>
|
<h1>Tags</h1>
|
||||||
<div className="automation-editor--info-box--tag-list">
|
<div className="automation-editor--info-box--tag-list">
|
||||||
{tags.map(([tagName, tagValue], tagIndex) => <div className="automation-editor--info-box--tag">
|
{tags.map(([tagName, tagValue], tagIndex) => <div key={tagIndex} className="automation-editor--info-box--tag">
|
||||||
<InputAutoText
|
<InputAutoText
|
||||||
value={tagName}
|
value={tagName}
|
||||||
label="Name"
|
label="Name"
|
||||||
|
|||||||
@@ -40,8 +40,11 @@ export const InternalPage: FC<{
|
|||||||
if (snackbarKeyHAConKey.current) {
|
if (snackbarKeyHAConKey.current) {
|
||||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||||
}
|
}
|
||||||
|
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Connected to HA!`, {
|
||||||
|
"variant": "success",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [conn.status])
|
}, [conn, snackbar])
|
||||||
|
|
||||||
return <main className="page" style={{
|
return <main className="page" style={{
|
||||||
color: theme.palette.text.primary,
|
color: theme.palette.text.primary,
|
||||||
|
|||||||
@@ -1,20 +1,16 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import {
|
import {
|
||||||
getAuth,
|
|
||||||
createConnection,
|
|
||||||
ERR_HASS_HOST_REQUIRED,
|
ERR_HASS_HOST_REQUIRED,
|
||||||
createLongLivedTokenAuth,
|
createLongLivedTokenAuth,
|
||||||
Auth,
|
|
||||||
Connection,
|
Connection,
|
||||||
ERR_CANNOT_CONNECT,
|
ERR_CANNOT_CONNECT,
|
||||||
ERR_CONNECTION_LOST,
|
ERR_CONNECTION_LOST,
|
||||||
ERR_INVALID_AUTH,
|
ERR_INVALID_AUTH,
|
||||||
ERR_INVALID_HTTPS_TO_HTTP,
|
ERR_INVALID_HTTPS_TO_HTTP,
|
||||||
|
createConnection as _createConnection,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
|
import { remoteDetailsAPI } from 'apiService';
|
||||||
|
|
||||||
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 = {
|
export type HAConnection = {
|
||||||
status: 'loading'
|
status: 'loading'
|
||||||
} | {
|
} | {
|
||||||
@@ -47,52 +43,81 @@ const translateErrorCodes = (errorCode: number) => {
|
|||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createAuth = async () => {
|
type ReturnedToken = {
|
||||||
let auth: Auth
|
hassURL: string;
|
||||||
if (HASS_TOKEN) {
|
longToken: string
|
||||||
return createLongLivedTokenAuth(HASS_URL, HASS_TOKEN);
|
} | {
|
||||||
}
|
hassURL: string;
|
||||||
if (HASS_SUPERVISOR_TOKEN) {
|
hassioToken: string
|
||||||
return await getAuth({ hassUrl: HASS_URL, authCode: HASS_SUPERVISOR_TOKEN });
|
} | {
|
||||||
}
|
error: any;
|
||||||
try {
|
}
|
||||||
auth = await getAuth();
|
const getToken = async (): Promise<ReturnedToken> => {
|
||||||
return auth
|
const data = await remoteDetailsAPI.makeCall({
|
||||||
} catch (err) {
|
"path": "/",
|
||||||
if (err !== ERR_HASS_HOST_REQUIRED) {
|
"method": "GET",
|
||||||
throw err
|
});
|
||||||
|
if (!data.ok) {
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
message: "Failed to get token from api.",
|
||||||
|
originalError: data.error,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
const hassURL = data.data.hass_url;
|
||||||
auth = await getAuth({ hassUrl: HASS_URL });
|
const hassioToken = data.data.hassio_token;
|
||||||
return auth
|
if (!hassioToken) {
|
||||||
} catch (err) {
|
return {
|
||||||
throw err
|
error: {
|
||||||
|
message: [
|
||||||
|
"Missing HASSIO Token, Please make sure the token is correctly passing to the container!",
|
||||||
|
"Make sure the token `HASSIO_TOKEN` and `HASS_URL` are set properly."
|
||||||
|
].join('\n'),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return { hassioToken, hassURL }
|
||||||
|
}
|
||||||
|
|
||||||
|
const createConnection = async () => {
|
||||||
|
const tokens = await getToken();
|
||||||
|
try {
|
||||||
|
if ('hassioToken' in tokens) {
|
||||||
|
return _createConnection({
|
||||||
|
auth: createLongLivedTokenAuth(tokens.hassURL, tokens.hassioToken),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
throw {
|
||||||
|
originalError: JSON.stringify(error),
|
||||||
|
message: translateErrorCodes(error as any),
|
||||||
|
tokens,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startHAConnection() {
|
async function startHAConnection() {
|
||||||
|
let connection: Connection;
|
||||||
try {
|
try {
|
||||||
const auth = await createAuth();
|
connection = await createConnection();
|
||||||
const connection = await createConnection({ auth });
|
|
||||||
haConnection = {
|
|
||||||
status: 'loaded',
|
|
||||||
connection,
|
|
||||||
}
|
|
||||||
return haConnection;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
haConnection = {
|
haConnection = {
|
||||||
status: 'error',
|
status: 'error',
|
||||||
error: {
|
error: {
|
||||||
originalError: JSON.stringify(error),
|
originalError: JSON.stringify(error),
|
||||||
message: translateErrorCodes(error as any),
|
message: translateErrorCodes(error as any),
|
||||||
hassToken: !HASS_TOKEN ? "no" : "yes",
|
}
|
||||||
hasSuperToken: !HASS_SUPERVISOR_TOKEN ? "no" : "yes",
|
|
||||||
url: HASS_URL,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
haConnection = {
|
||||||
|
status: 'loaded',
|
||||||
|
connection,
|
||||||
|
}
|
||||||
|
return haConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
startHAConnection().then(console.log).catch(console.error);
|
startHAConnection().then(console.log).catch(console.error);
|
||||||
|
|||||||
@@ -15,3 +15,11 @@ ReactDOM.render(
|
|||||||
// to log results (for example: reportWebVitals(console.log))
|
// to log results (for example: reportWebVitals(console.log))
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||||
reportWebVitals();
|
reportWebVitals();
|
||||||
|
|
||||||
|
|
||||||
|
// import { createRoot } from 'react-dom/client';
|
||||||
|
// const container = document.getElementById('root');
|
||||||
|
// const root = createRoot(container!);
|
||||||
|
// root.render(<React.StrictMode>
|
||||||
|
// <App />
|
||||||
|
// </React.StrictMode>);
|
||||||
+2
-2
@@ -3995,7 +3995,7 @@
|
|||||||
anymatch "^3.0.0"
|
anymatch "^3.0.0"
|
||||||
source-map "^0.6.0"
|
source-map "^0.6.0"
|
||||||
|
|
||||||
"@types/ws@^8.5.1":
|
"@types/ws@^8.5.1", "@types/ws@^8.5.3":
|
||||||
version "8.5.3"
|
version "8.5.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"
|
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"
|
||||||
integrity sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==
|
integrity sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==
|
||||||
@@ -15767,7 +15767,7 @@ ws@^7.4.6:
|
|||||||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.8.tgz#ac2729881ab9e7cbaf8787fe3469a48c5c7f636a"
|
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.8.tgz#ac2729881ab9e7cbaf8787fe3469a48c5c7f636a"
|
||||||
integrity sha512-ri1Id1WinAX5Jqn9HejiGb8crfRio0Qgu8+MtL36rlTA6RLsMdWt1Az/19A2Qij6uSHUMphEFaTKa4WG+UNHNw==
|
integrity sha512-ri1Id1WinAX5Jqn9HejiGb8crfRio0Qgu8+MtL36rlTA6RLsMdWt1Az/19A2Qij6uSHUMphEFaTKa4WG+UNHNw==
|
||||||
|
|
||||||
ws@^8.2.3, ws@^8.4.2:
|
ws@^8.2.3, ws@^8.4.2, ws@^8.7.0:
|
||||||
version "8.7.0"
|
version "8.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.7.0.tgz#eaf9d874b433aa00c0e0d8752532444875db3957"
|
resolved "https://registry.yarnpkg.com/ws/-/ws-8.7.0.tgz#eaf9d874b433aa00c0e0d8752532444875db3957"
|
||||||
integrity sha512-c2gsP0PRwcLFzUiA8Mkr37/MI7ilIlHQxaEAtd0uNMbVMoy8puJyafRlm0bV9MbGSabUPeLrRRaqIBcFcA2Pqg==
|
integrity sha512-c2gsP0PRwcLFzUiA8Mkr37/MI7ilIlHQxaEAtd0uNMbVMoy8puJyafRlm0bV9MbGSabUPeLrRRaqIBcFcA2Pqg==
|
||||||
|
|||||||
Reference in new issue
Block a user