Merge pull request #14 from adafruit/tylerdcooper-patch-10
docs: compare text matcher block
This commit is contained in:
commit
e6d76cf361
1 changed files with 6 additions and 15 deletions
|
|
@ -5,48 +5,40 @@ export default {
|
||||||
name: "Compare Text Matcher",
|
name: "Compare Text Matcher",
|
||||||
colour: 180,
|
colour: 180,
|
||||||
inputsInline: true,
|
inputsInline: true,
|
||||||
description: "Compare the new feed value with text for equality, inequality, or inclusion.",
|
description: "Compare text-based feed data using smart text matching. Perfect for triggers based on status messages ('door opened', 'motion detected'), device states ('online', 'offline'), or any text-based sensor data. Works with exact matches, exclusions, or partial text detection within longer messages.",
|
||||||
|
|
||||||
connections: { mode: 'value', output: 'matcher' },
|
connections: { mode: 'value', output: 'matcher' },
|
||||||
|
|
||||||
template: "%OP %B",
|
template: "%OP %B",
|
||||||
|
|
||||||
inputs: {
|
inputs: {
|
||||||
B: {
|
B: {
|
||||||
description: "The string to compare with the Feed value.",
|
description: "The text to compare against your feed data. Examples: 'open' to detect door status, 'motion' for PIR sensors, 'online' for device connectivity, or any specific word/phrase you're monitoring for.",
|
||||||
check: "expression",
|
check: "expression",
|
||||||
shadow: 'io_text'
|
shadow: 'io_text'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
OP: {
|
OP: {
|
||||||
description: "Select what kind of comparison to do:",
|
description: "Choose how to compare the incoming feed data with your text:",
|
||||||
options: [
|
options: [
|
||||||
['=', 'EQ', "Returns true if the Feed value and text are the same."],
|
['=', 'EQ', "Exact match: Feed value must be exactly the same as your text (e.g., feed='online' matches text='online', but 'ONLINE' or 'device online' would not match)."],
|
||||||
['\u2260', 'NEQ', "Returns true if the Feed value and text are not the same."],
|
['\u2260', 'NEQ', "Not equal: Feed value must be different from your text (e.g., useful for 'not offline' conditions or excluding specific status messages)."],
|
||||||
['includes', 'INC', "Returns true if the Feed value includes the text."],
|
['includes', 'INC', "Contains: Feed value includes your text anywhere within it (e.g., feed='motion detected at 3pm' would match text='motion', perfect for parsing longer status messages)."],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
generators: {
|
generators: {
|
||||||
json: (block, generator) => {
|
json: (block, generator) => {
|
||||||
const
|
const
|
||||||
comparator = block.getFieldValue('OP'),
|
comparator = block.getFieldValue('OP'),
|
||||||
rightExp = generator.valueToCode(block, 'B', 0) || null,
|
rightExp = generator.valueToCode(block, 'B', 0) || null,
|
||||||
|
|
||||||
blockPayload = JSON.stringify({
|
blockPayload = JSON.stringify({
|
||||||
matcherTextCompare: {
|
matcherTextCompare: {
|
||||||
comparator: comparator?.toLowerCase() || null,
|
comparator: comparator?.toLowerCase() || null,
|
||||||
right: JSON.parse(rightExp),
|
right: JSON.parse(rightExp),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return [ blockPayload, 0 ]
|
return [ blockPayload, 0 ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
regenerators: {
|
regenerators: {
|
||||||
json: (blockObject, helpers) => {
|
json: (blockObject, helpers) => {
|
||||||
const
|
const
|
||||||
|
|
@ -57,7 +49,6 @@ export default {
|
||||||
inputs = {
|
inputs = {
|
||||||
B: helpers.expressionToBlock(right, { shadow: "io_text" }),
|
B: helpers.expressionToBlock(right, { shadow: "io_text" }),
|
||||||
}
|
}
|
||||||
|
|
||||||
return { type: 'matcher_text_compare', fields, inputs }
|
return { type: 'matcher_text_compare', fields, inputs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue