diff --git a/docs/api.md b/docs/api.md index 8d29c318e5..891a289712 100644 --- a/docs/api.md +++ b/docs/api.md @@ -18925,7 +18925,6 @@ things were successful or not. * [~validateSpecificAttribute(endpointAttribute, attribute, db, zapSessionId)](#module_Validation API_ Validation APIs..validateSpecificAttribute) ⇒ * [~validateSpecificEndpoint(endpoint)](#module_Validation API_ Validation APIs..validateSpecificEndpoint) ⇒ * [~isValidNumberString(value)](#module_Validation API_ Validation APIs..isValidNumberString) ⇒ - * [~isValidSignedNumberString(value)](#module_Validation API_ Validation APIs..isValidSignedNumberString) ⇒ * [~isValidHexString(value)](#module_Validation API_ Validation APIs..isValidHexString) ⇒ * [~isValidDecimalString(value)](#module_Validation API_ Validation APIs..isValidDecimalString) ⇒ * [~isValidFloat(value)](#module_Validation API_ Validation APIs..isValidFloat) ⇒ @@ -18976,7 +18975,7 @@ Enforce zigbee specific common cluster initialization. ### Validation API: Validation APIs~validateAttribute(db, endpointTypeId, attributeRef, clusterRef, zapSessionId) ⇒ Main attribute validation function. -Returns a promise of an object which stores a list of validational issues. +Returns a promise of an object which stores a list of validation issues. Such issues as "Invalid type" or "Out of Range". **Kind**: inner method of [Validation API: Validation APIs](#module_Validation API_ Validation APIs) @@ -19057,18 +19056,6 @@ This applies to both actual numbers as well as octet strings. | --- | --- | | value | \* | - - -### Validation API: Validation APIs~isValidSignedNumberString(value) ⇒ -Check if value is a valid signed number in string form. - -**Kind**: inner method of [Validation API: Validation APIs](#module_Validation API_ Validation APIs) -**Returns**: boolean - -| Param | Type | -| --- | --- | -| value | \* | - ### Validation API: Validation APIs~isValidHexString(value) ⇒ @@ -19300,7 +19287,6 @@ things were successful or not. * [~validateSpecificAttribute(endpointAttribute, attribute, db, zapSessionId)](#module_Validation API_ Validation APIs..validateSpecificAttribute) ⇒ * [~validateSpecificEndpoint(endpoint)](#module_Validation API_ Validation APIs..validateSpecificEndpoint) ⇒ * [~isValidNumberString(value)](#module_Validation API_ Validation APIs..isValidNumberString) ⇒ - * [~isValidSignedNumberString(value)](#module_Validation API_ Validation APIs..isValidSignedNumberString) ⇒ * [~isValidHexString(value)](#module_Validation API_ Validation APIs..isValidHexString) ⇒ * [~isValidDecimalString(value)](#module_Validation API_ Validation APIs..isValidDecimalString) ⇒ * [~isValidFloat(value)](#module_Validation API_ Validation APIs..isValidFloat) ⇒ @@ -19351,7 +19337,7 @@ Enforce zigbee specific common cluster initialization. ### Validation API: Validation APIs~validateAttribute(db, endpointTypeId, attributeRef, clusterRef, zapSessionId) ⇒ Main attribute validation function. -Returns a promise of an object which stores a list of validational issues. +Returns a promise of an object which stores a list of validation issues. Such issues as "Invalid type" or "Out of Range". **Kind**: inner method of [Validation API: Validation APIs](#module_Validation API_ Validation APIs) @@ -19432,18 +19418,6 @@ This applies to both actual numbers as well as octet strings. | --- | --- | | value | \* | - - -### Validation API: Validation APIs~isValidSignedNumberString(value) ⇒ -Check if value is a valid signed number in string form. - -**Kind**: inner method of [Validation API: Validation APIs](#module_Validation API_ Validation APIs) -**Returns**: boolean - -| Param | Type | -| --- | --- | -| value | \* | - ### Validation API: Validation APIs~isValidHexString(value) ⇒ diff --git a/src-electron/validation/validation.js b/src-electron/validation/validation.js index 1530970d53..fca333d098 100644 --- a/src-electron/validation/validation.js +++ b/src-electron/validation/validation.js @@ -30,7 +30,7 @@ const queryPackage = require('../db/query-package.js') /** * Main attribute validation function. - * Returns a promise of an object which stores a list of validational issues. + * Returns a promise of an object which stores a list of validation issues. * Such issues as "Invalid type" or "Out of Range". * @param {*} db db reference * @param {*} endpointTypeId endpoint reference @@ -128,20 +128,6 @@ async function validateSpecificAttribute( //Interpreting float values if (!checkAttributeBoundsFloat(attribute, endpointAttribute)) defaultAttributeIssues.push('Out of range') - } else if (await types.isSignedInteger(db, zapSessionId, attribute.type)) { - // we shouldn't check boundaries for an invalid number string - if (!isValidSignedNumberString(endpointAttribute.defaultValue)) { - defaultAttributeIssues.push('Invalid Integer') - } else if ( - !(await checkAttributeBoundsInteger( - attribute, - endpointAttribute, - db, - zapSessionId - )) - ) { - defaultAttributeIssues.push('Out of range') - } } else { // we shouldn't check boundaries for an invalid number string if (!isValidNumberString(endpointAttribute.defaultValue)) { @@ -210,16 +196,6 @@ function isValidNumberString(value) { return /^(0x)?[\dA-F]+$/i.test(value) || Number.isInteger(Number(value)) } -/** - * Check if value is a valid signed number in string form. - * - * @param {*} value - * @returns boolean - */ -function isValidSignedNumberString(value) { - return /^(0x)?[\dA-F]+$/i.test(value) || Number.isInteger(Number(value)) -} - /** * Check if value is a valid hex string. * @@ -312,13 +288,17 @@ function isBigInteger(bits) { * @returns object */ async function getBoundsInteger(attribute, typeSize, isSigned) { + let typeMin = isSigned ? -Math.pow(2, typeSize - 1) : 0 + let typeMax = isSigned + ? Math.pow(2, typeSize - 1) - 1 + : Math.pow(2, typeSize) - 1 return { min: attribute.min ? await getIntegerFromAttribute(attribute.min, typeSize, isSigned) - : null, + : typeMin, max: attribute.max ? await getIntegerFromAttribute(attribute.max, typeSize, isSigned) - : null + : typeMax } }