Compare commits

...
3 Commits
Author SHA1 Message Date
ari 6b465219a9 upping limits of display 2022-07-15 13:25:43 -04:00
ari e769a8e798 clean up
added mock large qty autos
2022-07-15 12:37:10 -04:00
ari d8a2dd53d5 ensuring triggers & conditions are not too close to one another 2022-07-15 12:02:02 -04:00
25 changed files with 7192 additions and 190 deletions

No files matched your search

+2 -2
View File
@@ -10,9 +10,9 @@ def find_hass_config() -> HassConfig:
"""Try to find HASS config."""
if config("USE_EXAMPLE_REPO", False, cast=bool):
print("using USE_EXAMPLE_REPO")
from tests.utils import create_copy_of_example_config
from tests.utils import create_copy_of_example_config, HA_CONFIG3_EXAMPLE
path = create_copy_of_example_config()
path = create_copy_of_example_config(HA_CONFIG3_EXAMPLE)
print("|-> ", path)
return HassConfig(path)
@@ -0,0 +1,77 @@
'1616887975473':
Type: HA
'1616888026264':
Type: HA
'1619371298367':
Room: Living
Type: Button
'1620239986670':
Room: Kitchen
Type: Button
'1620324780561':
Room: Kitchen
Type: Button
'1621352850204':
Room: Kitchen
Type: Button
'1622210698281':
Room: Kitchen
Type: Button
'1622769811245':
Room: Living
Type: Button
'1623430479201':
Room: Baby
Type: Button
'1623642118976':
Room: Baby
Type: Button
'1624640900951':
Room: Baby
Type: Button
'1628024070687':
Room: Baby
Type: Routine
'1628024123214':
Room: Baby
Type: Routine
'1628444671951':
Room: Office
Type: Window
'1629309267204':
Room: Balcony
Type: Door
'1629422438707':
Type: Routine
'1634497376234':
Room: Baby
Type: Button
'1635539262562':
Type: Routine
'1636428429596':
Type: Routine
'1639500650865':
Room: Bedroom
Type: Door
'1641617168123':
Type: Ensure Power
'1648071019802':
Type: Ensure Power
'1649426399020':
Room: Office
Type: Motion
'1649432254675':
Room: Baby
Type: Routine
'1649726828269':
Climate: Heat
Type: Climate
'1649727810678':
Climate: Time
Type: Climate
'1649820885714':
Type: Routine
'1649947692702':
BadOne: true
Room: Bedroom
Type: Button
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,2 @@
# empty configuration file
cloud:
+1
View File
@@ -13,6 +13,7 @@ THIS_FOLDER = Path(__file__).parent
SAMPLES_FOLDER = THIS_FOLDER / "samples"
HA_CONFIG_EXAMPLE = SAMPLES_FOLDER / "config"
HA_CONFIG2_EXAMPLE = SAMPLES_FOLDER / "config-2"
HA_CONFIG3_EXAMPLE = SAMPLES_FOLDER / "config-3"
def get_example_automation_loader(
+17 -19
View File
@@ -1,42 +1,40 @@
import { useState } from "react";
import { ApiState } from "./types";
import { AutomationAPI } from './automations';
import { AutomationAPI } from "./automations";
export const useDefaultApiState = () => useState<ApiState>({
automations: { ready: false },
});
export const useDefaultApiState = () =>
useState<ApiState>({
automations: { ready: false },
});
export const makeReloadAutomations = (
automationAPI: AutomationAPI,
state: ApiState,
setState: (s: ApiState) => void,
setState: (s: ApiState) => void
) => {
const reload = async () => {
let params = { offset: 0, limit: 100 };
let params = { offset: 0, limit: 10000 };
if (state.automations.ready && state.automations.ok) {
params = state.automations.data.params
params = state.automations.data.params;
}
const resp = await automationAPI.list(params);
setState({
...state, automations: {
...state,
automations: {
ready: true,
...resp,
}
},
});
}
const wrapCall = <
Call extends (a: any) => Promise<any>
>(fcn: Call) => {
};
const wrapCall = <Call extends (a: any) => Promise<any>>(fcn: Call) => {
return async (args: Parameters<Call>[0]): Promise<ReturnType<Call>> => {
const resp = await fcn(args);
await reload();
return resp;
}
}
};
};
return {
reload,
wrapCall,
}
}
};
};
@@ -5,6 +5,7 @@ import { AutomationList } from ".";
import { bigMockAutoList } from "utils/mocks";
import { Page } from "components/Page";
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
import { AutomationData } from "types/automations";
export default {
title: "App/AutomationList",
@@ -16,12 +17,15 @@ export default {
} as ComponentMeta<typeof AutomationList>;
const Template: ComponentStory<typeof AutomationList> = (args) => {
const [autos, setAutos] = useState(args.automations);
const [autos, setAutos] = useState(args.automations.data);
return (
<Page>
<AutomationList
{...args}
automations={autos}
automations={{
...args.automations,
data: autos,
}}
onAdd={(a) => {
args.onAdd(a);
setAutos([...autos, a]);
@@ -39,107 +43,115 @@ const Template: ComponentStory<typeof AutomationList> = (args) => {
);
};
export const EmptyStart = Template.bind({});
EmptyStart.args = {
...EmptyStart.args,
automations: [],
const make = (autos: AutomationData[]) => {
const NewTemp = Template.bind({});
NewTemp.args = {
...NewTemp.args,
automations: {
data: autos,
params: {
offset: 0,
limit: 100,
},
totalItems: autos.length,
},
};
return NewTemp;
};
export const FewAutos = Template.bind({});
FewAutos.args = {
...FewAutos.args,
automations: bigMockAutoList,
};
export const EmptyStart = make([]);
export const BadAutmations = Template.bind({});
BadAutmations.args = {
...BadAutmations.args,
automations: [
{
metadata: {
alias: "Set Thermostat to 76 at 8am",
description: "",
mode: "single",
} as any,
trigger: [
{
at: "08:00:00",
platform: "time",
export const FewAutos = make(bigMockAutoList);
export const BadAutmations = make([
{
metadata: {
alias: "Set Thermostat to 76 at 8am",
description: "",
mode: "single",
} as any,
trigger: [
{
at: "08:00:00",
platform: "time",
},
],
condition: [
{
condition: "state",
entity_id: "climate.thermostat",
state: "cool",
},
],
sequence: [
{
data: {
temperature: 76,
},
],
condition: [
{
condition: "state",
service: "climate.set_temperature",
target: {
entity_id: "climate.thermostat",
state: "cool",
},
],
sequence: [
{
data: {
temperature: 76,
},
service: "climate.set_temperature",
target: {
entity_id: "climate.thermostat",
},
},
],
tags: {},
},
{
condition: [],
tags: {},
metadata: {
id: "Bad Choose Sequence",
alias: "Bad Choose",
description: "Example Metadata",
trigger_variables: {
wowo: "!",
},
mode: "single",
},
trigger: [],
sequence: [
{
choose: {},
},
] as any,
},
{
condition: [],
tags: {},
metadata: {
id: "random",
alias: "Bad Trigger",
description: "Example Metadata",
trigger_variables: {
wowo: "!",
},
mode: "single",
],
tags: {},
},
{
condition: [],
tags: {},
metadata: {
id: "Bad Choose Sequence",
alias: "Bad Choose",
description: "Example Metadata",
trigger_variables: {
wowo: "!",
},
trigger: ["haha I am a string"] as any,
sequence: [],
mode: "single",
},
{
condition: [],
tags: {},
metadata: {} as any,
trigger: [],
sequence: [],
trigger: [],
sequence: [
{
choose: {},
},
] as any,
},
{
condition: [],
tags: {},
metadata: {
id: "random",
alias: "Bad Trigger",
description: "Example Metadata",
trigger_variables: {
wowo: "!",
},
mode: "single",
},
],
};
trigger: ["haha I am a string"] as any,
sequence: [],
},
{
condition: [],
tags: {},
metadata: {} as any,
trigger: [],
sequence: [],
},
]);
export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
args
) => {
const [autos, setAutos] = useState(args.automations);
const [autos, setAutos] = useState(args.automations.data);
return (
<Page>
<AutomationList
{...args}
automations={autos}
automations={{
...args.automations,
data: autos,
}}
onAdd={(a) => {
window.setTimeout(() => {
args.onAdd(a);
@@ -164,5 +176,12 @@ export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
};
FewAutosWithSlowLoader.args = {
...FewAutosWithSlowLoader.args,
automations: bigMockAutoList,
automations: {
data: bigMockAutoList,
params: {
limit: 100,
offset: 0,
},
totalItems: 100,
},
};
@@ -65,8 +65,20 @@
align-items: center;
}
.automation-list-box--bottom>button {
background-color: #070;
color: var(--mui-grey-400);
.automation-list-box--bottom>.automation-list-box--bottom--add {
background-color: var(--mui-primary-main);
color: var(--mui-primary-contrastText);
padding: 0.5em 2em;
}
.automation-list-box--bottom>.automation-list-box--bottom--add:hover {
color: var(--mui-primary-light);
}
.automation-list-box--bottom--load svg {
color: var(--mui-primary-main);
}
.automation-list-box--bottom--load.less svg {
transform: rotate(180deg);
}
@@ -5,6 +5,7 @@ import { createMockAuto } from "utils/mocks";
import { Page } from "components/Page";
import { CookiesProvider } from "react-cookie";
import { makeTagDB } from "./TagDB";
import { AutomationData } from "types/automations";
export default {
title: "App/AutomationList/Box",
@@ -20,7 +21,7 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
<CookiesProvider>
<AutomationListBox
{...args}
tagsDB={makeTagDB(args.automations)}
tagsDB={makeTagDB(args.automations.data)}
automations={args.automations}
selected={selected}
onSelectAutomation={(i) => {
@@ -33,41 +34,46 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
);
};
export const EmptyStart = Template.bind({});
EmptyStart.args = {
...EmptyStart.args,
automations: [],
const make = (autos: AutomationData[]) => {
const NewTemp = Template.bind({});
NewTemp.args = {
...NewTemp.args,
automations: {
data: autos,
params: {
offset: 0,
limit: 100,
},
totalItems: autos.length,
},
};
return NewTemp;
};
export const FewAutos = Template.bind({});
FewAutos.args = {
...FewAutos.args,
automations: [
createMockAuto({
Room: "Bathroom",
Type: "Lights",
NewDevice: "Yes",
Remote: "No",
Floor: "1",
}),
createMockAuto({ Room: "Bathroom", Type: "Climate" }),
createMockAuto({ Room: "Living Room", Type: "Climate" }),
createMockAuto({ Type: "Climate" }),
createMockAuto({ Type: "Lights", Routine: "Myself" }),
createMockAuto({ Routine: "DNS", Type: "SSL" }),
createMockAuto({ Room: "Bedroom", Type: "Lights", Routine: "Baby" }),
createMockAuto({ Room: "Office", Type: "Lights" }),
createMockAuto({ Room: "Office" }),
createMockAuto(),
],
};
export const EmptyStart = make([]);
export const OneAuto = Template.bind({});
OneAuto.args = {
...OneAuto.args,
automations: [
createMockAuto({
Type: "Climate",
}),
],
};
export const FewAutos = make([
createMockAuto({
Room: "Bathroom",
Type: "Lights",
NewDevice: "Yes",
Remote: "No",
Floor: "1",
}),
createMockAuto({ Room: "Bathroom", Type: "Climate" }),
createMockAuto({ Room: "Living Room", Type: "Climate" }),
createMockAuto({ Type: "Climate" }),
createMockAuto({ Type: "Lights", Routine: "Myself" }),
createMockAuto({ Routine: "DNS", Type: "SSL" }),
createMockAuto({ Room: "Bedroom", Type: "Lights", Routine: "Baby" }),
createMockAuto({ Room: "Office", Type: "Lights" }),
createMockAuto({ Room: "Office" }),
createMockAuto(),
]);
export const OneAuto = make([
createMockAuto({
Type: "Climate",
}),
]);
@@ -8,14 +8,20 @@ import { makeGrouping } from "./automationGrouper";
import { AutomationListBoxGroup } from "./AutomationListBoxGroup";
import { useCookies } from "react-cookie";
import { TagDB } from "components/AutomationList/TagDB";
// import { ButtonIcon } from "components/Icons/ButtonIcons";
// import ReadMoreOutlinedIcon from "@mui/icons-material/ReadMoreOutlined";
import { ListData, ListParams } from "apiService/types";
import Chip from "@mui/material/Chip";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
export type AutomationListBoxProps = {
automations: AutomationData[];
automations: ListData<AutomationData>;
selected: number;
onSelectAutomation: (i: number) => void;
onRemove: (i: number) => void;
onAdd: () => void;
onUpdate: (a: AutomationData, i: number) => void;
onLoadMore: (p: ListParams) => void;
tagsDB: TagDB;
};
@@ -54,11 +60,16 @@ const useAutomationListBoxState = () => {
};
export const AutomationListBox: FC<AutomationListBoxProps> = ({
automations,
automations: {
data: automations,
params: autoParams,
totalItems: totalAutomations,
},
selected,
onSelectAutomation,
onAdd,
onRemove,
onLoadMore,
tagsDB,
onUpdate,
}) => {
@@ -101,11 +112,44 @@ export const AutomationListBox: FC<AutomationListBoxProps> = ({
/>
</div>
<div className="automation-list-box--bottom">
<Button onClick={onAdd}>Add</Button>
<span>
Showing Automations: {filteredAutomations.length} out of{" "}
{automations.length}
</span>
<Button className="automation-list-box--bottom--add" onClick={onAdd}>
Add
</Button>
{automations.length < totalAutomations ? (
<>
<Chip
label={`Only loaded ${automations.length} out of ${totalAutomations}`}
variant="outlined"
color="warning"
icon={<InfoOutlinedIcon />}
onClick={() =>
window.open(
"https://github.com/asosnovsky/Shortumation/issues/78",
"_blank"
)
}
/>
<small>support for more is not yet implemented</small>
</>
) : (
""
)}
{/* {autoParams.offset > 0 && (
<ButtonIcon
borderless
className="automation-list-box--bottom--load less"
icon={<ReadMoreOutlinedIcon />}
onClick={() => onLoadMore()}
/>
)} */}
{/* {filteredAutomations.length} out of {totalAutomations} */}
{/* {autoParams.offset + automations.length < totalAutomations && (
<ButtonIcon
borderless
className="automation-list-box--bottom--load more"
icon={<ReadMoreOutlinedIcon />}
/>
)} */}
</div>
</div>
);
@@ -6,7 +6,7 @@ import { Page } from "components/Page";
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
export default {
title: "App/AutomationList/Connected",
title: "App/AutomationList/MockConnected",
component: ConnectedAutomationList,
parameters: { actions: { argTypesRegex: "^on.*" } },
args: {
+13 -5
View File
@@ -16,12 +16,14 @@ import { useHA } from "haService";
import { ArrowBack } from "@mui/icons-material";
import { useSnackbar } from "notistack";
import { DAGDims } from "components/DAGGraph/elements/types";
import { ListData, ListParams } from "apiService/types";
interface AutomationListParams {
automations: AutomationData[];
automations: ListData<AutomationData>;
onUpdate: (i: number, auto: AutomationData) => void;
onAdd: (auto: AutomationData) => void;
onRemove: (i: number) => void;
onLoadMore: (p: ListParams) => void;
dims: DAGDims;
children?: ReactNode;
}
@@ -54,6 +56,7 @@ export const useAutomationListState = () => {
export const AutomationList: FC<AutomationListParams> = ({
automations,
onLoadMore,
onUpdate,
onAdd,
onRemove,
@@ -67,8 +70,11 @@ export const AutomationList: FC<AutomationListParams> = ({
const { isMobile } = useWindowSize();
const firstRender = useRef(true);
// alias
const currentAuto = automations.length > 0 ? automations[current] : null;
const tagDB = makeTagDB(automations);
const currentAuto =
automations.data.length > 0
? automations.data[current - automations.params.offset]
: null;
const tagDB = makeTagDB(automations.data);
// effect
useEffect(() => {
if (firstRender.current) {
@@ -92,7 +98,7 @@ export const AutomationList: FC<AutomationListParams> = ({
onUpdate={(a, i) => onUpdate(i, a)}
onAdd={() => {
onAdd(defaultAutomation(String(Date.now())));
setCurrent(automations.length);
setCurrent(automations.data.length);
if (isMobile) {
setHideList(true);
}
@@ -103,6 +109,7 @@ export const AutomationList: FC<AutomationListParams> = ({
setHideList(true);
}
}}
onLoadMore={onLoadMore}
selected={current}
onRemove={onRemove}
tagsDB={tagDB}
@@ -171,7 +178,8 @@ export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
return (
<AutomationList
dims={dims}
automations={automations.data.data}
automations={automations.data}
onLoadMore={() => {}}
onAdd={(auto) =>
updateAutomation({ auto, index: automations.data.totalItems + 1 })
}
@@ -13,8 +13,8 @@ export const DEFAULT_DIMS: DAGDims = {
width: NODE_WIDTH,
},
distanceFactor: {
node: 1.5,
collection: 1,
node: [1.5, 1.5],
collection: [1.25, 1.05],
},
position: {
x: 50,
@@ -9,11 +9,11 @@ export const moveAlong = (
reversed: boolean = false
): XYPosition => {
const moveOnY = {
y: startPoint.y + dims[by].height * dims.distanceFactor.node * increment,
y: startPoint.y + dims[by].height * dims.distanceFactor[by][0] * increment,
x: startPoint.x,
};
const moveOnX = {
x: startPoint.x + dims[by].width * dims.distanceFactor.node * increment,
x: startPoint.x + dims[by].width * dims.distanceFactor[by][1] * increment,
y: startPoint.y,
};
if (reversed) {
@@ -30,11 +30,14 @@ export const moveAlongRelativeTo = (
) =>
dims.flipped
? {
x: relatedPos.x + dims.distanceFactor.node * dims[incrementBy].width,
x:
relatedPos.x +
dims.distanceFactor.node[0] * 1.5 * dims[incrementBy].width,
y: offsetPos.y,
}
: {
y: relatedPos.y + dims.distanceFactor.node * dims[incrementBy].height,
y:
relatedPos.y + dims.distanceFactor.node[1] * dims[incrementBy].height,
x: offsetPos.x,
};
@@ -46,12 +49,12 @@ export const moveFromTo = (
): XYPosition => {
if (!dims.flipped) {
return {
x: startPoint.x + dims[from].width * dims.distanceFactor.collection,
x: startPoint.x + dims[from].width * dims.distanceFactor[to][0],
y: startPoint.y + (dims[from].height - dims[to].height) / 2,
};
} else {
return {
y: startPoint.y + dims[from].height * dims.distanceFactor.collection,
y: startPoint.y + dims[from].height * dims.distanceFactor[to][1],
x: startPoint.x + (dims[from].width - dims[to].width) / 2,
};
}
@@ -62,6 +65,6 @@ export const offsetBy = (
position: XYPosition,
dims: DAGDims
): XYPosition => ({
x: position.x + dims.distanceFactor[by] * dims[by].width,
y: position.y + dims.distanceFactor[by] * dims[by].height,
x: position.x + dims.distanceFactor[by][0] * dims[by].width,
y: position.y + dims.distanceFactor[by][1] * dims[by].height,
});
@@ -19,7 +19,7 @@ import { ButtonNodeMaker } from "../nodes/ButtonNode";
import { AddIcon } from "components/Icons";
import { useDAGElementsState } from "./state";
import AddBox from "@mui/icons-material/AddBox";
import { DAGGraphChooseUpdater, DAGGraphUpdater } from "../updater";
import { DAGGraphChooseUpdater } from "../updater";
import { getSpecialNodeMaker, makeSpecialNodeMaker } from "./specialnodes";
import { getNodeSubType } from "../../../utils/automations";
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
@@ -44,7 +44,6 @@ export const useAutomationNodes = (
nodeIndex: 0,
})
);
outputState.extend(
makeConditionNodes(automation.condition, {
...args,
@@ -338,7 +337,7 @@ export const makeChooseeNodes = makeSpecialNodeMaker(
let addPos = distance.moveAlong(
"node",
elseOutput.data.nodes[0].position,
1 / args.dims.distanceFactor.node,
1 / args.dims.distanceFactor.node[0],
args.dims,
true
);
@@ -20,7 +20,7 @@ export type DAGEntities = {
};
export type DAGDims = DAGEntities & {
position: XYPosition;
distanceFactor: Record<keyof DAGEntities, number>;
distanceFactor: Record<keyof DAGEntities, [number, number]>;
flipped: boolean;
};
export type ElementMakerBaseProps = {
+1 -4
View File
@@ -1,8 +1,5 @@
import { FC, useState } from "react";
import {
AutomationActionData,
AutomationSequenceNode,
} from "types/automations";
import { AutomationSequenceNode } from "types/automations";
import { useHA } from "haService";
import { ModalState } from "./board/types";
import { createUpdater } from "./updater";
@@ -62,14 +62,14 @@ const Template: ComponentStory<typeof ButtonNode> = (args) => {
? {
x:
DEFAULT_DIMS.node.width *
DEFAULT_DIMS.distanceFactor.node,
DEFAULT_DIMS.distanceFactor.node[0],
y: 0,
}
: {
x: 0,
y:
DEFAULT_DIMS.node.height *
DEFAULT_DIMS.distanceFactor.node,
DEFAULT_DIMS.distanceFactor.node[1],
},
},
dims,
@@ -179,7 +179,7 @@ export const ReturnTarget: ComponentStory<typeof Demo> = (args) => {
50 +
args.height *
2 *
DEFAULT_DIMS.distanceFactor.collection,
DEFAULT_DIMS.distanceFactor.collection[1],
},
},
DEFAULT_DIMS,
@@ -3,7 +3,6 @@ import { NodeTypes } from "react-flow-renderer";
import { makeNodeMaker } from "./NodeMaker";
import { DAGDims } from "../elements/types";
export type NodeManager = typeof NodeManager;
export const NodeManager = (() => {
const nodeTypes: NodeTypes = {};
return {
@@ -68,12 +68,12 @@ export const Colors: ComponentStory<typeof SequenceNode> = (args) => {
x:
50 +
DEFAULT_DIMS.node.height *
DEFAULT_DIMS.distanceFactor.node *
DEFAULT_DIMS.distanceFactor.node[0] *
i,
y:
50 +
DEFAULT_DIMS.node.height *
DEFAULT_DIMS.distanceFactor.node *
DEFAULT_DIMS.distanceFactor.node[1] *
i,
},
},
@@ -11,7 +11,6 @@ import {
RepeatAction,
ParallelAction,
} from "types/automations/actions";
import { ScriptConditionField } from "types/automations/common";
import { convertScriptConditionFieldToAutomationConditions } from "utils/automations";
import { AutomationNode } from "types/automations";
@@ -8,7 +8,7 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
choose: [],
}),
isReady: () => true,
Component: ({}) => {
Component: () => {
return <></>;
},
};
@@ -1,8 +1,6 @@
import InputNumber from "components/Inputs/InputNumber";
import InputYaml from "components/Inputs/InputYaml";
import { useState } from "react";
import { RepeatAction } from "types/automations/actions";
import { OptionManager, updateActionData } from "./OptionManager";
import { OptionManager } from "./OptionManager";
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
const determineType = (repeatNode: RepeatAction["repeat"]) =>
@@ -16,7 +14,7 @@ export const ActionRepeatState: OptionManager<RepeatAction> = {
sequence: [],
},
}),
isReady: ({}) => true,
isReady: () => true,
Component: ({ state, setState }) => {
const repeatType = determineType(state.repeat);
return (
-1
View File
@@ -8,7 +8,6 @@ import {
} from "types/automations/common";
import { AutomationTriggerZone } from "types/automations/triggers";
import StopIcon from "@mui/icons-material/PanToolOutlined";
import { RepeatAction } from "types/automations/actions";
export interface Namer {
getEntityName(entity_id: string | string[], maxEntities?: number): string;
getDeviceName(device_id: string): string;