Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bcbcaa801 | ||
|
|
b479476833 | ||
|
|
baa31ab649 | ||
|
|
dc7c6273e4 | ||
|
|
2942b6173b | ||
|
|
bcfc648011 | ||
|
|
084d86ad7a | ||
|
|
ea6be4a8f3 | ||
|
|
14649ac1fd | ||
|
|
f1b99cad1c | ||
|
|
ab7f50d4aa | ||
|
|
d22bba8c4d | ||
|
|
549f52655b | ||
|
|
2c5d64ab86 | ||
|
|
7c50c345ec | ||
|
|
f4261f9701 | ||
|
|
34826acb97 | ||
|
|
cd1b4e8e2b | ||
|
|
2b4c64c94b | ||
|
|
067f5fa642 |
No files matched your search
@@ -1,5 +1,25 @@
|
||||
# Changelog 
|
||||
|
||||
## [0.5.2] - Better Controls
|
||||
|
||||
- Add automation trigger
|
||||
- Speed dial on the bottom
|
||||
<img src="https://user-images.githubusercontent.com/7451445/183231968-9891bbb4-5c7c-4e05-b804-36978c809a5c.png" width="200px"/>
|
||||
- Infinite undos <img src="https://user-images.githubusercontent.com/7451445/183231977-ed000017-2886-4a57-b5fb-c7e527bf3894.png" width="200px"/>
|
||||
|
||||
## [0.5.1] - Sidebar!
|
||||
|
||||
- completely redesigned the sidebar!
|
||||
|
||||
- Disable/enable automatons
|
||||
- See 'bad state' automatons
|
||||
- Delete automatons from registry (in cases where references are stale)
|
||||
- Refactored sidebar UX to match MUI standards
|
||||
- Cleaned up editing tags in sidebar
|
||||
<img src="https://user-images.githubusercontent.com/7451445/182066721-07a93651-2f83-44d5-8420-15093caa52df.png" width="400px"/>
|
||||
|
||||
- Websockets now live-refresh when updates occur
|
||||
|
||||
## [0.4.0] - Depedency update
|
||||
|
||||
- Core dependency updates
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Shortumation 
|
||||
# <img src="logo.png" height="40x"/> Shortumation 
|
||||
|
||||
[](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml)
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
| ------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Version |  |  |
|
||||
|
||||
A [home-assistant addon](https://www.home-assistant.io/addons/) for a better UI for managing and writing your automations. We provide a way to visualize your automation using a visual-programming language that draws inspirations from [Node-Red](https://nodered.org/).
|
||||
A [home-assistant addon](https://www.home-assistant.io/addons/) for a better UI for managing and writing your automations. We provide a way to visualize your automation using a visual-programming language that draws inspirations from [Node-Red](https://nodered.org/).
|
||||
|
||||
<img src="./assets/comparisons.png">
|
||||
|
||||
## Features
|
||||
|
||||
@@ -46,6 +48,8 @@ Add the repository URL under **Supervisor → Add-on store → ⋮ → Manage ad
|
||||
|
||||
It should now appear in your `Add-on Store` and you should be able to install it!
|
||||
|
||||
**Please note that you may need to enable advance mode in your settings first!**
|
||||
|
||||
### Containerized or HA Core
|
||||
|
||||
Please note that this way of using Shortumation is **not future proof**.
|
||||
|
||||
+11
-1
@@ -1,6 +1,7 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
from src.automations.manager import AutomationManager
|
||||
from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER
|
||||
@@ -10,7 +11,8 @@ from .routes import automations, details, ping, socket
|
||||
|
||||
def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
||||
app = FastAPI()
|
||||
if (ROOT_FOLDER / "web").exists():
|
||||
has_web_folder = (ROOT_FOLDER / "web").exists()
|
||||
if has_web_folder:
|
||||
app.mount(
|
||||
f"{API_PREFIX}/web",
|
||||
StaticFiles(
|
||||
@@ -19,6 +21,7 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
||||
),
|
||||
name="web",
|
||||
)
|
||||
|
||||
else:
|
||||
print("WARN: could not find web folder")
|
||||
app.add_middleware(
|
||||
@@ -36,4 +39,11 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
||||
details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details"
|
||||
)
|
||||
app.include_router(socket.router, prefix=f"{API_PREFIX}/socket")
|
||||
|
||||
@app.get("/")
|
||||
def get_index():
|
||||
if has_web_folder:
|
||||
return RedirectResponse("/web")
|
||||
return RedirectResponse("/details")
|
||||
|
||||
return app
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.9 MiB |
+1
-1
@@ -1,5 +1,5 @@
|
||||
name: Shortumation
|
||||
version: v0.4.0
|
||||
version: v0.5.2
|
||||
slug: shortumation
|
||||
image: asosnovsky/shortumation-{arch}
|
||||
url: "https://github.com/asosnovsky/Shortumation"
|
||||
|
||||
@@ -12,9 +12,12 @@ services:
|
||||
shortumation:
|
||||
# make sure to replace the ARCH with whatever system you are running!
|
||||
image: "asosnovsky/shortumation-${ARCH:-amd64}:${SHORTUMATION_VERSION:-latest}"
|
||||
network_mode: host
|
||||
ports:
|
||||
- 8000:8000
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
volumes:
|
||||
- ./config:/config
|
||||
environment:
|
||||
- SUPERVISOR_TOKEN=${SUPERVISOR_TOKEN}
|
||||
- HASSIO_WS=ws://0.0.0.0:8123/api/websocket
|
||||
- HASSIO_WS=ws://host.docker.internal:8123/api/websocket
|
||||
Vendored
+6
-2
@@ -2,13 +2,17 @@
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"icon": {
|
||||
"id": "server-environment"
|
||||
},
|
||||
"type": "shell",
|
||||
"label": "Docker: Server",
|
||||
"label": "Docker: Start Server",
|
||||
"group": "none",
|
||||
"command": [".vscode/bin/start-docker-server.sh"],
|
||||
"runOptions": {
|
||||
"runOn": "folderOpen"
|
||||
}
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
"@uiw/react-codemirror": "4.10.4",
|
||||
"autosuggest-highlight": "3.3.4",
|
||||
"home-assistant-js-websocket": "7.1.0",
|
||||
"jss": "10.9.1",
|
||||
"jss": "10.9.2",
|
||||
"material-ui-confirm": "3.0.4",
|
||||
"notistack": "2.0.5",
|
||||
"react": "18.2.0",
|
||||
@@ -25,7 +25,7 @@
|
||||
"react-dom": "18.2.0",
|
||||
"react-flow-renderer": "10.3.12",
|
||||
"react-imask": "6.4.2",
|
||||
"react-jss": "10.9.1",
|
||||
"react-jss": "10.9.2",
|
||||
"react-router-dom": "6.3.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"superstruct": "0.16.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "./AutoInfoBox.css";
|
||||
import { AutomationMetadata } from "types/automations";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { FC, ReactNode, useRef, useState } from "react";
|
||||
import { AddIcon, TrashIcon } from "components/Icons";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
|
||||
@@ -3,19 +3,23 @@ import "./index.mobile.css";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { ControlButton } from "react-flow-renderer";
|
||||
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import SpeedDial from "@mui/material/SpeedDial";
|
||||
import SpeedDialAction from "@mui/material/SpeedDialAction";
|
||||
|
||||
import Edit from "@mui/icons-material/Edit";
|
||||
import SpeedDialIcon from "@mui/icons-material/SettingsRounded";
|
||||
import UndoIcon from "@mui/icons-material/UndoSharp";
|
||||
import Icon from "@mui/material/Icon";
|
||||
import ModeEditOutlineTwoToneIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
|
||||
import EditIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
|
||||
import DeleteIcon from "@mui/icons-material/DeleteForever";
|
||||
import { CheckMarkIcon } from "components/Icons";
|
||||
import RunIcon from "@mui/icons-material/RunCircleOutlined";
|
||||
|
||||
import { Modal } from "components/Modal";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { TagDB } from "components/AutomationManager/TagDB";
|
||||
import { DAGDims } from "components/DAGGraph/elements/types";
|
||||
import { DAGAutomationGraph } from "components/DAGGraph";
|
||||
@@ -32,6 +36,8 @@ interface Props {
|
||||
automation?: AutomationData;
|
||||
dims: DAGDims;
|
||||
onUpdate: (auto: AutomationData) => void;
|
||||
onTrigger: () => void;
|
||||
onDelete: () => void;
|
||||
tagDB: TagDB;
|
||||
isNew?: boolean;
|
||||
}
|
||||
@@ -39,6 +45,8 @@ export const AutomationEditor: FC<Props> = ({
|
||||
dims,
|
||||
automation: propsAutos,
|
||||
onUpdate: propsOnUpdate,
|
||||
onDelete,
|
||||
onTrigger,
|
||||
tagDB,
|
||||
isNew,
|
||||
}) => {
|
||||
@@ -52,6 +60,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
validate,
|
||||
save,
|
||||
saveAndUpdate,
|
||||
undo,
|
||||
} = useAutomatioEditorState(propsAutos, propsOnUpdate);
|
||||
const [infoBoxOpen, setInfoBox] = useState(false);
|
||||
const [
|
||||
@@ -198,12 +207,11 @@ export const AutomationEditor: FC<Props> = ({
|
||||
Flip
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--edit-btn"}
|
||||
onClick={() => setInfoBox(!infoBoxOpen)}
|
||||
>
|
||||
Metadata <Edit />
|
||||
</Button>
|
||||
{state.status === "changed" && (
|
||||
<Button onClick={undo}>
|
||||
<UndoIcon />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||
onClick={save}
|
||||
@@ -220,12 +228,39 @@ export const AutomationEditor: FC<Props> = ({
|
||||
onTriggerUpdate={updateTrigger}
|
||||
onConditionUpdate={updateCondition}
|
||||
isFlipped={flipped}
|
||||
additionalControls={
|
||||
<ControlButton onClick={() => setInfoBox(!infoBoxOpen)}>
|
||||
<ModeEditOutlineTwoToneIcon />
|
||||
</ControlButton>
|
||||
}
|
||||
/>
|
||||
<SpeedDial
|
||||
ariaLabel="options label"
|
||||
sx={{ position: "absolute", bottom: 16, right: 16 }}
|
||||
icon={<SpeedDialIcon />}
|
||||
>
|
||||
<SpeedDialAction
|
||||
tooltipOpen
|
||||
icon={<RunIcon />}
|
||||
tooltipTitle={"Trigger"}
|
||||
onClick={onTrigger}
|
||||
/>
|
||||
<SpeedDialAction
|
||||
tooltipOpen
|
||||
icon={<DeleteIcon />}
|
||||
tooltipTitle={"Delete"}
|
||||
onClick={onDelete}
|
||||
/>
|
||||
<SpeedDialAction
|
||||
tooltipOpen
|
||||
icon={<EditIcon />}
|
||||
tooltipTitle={"Metadata"}
|
||||
onClick={() => setInfoBox(!infoBoxOpen)}
|
||||
/>
|
||||
{state.status === "changed" && (
|
||||
<SpeedDialAction
|
||||
tooltipOpen
|
||||
icon={<UndoIcon />}
|
||||
tooltipTitle={"Undo"}
|
||||
onClick={undo}
|
||||
/>
|
||||
)}
|
||||
</SpeedDial>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,117 +1,156 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from "react";
|
||||
import { AutomationData, AutomationMetadata } from "types/automations";
|
||||
import * as v from "types/validators/autmation";
|
||||
import { getFailures } from "types/validators/helper";
|
||||
import { MiniFailure } from '../../types/validators/helper';
|
||||
import { MiniFailure } from "../../types/validators/helper";
|
||||
|
||||
export type EditorData = ReturnType<typeof genEditorData>;
|
||||
export type EditorState = {
|
||||
status: 'unchanged' | 'changed' | 'saving',
|
||||
data: EditorData
|
||||
} | {
|
||||
status: 'loading'
|
||||
} | {
|
||||
status: 'invalid',
|
||||
failures: MiniFailure[],
|
||||
data: EditorData,
|
||||
}
|
||||
export type EditorStatus = EditorState['status'];
|
||||
export type EditorState =
|
||||
| {
|
||||
status: "unchanged";
|
||||
data: EditorData;
|
||||
}
|
||||
| {
|
||||
status: "changed" | "saving";
|
||||
previous: EditorData[];
|
||||
data: EditorData;
|
||||
}
|
||||
| {
|
||||
status: "loading";
|
||||
}
|
||||
| {
|
||||
status: "invalid";
|
||||
failures: MiniFailure[];
|
||||
data: EditorData;
|
||||
};
|
||||
export type EditorStatus = EditorState["status"];
|
||||
|
||||
export const useAutomatioEditorState = (
|
||||
automation: AutomationData | undefined,
|
||||
onSave: (a: AutomationData) => void,
|
||||
automation: AutomationData | undefined,
|
||||
onSave: (a: AutomationData) => void
|
||||
) => {
|
||||
const [state, update] = useState<EditorState>({
|
||||
status: "loading",
|
||||
});
|
||||
const makeUpdate = <K extends keyof EditorData, D extends EditorData[K]>(name: K) => (
|
||||
data: D
|
||||
) => ((state.status === 'changed') || (state.status === 'unchanged')) && update({
|
||||
status: 'changed',
|
||||
const [state, update] = useState<EditorState>({
|
||||
status: "loading",
|
||||
});
|
||||
const makeUpdate =
|
||||
<K extends keyof EditorData, D extends EditorData[K]>(name: K) =>
|
||||
(data: D) =>
|
||||
(state.status === "changed" || state.status === "unchanged") &&
|
||||
update({
|
||||
status: "changed",
|
||||
previous:
|
||||
state.status === "unchanged"
|
||||
? [state.data]
|
||||
: state.previous.concat([state.data]),
|
||||
data: {
|
||||
...state.data,
|
||||
[name]: data,
|
||||
}
|
||||
})
|
||||
...state.data,
|
||||
[name]: data,
|
||||
},
|
||||
});
|
||||
|
||||
const saveAndUpdate = (data: EditorData) => {
|
||||
const cleanData = {
|
||||
...data,
|
||||
tags: data.tags.reduce((all, [tagName, tagValue]) => ({
|
||||
...all,
|
||||
[tagName.trim()]: tagValue.trim(),
|
||||
}), {})
|
||||
};
|
||||
const saveAndUpdate = (data: EditorData) => {
|
||||
if (state.status === "changed") {
|
||||
const cleanData = {
|
||||
...data,
|
||||
tags: data.tags.reduce(
|
||||
(all, [tagName, tagValue]) => ({
|
||||
...all,
|
||||
[tagName.trim()]: tagValue.trim(),
|
||||
}),
|
||||
{}
|
||||
),
|
||||
};
|
||||
update({
|
||||
status: "saving",
|
||||
previous: state.previous,
|
||||
data,
|
||||
});
|
||||
onSave(cleanData);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (automation) {
|
||||
const failures = getFailures(automation, v.AutomationData);
|
||||
if (failures) {
|
||||
update({
|
||||
status: "saving",
|
||||
data,
|
||||
})
|
||||
onSave(cleanData);
|
||||
status: "invalid",
|
||||
failures,
|
||||
data: genEditorData(automation),
|
||||
});
|
||||
} else {
|
||||
update({
|
||||
status: "unchanged",
|
||||
data: genEditorData(automation),
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [automation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (automation) {
|
||||
const failures = getFailures(automation, v.AutomationData);
|
||||
if (failures) {
|
||||
update({
|
||||
status: 'invalid',
|
||||
failures,
|
||||
data: genEditorData(automation),
|
||||
})
|
||||
} else {
|
||||
update({
|
||||
status: 'unchanged',
|
||||
data: genEditorData(automation),
|
||||
})
|
||||
}
|
||||
return {
|
||||
validate: (data: any) => getFailures(data, v.AutomationData),
|
||||
updateTrigger: makeUpdate("trigger"),
|
||||
updateSequence: makeUpdate("sequence"),
|
||||
updateCondition: makeUpdate("condition"),
|
||||
saveAndUpdate,
|
||||
updateMetadata: (
|
||||
metadata: AutomationMetadata,
|
||||
tags: Array<[string, string]>
|
||||
) => {
|
||||
if (state.status === "changed" || state.status === "unchanged") {
|
||||
update({
|
||||
status: "changed",
|
||||
previous:
|
||||
state.status === "changed"
|
||||
? state.previous.concat([state.data])
|
||||
: [state.data],
|
||||
data: {
|
||||
...state.data,
|
||||
tags,
|
||||
metadata,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
save: () => {
|
||||
if (state.status !== "loading") {
|
||||
saveAndUpdate(state.data);
|
||||
}
|
||||
},
|
||||
undo: () => {
|
||||
if (state.status === "changed") {
|
||||
if (state.previous.length === 1) {
|
||||
update({
|
||||
status: "unchanged",
|
||||
data: state.previous[0],
|
||||
});
|
||||
} else {
|
||||
update({
|
||||
status: "changed",
|
||||
data: state.previous[state.previous.length - 1],
|
||||
previous: state.previous.slice(0, state.previous.length - 1),
|
||||
});
|
||||
}
|
||||
}, [automation]);
|
||||
|
||||
return {
|
||||
validate: (data: any) => getFailures(data, v.AutomationData),
|
||||
updateTrigger: makeUpdate('trigger'),
|
||||
updateSequence: makeUpdate('sequence'),
|
||||
updateCondition: makeUpdate('condition'),
|
||||
saveAndUpdate,
|
||||
updateMetadata: (metadata: AutomationMetadata, tags: Array<[string, string]>) => {
|
||||
if ((state.status === 'changed') || (state.status === 'unchanged')) {
|
||||
update({
|
||||
status: 'changed',
|
||||
data: {
|
||||
...state.data,
|
||||
tags,
|
||||
metadata,
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
save: () => {
|
||||
if (state.status !== 'loading') {
|
||||
saveAndUpdate(state.data)
|
||||
}
|
||||
},
|
||||
get state() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
get state() {
|
||||
return state;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const genEditorData = (automation: AutomationData) => {
|
||||
const {
|
||||
metadata,
|
||||
trigger,
|
||||
sequence,
|
||||
condition,
|
||||
} = automation;
|
||||
const { metadata, trigger, sequence, condition } = automation;
|
||||
|
||||
const tags: [string, string][] = Object.keys(automation.tags).map(tagName => [tagName, automation.tags[tagName]]);
|
||||
const tags: [string, string][] = Object.keys(automation.tags).map(
|
||||
(tagName) => [tagName, automation.tags[tagName]]
|
||||
);
|
||||
|
||||
return {
|
||||
metadata,
|
||||
trigger,
|
||||
sequence,
|
||||
condition,
|
||||
tags,
|
||||
}
|
||||
}
|
||||
return {
|
||||
metadata,
|
||||
trigger,
|
||||
sequence,
|
||||
condition,
|
||||
tags,
|
||||
};
|
||||
};
|
||||
@@ -13,6 +13,10 @@
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.automation-manager--list-box-group.modified {
|
||||
border: 1px var(--mui-success-main) solid;
|
||||
}
|
||||
|
||||
.automation-manager--list-box-group {
|
||||
border-color: var(--mui-text-secondary);
|
||||
border-width: 0.125px;
|
||||
|
||||
@@ -14,7 +14,10 @@ const { make, componentMeta } = makeStory({
|
||||
args: {
|
||||
title: "Example",
|
||||
type: "items",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
id: "1",
|
||||
@@ -23,7 +26,10 @@ const { make, componentMeta } = makeStory({
|
||||
description: "Amazing automation!",
|
||||
tags: {},
|
||||
state: "on",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
@@ -31,7 +37,10 @@ const { make, componentMeta } = makeStory({
|
||||
entityId: "automation.2",
|
||||
description: "Cool!",
|
||||
state: "on",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
tags: {
|
||||
room: "main bedroom",
|
||||
routine: "night time",
|
||||
@@ -48,16 +57,25 @@ export const Basic = make({});
|
||||
export const Nested = make({
|
||||
title: "Top Group",
|
||||
type: "group",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
title: "Subgroup 1",
|
||||
type: "group",
|
||||
isSelected: true,
|
||||
flags: {
|
||||
isSelected: true,
|
||||
isModified: false,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
type: "items",
|
||||
isSelected: true,
|
||||
flags: {
|
||||
isSelected: true,
|
||||
isModified: false,
|
||||
},
|
||||
title: "Subsub group",
|
||||
data: [
|
||||
{
|
||||
@@ -66,7 +84,10 @@ export const Nested = make({
|
||||
description: "",
|
||||
title: "Automation #1",
|
||||
state: "on",
|
||||
isSelected: true,
|
||||
flags: {
|
||||
isSelected: true,
|
||||
isModified: false,
|
||||
},
|
||||
tags: {},
|
||||
},
|
||||
{
|
||||
@@ -75,7 +96,10 @@ export const Nested = make({
|
||||
description: "another one",
|
||||
title: "Automation #2",
|
||||
state: "off",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
tags: {},
|
||||
},
|
||||
{
|
||||
@@ -84,7 +108,10 @@ export const Nested = make({
|
||||
description: "bad one",
|
||||
title: "Automation #3",
|
||||
state: "offing",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
tags: {
|
||||
type: "bad",
|
||||
},
|
||||
@@ -96,20 +123,29 @@ export const Nested = make({
|
||||
{
|
||||
title: "Subgroup 2",
|
||||
type: "group",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
data: [],
|
||||
},
|
||||
{
|
||||
title: "Other",
|
||||
type: "items",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
id: "4",
|
||||
entityId: "automation.4",
|
||||
description: "Cool thing",
|
||||
title: "Automation #4",
|
||||
isSelected: false,
|
||||
flags: {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
},
|
||||
state: "on",
|
||||
tags: {
|
||||
type: "good",
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -23,7 +24,7 @@ export const ListBoxGroup: FC<ListBoxGroupProps> = ({
|
||||
title,
|
||||
type,
|
||||
data,
|
||||
isSelected,
|
||||
flags,
|
||||
initialOpenState,
|
||||
tagsDB,
|
||||
...events
|
||||
@@ -41,7 +42,8 @@ export const ListBoxGroup: FC<ListBoxGroupProps> = ({
|
||||
<div
|
||||
className={[
|
||||
"automation-manager--list-box-group",
|
||||
isSelected ? "selected" : "",
|
||||
flags.isSelected ? "selected" : "",
|
||||
flags.isModified ? "modified" : "",
|
||||
].join(" ")}
|
||||
>
|
||||
<div
|
||||
@@ -67,7 +69,9 @@ export const ListBoxGroup: FC<ListBoxGroupProps> = ({
|
||||
onDelete={() =>
|
||||
events.onAutomationDelete(auto.id, auto.entityId)
|
||||
}
|
||||
isSelected={auto.flags.isSelected}
|
||||
onSelect={() => events.onSelect(auto.id)}
|
||||
onRun={() => events.onRun(auto.entityId)}
|
||||
onDescriptionUpdate={(description) =>
|
||||
events.onAutomationUpdate(
|
||||
{
|
||||
|
||||
@@ -28,17 +28,13 @@ export const useAutomationDB = (
|
||||
return out;
|
||||
}
|
||||
},
|
||||
getAutomationData(autoId: string) {
|
||||
getAutomationData(
|
||||
autoId: string
|
||||
): null | [AutomationManagerAuto, AutomationData | null] {
|
||||
if (newAuto && newAuto[0].id === autoId) {
|
||||
return newAuto[1];
|
||||
return newAuto;
|
||||
}
|
||||
return (autoMap[autoId] ?? [null, null])[1];
|
||||
},
|
||||
getAutomationState(autoId: string): string | null {
|
||||
if (newAuto && newAuto[0].id === autoId) {
|
||||
return newAuto[0].state;
|
||||
}
|
||||
return (autoMap[autoId] ?? [{ state: null }, null])[0].state;
|
||||
return autoMap[autoId] ?? null;
|
||||
},
|
||||
isAutoNew(autoId: string) {
|
||||
return (newAuto && newAuto[0].id === autoId) ?? false;
|
||||
|
||||
@@ -9,14 +9,27 @@ import {
|
||||
UseAutomationManagerStateArgs,
|
||||
} from "./state";
|
||||
import Alert from "@mui/material/Alert";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
|
||||
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||
onAutomationDelete: (aid: string, eid: string) => void;
|
||||
};
|
||||
export const AutomationManagerLoaded: FC<
|
||||
PropsWithChildren<AutomationManagerLoadedProps>
|
||||
> = ({ children, onAutomationDelete, ...args }) => {
|
||||
> = ({ children, ...args }) => {
|
||||
const state = useAutomationManagerState(args);
|
||||
const confirm = useConfirm();
|
||||
|
||||
const onAutomationDelete = async (aid: string, eid: string) =>
|
||||
confirm({
|
||||
title: "Are you sure you want to delete this automation?",
|
||||
confirmationText: "Delete",
|
||||
})
|
||||
.then(() => {
|
||||
args.onAutomationDelete(aid, eid);
|
||||
state.setSelectedAutomationId(null);
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
return (
|
||||
<div className="automation-manager">
|
||||
@@ -27,11 +40,9 @@ export const AutomationManagerLoaded: FC<
|
||||
selectedAutomationId={state.currentAutomationId}
|
||||
onSelectedAutomationId={state.setSelectedAutomationId}
|
||||
onAutomationAdd={() => state.addNew()}
|
||||
onAutomationDelete={(aid, eid) => {
|
||||
onAutomationDelete(aid, eid);
|
||||
state.setSelectedAutomationId(null);
|
||||
}}
|
||||
onAutomationDelete={onAutomationDelete}
|
||||
onAutomationUpdate={state.sideBarUpdateAutomation}
|
||||
onRun={args.onAutomationRun}
|
||||
/>
|
||||
<div className={["automation-manager--editor"].join(" ")}>
|
||||
{state.currentAutomationId !== null ? (
|
||||
@@ -43,6 +54,22 @@ export const AutomationManagerLoaded: FC<
|
||||
}}
|
||||
automation={state.currentAutomation}
|
||||
onUpdate={state.editorUpdateAutomation}
|
||||
onDelete={() => {
|
||||
if (
|
||||
state.currentAutomationId &&
|
||||
state.currentAutomationEntityId
|
||||
) {
|
||||
onAutomationDelete(
|
||||
state.currentAutomationId,
|
||||
state.currentAutomationEntityId
|
||||
);
|
||||
}
|
||||
}}
|
||||
onTrigger={() => {
|
||||
if (state.currentAutomationEntityId) {
|
||||
args.onAutomationRun(state.currentAutomationEntityId);
|
||||
}
|
||||
}}
|
||||
tagDB={state.tagsDB}
|
||||
isNew={state.currentAutomationIsNew}
|
||||
/>
|
||||
|
||||
@@ -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,
|
||||
@@ -65,12 +66,15 @@ export const useAutomationManagerState = ({
|
||||
get tagsDB() {
|
||||
return tagsDB;
|
||||
},
|
||||
get currentAutomation() {
|
||||
return currentAutomation;
|
||||
get currentAutomation(): AutomationData | null {
|
||||
return currentAutomation === null ? null : currentAutomation[1];
|
||||
},
|
||||
get currentAutomationIsNew() {
|
||||
return automationDB.isAutoNew(cookies.currentAutomationId ?? "");
|
||||
},
|
||||
get currentAutomationEntityId(): string | null {
|
||||
return currentAutomation === null ? null : currentAutomation[0].entityId;
|
||||
},
|
||||
async setSelectedAutomationId(i: string | null, force: boolean = false) {
|
||||
if (methods.currentAutomationIsNew && !force) {
|
||||
if (!(await stillHaveNewAreYouSure())) {
|
||||
@@ -101,8 +105,9 @@ export const useAutomationManagerState = ({
|
||||
aid: string,
|
||||
eid: string
|
||||
) {
|
||||
const previousAutoState = automationDB.getAutomationData(aid);
|
||||
if (previousAutoState) {
|
||||
const previousAuto = automationDB.getAutomationData(aid);
|
||||
if (previousAuto && previousAuto[1]) {
|
||||
const previousAutoState = previousAuto[1];
|
||||
if (
|
||||
previousAutoState.metadata.alias !== a.title ||
|
||||
previousAutoState.metadata.description !== a.description
|
||||
@@ -124,7 +129,8 @@ export const useAutomationManagerState = ({
|
||||
{ variant: "error" }
|
||||
);
|
||||
}
|
||||
const previousState = automationDB.getAutomationState(aid);
|
||||
const previousState =
|
||||
previousAuto === null ? null : previousAuto[0].state;
|
||||
if (previousState !== a.state) {
|
||||
onAutomationStateChange(eid, a.state === "on");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import SaveIcon from "@mui/icons-material/SaveOutlined";
|
||||
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { Modal } from "components/Modal";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
|
||||
import { TagDB } from "../TagDB";
|
||||
@@ -30,7 +30,7 @@ export type TagModalState =
|
||||
|
||||
export const Tags: FC<TagsProps> = ({ automationId, tagsDB }) => {
|
||||
const [modalState, setModal] = useState<TagModalState>({ open: false });
|
||||
const tags = tagsDB.getTags(automationId);
|
||||
const tags = tagsDB.getTags(automationId, true);
|
||||
const onUpdate = (t: Record<string, string>) =>
|
||||
tagsDB.update(automationId, t);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<MetadataBoxProps> = (props) => {
|
||||
icon={<SelectIcon />}
|
||||
onClick={props.onSelect}
|
||||
/>
|
||||
<ButtonIcon className="run" icon={<RunIcon />} onClick={props.onRun} />
|
||||
<ButtonIcon
|
||||
className="delete"
|
||||
icon={<DeleteForeverIcon />}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { FC, useState } from "react";
|
||||
|
||||
import ArrowIcon from "@mui/icons-material/ArrowBackIosNewOutlined";
|
||||
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import InputMultiSelect from "components/Inputs/InputMultiSelect";
|
||||
|
||||
import { ListBoxGroup } from "../ListBoxGroup";
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
AutomationManagerAuto,
|
||||
AutomationManagerAutoUpdatable,
|
||||
} from "../types";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type AutomationManagerSidebarProps = {
|
||||
@@ -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<AutomationManagerSidebarProps> = ({
|
||||
automations,
|
||||
@@ -60,7 +61,11 @@ export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
|
||||
);
|
||||
|
||||
const items = grouping.top.map((i) =>
|
||||
convertGroupingToItems(i, selectedAutomationId, automations, grouping)
|
||||
convertGroupingToItems(i, automations, grouping, (aid, t) => ({
|
||||
...t,
|
||||
isSelected: aid === selectedAutomationId,
|
||||
isModified: tagsDB.isModified(aid),
|
||||
}))
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -85,7 +90,10 @@ export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
|
||||
<ListBoxGroup
|
||||
{...item}
|
||||
key={i}
|
||||
onSelect={onSelectedAutomationId}
|
||||
onSelect={(id) => {
|
||||
onSelectedAutomationId(id);
|
||||
setHidden(true);
|
||||
}}
|
||||
{...events}
|
||||
tagsDB={tagsDB}
|
||||
initialOpenState={true}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
type TagDBState = {
|
||||
original: Record<string, Record<string, string>>;
|
||||
changed: Record<string, Record<string, string>>;
|
||||
};
|
||||
export type TagDB = ReturnType<typeof useTagDB>;
|
||||
export const useTagDB = (
|
||||
automations: Array<{
|
||||
@@ -8,28 +13,30 @@ export const useTagDB = (
|
||||
onUpdate: (aid: string, tags: Record<string, string>) => void
|
||||
) => {
|
||||
const lastAuto = useRef(JSON.stringify(automations));
|
||||
const [{ automationTags, changed }, setState] = useState({
|
||||
automationTags: convertAutoListToMap(automations),
|
||||
changed: new Set<string>(),
|
||||
const [{ original, changed }, setState] = useState<TagDBState>({
|
||||
original: convertAutoListToMap(automations),
|
||||
changed: {},
|
||||
});
|
||||
const allTags = computeAllTags(automationTags);
|
||||
const allTags = computeAllTags(original);
|
||||
const allTagNames = Object.keys(allTags);
|
||||
const isModified = changed.size > 0;
|
||||
|
||||
const isModified = Object.keys(changed).length > 0;
|
||||
useEffect(() => {
|
||||
const c = JSON.stringify(automations);
|
||||
if (lastAuto.current !== c) {
|
||||
lastAuto.current = c;
|
||||
setState({
|
||||
automationTags: convertAutoListToMap(automations),
|
||||
changed: new Set(),
|
||||
original: convertAutoListToMap(automations),
|
||||
changed: {},
|
||||
});
|
||||
}
|
||||
}, [automations, setState]);
|
||||
|
||||
return {
|
||||
getTags(automationId: string) {
|
||||
return automationTags[automationId] ?? {};
|
||||
getTags(automationId: string, includeChanged: boolean = false) {
|
||||
if (includeChanged) {
|
||||
return changed[automationId] ?? original[automationId] ?? {};
|
||||
}
|
||||
return original[automationId] ?? {};
|
||||
},
|
||||
getTagNames(myTags: string[]): string[] {
|
||||
return allTagNames.filter((n) => !myTags.includes(n)).sort();
|
||||
@@ -39,27 +46,33 @@ export const useTagDB = (
|
||||
? Array.from(allTags[tagName].values()).sort()
|
||||
: [];
|
||||
},
|
||||
isModified(aid: string) {
|
||||
return changed.has(aid);
|
||||
isModified(aid: string): boolean {
|
||||
return aid in changed;
|
||||
},
|
||||
update(aid: string, tags: Record<string, string>) {
|
||||
if (JSON.stringify(tags) !== JSON.stringify(automationTags[aid])) {
|
||||
setState({
|
||||
changed: changed.add(aid),
|
||||
automationTags: {
|
||||
...automationTags,
|
||||
[aid]: tags,
|
||||
},
|
||||
});
|
||||
const update = JSON.stringify(tags);
|
||||
if (aid in changed) {
|
||||
if (update === JSON.stringify(changed[aid])) {
|
||||
return;
|
||||
}
|
||||
} else if (update === JSON.stringify(original[aid])) {
|
||||
return;
|
||||
}
|
||||
setState({
|
||||
changed: {
|
||||
...changed,
|
||||
[aid]: tags,
|
||||
},
|
||||
original,
|
||||
});
|
||||
},
|
||||
save(aid: string | null) {
|
||||
if (isModified) {
|
||||
if (aid) {
|
||||
onUpdate(aid, automationTags[aid]);
|
||||
onUpdate(aid, changed[aid]);
|
||||
} else {
|
||||
for (const aid of changed.values()) {
|
||||
onUpdate(aid, automationTags[aid]);
|
||||
for (const [aid, change] of Object.entries(changed)) {
|
||||
onUpdate(aid, change);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ test("bigAutoList groupings has not duplicate ids", () => {
|
||||
test("convert grouper to items when no tags are selected", () => {
|
||||
const grouping = makeGrouping(automations, [], null);
|
||||
const items = grouping.top.map((i) =>
|
||||
convertGroupingToItems(i, "", automations, grouping)
|
||||
convertGroupingToItems(i, automations, grouping)
|
||||
);
|
||||
expect(items.filter((i) => i.type === "group")).toHaveLength(0);
|
||||
expect(items).toHaveLength(1);
|
||||
@@ -109,7 +109,7 @@ test("convert grouper to items when no tags are selected", () => {
|
||||
test("convert grouper to items when 1 tag is selected", () => {
|
||||
const grouping = makeGrouping(automations, ["Room"], null);
|
||||
const items = grouping.top.map((i) =>
|
||||
convertGroupingToItems(i, "", automations, grouping)
|
||||
convertGroupingToItems(i, automations, grouping)
|
||||
);
|
||||
expect(grouping.top).toHaveLength(3);
|
||||
expect(items.filter((i) => i.type === "group")).toHaveLength(0);
|
||||
@@ -125,7 +125,7 @@ test("convert grouper to items when 1 tag is selected", () => {
|
||||
test("convert grouper to items when 2 tag is selected", () => {
|
||||
const grouping = makeGrouping(automations, ["Room", "Type"], null);
|
||||
const items = grouping.top.map((i) =>
|
||||
convertGroupingToItems(i, "", automations, grouping)
|
||||
convertGroupingToItems(i, automations, grouping)
|
||||
);
|
||||
expect(grouping.top).toHaveLength(3);
|
||||
expect(items.filter((i) => i.type === "group")).toHaveLength(2);
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { AutomationManagerAuto, AutomationManagerItem } from "./types";
|
||||
import {
|
||||
AutomationManagerAuto,
|
||||
AutomationManagerAutoItem,
|
||||
AutomationManagerItem,
|
||||
AutomationManagerItemFlags,
|
||||
} from "./types";
|
||||
|
||||
const makeGrouper = () => {
|
||||
const groupIdNames: string[] = [];
|
||||
@@ -149,33 +154,59 @@ export const makeGrouping = (
|
||||
|
||||
export const convertGroupingToItems = (
|
||||
currentGroupIdx: number,
|
||||
selectedAutomationId: string | null,
|
||||
autos: AutomationManagerAuto[],
|
||||
grouping: AutomationGrouping
|
||||
grouping: AutomationGrouping,
|
||||
computeFlags: (
|
||||
aid: string,
|
||||
f: AutomationManagerItemFlags
|
||||
) => AutomationManagerItemFlags = (aid, t) => t
|
||||
): AutomationManagerItem => {
|
||||
const groupData = grouping.getData(currentGroupIdx);
|
||||
const automationIds = grouping.getAutomations(currentGroupIdx);
|
||||
|
||||
if (automationIds.length > 0) {
|
||||
const data = automationIds.map<AutomationManagerAutoItem>((i) => {
|
||||
return {
|
||||
...autos[i],
|
||||
flags: computeFlags(autos[i].id, {
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
}),
|
||||
};
|
||||
});
|
||||
return {
|
||||
type: "items",
|
||||
title: groupData.name,
|
||||
data: automationIds.map((i) => {
|
||||
return {
|
||||
...autos[i],
|
||||
isSelected: autos[i].id === selectedAutomationId,
|
||||
};
|
||||
}),
|
||||
isSelected: groupData.selected,
|
||||
data,
|
||||
flags: data.reduce<AutomationManagerItemFlags>(
|
||||
(out, a) => ({
|
||||
isSelected: out.isSelected || a.flags.isSelected,
|
||||
isModified: out.isModified || a.flags.isModified,
|
||||
}),
|
||||
{
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
}
|
||||
),
|
||||
};
|
||||
}
|
||||
const subgroups = grouping.getSubGroups(currentGroupIdx);
|
||||
const data = subgroups.map((i) =>
|
||||
convertGroupingToItems(i, autos, grouping, computeFlags)
|
||||
);
|
||||
return {
|
||||
type: "group",
|
||||
title: groupData.name,
|
||||
data: subgroups.map((i) =>
|
||||
convertGroupingToItems(i, selectedAutomationId, autos, grouping)
|
||||
data,
|
||||
flags: data.reduce<AutomationManagerItemFlags>(
|
||||
(out, a) => ({
|
||||
isSelected: out.isSelected || a.flags.isSelected,
|
||||
isModified: out.isModified || a.flags.isModified,
|
||||
}),
|
||||
{
|
||||
isSelected: false,
|
||||
isModified: false,
|
||||
}
|
||||
),
|
||||
isSelected: groupData.selected,
|
||||
};
|
||||
};
|
||||
@@ -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) {
|
||||
@@ -119,3 +120,54 @@ export const MissingAutoInConfig = make({
|
||||
entitySource: {},
|
||||
},
|
||||
});
|
||||
export const BadAutomation = make({
|
||||
haProps: {
|
||||
loading: false,
|
||||
entities: {
|
||||
[`automation.${auto1.metadata.id}`]: {
|
||||
entity_id: `automation.${auto1.metadata.id}`,
|
||||
attributes: {
|
||||
id: "test",
|
||||
},
|
||||
context: { id: "", parent_id: null, user_id: null },
|
||||
last_changed: "",
|
||||
last_updated: "",
|
||||
state: "on",
|
||||
},
|
||||
},
|
||||
entitySource: {},
|
||||
},
|
||||
automations: [
|
||||
{
|
||||
tags: {},
|
||||
metadata: {
|
||||
id: "test",
|
||||
mode: "single",
|
||||
alias: "Light.Tank_Day",
|
||||
description: "",
|
||||
},
|
||||
trigger: [
|
||||
{
|
||||
platform: "sun",
|
||||
event: "sunrise",
|
||||
offset: "30",
|
||||
} as any,
|
||||
{ whoAmI: "bad node is who" } as any,
|
||||
],
|
||||
condition: [{ whoAmI: "bad node is who" } as any],
|
||||
sequence: [
|
||||
{ scene: "scene.light_day" } as any,
|
||||
{ whoAmI: "bad node is who" } as any,
|
||||
{
|
||||
service: "input_select.set_options",
|
||||
target: {
|
||||
entity_id: "input_select.tank_light_mode",
|
||||
},
|
||||
data: {
|
||||
options: "day",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import "./index.css";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { FC, useEffect, useState } from "react";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
|
||||
@@ -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,10 +25,16 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
onAutomationStateChange,
|
||||
refreshAutomations,
|
||||
forceDeleteAutomation,
|
||||
triggerAutomation,
|
||||
}) => {
|
||||
const snackbr = useSnackbar();
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
refreshAutomations();
|
||||
// eslint-disable-next-line
|
||||
}, []);
|
||||
|
||||
// handle bad states
|
||||
if (!haEntities.ready && haEntities.error) {
|
||||
return (
|
||||
@@ -74,6 +81,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
<AutomationManagerLoaded
|
||||
configAutomations={configAutomations.data}
|
||||
hassEntities={hassEntities}
|
||||
onAutomationRun={triggerAutomation}
|
||||
onAutomationStateChange={onAutomationStateChange}
|
||||
onAutomationAdd={async (auto) => {
|
||||
await api.updateAutomation({
|
||||
|
||||
@@ -10,10 +10,16 @@ export type AutomationManagerAuto = AutomationManagerAutoUpdatable & {
|
||||
issue?: string;
|
||||
isNew?: boolean;
|
||||
};
|
||||
|
||||
export type AutomationManagerAutoItem = AutomationManagerAuto & {
|
||||
flags: AutomationManagerItemFlags;
|
||||
};
|
||||
export type AutomationManagerItemFlags = {
|
||||
isSelected: boolean;
|
||||
isModified: boolean;
|
||||
};
|
||||
export type AutomationManagerItem = {
|
||||
title: string;
|
||||
isSelected: boolean;
|
||||
flags: AutomationManagerItemFlags;
|
||||
} & (
|
||||
| {
|
||||
type: "group";
|
||||
@@ -21,6 +27,6 @@ export type AutomationManagerItem = {
|
||||
}
|
||||
| {
|
||||
type: "items";
|
||||
data: Array<AutomationManagerAuto & { isSelected: boolean }>;
|
||||
data: Array<AutomationManagerAutoItem>;
|
||||
}
|
||||
);
|
||||
@@ -7,7 +7,7 @@ import { AutomationCondition } from "types/automations/conditions";
|
||||
import { getSubTypeList } from "utils/automations";
|
||||
import { getConditionDefaultValues } from "utils/defaults";
|
||||
import { useHA } from "haService";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { getViewer } from "./viewRender";
|
||||
import { getEditor } from "./editorRender";
|
||||
import useWindowSize from "utils/useWindowSize";
|
||||
|
||||
@@ -10,26 +10,26 @@ import {
|
||||
TriggerCondition,
|
||||
ZoneCondition,
|
||||
} from "types/automations/conditions";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import InputNumber from "components/Inputs/Base/InputNumber";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import {
|
||||
ConditionNodeBase,
|
||||
ConditionNodeBaseViewMode,
|
||||
} from "./ConditionNodeBase";
|
||||
import { genUpdateMethods } from "./nestedUpdater";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { HAService } from "haService";
|
||||
import { DeviceEditor } from "components/DeviceEditor";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { getEntityDomains } from "utils/automations";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputTimeEntity } from "components/Inputs/InputTimeEntity";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
|
||||
interface Editor<C extends AutomationCondition>
|
||||
|
||||
@@ -6,7 +6,7 @@ export const NODE_HEIGHT = 80 as const;
|
||||
export const DEFAULT_DIMS: DAGDims = {
|
||||
collection: {
|
||||
height: NODE_HEIGHT * 3,
|
||||
width: NODE_WIDTH * 1.5,
|
||||
width: NODE_WIDTH * 2.5,
|
||||
},
|
||||
node: {
|
||||
height: NODE_HEIGHT,
|
||||
|
||||
@@ -8,67 +8,61 @@ import { AutomationActionData } from "types/automations";
|
||||
import { createUpdaterFromAutomationData } from "../updater";
|
||||
import { ModalState } from "../board/types";
|
||||
import { DEFAULT_DIMS } from "./constants";
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Demo: FC<{
|
||||
automation: AutomationActionData;
|
||||
flipped: boolean;
|
||||
}> = (props) => {
|
||||
const { namer } = useHA();
|
||||
const [state, setState] = useState<AutomationActionData>(props.automation);
|
||||
const [modalState, setModalState] =
|
||||
useState<ModalState | undefined>(undefined);
|
||||
const updater = createUpdaterFromAutomationData(
|
||||
setModalState,
|
||||
state,
|
||||
setState
|
||||
);
|
||||
const elementData = useAutomationNodes(state, {
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.flipped,
|
||||
},
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
});
|
||||
return (
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
closeModal={() => setModalState(undefined)}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: elementData,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
title: "DAGGraph/Elements",
|
||||
component: Demo,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
flipped: true,
|
||||
automation: {
|
||||
trigger: [],
|
||||
condition: [],
|
||||
sequence: [],
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: (props: {
|
||||
automation: AutomationActionData;
|
||||
flipped: boolean;
|
||||
}) => {
|
||||
const { namer } = useHA();
|
||||
const [state, setState] = useState<AutomationActionData>(props.automation);
|
||||
const [modalState, setModalState] =
|
||||
useState<ModalState | undefined>(undefined);
|
||||
const updater = createUpdaterFromAutomationData(
|
||||
setModalState,
|
||||
state,
|
||||
setState
|
||||
);
|
||||
const elementData = useAutomationNodes(state, {
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.flipped,
|
||||
},
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
});
|
||||
return (
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
closeModal={() => setModalState(undefined)}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: elementData,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "DAGGraph/Elements",
|
||||
args: {
|
||||
flipped: true,
|
||||
automation: {
|
||||
trigger: [],
|
||||
condition: [],
|
||||
sequence: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ComponentMeta<typeof Demo>;
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof Demo> = (args) => (
|
||||
<Page>
|
||||
<Demo {...args} />
|
||||
</Page>
|
||||
);
|
||||
export default componentMeta;
|
||||
|
||||
export const Empty = Template.bind({});
|
||||
export const Trigger = Template.bind({});
|
||||
Trigger.args = {
|
||||
...Trigger.args,
|
||||
export const Empty = make({});
|
||||
export const Trigger = make({
|
||||
automation: {
|
||||
trigger: [
|
||||
{ platform: "homeassistant", event: "up" },
|
||||
@@ -82,10 +76,9 @@ Trigger.args = {
|
||||
condition: [],
|
||||
sequence: [],
|
||||
},
|
||||
};
|
||||
export const Conditions = Template.bind({});
|
||||
Conditions.args = {
|
||||
...Conditions.args,
|
||||
});
|
||||
|
||||
export const Conditions = make({
|
||||
automation: {
|
||||
trigger: [
|
||||
{
|
||||
@@ -119,11 +112,9 @@ Conditions.args = {
|
||||
],
|
||||
sequence: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const FullAuto = Template.bind({});
|
||||
FullAuto.args = {
|
||||
...FullAuto.args,
|
||||
export const FullAuto = make({
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
@@ -272,11 +263,9 @@ FullAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const ChooseAuto = Template.bind({});
|
||||
ChooseAuto.args = {
|
||||
...ChooseAuto.args,
|
||||
export const ChooseAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -370,12 +359,9 @@ ChooseAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const EmptyChooseAuto = Template.bind({});
|
||||
|
||||
EmptyChooseAuto.args = {
|
||||
...EmptyChooseAuto.args,
|
||||
export const EmptyChooseAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -386,11 +372,9 @@ EmptyChooseAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const RepeatAuto = Template.bind({});
|
||||
RepeatAuto.args = {
|
||||
...RepeatAuto.args,
|
||||
export const RepeatAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -437,11 +421,9 @@ RepeatAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const ParallelAuto = Template.bind({});
|
||||
ParallelAuto.args = {
|
||||
...ParallelAuto.args,
|
||||
export const ParallelAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -467,11 +449,9 @@ ParallelAuto.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const BadNodes = Template.bind({});
|
||||
BadNodes.args = {
|
||||
...BadNodes.args,
|
||||
export const BadNodes = make({
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
@@ -500,11 +480,9 @@ BadNodes.args = {
|
||||
},
|
||||
] as any,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const IfElseNode = Template.bind({});
|
||||
IfElseNode.args = {
|
||||
...IfElseNode.args,
|
||||
export const IfElseNode = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
@@ -516,4 +494,24 @@ IfElseNode.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const TimeNodes = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [
|
||||
{
|
||||
platform: "time",
|
||||
at: "",
|
||||
},
|
||||
{
|
||||
platform: "time_pattern",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
condition: "time",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -29,7 +29,7 @@ export const useDAGElementsState = () => {
|
||||
},
|
||||
|
||||
getIsClosedActions(nodeId: string, node: AutomationNode) {
|
||||
if (isSpecialNode(getNodeSubType(node))) {
|
||||
if (isSpecialNode(getNodeSubType(node, true))) {
|
||||
return {
|
||||
isClosed: this.get(nodeId).isClosed ?? false,
|
||||
setIsClosed: (v: boolean) => this.set(nodeId, "isClosed", v),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { FC } from "react";
|
||||
import { ButtonNodeProps } from "./types";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
|
||||
export const ButtonNode: FC<ButtonNodeProps> = ({
|
||||
height,
|
||||
|
||||
@@ -12,7 +12,7 @@ import Edit from "@mui/icons-material/Edit";
|
||||
import KeyboardArrowDownSharpIcon from "@mui/icons-material/KeyboardArrowDownSharp";
|
||||
import AddOutlined from "@mui/icons-material/AddOutlined";
|
||||
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { SpeedDial } from "components/SpeedDial";
|
||||
import { SequenceNodeElementProps } from "./types";
|
||||
import { useSequenceNodeColor } from "./util";
|
||||
|
||||
@@ -104,6 +104,9 @@ export const createUpdater = (
|
||||
}),
|
||||
trigger: createBasicUpdater("trigger", {
|
||||
platform: "device",
|
||||
domain: "",
|
||||
type: "",
|
||||
device_id: "",
|
||||
})({
|
||||
trigger: args.trigger,
|
||||
openModal: args.openModal,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
BaseOption,
|
||||
InputAutoComplete,
|
||||
} from "components/Inputs/InputAutoComplete";
|
||||
import { InputDevice } from "components/Inputs/InputDevice";
|
||||
import { InputDeviceCapabilties } from "components/Inputs/InputDeviceCapabilties";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
||||
import { InputDeviceCapabilties } from "components/Inputs/AutoComplete/InputDeviceCapabilties";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { DeviceBaseType, DeviceTypeCapability } from "haService/types";
|
||||
import { AutomationDeviceState } from "types/automations/common";
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+4
-4
@@ -4,10 +4,10 @@ import { useSnackbar } from "notistack";
|
||||
import { useRef } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { InputAutoComplete, Option } from "./InputAutoComplete";
|
||||
import InputBoolean from "./InputBoolean";
|
||||
import { InputTime } from "./InputDayTime";
|
||||
import InputNumber from "./InputNumber";
|
||||
import InputText from "./InputText";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { InputTime } from "../Base/InputTime";
|
||||
import InputNumber from "components/Inputs/Base/InputNumber";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
|
||||
export type InputDeviceCapabiltiesProps<T extends Record<string, any>> = {
|
||||
defn: HaFormSchema[];
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -11,7 +11,7 @@ import {
|
||||
isAutomationTimeString24Hours,
|
||||
} from "utils/time";
|
||||
import { InputEntity } from "./InputEntities";
|
||||
import { InputTime } from "./InputTime";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
|
||||
export type InputTimeEntityProps = {
|
||||
value: string;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
@@ -1,4 +1,5 @@
|
||||
import "./InputTime.css";
|
||||
|
||||
import { useState, useEffect, FC } from "react";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,150 +0,0 @@
|
||||
import "./InputTime.css";
|
||||
import { useState, useEffect, FC } from "react";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import { AutomationTime, AutomationTimeObject } from "types/automations/common";
|
||||
import {
|
||||
convertAutomationTimeToTimeObject,
|
||||
convertObjectToAutomationTimeString,
|
||||
} from "utils/time";
|
||||
import { convertAutomationTimeToTimeString } from "utils/time";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import InputLabel from "@mui/material/InputLabel";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
// constants
|
||||
const fields: Array<keyof AutomationTimeObject> = [
|
||||
"hours",
|
||||
"minutes",
|
||||
"seconds",
|
||||
"milliseconds",
|
||||
];
|
||||
export interface Props {
|
||||
label: string;
|
||||
value?: AutomationTime;
|
||||
onChange: (v?: AutomationTimeObject) => void;
|
||||
}
|
||||
export const InputTime: FC<Props> = (props) => {
|
||||
// state
|
||||
const [disabled, setDisabled] = useState(!props.value);
|
||||
const [displayValue, setDisplayValue] = useState(
|
||||
convertAutomationTimeToTimeObject(props.value)
|
||||
);
|
||||
|
||||
// process display input
|
||||
const updateOne = (k: keyof AutomationTimeObject) => (v: string) => {
|
||||
if (Number(v) < 0) {
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
[k]: 0,
|
||||
});
|
||||
} else if (k === "hours") {
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
[k]: Number(v),
|
||||
});
|
||||
} else if (k === "minutes") {
|
||||
let minutes = Number(v);
|
||||
let { hours = 0 } = displayValue;
|
||||
if (minutes > 59) {
|
||||
const additonalHours = Math.floor(minutes / 60);
|
||||
hours += additonalHours;
|
||||
minutes = minutes - additonalHours * 60;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
});
|
||||
} else if (k === "seconds") {
|
||||
let seconds = Number(v);
|
||||
let { hours = 0, minutes = 0 } = displayValue;
|
||||
if (seconds > 59) {
|
||||
const additonalHours = Math.floor(seconds / (60 * 60));
|
||||
hours += additonalHours;
|
||||
seconds = seconds - additonalHours * 60;
|
||||
}
|
||||
if (seconds > 59) {
|
||||
const additionalMinutes = Math.floor(seconds / 60);
|
||||
minutes += additionalMinutes;
|
||||
seconds = seconds - additionalMinutes * 60;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
seconds,
|
||||
});
|
||||
} else if (k === "milliseconds") {
|
||||
let milliseconds = Number(v);
|
||||
let { hours = 0, minutes = 0, seconds = 0 } = displayValue;
|
||||
if (milliseconds > 1000) {
|
||||
const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000));
|
||||
hours += additonalHours;
|
||||
milliseconds = milliseconds - additonalHours * 60 * 60 * 1000;
|
||||
}
|
||||
if (milliseconds > 1000) {
|
||||
const additionalMinutes = Math.floor(milliseconds / (60 * 1000));
|
||||
minutes += additionalMinutes;
|
||||
milliseconds = milliseconds - additionalMinutes * 60 * 1000;
|
||||
}
|
||||
if (milliseconds > 1000) {
|
||||
const additionalSeconds = Math.floor(milliseconds / 1000);
|
||||
seconds += additionalSeconds;
|
||||
milliseconds = milliseconds - additionalSeconds * 1000;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
seconds,
|
||||
milliseconds,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (disabled && !props.value) {
|
||||
return;
|
||||
}
|
||||
if (disabled) {
|
||||
props.onChange(undefined);
|
||||
} else {
|
||||
const pVal = convertAutomationTimeToTimeString(props.value);
|
||||
const cVal = convertObjectToAutomationTimeString(displayValue);
|
||||
if (pVal !== cVal) {
|
||||
props.onChange(displayValue);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
}, [disabled, displayValue]);
|
||||
|
||||
return (
|
||||
<div className="input-time">
|
||||
<InputLabel>{props.label}</InputLabel>
|
||||
<div className="input-time--inner">
|
||||
{fields.map((name) => (
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={prettyName(name)}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: prettyName(name),
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
))}
|
||||
<ButtonIcon
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import InputText from "./InputText";
|
||||
import InputText from "./Base/InputText";
|
||||
|
||||
import { InputTextView } from "./InputTextView";
|
||||
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Modal } from ".";
|
||||
import { useState } from 'react';
|
||||
import { Button } from "components/Inputs/Button";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
|
||||
export default {
|
||||
title: 'Modal',
|
||||
title: "Modal",
|
||||
component: Modal,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
open: true
|
||||
}
|
||||
} as ComponentMeta<typeof Modal>
|
||||
open: true,
|
||||
},
|
||||
} as ComponentMeta<typeof Modal>;
|
||||
|
||||
export const Simple: ComponentStory<typeof Modal> = args => {
|
||||
return <>
|
||||
<Modal {...args}>
|
||||
<div>Hello World!</div>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
export const WithButtons: ComponentStory<typeof Modal> = args => {
|
||||
export const Simple: ComponentStory<typeof Modal> = (args) => {
|
||||
return (
|
||||
<>
|
||||
<Modal {...args}>
|
||||
<div>Hello World!</div>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
export const WithButtons: ComponentStory<typeof Modal> = (args) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <>
|
||||
<Button onClick={() => setOpen(!open)}>Open Me!</Button>
|
||||
<Modal open={open}>
|
||||
<div>Hello World!</div>
|
||||
<Button onClick={() => setOpen(!open)}>Close Me!</Button>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => setOpen(!open)}>Open Me!</Button>
|
||||
<Modal open={open}>
|
||||
<div>Hello World!</div>
|
||||
<Button onClick={() => setOpen(!open)}>Close Me!</Button>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -1,33 +1,31 @@
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { FireEventAction } from "types/automations/actions";
|
||||
import { OptionManager, updateActionData } from "./OptionManager";
|
||||
|
||||
|
||||
export const ActionEventState: OptionManager<FireEventAction> = {
|
||||
defaultState: () => ({
|
||||
alias: "Fire Event",
|
||||
event: "",
|
||||
event_data: {},
|
||||
}),
|
||||
isReady: ({ alias, event }) => (
|
||||
alias !== '' &&
|
||||
event !== ""
|
||||
),
|
||||
isReady: ({ alias, event }) => alias !== "" && event !== "",
|
||||
renderOptionList: (state, setState) => {
|
||||
const update = updateActionData(state, setState);
|
||||
return <>
|
||||
<InputText
|
||||
textBoxFor="event"
|
||||
label="Event"
|
||||
value={state.event}
|
||||
onChange={event => update({ event })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Event Data"
|
||||
value={state.event_data}
|
||||
onChange={event_data => update({ event_data })}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
textBoxFor="event"
|
||||
label="Event"
|
||||
value={state.event}
|
||||
onChange={(event) => update({ event })}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Event Data"
|
||||
value={state.event_data}
|
||||
onChange={(event_data) => update({ event_data })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import InputNumber from "components/Inputs/Base/InputNumber";
|
||||
import { RepeatAction } from "types/automations/actions";
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
|
||||
const determineType = (repeatNode: RepeatAction["repeat"]) =>
|
||||
"count" in repeatNode ? "count" : "until" in repeatNode ? "until" : "while";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InputService } from "components/Inputs/InputService";
|
||||
import { InputService } from "components/Inputs/AutoComplete/InputService";
|
||||
import { ServiceEditor } from "components/ServiceEditor";
|
||||
import { ServiceAction } from "types/automations/actions";
|
||||
import { OptionManager, updateActionData } from "./OptionManager";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { StopAction } from "types/automations/actions";
|
||||
import { OptionManager } from "./OptionManager";
|
||||
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import "./ActionWait.css";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import InputNumber from "components/Inputs/Base/InputNumber";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
import { useState } from "react";
|
||||
import { DelayAction, WaitAction } from "types/automations/actions";
|
||||
import { OptionManager, updateActionData } from './OptionManager';
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { OptionManager, updateActionData } from "./OptionManager";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
|
||||
type ThisAction = WaitAction | DelayAction;
|
||||
type Option = 'delay' | 'template' | 'trigger'
|
||||
type Option = "delay" | "template" | "trigger";
|
||||
const getCurrentOption = (node: ThisAction): Option => {
|
||||
if ('delay' in node) {
|
||||
return 'delay'
|
||||
if ("delay" in node) {
|
||||
return "delay";
|
||||
} else {
|
||||
return 'template'
|
||||
return "template";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
defaultState: () => ({
|
||||
@@ -32,78 +32,108 @@ export const ActionWaitState: OptionManager<ThisAction> = {
|
||||
const base: any = {
|
||||
alias: state.alias,
|
||||
variables: state.variables,
|
||||
}
|
||||
if (opt === 'delay') {
|
||||
};
|
||||
if (opt === "delay") {
|
||||
setState({
|
||||
...base,
|
||||
delay: (state as any).delay ?? "",
|
||||
})
|
||||
});
|
||||
} else {
|
||||
base.timeout = (state as any).timeout
|
||||
base.continue_on_timeout = (state as any).continue_on_timeout
|
||||
if (opt === 'template') {
|
||||
base.timeout = (state as any).timeout;
|
||||
base.continue_on_timeout = (state as any).continue_on_timeout;
|
||||
if (opt === "template") {
|
||||
setState({
|
||||
...base,
|
||||
wait_template: (state as any).wait_template ?? "",
|
||||
})
|
||||
});
|
||||
} else {
|
||||
setState({
|
||||
...base,
|
||||
wait_for_trigger: (state as any).wait_for_trigger ?? "",
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
_setCurrent(opt)
|
||||
}
|
||||
_setCurrent(opt);
|
||||
};
|
||||
|
||||
// determine options
|
||||
let option: JSX.Element = <></>;
|
||||
if (current === "delay") {
|
||||
option = <>
|
||||
<InputTime className="for" label="for" value={(state as any).delay} onChange={delay => update({ delay })} />
|
||||
</>
|
||||
} else if (current === 'template') {
|
||||
option = (
|
||||
<>
|
||||
<InputTime
|
||||
className="for"
|
||||
label="for"
|
||||
value={(state as any).delay}
|
||||
onChange={(delay) => update({ delay })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else if (current === "template") {
|
||||
state = state as WaitAction;
|
||||
option = <>
|
||||
<InputText
|
||||
label="Template"
|
||||
className="template"
|
||||
value={state.wait_template ?? ""}
|
||||
onChange={wait_template => update({ wait_template })}
|
||||
/>
|
||||
</>
|
||||
} else if (current === 'trigger') {
|
||||
option = (
|
||||
<>
|
||||
<InputText
|
||||
label="Template"
|
||||
className="template"
|
||||
value={state.wait_template ?? ""}
|
||||
onChange={(wait_template) => update({ wait_template })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else if (current === "trigger") {
|
||||
state = state as WaitAction;
|
||||
option = <>
|
||||
<InputYaml
|
||||
className="triggers"
|
||||
label="Triggers"
|
||||
value={state.wait_for_trigger ?? []}
|
||||
onChange={wait_for_trigger => update({ wait_for_trigger })}
|
||||
/>
|
||||
</>
|
||||
option = (
|
||||
<>
|
||||
<InputYaml
|
||||
className="triggers"
|
||||
label="Triggers"
|
||||
value={state.wait_for_trigger ?? []}
|
||||
onChange={(wait_for_trigger) => update({ wait_for_trigger })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// render
|
||||
return <div className="node-editor--action-wait">
|
||||
<InputList
|
||||
className="wait-type"
|
||||
label="Wait Type" prettyOptionLabels
|
||||
options={["template", 'trigger', "delay"]}
|
||||
current={current} onChange={setCurrent} />
|
||||
{option}
|
||||
{current !== 'delay' ? <div className="wait-options">
|
||||
<InputNumber
|
||||
label="Timeout"
|
||||
value={(state as any).timeout ? Number((state as any).timeout) : undefined}
|
||||
onChange={timeout => update({ timeout: timeout === undefined ? undefined : String(timeout) })}
|
||||
return (
|
||||
<div className="node-editor--action-wait">
|
||||
<InputList
|
||||
className="wait-type"
|
||||
label="Wait Type"
|
||||
prettyOptionLabels
|
||||
options={["template", "trigger", "delay"]}
|
||||
current={current}
|
||||
onChange={setCurrent}
|
||||
/>
|
||||
<InputBoolean
|
||||
label="Continue on Timeout"
|
||||
value={(state as any).continue_on_timeout ?? false}
|
||||
onChange={continue_on_timeout => update({ continue_on_timeout })}
|
||||
/>
|
||||
</div> : <></>}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
{option}
|
||||
{current !== "delay" ? (
|
||||
<div className="wait-options">
|
||||
<InputNumber
|
||||
label="Timeout"
|
||||
value={
|
||||
(state as any).timeout
|
||||
? Number((state as any).timeout)
|
||||
: undefined
|
||||
}
|
||||
onChange={(timeout) =>
|
||||
update({
|
||||
timeout: timeout === undefined ? undefined : String(timeout),
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputBoolean
|
||||
label="Continue on Timeout"
|
||||
value={(state as any).continue_on_timeout ?? false}
|
||||
onChange={(continue_on_timeout) =>
|
||||
update({ continue_on_timeout })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -5,6 +5,9 @@ import { DeviceEditor } from "components/DeviceEditor";
|
||||
export const TriggerDevice: OptionManager<AutomationTriggerDevice> = {
|
||||
defaultState: () => ({
|
||||
platform: "device",
|
||||
device_id: "",
|
||||
domain: "",
|
||||
type: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
Component: ({ state, setState, ha }) => {
|
||||
@@ -27,6 +30,9 @@ export const TriggerDevice: OptionManager<AutomationTriggerDevice> = {
|
||||
setState={(s) =>
|
||||
setState({
|
||||
platform: "device",
|
||||
device_id: "",
|
||||
domain: "",
|
||||
type: "",
|
||||
...s,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerEvent } from "../../../types/automations/triggers";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
|
||||
export const TriggerEventState: OptionManager<AutomationTriggerEvent> = {
|
||||
defaultState: () => ({
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerMQTT } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerMQTT } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
|
||||
export const TriggerMQTTState: OptionManager<AutomationTriggerMQTT> = {
|
||||
defaultState: () => ({
|
||||
"platform": "mqtt",
|
||||
"payload": "",
|
||||
"topic": "",
|
||||
"value_template": ""
|
||||
platform: "mqtt",
|
||||
payload: "",
|
||||
topic: "",
|
||||
value_template: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputText
|
||||
label='Payload'
|
||||
value={state.payload}
|
||||
onChange={payload => setState({ ...state, payload })}
|
||||
/>
|
||||
<InputText
|
||||
label='Topic'
|
||||
value={state.topic}
|
||||
onChange={topic => setState({ ...state, topic })}
|
||||
/>
|
||||
<InputText
|
||||
label='Template'
|
||||
value={state.value_template}
|
||||
onChange={value_template => setState({ ...state, value_template })}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
label="Payload"
|
||||
value={state.payload}
|
||||
onChange={(payload) => setState({ ...state, payload })}
|
||||
/>
|
||||
<InputText
|
||||
label="Topic"
|
||||
value={state.topic}
|
||||
onChange={(topic) => setState({ ...state, topic })}
|
||||
/>
|
||||
<InputText
|
||||
label="Template"
|
||||
value={state.value_template}
|
||||
onChange={(value_template) => setState({ ...state, value_template })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,63 +1,82 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerNumericState } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
import InputNumber from 'components/Inputs/InputNumber';
|
||||
import { InputTime } from 'components/Inputs/InputTime'; import InputYaml from 'components/Inputs/InputYaml';
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerNumericState } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import InputNumber from "components/Inputs/Base/InputNumber";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
|
||||
|
||||
export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'numeric_state',
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
multiple
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
})}
|
||||
/>
|
||||
<InputText label="Attribute" value={state.attribute ?? ""} onChange={attribute => setState({
|
||||
...state,
|
||||
attribute
|
||||
})} />
|
||||
<InputNumber
|
||||
label="Above"
|
||||
value={state.above ? Number(state.above) : undefined}
|
||||
onChange={above => setState({
|
||||
...state,
|
||||
above: above ? String(above) : undefined,
|
||||
})}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Below"
|
||||
value={state.below ? Number(state.below) : undefined}
|
||||
onChange={below => setState({
|
||||
...state,
|
||||
below: below ? String(below) : undefined,
|
||||
})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Template"
|
||||
value={state.value_template ?? ""}
|
||||
onChange={value_template => setState({
|
||||
...state,
|
||||
value_template
|
||||
})}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={_for => setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> =
|
||||
{
|
||||
defaultState: () => ({
|
||||
platform: "numeric_state",
|
||||
entity_id: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
multiple
|
||||
onChange={(entity_id) =>
|
||||
setState({
|
||||
...state,
|
||||
entity_id,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputText
|
||||
label="Attribute"
|
||||
value={state.attribute ?? ""}
|
||||
onChange={(attribute) =>
|
||||
setState({
|
||||
...state,
|
||||
attribute,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Above"
|
||||
value={state.above ? Number(state.above) : undefined}
|
||||
onChange={(above) =>
|
||||
setState({
|
||||
...state,
|
||||
above: above ? String(above) : undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Below"
|
||||
value={state.below ? Number(state.below) : undefined}
|
||||
onChange={(below) =>
|
||||
setState({
|
||||
...state,
|
||||
below: below ? String(below) : undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Template"
|
||||
value={state.value_template ?? ""}
|
||||
onChange={(value_template) =>
|
||||
setState({
|
||||
...state,
|
||||
value_template,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={(_for) =>
|
||||
setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerState } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { FC } from "react";
|
||||
import { getEntityDomains } from "utils/automations";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerTemplate } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputTime } from 'components/Inputs/InputTime';
|
||||
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerTemplate } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||
|
||||
export const TriggerTemplate: OptionManager<AutomationTriggerTemplate> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'template',
|
||||
"value_template": "",
|
||||
platform: "template",
|
||||
value_template: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputText
|
||||
label='Template'
|
||||
value={state.value_template}
|
||||
onChange={value_template => setState({ ...state, value_template })}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={_for => setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
label="Template"
|
||||
value={state.value_template}
|
||||
onChange={(value_template) => setState({ ...state, value_template })}
|
||||
/>
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={(_for) =>
|
||||
setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -8,13 +8,13 @@ import {
|
||||
AutomationTriggerExactTime,
|
||||
AutomationTriggerTimePattern,
|
||||
} from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { FC } from "react";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { useState } from "react";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { InputTimeEntity } from "components/Inputs/InputTimeEntity";
|
||||
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
||||
|
||||
export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||
defaultState: () => ({
|
||||
@@ -59,7 +59,8 @@ export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||
divisible by that number. You can specify "*" to match any value.{" "}
|
||||
<a
|
||||
href="https://www.home-assistant.io/docs/automation/trigger/#time-pattern-trigger"
|
||||
target="_blank" rel="noreferrer"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
More Info.
|
||||
</a>
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerWebhook } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerWebhook } from "types/automations/triggers";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
|
||||
export const TriggerWebhook: OptionManager<AutomationTriggerWebhook> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'webhook',
|
||||
"webhook_id": "",
|
||||
platform: "webhook",
|
||||
webhook_id: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputText label="Webhook ID" value={state.webhook_id ?? ""} onChange={webhook_id => setState({
|
||||
...state,
|
||||
webhook_id
|
||||
})} />
|
||||
</>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<InputText
|
||||
label="Webhook ID"
|
||||
value={state.webhook_id ?? ""}
|
||||
onChange={(webhook_id) =>
|
||||
setState({
|
||||
...state,
|
||||
webhook_id,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,40 +1,53 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerZone } from 'types/automations/triggers';
|
||||
import { InputList } from 'components/Inputs/InputList';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
|
||||
import { OptionManager } from "./OptionManager";
|
||||
import { AutomationTriggerZone } from "types/automations/triggers";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
|
||||
export const TriggerZone: OptionManager<AutomationTriggerZone> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'zone',
|
||||
"zone": "",
|
||||
"event": "enter",
|
||||
"entity_id": "",
|
||||
platform: "zone",
|
||||
zone: "",
|
||||
event: "enter",
|
||||
entity_id: "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputEntity label="Zone" restrictToDomain={['zone']} value={state.zone} onChange={zone => setState({
|
||||
...state,
|
||||
zone: zone ?? ""
|
||||
})} />
|
||||
<InputList
|
||||
label="Event"
|
||||
current={state.event}
|
||||
options={['enter', 'leave']}
|
||||
onChange={event => setState({
|
||||
...state, event,
|
||||
})}
|
||||
/>
|
||||
<InputEntity
|
||||
multiple
|
||||
restrictToDomain={["device_tracker", "person"]}
|
||||
value={state.entity_id}
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<InputEntity
|
||||
label="Zone"
|
||||
restrictToDomain={["zone"]}
|
||||
value={state.zone}
|
||||
onChange={(zone) =>
|
||||
setState({
|
||||
...state,
|
||||
zone: zone ?? "",
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputList
|
||||
label="Event"
|
||||
current={state.event}
|
||||
options={["enter", "leave"]}
|
||||
onChange={(event) =>
|
||||
setState({
|
||||
...state,
|
||||
event,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<InputEntity
|
||||
multiple
|
||||
restrictToDomain={["device_tracker", "person"]}
|
||||
value={state.entity_id}
|
||||
onChange={(entity_id) =>
|
||||
setState({
|
||||
...state,
|
||||
entity_id,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
getSubTypeList,
|
||||
validateNode,
|
||||
} from "utils/automations";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { useHA } from "haService";
|
||||
import { Generic } from "./Generic";
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { NodeEditor } from ".";
|
||||
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { useState } from "react";
|
||||
import { Modal } from "components/Modal";
|
||||
import { Page } from "components/Page";
|
||||
|
||||
@@ -4,8 +4,8 @@ import { FC, ReactNode } from "react";
|
||||
import { AutomationNode, AutomationNodeMapping } from "types/automations/index";
|
||||
import { useEditorNodeState } from "./OptionManager";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { getNodeSubTypeDescription } from "./utils";
|
||||
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import "./ServiceEditorField.css";
|
||||
import { FC, useRef } from "react";
|
||||
import { ServiceEditorOption } from "./options";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import InputText from "components/Inputs/Base/InputText";
|
||||
import InputNumber from "components/Inputs/Base/InputNumber";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
import { InputAutoComplete, Option } from "components/Inputs/InputAutoComplete";
|
||||
import {
|
||||
InputAutoComplete,
|
||||
Option,
|
||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
import { SelectorNumber, SelectorText } from "haService/fieldTypes";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type ServiceEditorFieldProps = {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import "./ServiceEditorTarget.css";
|
||||
import { InputDevice } from "components/Inputs/InputDevice";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { Targets } from "haService/fieldTypes";
|
||||
import { FC } from "react";
|
||||
import { InputArea } from "components/Inputs/InputArea";
|
||||
import { InputArea } from "components/Inputs/AutoComplete/InputArea";
|
||||
|
||||
type RawTargetData = {
|
||||
entity_id?: string[] | string;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { ServiceEditor } from ".";
|
||||
import { TypedHassService } from "haService/fieldTypes";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
|
||||
export default {
|
||||
title: "Services/ServiceEditor",
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
ServiceEditorData,
|
||||
} from "./options";
|
||||
import { ServiceEditorField } from "./ServiceEditorField";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { ServiceEditorTarget } from "./ServiceEditorTarget";
|
||||
|
||||
export type ServiceEditorProps = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseOption } from "components/Inputs/InputAutoComplete";
|
||||
import { BaseOption } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { FieldData, TypedHassService } from "haService/fieldTypes";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
@@ -7,17 +7,22 @@ export type ServiceEditorData = {
|
||||
target: Record<string, any>;
|
||||
};
|
||||
export type ServiceEditorOption = BaseOption<{
|
||||
data: FieldData
|
||||
data: FieldData;
|
||||
}>;
|
||||
|
||||
export const convertFieldToOption = (id: string, data: FieldData): ServiceEditorOption => ({
|
||||
export const convertFieldToOption = (
|
||||
id: string,
|
||||
data: FieldData
|
||||
): ServiceEditorOption => ({
|
||||
id,
|
||||
label: data.name ?? prettyName(id),
|
||||
data,
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
export const splitUpOptions = (service: TypedHassService, data: ServiceEditorData) => {
|
||||
export const splitUpOptions = (
|
||||
service: TypedHassService,
|
||||
data: ServiceEditorData
|
||||
) => {
|
||||
const required: ServiceEditorOption[] = [];
|
||||
const additional: ServiceEditorOption[] = [];
|
||||
const incmFields: string[] = [];
|
||||
@@ -28,7 +33,7 @@ export const splitUpOptions = (service: TypedHassService, data: ServiceEditorDat
|
||||
required.push(opt);
|
||||
} else {
|
||||
if (data.field[opt.id]) {
|
||||
incmFields.push(opt.id)
|
||||
incmFields.push(opt.id);
|
||||
} else {
|
||||
additional.push(opt);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { Connection, getCollection } from "home-assistant-js-websocket";
|
||||
import { useHassCollection } from "./useHassCollection";
|
||||
import { Option, BaseOption } from "components/Inputs/InputAutoComplete";
|
||||
import {
|
||||
Option,
|
||||
BaseOption,
|
||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { EntityRegisteryItem, HassEntitiesRegistry } from "./types";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Option } from "components/Inputs/InputAutoComplete";
|
||||
import { Option } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { HACollectionState, useHassCollection } from "./useHassCollection";
|
||||
import { entitiesColl, HassEntities } from "home-assistant-js-websocket";
|
||||
import { entitySourceColl } from "./additionalCollections";
|
||||
|
||||
@@ -2,9 +2,9 @@ import React, { FC, useEffect, useState } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useHA } from "haService";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { ServiceEditor } from "components/ServiceEditor";
|
||||
|
||||
const Test: FC = () => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { FC } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useHADeviceRegistry } from "haService";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
|
||||
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||
const conn = useHADeviceRegistry();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseOption } from "components/Inputs/InputAutoComplete";
|
||||
import { BaseOption } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { MessageBase } from "home-assistant-js-websocket";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useHassCollection } from "./useHassCollection";
|
||||
import { useHAConnection } from "./connection";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { TypedHassService } from "./fieldTypes";
|
||||
import { Option } from "components/Inputs/InputAutoComplete";
|
||||
import { Option } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { getDeviceExtraWsCalls } from "./extras";
|
||||
import { useHAEntities } from "./HAEntities";
|
||||
|
||||
|
||||
Loaded 100 of 107 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user