fixed up alias issues
This commit is contained in:
1 parent
98133607ca
commit
cdf67aa1a9
20 files changed
+52
-76
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { FC } from "react";
|
||||
import { AutomationCondition, LogicCondition, NumericCondition, StateCondition, TemplateCondition, TimeCondition, TriggerCondition, ZoneCondition } from 'types/automations/conditions';
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { InputEntity } from "components/Inputs/InputTextBubble";
|
||||
@@ -46,10 +45,6 @@ export const TemplateEditor: Editor<TemplateCondition> = ({
|
||||
condition,
|
||||
}) => {
|
||||
return <>
|
||||
<InputText label="Alias" value={condition.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
alias
|
||||
})} />
|
||||
<InputYaml label="Template" value={condition.value_template} onChange={value_template => onChange({
|
||||
...condition,
|
||||
value_template
|
||||
@@ -63,10 +58,6 @@ export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
condition,
|
||||
}) => {
|
||||
return <>
|
||||
<InputText label="Alias" value={condition.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
alias
|
||||
})} />
|
||||
<InputEntity
|
||||
value={condition.entity_id}
|
||||
onChange={entity_id => onChange({
|
||||
@@ -127,10 +118,6 @@ export const StateEditor: Editor<StateCondition> = ({
|
||||
condition,
|
||||
}) => {
|
||||
return <>
|
||||
<InputText label="Alias" value={condition.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
alias
|
||||
})} />
|
||||
<InputEntity
|
||||
value={condition.entity_id}
|
||||
onChange={entity_id => onChange({
|
||||
@@ -166,10 +153,6 @@ export const TimeEditor: Editor<TimeCondition> = ({
|
||||
condition,
|
||||
}) => {
|
||||
return <>
|
||||
<InputText label="Alias" value={condition.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
alias
|
||||
})} />
|
||||
<InputTime
|
||||
label="After"
|
||||
value={condition.after}
|
||||
@@ -195,10 +178,6 @@ export const TriggerEditor: Editor<TriggerCondition> = ({
|
||||
condition,
|
||||
}) => {
|
||||
return <>
|
||||
<InputText label="Alias" value={condition.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
alias
|
||||
})} />
|
||||
<InputText label="Trigger ID" value={condition.id} onChange={id => onChange({
|
||||
...condition,
|
||||
id
|
||||
@@ -211,10 +190,6 @@ export const ZoneEditor: Editor<ZoneCondition> = ({
|
||||
condition,
|
||||
}) => {
|
||||
return <>
|
||||
<InputText label="Alias" value={condition.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
alias
|
||||
})} />
|
||||
<InputText label="Zone" value={condition.zone} onChange={zone => onChange({
|
||||
...condition,
|
||||
zone
|
||||
|
||||
@@ -40,8 +40,8 @@ test("sequence updater updates nodes", () => {
|
||||
mock.updater.updateNode(0, {
|
||||
...mock.state[0],
|
||||
alias: "Hello"
|
||||
})
|
||||
expect(mock.state[0].alias).toBe("Hello")
|
||||
} as any)
|
||||
expect((mock.state[0] as any).alias).toBe("Hello")
|
||||
})
|
||||
test('update conditions for node', () => {
|
||||
const mock = mockSequenceUpdater([
|
||||
|
||||
@@ -6,7 +6,6 @@ import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
|
||||
export const TriggerDevice: OptionManager<AutomationTriggerDevice> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'device',
|
||||
"domain": "",
|
||||
"type": "",
|
||||
@@ -14,8 +13,8 @@ export const TriggerDevice: OptionManager<AutomationTriggerDevice> = {
|
||||
"device_id": "",
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -6,14 +6,13 @@ import InputYaml from "components/Inputs/InputYaml";
|
||||
|
||||
export const TriggerEventState: OptionManager<AutomationTriggerEvent> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": "event",
|
||||
"event_type": "",
|
||||
"event_data": {},
|
||||
"context": {},
|
||||
}),
|
||||
isReady: ({ alias, event_type }) => {
|
||||
return (alias !== '') && (event_type !== "")
|
||||
isReady: ({ event_type }) => {
|
||||
return (event_type !== "")
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -5,12 +5,11 @@ import { InputList } from "components/Inputs/InputList";
|
||||
|
||||
export const TriggerHAState: OptionManager<AutomationTriggerHA> = {
|
||||
defaultState: () => ({
|
||||
"alias": "HA Starts",
|
||||
"platform": "homeassistant",
|
||||
"event": "start",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
@@ -20,7 +19,6 @@ export const TriggerHAState: OptionManager<AutomationTriggerHA> = {
|
||||
options={['start', 'shutdown']}
|
||||
onChange={event => setState({
|
||||
...state, event,
|
||||
alias: event === 'shutdown' ? "HA Shutdown" : "HA Starts"
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -5,14 +5,13 @@ import InputText from 'components/Inputs/InputText';
|
||||
|
||||
export const TriggerMQTTState: OptionManager<AutomationTriggerMQTT> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": "mqtt",
|
||||
"payload": "",
|
||||
"topic": "",
|
||||
"value_template": ""
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -9,12 +9,11 @@ import InputYaml from 'components/Inputs/InputYaml';
|
||||
|
||||
export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'numeric_state',
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -7,12 +7,11 @@ import InputTime from 'components/Inputs/InputTime';
|
||||
|
||||
export const TriggerState: OptionManager<AutomationTriggerState> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'state',
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -6,12 +6,11 @@ import InputTime from 'components/Inputs/InputTime';
|
||||
|
||||
export const TriggerTemplate: OptionManager<AutomationTriggerTemplate> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'template',
|
||||
"value_template": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -6,12 +6,11 @@ import { convertObjectToAutomationTimeString } from 'utils/time';
|
||||
|
||||
export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'time',
|
||||
"at": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -5,11 +5,10 @@ import InputText from 'components/Inputs/InputText';
|
||||
|
||||
export const TriggerTimePattern: OptionManager<AutomationTriggerTimePattern> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'time_pattern',
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -5,12 +5,11 @@ import InputText from 'components/Inputs/InputText';
|
||||
|
||||
export const TriggerWebhook: OptionManager<AutomationTriggerWebhook> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'webhook',
|
||||
"webhook_id": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -7,14 +7,13 @@ import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
|
||||
export const TriggerZone: OptionManager<AutomationTriggerZone> = {
|
||||
defaultState: () => ({
|
||||
"alias": "",
|
||||
"platform": 'zone',
|
||||
"zone": "",
|
||||
"event": "enter",
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
isReady: ({ }) => {
|
||||
return true
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
|
||||
@@ -59,10 +59,27 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool
|
||||
return currentNode
|
||||
},
|
||||
renderOptionList() {
|
||||
const aliasEditor = <InputText label="Alias" value={getDescriptionFromAutomationNode(allState.node)} onChange={alias => setState({
|
||||
...allState.node,
|
||||
alias
|
||||
})} />
|
||||
let aliasEditor = <></>
|
||||
if (nodeType === 'trigger') {
|
||||
aliasEditor = <InputText
|
||||
label="Trigger ID"
|
||||
value={(allState.node as any).id}
|
||||
onChange={id => setState({
|
||||
...allState.node,
|
||||
id
|
||||
} as any)}
|
||||
/>
|
||||
}
|
||||
if (nodeType === 'action') {
|
||||
aliasEditor = <InputText
|
||||
label="Alias"
|
||||
value={getDescriptionFromAutomationNode(allState.node)}
|
||||
onChange={alias => setState({
|
||||
...allState.node,
|
||||
alias
|
||||
} as any)}
|
||||
/>
|
||||
}
|
||||
if (yamlMode || allState.isErrored) {
|
||||
return <>
|
||||
{aliasEditor}
|
||||
|
||||
@@ -52,7 +52,7 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
onChange={state.setNodeType}
|
||||
/> : <></>}
|
||||
{state.nodeType !== 'condition' ? <InputList
|
||||
label={`${state.nodeType} type`}
|
||||
label={`${state.nodeType.slice(0, 1).toUpperCase()}${state.nodeType.slice(1)} Type`}
|
||||
current={state.subType as any}
|
||||
options={state.subTypes}
|
||||
onChange={state.setSubType}
|
||||
|
||||
@@ -3,7 +3,6 @@ import * as st from 'superstruct';
|
||||
import * as v from "types/validators/conditions";
|
||||
type AutomationConditionNodeBase<Name extends String, Data extends Object> = {
|
||||
condition: Name;
|
||||
alias?: string;
|
||||
} & Data;
|
||||
export type LogicCondition = AutomationConditionNodeBase<'and' | 'or' | 'not', {
|
||||
conditions: AutomationCondition[];
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import * as st from 'superstruct'
|
||||
import * as v from "types/validators/triggers";
|
||||
|
||||
interface AutomationTriggerBase {
|
||||
alias?: string;
|
||||
}
|
||||
|
||||
export type AutomationTriggerEvent = st.Infer<typeof v.AutomationTriggerEvent>;
|
||||
export type AutomationTriggerHA = st.Infer<typeof v.AutomationTriggerHA>;
|
||||
export type AutomationTriggerMQTT = st.Infer<typeof v.AutomationTriggerMQTT>;
|
||||
|
||||
@@ -2,9 +2,7 @@ import * as st from 'superstruct'
|
||||
import { AutomationTime, EntityId } from './common';
|
||||
|
||||
|
||||
export const AutomationConditionNodeBase = st.type({
|
||||
alias: st.optional(st.string()),
|
||||
});
|
||||
export const AutomationConditionNodeBase = st.type({});
|
||||
export const LogicCondition = st.intersection([
|
||||
AutomationConditionNodeBase,
|
||||
st.type({
|
||||
|
||||
@@ -3,7 +3,6 @@ import { AutomationTimeString, AutomationTime, EntityId } from './common'
|
||||
|
||||
|
||||
const AutomationTriggerBase = {
|
||||
alias: st.optional(st.string()),
|
||||
id: st.optional(st.string()),
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,14 @@ export const convertTimeToString = (t: AutomationTime) => {
|
||||
}
|
||||
}
|
||||
export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(node: AutomationNode<N>): string => {
|
||||
if (node.alias) {
|
||||
if (('alias' in node) && node.alias) {
|
||||
return node.alias;
|
||||
}
|
||||
|
||||
if ('platform' in node) {
|
||||
if (node.id) {
|
||||
return node.id ?? '';
|
||||
}
|
||||
if (node.platform === 'time') {
|
||||
return node.at
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user