more trigger editors
This commit is contained in:
1 parent
2ee980b862
commit
56baef2662
4 files changed
+100
-36
No files matched your search
@@ -13,9 +13,7 @@ export default {
|
||||
|
||||
const Template: ComponentStory<typeof InputTime> = args => {
|
||||
|
||||
const [value, setValue] = useState<AutomationTime>({
|
||||
|
||||
})
|
||||
const [value, setValue] = useState<AutomationTime | undefined>(undefined);
|
||||
return <div className="page">
|
||||
<InputTime {...args} value={value} onChange={setValue} />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { OptionManager } from './OptionManager';
|
||||
import { AutomationTriggerNumericState } from 'types/automations/triggers';
|
||||
import InputText from 'components/Inputs/InputText';
|
||||
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||
import InputNumber from 'components/Inputs/InputNumber';
|
||||
import InputTextArea from 'components/Inputs/InputTextArea';
|
||||
import InputTime from 'components/Inputs/InputTime';
|
||||
|
||||
|
||||
export const TriggerNumericState: OptionManager<AutomationTriggerNumericState> = {
|
||||
defaultState: () => ({
|
||||
$smType: 'trigger',
|
||||
"alias": "",
|
||||
"platform": 'numeric_state',
|
||||
"entity_id": "",
|
||||
}),
|
||||
isReady: ({ alias }) => {
|
||||
return (alias !== '')
|
||||
},
|
||||
renderOptionList: (state, setState) => {
|
||||
return <>
|
||||
<InputEntity
|
||||
value={state.entity_id}
|
||||
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,
|
||||
})}
|
||||
/>
|
||||
<InputTextArea label="Template" value={state.value_template ?? ""} onChange={value_template => setState({
|
||||
...state,
|
||||
value_template
|
||||
})} resizable />
|
||||
<InputTime
|
||||
label="For"
|
||||
value={state.for}
|
||||
onChange={_for => setState({
|
||||
...state,
|
||||
for: _for,
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
@@ -11,41 +11,44 @@ import { ActionEventState } from "./ActionEvent";
|
||||
import { TriggerEventState } from "./TriggerEvent";
|
||||
import { TriggerHAState } from "./TriggerHA";
|
||||
import { TriggerMQTTState } from "./TriggerMQTT";
|
||||
import { TriggerNumericState } from "./TriggerNumericState";
|
||||
|
||||
|
||||
|
||||
export const getOptionManager = <T extends AutomationNodeTypes>(
|
||||
nodeType: T,
|
||||
nodeSubtype: AutomationNodeSubtype<T>,
|
||||
) : OptionManager<any> => {
|
||||
if ( nodeType === 'action') {
|
||||
switch (nodeSubtype) {
|
||||
case "choose":
|
||||
return ActionChooseState;
|
||||
case "device":
|
||||
return ActionDeviceState;
|
||||
case 'event':
|
||||
return ActionEventState;
|
||||
case "repeat":
|
||||
return ActionRepeatState;
|
||||
case 'service':
|
||||
return ActionCallServiceState;
|
||||
case "wait":
|
||||
return ActionWaitState;
|
||||
}
|
||||
}
|
||||
if (nodeType === 'condition') {
|
||||
return ConditionLogicState
|
||||
nodeType: T,
|
||||
nodeSubtype: AutomationNodeSubtype<T>,
|
||||
): OptionManager<any> => {
|
||||
if (nodeType === 'action') {
|
||||
switch (nodeSubtype) {
|
||||
case "choose":
|
||||
return ActionChooseState;
|
||||
case "device":
|
||||
return ActionDeviceState;
|
||||
case 'event':
|
||||
return ActionEventState;
|
||||
case "repeat":
|
||||
return ActionRepeatState;
|
||||
case 'service':
|
||||
return ActionCallServiceState;
|
||||
case "wait":
|
||||
return ActionWaitState;
|
||||
}
|
||||
}
|
||||
if (nodeType === 'condition') {
|
||||
return ConditionLogicState
|
||||
}
|
||||
if (nodeType === "trigger") {
|
||||
switch (nodeSubtype) {
|
||||
case "event":
|
||||
return TriggerEventState
|
||||
case "homeassistant":
|
||||
return TriggerHAState
|
||||
case "mqtt":
|
||||
return TriggerMQTTState
|
||||
}
|
||||
switch (nodeSubtype) {
|
||||
case "event":
|
||||
return TriggerEventState
|
||||
case "homeassistant":
|
||||
return TriggerHAState
|
||||
case "mqtt":
|
||||
return TriggerMQTTState
|
||||
case "numeric_state":
|
||||
return TriggerNumericState
|
||||
}
|
||||
}
|
||||
return Generic
|
||||
}
|
||||
Reference in new issue
Block a user