Update number.js
This commit is contained in:
parent
55e3b09415
commit
fd2912518d
1 changed files with 5 additions and 12 deletions
|
|
@ -3,39 +3,32 @@ export default {
|
||||||
type: 'io_math_number',
|
type: 'io_math_number',
|
||||||
name: "Number",
|
name: "Number",
|
||||||
color: 120,
|
color: 120,
|
||||||
|
description: "Enter any numerical value for use in your IoT Actions - whole numbers, decimals, positive, or negative. Perfect for setting thresholds (like 75 for temperature alerts), target values (like 50% for humidity control), timer durations (like 300 seconds), or any numerical data your automation needs. The foundation for all mathematical operations and comparisons.",
|
||||||
description: "A numeric value, whole or decimal.",
|
|
||||||
|
|
||||||
connections: {
|
connections: {
|
||||||
mode: "value",
|
mode: "value",
|
||||||
output: [ "expression", "number" ],
|
output: [ "expression", "number" ],
|
||||||
},
|
},
|
||||||
|
|
||||||
extensions: {
|
extensions: {
|
||||||
validateNumbers: ({ block }) => {
|
validateNumbers: ({ block }) => {
|
||||||
const numField = block.getField("NUM")
|
const numField = block.getField("NUM")
|
||||||
|
|
||||||
if(!numField) { throw new Error("NUM field missing on io_math_number?") }
|
if(!numField) { throw new Error("NUM field missing on io_math_number?") }
|
||||||
|
|
||||||
numField.setValidator(newValue => {
|
numField.setValidator(newValue => {
|
||||||
const parsed = Number(newValue)
|
const parsed = Number(newValue)
|
||||||
|
|
||||||
if(!parsed && parsed !== 0) {
|
if(!parsed && parsed !== 0) {
|
||||||
return null // failed to parse, signal validation failure
|
return null // failed to parse, signal validation failure
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return parsed// parsed fine, use the result
|
return parsed// parsed fine, use the result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
template: " %NUM",
|
template: " %NUM",
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
NUM: { text: '0' }
|
NUM: {
|
||||||
|
description: "Enter your numerical value here. Examples: 75 (temperature threshold), 3.14159 (mathematical constant), -10 (negative temperature), 0.5 (percentage as decimal), or any number your automation requires. Validates input to ensure it's a proper number.",
|
||||||
|
text: '0'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
generators: {
|
generators: {
|
||||||
json: block => {
|
json: block => {
|
||||||
return [Number(block.getFieldValue('NUM')) || '0', 0]
|
return [Number(block.getFieldValue('NUM')) || '0', 0]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue