input entities
This commit is contained in:
1 parent
878035e748
commit
996626f9af
27 files changed
+596
-92
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { DeviceAction } from "types/automations/actions";
|
||||
import { OptionManager, updateActionData } from './OptionManager';
|
||||
@@ -39,9 +40,7 @@ export const ActionDeviceState: OptionManager<DeviceAction> = {
|
||||
value={state.type}
|
||||
onChange={type => update({ type })}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="entity_id"
|
||||
label="Entity ID"
|
||||
<InputEntity
|
||||
value={state.entity_id ?? ""}
|
||||
onChange={entity_id => update({ entity_id, domain: entity_id.split('.')[0] })}
|
||||
/>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { HAEntitiesState } from 'haService';
|
||||
import { AutomationAction } from 'types/automations/actions';
|
||||
import { AutomationCondition } from 'types/automations/conditions';
|
||||
export interface OptionManager<T> {
|
||||
defaultState(): T;
|
||||
isReady(s: T): boolean;
|
||||
renderOptionList(s: T, set: (s: T) => void): JSX.Element;
|
||||
renderOptionList(s: T, set: (s: T) => void, entities: HAEntitiesState): JSX.Element;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerDevice } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
import InputTextBubble from 'components/Inputs/InputTextBubble';
|
||||
|
||||
|
||||
export const TriggerDevice: OptionManager<AutomationTriggerDevice> = {
|
||||
defaultState: () => ({
|
||||
"platform": 'device',
|
||||
"domain": "",
|
||||
"type": "",
|
||||
"subtype": "",
|
||||
"device_id": "",
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
renderOptionList: (state, setState, { getDomainList }) => {
|
||||
return <>
|
||||
<InputText label="Domain" value={state.domain ?? ""} onChange={domain => setState({
|
||||
<InputTextBubble label="Domain" options={getDomainList()} value={state.domain} onChange={domain => setState({
|
||||
...state,
|
||||
domain
|
||||
domain: domain ? domain[0] : "",
|
||||
})} />
|
||||
<InputText label="Type" value={state.type ?? ""} onChange={type => setState({
|
||||
...state,
|
||||
@@ -32,7 +28,7 @@ export const TriggerDevice: OptionManager<AutomationTriggerDevice> = {
|
||||
...state,
|
||||
device_id
|
||||
})} />
|
||||
<InputEntity value={state.entity_id ?? ""} onChange={entity_id => setState({
|
||||
<InputEntity restrictToDomain={state.domain ? [state.domain] : undefined} value={state.entity_id ?? ""} multiple onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
})} />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerNumericState } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
import InputNumber from 'components/Inputs/InputNumber';
|
||||
import InputTime from 'components/Inputs/InputTime';
|
||||
import InputYaml from 'components/Inputs/InputYaml';
|
||||
@@ -17,6 +17,7 @@ export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> =
|
||||
return <>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
multiple
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerState } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
import InputTime from 'components/Inputs/InputTime';
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ export const TriggerState: OptionManager<AutomationTriggerState> = {
|
||||
return <>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
multiple
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
entity_id
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerZone } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputList } from 'components/Inputs/InputList';
|
||||
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
import { InputEntity } from 'components/Inputs/InputEntities';
|
||||
|
||||
|
||||
export const TriggerZone: OptionManager<AutomationTriggerZone> = {
|
||||
@@ -15,9 +14,9 @@ export const TriggerZone: OptionManager<AutomationTriggerZone> = {
|
||||
isReady: () => true,
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputText label="Zone" value={state.zone ?? ""} onChange={zone => setState({
|
||||
<InputEntity label="Zone" restrictToDomain={['zone']} value={state.zone} onChange={zone => setState({
|
||||
...state,
|
||||
zone
|
||||
zone: zone ?? ""
|
||||
})} />
|
||||
<InputList
|
||||
label="Event"
|
||||
@@ -28,6 +27,8 @@ export const TriggerZone: OptionManager<AutomationTriggerZone> = {
|
||||
})}
|
||||
/>
|
||||
<InputEntity
|
||||
multiple
|
||||
restrictToDomain={["device_tracker", "person"]}
|
||||
value={state.entity_id}
|
||||
onChange={entity_id => setState({
|
||||
...state,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getNodeType, getNodeSubType, getSubTypeList, validateNode } from 'utils
|
||||
import InputYaml from 'components/Inputs/InputYaml';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { getDescriptionFromAutomationNode } from 'utils/formatting';
|
||||
import { useHAEntities } from 'haService';
|
||||
|
||||
type UseState = <S>(s: S) => [S, Dispatch<SetStateAction<S>>]
|
||||
|
||||
@@ -15,6 +16,7 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool
|
||||
isModified: false,
|
||||
...computeInvalidYaml(originalNode)
|
||||
});
|
||||
const entities = useHAEntities();
|
||||
const { node: currentNode, isModified, yamlMode, invalidManualYaml } = allState;
|
||||
useEffect(() => {
|
||||
setAllState({ ...allState, node: originalNode, isModified: false, })
|
||||
@@ -93,7 +95,7 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool
|
||||
}
|
||||
return <>
|
||||
{aliasEditor}
|
||||
{optionManager.renderOptionList(currentNode, setState)}
|
||||
{optionManager.renderOptionList(currentNode, setState, entities)}
|
||||
</>;
|
||||
},
|
||||
isReady() {
|
||||
|
||||
Reference in new issue
Block a user