From c62393afac5038435e799253b76f60000c11542a Mon Sep 17 00:00:00 2001 From: ptvoinfo Date: Wed, 5 Feb 2025 16:13:47 +0300 Subject: [PATCH 1/4] PTVO converters. Added rounding for pressure, humidity, illuminance. --- src/devices/custom_devices_diy.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index b10ce5c07756e..f80d97b3f78ce 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -7,7 +7,7 @@ import * as legacy from '../lib/legacy'; import * as m from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Expose, Fz, KeyValue, KeyValueAny, Tz, Zh} from '../lib/types'; -import {getFromLookup, getKey, isEndpoint, postfixWithEndpointName} from '../lib/utils'; +import {getFromLookup, getKey, isEndpoint, postfixWithEndpointName, calibrateAndPrecisionRoundOptions} from '../lib/utils'; const e = exposes.presets; const ea = exposes.access; @@ -70,7 +70,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { // multi-endpoint version based on the stastard onverter 'fz.humidity' - const humidity = parseFloat(msg.data['measuredValue']) / 100.0; + const humidity = calibrateAndPrecisionRoundOptions(parseFloat(msg.data['measuredValue']) / 100.0, options, 'humidity'); // https://github.com/Koenkk/zigbee2mqtt/issues/798 // Sometimes the sensor publishes non-realistic vales, it should only publish message @@ -88,7 +88,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { // multi-endpoint version based on the stastard onverter 'fz.illuminance' const illuminance = msg.data['measuredValue']; - const illuminanceLux = illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000); + const illuminanceLux = calibrateAndPrecisionRoundOptions(illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000), options, 'illuminance'), const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property1 = multiEndpoint ? postfixWithEndpointName('illuminance', msg, model, meta) : 'illuminance'; return {[property1]: illuminanceLux}; @@ -106,6 +106,7 @@ const fzLocal = { } else { pressure = parseFloat(msg.data['measuredValue']); } + pressure = calibrateAndPrecisionRoundOptions(pressure, options, 'pressure'); const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property = multiEndpoint ? postfixWithEndpointName('pressure', msg, model, meta) : 'pressure'; return {[property]: pressure}; From 706b5b0cd3ddac090083b2f3ae6333fc2282c0d3 Mon Sep 17 00:00:00 2001 From: ptvoinfo Date: Wed, 5 Feb 2025 16:30:01 +0300 Subject: [PATCH 2/4] Typo fix --- src/devices/custom_devices_diy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index f80d97b3f78ce..86ed1f6079f3b 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -88,7 +88,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { // multi-endpoint version based on the stastard onverter 'fz.illuminance' const illuminance = msg.data['measuredValue']; - const illuminanceLux = calibrateAndPrecisionRoundOptions(illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000), options, 'illuminance'), + const illuminanceLux = calibrateAndPrecisionRoundOptions(illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000), options, 'illuminance'); const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property1 = multiEndpoint ? postfixWithEndpointName('illuminance', msg, model, meta) : 'illuminance'; return {[property1]: illuminanceLux}; From 9f6b16653064a82b024f11467948aed38507f808 Mon Sep 17 00:00:00 2001 From: ptvoinfo Date: Wed, 5 Feb 2025 16:37:02 +0300 Subject: [PATCH 3/4] Fix --- src/devices/custom_devices_diy.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index 86ed1f6079f3b..7037c36677745 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -70,7 +70,8 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { // multi-endpoint version based on the stastard onverter 'fz.humidity' - const humidity = calibrateAndPrecisionRoundOptions(parseFloat(msg.data['measuredValue']) / 100.0, options, 'humidity'); + let humidity = parseFloat(msg.data['measuredValue']) / 100.0; + humidity = calibrateAndPrecisionRoundOptions(humidity, options, 'humidity'); // https://github.com/Koenkk/zigbee2mqtt/issues/798 // Sometimes the sensor publishes non-realistic vales, it should only publish message @@ -88,7 +89,8 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { // multi-endpoint version based on the stastard onverter 'fz.illuminance' const illuminance = msg.data['measuredValue']; - const illuminanceLux = calibrateAndPrecisionRoundOptions(illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000), options, 'illuminance'); + let illuminanceLux = illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000); + illuminanceLux = calibrateAndPrecisionRoundOptions(illuminanceLux, options, 'illuminance'); const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property1 = multiEndpoint ? postfixWithEndpointName('illuminance', msg, model, meta) : 'illuminance'; return {[property1]: illuminanceLux}; From b949aacd596c4bdff4ff9b2358f770b5113adcc8 Mon Sep 17 00:00:00 2001 From: ptvoinfo Date: Wed, 5 Feb 2025 16:42:05 +0300 Subject: [PATCH 4/4] Fix --- src/devices/custom_devices_diy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index 7037c36677745..e96b0c43c533e 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -7,7 +7,7 @@ import * as legacy from '../lib/legacy'; import * as m from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Expose, Fz, KeyValue, KeyValueAny, Tz, Zh} from '../lib/types'; -import {getFromLookup, getKey, isEndpoint, postfixWithEndpointName, calibrateAndPrecisionRoundOptions} from '../lib/utils'; +import {calibrateAndPrecisionRoundOptions, getFromLookup, getKey, isEndpoint, postfixWithEndpointName} from '../lib/utils'; const e = exposes.presets; const ea = exposes.access;