Update operation.js
This commit is contained in:
parent
25fc9cfda5
commit
c6571763a0
1 changed files with 7 additions and 17 deletions
|
|
@ -5,46 +5,39 @@ export default {
|
|||
name: "Logic Operation",
|
||||
inputsInline: true,
|
||||
colour: 60,
|
||||
description: "Perform the specifed boolean logic operation on two operands.",
|
||||
|
||||
description: "Combine multiple conditions to create sophisticated decision logic in your Actions. Perfect for complex automation like 'if temperature is high AND humidity is low', 'if motion detected OR door opened', or any scenario where you need multiple criteria to work together. Essential for building smart, multi-factor IoT control systems.",
|
||||
connections: {
|
||||
mode: "value",
|
||||
output: "expression",
|
||||
},
|
||||
|
||||
template: `%A %OP %B`,
|
||||
|
||||
inputs: {
|
||||
A: {
|
||||
description: "A block diagram that will be resolved to a truthy/falsy value",
|
||||
description: "The first condition to evaluate (left side). Connect comparison blocks, sensor checks, or any logic that results in true/false. Examples: 'temperature > 80', 'door equals open', or 'battery < 20%'.",
|
||||
check: "expression",
|
||||
shadow: 'io_logic_boolean'
|
||||
},
|
||||
|
||||
B: {
|
||||
description: "A block diagram that will be resolved to a truthy/falsy value",
|
||||
description: "The second condition to evaluate (right side). Connect another comparison, sensor check, or boolean logic. Examples: 'humidity > 60%', 'motion detected', or 'time between 9 AM and 5 PM'.",
|
||||
check: "expression",
|
||||
shadow: 'io_logic_boolean'
|
||||
}
|
||||
},
|
||||
|
||||
fields: {
|
||||
OP: {
|
||||
description: "Select the logic operation to perform on the inputs:",
|
||||
description: "Choose how to combine your two conditions:",
|
||||
options: [
|
||||
['and', 'AND', "Resolve `true` if both operands are true, otherwise `false`."],
|
||||
['or', 'OR', "Resolve `true` if either or both operands are true, otherwise `false`."],
|
||||
['and', 'AND', "Both conditions must be true: Returns true only when BOTH inputs are true (e.g., 'temperature > 80 AND humidity < 30' for hot and dry conditions requiring both criteria simultaneously)."],
|
||||
['or', 'OR', "Either condition can be true: Returns true when AT LEAST ONE input is true (e.g., 'motion detected OR door opened' triggers on any activity, 'battery < 10% OR offline > 1 hour' for multiple alert conditions)."],
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
generators: {
|
||||
json: (block, generator) => {
|
||||
const
|
||||
operator = block.getFieldValue('OP'),
|
||||
leftExp = generator.valueToCode(block, 'A', 0) || null,
|
||||
rightExp = generator.valueToCode(block, 'B', 0) || null,
|
||||
|
||||
blockPayload = JSON.stringify({
|
||||
logic: {
|
||||
left: JSON.parse(leftExp),
|
||||
|
|
@ -52,11 +45,9 @@ export default {
|
|||
right: JSON.parse(rightExp),
|
||||
},
|
||||
})
|
||||
|
||||
return [ blockPayload, 0 ]
|
||||
}
|
||||
},
|
||||
|
||||
regenerators: {
|
||||
json: (blockObject, helpers) => {
|
||||
const
|
||||
|
|
@ -64,11 +55,10 @@ export default {
|
|||
fields = {
|
||||
OP: comparator?.toUpperCase()
|
||||
},
|
||||
inputs = {
|
||||
inputs: {
|
||||
A: helpers.expressionToBlock(left, { shadow: 'io_logic_boolean' }),
|
||||
B: helpers.expressionToBlock(right, { shadow: 'io_logic_boolean' }),
|
||||
}
|
||||
|
||||
return { type: 'io_logic_operation', fields, inputs }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue