refactor inputs
This commit is contained in:
1 parent
2c5d64ab86
commit
549f52655b
45 files changed
+301
-256
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import InputNumber from "components/Inputs/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,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/InputText";
|
||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import InputYaml from "components/Inputs/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 { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||
import { InputTime } from "components/Inputs/InputTime";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { InputAutoComplete } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||
import { FC } from "react";
|
||||
import { getEntityDomains } from "utils/automations";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
|
||||
@@ -11,10 +11,10 @@ import {
|
||||
import InputText from "components/Inputs/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,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,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user