Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b465219a9 | ||
|
|
e769a8e798 | ||
|
|
d8a2dd53d5 |
No files matched your search
@@ -10,9 +10,9 @@ def find_hass_config() -> HassConfig:
|
|||||||
"""Try to find HASS config."""
|
"""Try to find HASS config."""
|
||||||
if config("USE_EXAMPLE_REPO", False, cast=bool):
|
if config("USE_EXAMPLE_REPO", False, cast=bool):
|
||||||
print("using USE_EXAMPLE_REPO")
|
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)
|
print("|-> ", path)
|
||||||
return HassConfig(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:
|
||||||
@@ -13,6 +13,7 @@ THIS_FOLDER = Path(__file__).parent
|
|||||||
SAMPLES_FOLDER = THIS_FOLDER / "samples"
|
SAMPLES_FOLDER = THIS_FOLDER / "samples"
|
||||||
HA_CONFIG_EXAMPLE = SAMPLES_FOLDER / "config"
|
HA_CONFIG_EXAMPLE = SAMPLES_FOLDER / "config"
|
||||||
HA_CONFIG2_EXAMPLE = SAMPLES_FOLDER / "config-2"
|
HA_CONFIG2_EXAMPLE = SAMPLES_FOLDER / "config-2"
|
||||||
|
HA_CONFIG3_EXAMPLE = SAMPLES_FOLDER / "config-3"
|
||||||
|
|
||||||
|
|
||||||
def get_example_automation_loader(
|
def get_example_automation_loader(
|
||||||
|
|||||||
@@ -1,42 +1,40 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ApiState } from "./types";
|
import { ApiState } from "./types";
|
||||||
import { AutomationAPI } from './automations';
|
import { AutomationAPI } from "./automations";
|
||||||
|
|
||||||
|
export const useDefaultApiState = () =>
|
||||||
|
useState<ApiState>({
|
||||||
export const useDefaultApiState = () => useState<ApiState>({
|
automations: { ready: false },
|
||||||
automations: { ready: false },
|
});
|
||||||
});
|
|
||||||
|
|
||||||
export const makeReloadAutomations = (
|
export const makeReloadAutomations = (
|
||||||
automationAPI: AutomationAPI,
|
automationAPI: AutomationAPI,
|
||||||
state: ApiState,
|
state: ApiState,
|
||||||
setState: (s: ApiState) => void,
|
setState: (s: ApiState) => void
|
||||||
) => {
|
) => {
|
||||||
const reload = async () => {
|
const reload = async () => {
|
||||||
let params = { offset: 0, limit: 100 };
|
let params = { offset: 0, limit: 10000 };
|
||||||
if (state.automations.ready && state.automations.ok) {
|
if (state.automations.ready && state.automations.ok) {
|
||||||
params = state.automations.data.params
|
params = state.automations.data.params;
|
||||||
}
|
}
|
||||||
const resp = await automationAPI.list(params);
|
const resp = await automationAPI.list(params);
|
||||||
setState({
|
setState({
|
||||||
...state, automations: {
|
...state,
|
||||||
|
automations: {
|
||||||
ready: true,
|
ready: true,
|
||||||
...resp,
|
...resp,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
const wrapCall = <
|
const wrapCall = <Call extends (a: any) => Promise<any>>(fcn: Call) => {
|
||||||
Call extends (a: any) => Promise<any>
|
|
||||||
>(fcn: Call) => {
|
|
||||||
return async (args: Parameters<Call>[0]): Promise<ReturnType<Call>> => {
|
return async (args: Parameters<Call>[0]): Promise<ReturnType<Call>> => {
|
||||||
const resp = await fcn(args);
|
const resp = await fcn(args);
|
||||||
await reload();
|
await reload();
|
||||||
return resp;
|
return resp;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
return {
|
return {
|
||||||
reload,
|
reload,
|
||||||
wrapCall,
|
wrapCall,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
@@ -5,6 +5,7 @@ import { AutomationList } from ".";
|
|||||||
import { bigMockAutoList } from "utils/mocks";
|
import { bigMockAutoList } from "utils/mocks";
|
||||||
import { Page } from "components/Page";
|
import { Page } from "components/Page";
|
||||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||||
|
import { AutomationData } from "types/automations";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: "App/AutomationList",
|
title: "App/AutomationList",
|
||||||
@@ -16,12 +17,15 @@ export default {
|
|||||||
} as ComponentMeta<typeof AutomationList>;
|
} as ComponentMeta<typeof AutomationList>;
|
||||||
|
|
||||||
const Template: ComponentStory<typeof AutomationList> = (args) => {
|
const Template: ComponentStory<typeof AutomationList> = (args) => {
|
||||||
const [autos, setAutos] = useState(args.automations);
|
const [autos, setAutos] = useState(args.automations.data);
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<AutomationList
|
<AutomationList
|
||||||
{...args}
|
{...args}
|
||||||
automations={autos}
|
automations={{
|
||||||
|
...args.automations,
|
||||||
|
data: autos,
|
||||||
|
}}
|
||||||
onAdd={(a) => {
|
onAdd={(a) => {
|
||||||
args.onAdd(a);
|
args.onAdd(a);
|
||||||
setAutos([...autos, a]);
|
setAutos([...autos, a]);
|
||||||
@@ -39,107 +43,115 @@ const Template: ComponentStory<typeof AutomationList> = (args) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EmptyStart = Template.bind({});
|
const make = (autos: AutomationData[]) => {
|
||||||
EmptyStart.args = {
|
const NewTemp = Template.bind({});
|
||||||
...EmptyStart.args,
|
NewTemp.args = {
|
||||||
automations: [],
|
...NewTemp.args,
|
||||||
|
automations: {
|
||||||
|
data: autos,
|
||||||
|
params: {
|
||||||
|
offset: 0,
|
||||||
|
limit: 100,
|
||||||
|
},
|
||||||
|
totalItems: autos.length,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return NewTemp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FewAutos = Template.bind({});
|
export const EmptyStart = make([]);
|
||||||
FewAutos.args = {
|
|
||||||
...FewAutos.args,
|
|
||||||
automations: bigMockAutoList,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const BadAutmations = Template.bind({});
|
export const FewAutos = make(bigMockAutoList);
|
||||||
BadAutmations.args = {
|
|
||||||
...BadAutmations.args,
|
export const BadAutmations = make([
|
||||||
automations: [
|
{
|
||||||
{
|
metadata: {
|
||||||
metadata: {
|
alias: "Set Thermostat to 76 at 8am",
|
||||||
alias: "Set Thermostat to 76 at 8am",
|
description: "",
|
||||||
description: "",
|
mode: "single",
|
||||||
mode: "single",
|
} as any,
|
||||||
} as any,
|
trigger: [
|
||||||
trigger: [
|
{
|
||||||
{
|
at: "08:00:00",
|
||||||
at: "08:00:00",
|
platform: "time",
|
||||||
platform: "time",
|
},
|
||||||
|
],
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
condition: "state",
|
||||||
|
entity_id: "climate.thermostat",
|
||||||
|
state: "cool",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
sequence: [
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
temperature: 76,
|
||||||
},
|
},
|
||||||
],
|
service: "climate.set_temperature",
|
||||||
condition: [
|
target: {
|
||||||
{
|
|
||||||
condition: "state",
|
|
||||||
entity_id: "climate.thermostat",
|
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: [
|
tags: {},
|
||||||
{
|
},
|
||||||
choose: {},
|
{
|
||||||
},
|
condition: [],
|
||||||
] as any,
|
tags: {},
|
||||||
},
|
metadata: {
|
||||||
{
|
id: "Bad Choose Sequence",
|
||||||
condition: [],
|
alias: "Bad Choose",
|
||||||
tags: {},
|
description: "Example Metadata",
|
||||||
metadata: {
|
trigger_variables: {
|
||||||
id: "random",
|
wowo: "!",
|
||||||
alias: "Bad Trigger",
|
|
||||||
description: "Example Metadata",
|
|
||||||
trigger_variables: {
|
|
||||||
wowo: "!",
|
|
||||||
},
|
|
||||||
mode: "single",
|
|
||||||
},
|
},
|
||||||
trigger: ["haha I am a string"] as any,
|
mode: "single",
|
||||||
sequence: [],
|
|
||||||
},
|
},
|
||||||
{
|
trigger: [],
|
||||||
condition: [],
|
sequence: [
|
||||||
tags: {},
|
{
|
||||||
metadata: {} as any,
|
choose: {},
|
||||||
trigger: [],
|
},
|
||||||
sequence: [],
|
] 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> = (
|
export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
|
||||||
args
|
args
|
||||||
) => {
|
) => {
|
||||||
const [autos, setAutos] = useState(args.automations);
|
const [autos, setAutos] = useState(args.automations.data);
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<AutomationList
|
<AutomationList
|
||||||
{...args}
|
{...args}
|
||||||
automations={autos}
|
automations={{
|
||||||
|
...args.automations,
|
||||||
|
data: autos,
|
||||||
|
}}
|
||||||
onAdd={(a) => {
|
onAdd={(a) => {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
args.onAdd(a);
|
args.onAdd(a);
|
||||||
@@ -164,5 +176,12 @@ export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
|
|||||||
};
|
};
|
||||||
FewAutosWithSlowLoader.args = {
|
FewAutosWithSlowLoader.args = {
|
||||||
...FewAutosWithSlowLoader.args,
|
...FewAutosWithSlowLoader.args,
|
||||||
automations: bigMockAutoList,
|
automations: {
|
||||||
|
data: bigMockAutoList,
|
||||||
|
params: {
|
||||||
|
limit: 100,
|
||||||
|
offset: 0,
|
||||||
|
},
|
||||||
|
totalItems: 100,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
@@ -65,8 +65,20 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.automation-list-box--bottom>button {
|
.automation-list-box--bottom>.automation-list-box--bottom--add {
|
||||||
background-color: #070;
|
background-color: var(--mui-primary-main);
|
||||||
color: var(--mui-grey-400);
|
color: var(--mui-primary-contrastText);
|
||||||
padding: 0.5em 2em;
|
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 { Page } from "components/Page";
|
||||||
import { CookiesProvider } from "react-cookie";
|
import { CookiesProvider } from "react-cookie";
|
||||||
import { makeTagDB } from "./TagDB";
|
import { makeTagDB } from "./TagDB";
|
||||||
|
import { AutomationData } from "types/automations";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: "App/AutomationList/Box",
|
title: "App/AutomationList/Box",
|
||||||
@@ -20,7 +21,7 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
|
|||||||
<CookiesProvider>
|
<CookiesProvider>
|
||||||
<AutomationListBox
|
<AutomationListBox
|
||||||
{...args}
|
{...args}
|
||||||
tagsDB={makeTagDB(args.automations)}
|
tagsDB={makeTagDB(args.automations.data)}
|
||||||
automations={args.automations}
|
automations={args.automations}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
onSelectAutomation={(i) => {
|
onSelectAutomation={(i) => {
|
||||||
@@ -33,41 +34,46 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EmptyStart = Template.bind({});
|
const make = (autos: AutomationData[]) => {
|
||||||
EmptyStart.args = {
|
const NewTemp = Template.bind({});
|
||||||
...EmptyStart.args,
|
NewTemp.args = {
|
||||||
automations: [],
|
...NewTemp.args,
|
||||||
|
automations: {
|
||||||
|
data: autos,
|
||||||
|
params: {
|
||||||
|
offset: 0,
|
||||||
|
limit: 100,
|
||||||
|
},
|
||||||
|
totalItems: autos.length,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return NewTemp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FewAutos = Template.bind({});
|
export const EmptyStart = make([]);
|
||||||
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 OneAuto = Template.bind({});
|
export const FewAutos = make([
|
||||||
OneAuto.args = {
|
createMockAuto({
|
||||||
...OneAuto.args,
|
Room: "Bathroom",
|
||||||
automations: [
|
Type: "Lights",
|
||||||
createMockAuto({
|
NewDevice: "Yes",
|
||||||
Type: "Climate",
|
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 { AutomationListBoxGroup } from "./AutomationListBoxGroup";
|
||||||
import { useCookies } from "react-cookie";
|
import { useCookies } from "react-cookie";
|
||||||
import { TagDB } from "components/AutomationList/TagDB";
|
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 = {
|
export type AutomationListBoxProps = {
|
||||||
automations: AutomationData[];
|
automations: ListData<AutomationData>;
|
||||||
selected: number;
|
selected: number;
|
||||||
onSelectAutomation: (i: number) => void;
|
onSelectAutomation: (i: number) => void;
|
||||||
onRemove: (i: number) => void;
|
onRemove: (i: number) => void;
|
||||||
onAdd: () => void;
|
onAdd: () => void;
|
||||||
onUpdate: (a: AutomationData, i: number) => void;
|
onUpdate: (a: AutomationData, i: number) => void;
|
||||||
|
onLoadMore: (p: ListParams) => void;
|
||||||
tagsDB: TagDB;
|
tagsDB: TagDB;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,11 +60,16 @@ const useAutomationListBoxState = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
||||||
automations,
|
automations: {
|
||||||
|
data: automations,
|
||||||
|
params: autoParams,
|
||||||
|
totalItems: totalAutomations,
|
||||||
|
},
|
||||||
selected,
|
selected,
|
||||||
onSelectAutomation,
|
onSelectAutomation,
|
||||||
onAdd,
|
onAdd,
|
||||||
onRemove,
|
onRemove,
|
||||||
|
onLoadMore,
|
||||||
tagsDB,
|
tagsDB,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -101,11 +112,44 @@ export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="automation-list-box--bottom">
|
<div className="automation-list-box--bottom">
|
||||||
<Button onClick={onAdd}>Add</Button>
|
<Button className="automation-list-box--bottom--add" onClick={onAdd}>
|
||||||
<span>
|
Add
|
||||||
Showing Automations: {filteredAutomations.length} out of{" "}
|
</Button>
|
||||||
{automations.length}
|
{automations.length < totalAutomations ? (
|
||||||
</span>
|
<>
|
||||||
|
<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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Page } from "components/Page";
|
|||||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: "App/AutomationList/Connected",
|
title: "App/AutomationList/MockConnected",
|
||||||
component: ConnectedAutomationList,
|
component: ConnectedAutomationList,
|
||||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||||
args: {
|
args: {
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ import { useHA } from "haService";
|
|||||||
import { ArrowBack } from "@mui/icons-material";
|
import { ArrowBack } from "@mui/icons-material";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { DAGDims } from "components/DAGGraph/elements/types";
|
import { DAGDims } from "components/DAGGraph/elements/types";
|
||||||
|
import { ListData, ListParams } from "apiService/types";
|
||||||
|
|
||||||
interface AutomationListParams {
|
interface AutomationListParams {
|
||||||
automations: AutomationData[];
|
automations: ListData<AutomationData>;
|
||||||
onUpdate: (i: number, auto: AutomationData) => void;
|
onUpdate: (i: number, auto: AutomationData) => void;
|
||||||
onAdd: (auto: AutomationData) => void;
|
onAdd: (auto: AutomationData) => void;
|
||||||
onRemove: (i: number) => void;
|
onRemove: (i: number) => void;
|
||||||
|
onLoadMore: (p: ListParams) => void;
|
||||||
dims: DAGDims;
|
dims: DAGDims;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
@@ -54,6 +56,7 @@ export const useAutomationListState = () => {
|
|||||||
|
|
||||||
export const AutomationList: FC<AutomationListParams> = ({
|
export const AutomationList: FC<AutomationListParams> = ({
|
||||||
automations,
|
automations,
|
||||||
|
onLoadMore,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
onAdd,
|
onAdd,
|
||||||
onRemove,
|
onRemove,
|
||||||
@@ -67,8 +70,11 @@ export const AutomationList: FC<AutomationListParams> = ({
|
|||||||
const { isMobile } = useWindowSize();
|
const { isMobile } = useWindowSize();
|
||||||
const firstRender = useRef(true);
|
const firstRender = useRef(true);
|
||||||
// alias
|
// alias
|
||||||
const currentAuto = automations.length > 0 ? automations[current] : null;
|
const currentAuto =
|
||||||
const tagDB = makeTagDB(automations);
|
automations.data.length > 0
|
||||||
|
? automations.data[current - automations.params.offset]
|
||||||
|
: null;
|
||||||
|
const tagDB = makeTagDB(automations.data);
|
||||||
// effect
|
// effect
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (firstRender.current) {
|
if (firstRender.current) {
|
||||||
@@ -92,7 +98,7 @@ export const AutomationList: FC<AutomationListParams> = ({
|
|||||||
onUpdate={(a, i) => onUpdate(i, a)}
|
onUpdate={(a, i) => onUpdate(i, a)}
|
||||||
onAdd={() => {
|
onAdd={() => {
|
||||||
onAdd(defaultAutomation(String(Date.now())));
|
onAdd(defaultAutomation(String(Date.now())));
|
||||||
setCurrent(automations.length);
|
setCurrent(automations.data.length);
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
setHideList(true);
|
setHideList(true);
|
||||||
}
|
}
|
||||||
@@ -103,6 +109,7 @@ export const AutomationList: FC<AutomationListParams> = ({
|
|||||||
setHideList(true);
|
setHideList(true);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onLoadMore={onLoadMore}
|
||||||
selected={current}
|
selected={current}
|
||||||
onRemove={onRemove}
|
onRemove={onRemove}
|
||||||
tagsDB={tagDB}
|
tagsDB={tagDB}
|
||||||
@@ -171,7 +178,8 @@ export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
|
|||||||
return (
|
return (
|
||||||
<AutomationList
|
<AutomationList
|
||||||
dims={dims}
|
dims={dims}
|
||||||
automations={automations.data.data}
|
automations={automations.data}
|
||||||
|
onLoadMore={() => {}}
|
||||||
onAdd={(auto) =>
|
onAdd={(auto) =>
|
||||||
updateAutomation({ auto, index: automations.data.totalItems + 1 })
|
updateAutomation({ auto, index: automations.data.totalItems + 1 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ export const DEFAULT_DIMS: DAGDims = {
|
|||||||
width: NODE_WIDTH,
|
width: NODE_WIDTH,
|
||||||
},
|
},
|
||||||
distanceFactor: {
|
distanceFactor: {
|
||||||
node: 1.5,
|
node: [1.5, 1.5],
|
||||||
collection: 1,
|
collection: [1.25, 1.05],
|
||||||
},
|
},
|
||||||
position: {
|
position: {
|
||||||
x: 50,
|
x: 50,
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ export const moveAlong = (
|
|||||||
reversed: boolean = false
|
reversed: boolean = false
|
||||||
): XYPosition => {
|
): XYPosition => {
|
||||||
const moveOnY = {
|
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,
|
x: startPoint.x,
|
||||||
};
|
};
|
||||||
const moveOnX = {
|
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,
|
y: startPoint.y,
|
||||||
};
|
};
|
||||||
if (reversed) {
|
if (reversed) {
|
||||||
@@ -30,11 +30,14 @@ export const moveAlongRelativeTo = (
|
|||||||
) =>
|
) =>
|
||||||
dims.flipped
|
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: offsetPos.y,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
y: relatedPos.y + dims.distanceFactor.node * dims[incrementBy].height,
|
y:
|
||||||
|
relatedPos.y + dims.distanceFactor.node[1] * dims[incrementBy].height,
|
||||||
x: offsetPos.x,
|
x: offsetPos.x,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -46,12 +49,12 @@ export const moveFromTo = (
|
|||||||
): XYPosition => {
|
): XYPosition => {
|
||||||
if (!dims.flipped) {
|
if (!dims.flipped) {
|
||||||
return {
|
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,
|
y: startPoint.y + (dims[from].height - dims[to].height) / 2,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
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,
|
x: startPoint.x + (dims[from].width - dims[to].width) / 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -62,6 +65,6 @@ export const offsetBy = (
|
|||||||
position: XYPosition,
|
position: XYPosition,
|
||||||
dims: DAGDims
|
dims: DAGDims
|
||||||
): XYPosition => ({
|
): XYPosition => ({
|
||||||
x: position.x + dims.distanceFactor[by] * dims[by].width,
|
x: position.x + dims.distanceFactor[by][0] * dims[by].width,
|
||||||
y: position.y + dims.distanceFactor[by] * dims[by].height,
|
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 { AddIcon } from "components/Icons";
|
||||||
import { useDAGElementsState } from "./state";
|
import { useDAGElementsState } from "./state";
|
||||||
import AddBox from "@mui/icons-material/AddBox";
|
import AddBox from "@mui/icons-material/AddBox";
|
||||||
import { DAGGraphChooseUpdater, DAGGraphUpdater } from "../updater";
|
import { DAGGraphChooseUpdater } from "../updater";
|
||||||
import { getSpecialNodeMaker, makeSpecialNodeMaker } from "./specialnodes";
|
import { getSpecialNodeMaker, makeSpecialNodeMaker } from "./specialnodes";
|
||||||
import { getNodeSubType } from "../../../utils/automations";
|
import { getNodeSubType } from "../../../utils/automations";
|
||||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||||
@@ -44,7 +44,6 @@ export const useAutomationNodes = (
|
|||||||
nodeIndex: 0,
|
nodeIndex: 0,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
outputState.extend(
|
outputState.extend(
|
||||||
makeConditionNodes(automation.condition, {
|
makeConditionNodes(automation.condition, {
|
||||||
...args,
|
...args,
|
||||||
@@ -338,7 +337,7 @@ export const makeChooseeNodes = makeSpecialNodeMaker(
|
|||||||
let addPos = distance.moveAlong(
|
let addPos = distance.moveAlong(
|
||||||
"node",
|
"node",
|
||||||
elseOutput.data.nodes[0].position,
|
elseOutput.data.nodes[0].position,
|
||||||
1 / args.dims.distanceFactor.node,
|
1 / args.dims.distanceFactor.node[0],
|
||||||
args.dims,
|
args.dims,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export type DAGEntities = {
|
|||||||
};
|
};
|
||||||
export type DAGDims = DAGEntities & {
|
export type DAGDims = DAGEntities & {
|
||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
distanceFactor: Record<keyof DAGEntities, number>;
|
distanceFactor: Record<keyof DAGEntities, [number, number]>;
|
||||||
flipped: boolean;
|
flipped: boolean;
|
||||||
};
|
};
|
||||||
export type ElementMakerBaseProps = {
|
export type ElementMakerBaseProps = {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import {
|
import { AutomationSequenceNode } from "types/automations";
|
||||||
AutomationActionData,
|
|
||||||
AutomationSequenceNode,
|
|
||||||
} from "types/automations";
|
|
||||||
import { useHA } from "haService";
|
import { useHA } from "haService";
|
||||||
import { ModalState } from "./board/types";
|
import { ModalState } from "./board/types";
|
||||||
import { createUpdater } from "./updater";
|
import { createUpdater } from "./updater";
|
||||||
|
|||||||
@@ -62,14 +62,14 @@ const Template: ComponentStory<typeof ButtonNode> = (args) => {
|
|||||||
? {
|
? {
|
||||||
x:
|
x:
|
||||||
DEFAULT_DIMS.node.width *
|
DEFAULT_DIMS.node.width *
|
||||||
DEFAULT_DIMS.distanceFactor.node,
|
DEFAULT_DIMS.distanceFactor.node[0],
|
||||||
y: 0,
|
y: 0,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y:
|
y:
|
||||||
DEFAULT_DIMS.node.height *
|
DEFAULT_DIMS.node.height *
|
||||||
DEFAULT_DIMS.distanceFactor.node,
|
DEFAULT_DIMS.distanceFactor.node[1],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
dims,
|
dims,
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ export const ReturnTarget: ComponentStory<typeof Demo> = (args) => {
|
|||||||
50 +
|
50 +
|
||||||
args.height *
|
args.height *
|
||||||
2 *
|
2 *
|
||||||
DEFAULT_DIMS.distanceFactor.collection,
|
DEFAULT_DIMS.distanceFactor.collection[1],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DEFAULT_DIMS,
|
DEFAULT_DIMS,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { NodeTypes } from "react-flow-renderer";
|
|||||||
import { makeNodeMaker } from "./NodeMaker";
|
import { makeNodeMaker } from "./NodeMaker";
|
||||||
import { DAGDims } from "../elements/types";
|
import { DAGDims } from "../elements/types";
|
||||||
|
|
||||||
export type NodeManager = typeof NodeManager;
|
|
||||||
export const NodeManager = (() => {
|
export const NodeManager = (() => {
|
||||||
const nodeTypes: NodeTypes = {};
|
const nodeTypes: NodeTypes = {};
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -68,12 +68,12 @@ export const Colors: ComponentStory<typeof SequenceNode> = (args) => {
|
|||||||
x:
|
x:
|
||||||
50 +
|
50 +
|
||||||
DEFAULT_DIMS.node.height *
|
DEFAULT_DIMS.node.height *
|
||||||
DEFAULT_DIMS.distanceFactor.node *
|
DEFAULT_DIMS.distanceFactor.node[0] *
|
||||||
i,
|
i,
|
||||||
y:
|
y:
|
||||||
50 +
|
50 +
|
||||||
DEFAULT_DIMS.node.height *
|
DEFAULT_DIMS.node.height *
|
||||||
DEFAULT_DIMS.distanceFactor.node *
|
DEFAULT_DIMS.distanceFactor.node[1] *
|
||||||
i,
|
i,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
RepeatAction,
|
RepeatAction,
|
||||||
ParallelAction,
|
ParallelAction,
|
||||||
} from "types/automations/actions";
|
} from "types/automations/actions";
|
||||||
import { ScriptConditionField } from "types/automations/common";
|
|
||||||
import { convertScriptConditionFieldToAutomationConditions } from "utils/automations";
|
import { convertScriptConditionFieldToAutomationConditions } from "utils/automations";
|
||||||
import { AutomationNode } from "types/automations";
|
import { AutomationNode } from "types/automations";
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
|
|||||||
choose: [],
|
choose: [],
|
||||||
}),
|
}),
|
||||||
isReady: () => true,
|
isReady: () => true,
|
||||||
Component: ({}) => {
|
Component: () => {
|
||||||
return <></>;
|
return <></>;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import InputNumber from "components/Inputs/InputNumber";
|
import InputNumber from "components/Inputs/InputNumber";
|
||||||
import InputYaml from "components/Inputs/InputYaml";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { RepeatAction } from "types/automations/actions";
|
import { RepeatAction } from "types/automations/actions";
|
||||||
import { OptionManager, updateActionData } from "./OptionManager";
|
import { OptionManager } from "./OptionManager";
|
||||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||||
|
|
||||||
const determineType = (repeatNode: RepeatAction["repeat"]) =>
|
const determineType = (repeatNode: RepeatAction["repeat"]) =>
|
||||||
@@ -16,7 +14,7 @@ export const ActionRepeatState: OptionManager<RepeatAction> = {
|
|||||||
sequence: [],
|
sequence: [],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
isReady: ({}) => true,
|
isReady: () => true,
|
||||||
Component: ({ state, setState }) => {
|
Component: ({ state, setState }) => {
|
||||||
const repeatType = determineType(state.repeat);
|
const repeatType = determineType(state.repeat);
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
} from "types/automations/common";
|
} from "types/automations/common";
|
||||||
import { AutomationTriggerZone } from "types/automations/triggers";
|
import { AutomationTriggerZone } from "types/automations/triggers";
|
||||||
import StopIcon from "@mui/icons-material/PanToolOutlined";
|
import StopIcon from "@mui/icons-material/PanToolOutlined";
|
||||||
import { RepeatAction } from "types/automations/actions";
|
|
||||||
export interface Namer {
|
export interface Namer {
|
||||||
getEntityName(entity_id: string | string[], maxEntities?: number): string;
|
getEntityName(entity_id: string | string[], maxEntities?: number): string;
|
||||||
getDeviceName(device_id: string): string;
|
getDeviceName(device_id: string): string;
|
||||||
|
|||||||
Reference in new issue
Block a user