fixed typing for repeat

This commit is contained in:
ari committed 2022-07-12 22:04:13 -04:00
1 parent 595aa2dfa1
commit f392cf17fd
5 files changed
+135 -54

No files matched your search

@@ -168,3 +168,77 @@ BadAutomationInvalidSequence.args = {
] as any,
},
};
export const RepeatExample = Template.bind({});
RepeatExample.args = {
...RepeatExample.args,
automation: {
metadata: {
id: "1654976151462",
alias: "Get out of baby room",
description: "",
mode: "single",
},
trigger: [
{
type: "opened",
platform: "device",
device_id: "9b33663d2700da8efe0c31c946448f77",
entity_id: "binary_sensor.door_baby",
domain: "binary_sensor",
},
],
condition: [],
sequence: [
{
service: "notify.mobile_app_levas_phone",
data: {
message: "Someone is in Korie’s room!!!",
},
},
{
repeat: {
while: [
{
type: "is_open",
condition: "device",
device_id: "9b33663d2700da8efe0c31c946448f77",
entity_id: "binary_sensor.door_baby",
domain: "binary_sensor",
},
],
sequence: [
{
service: "notify.alexa_media",
data: {
message:
"Get the fuck out of the baby’s bedroom you sick fuck! This room belongs to Korie! Close the door! I said close. The. Door!",
data: null,
type: "tts",
target: "media_player.baby_bedroom_dot",
},
},
{
delay: {
hours: 0,
minutes: 0,
seconds: 7,
milliseconds: 0,
},
},
],
},
},
{
service: "light.turn_off",
target: {
entity_id: ["light.switch_baby"],
},
data: {
flash: "short",
},
},
],
tags: {},
},
};
@@ -1,37 +1,43 @@
import InputNumber from "components/Inputs/InputNumber";
import InputYaml from "components/Inputs/InputYaml";
import { RepeatAction } from "types/automations/actions";
import { OptionManager, updateActionData } from './OptionManager';
import { OptionManager, updateActionData } from "./OptionManager";
export const ActionRepeatState: OptionManager<RepeatAction> = {
defaultState: () => ({
alias: "Repeat",
repeat: {
count: 1,
while: [],
sequence: [],
}
},
}),
isReady: ({
alias,
repeat,
}) => (
alias !== '' &&
repeat?.sequence.length > 0
),
isReady: ({ alias, repeat }) => alias !== "" && repeat?.sequence.length > 0,
renderOptionList: (state, setState) => {
const update = updateActionData(state, setState);
return <>
<InputNumber
label="How many times?"
value={state.repeat.count}
onChange={(count = 1) => update({ repeat: { ...state.repeat, count } })}
/>
<InputYaml
label="Sequence"
value={state.repeat.sequence ?? []}
onChange={sequence => update({ repeat: { ...state.repeat, sequence } })}
/>
</>
}
}
return (
<>
<InputNumber
label="How many times?"
value={state.repeat.count}
onChange={(count = 1) =>
update({ repeat: { ...state.repeat, count } })
}
/>
<InputYaml
label="Sequence"
value={state.repeat.sequence ?? []}
onChange={(sequence) =>
update({ repeat: { ...state.repeat, sequence } })
}
/>
<InputYaml
label="Condition"
value={state.repeat.while ?? []}
onChange={(sequence) =>
update({ repeat: { ...state.repeat, sequence } })
}
/>
</>
);
},
};