Skip to content

Commit 0769495

Browse files
ptvoinfoptvoinfo
and
ptvoinfo
authored
fix: PTVO converters: added rounding for pressure, humidity, illuminance. (#8746)
Co-authored-by: ptvoinfo <[email protected]>
1 parent f6c2922 commit 0769495

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/devices/custom_devices_diy.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as legacy from '../lib/legacy';
77
import * as m from '../lib/modernExtend';
88
import * as reporting from '../lib/reporting';
99
import {DefinitionWithExtend, Expose, Fz, KeyValue, KeyValueAny, Tz, Zh} from '../lib/types';
10-
import {getFromLookup, getKey, isEndpoint, postfixWithEndpointName} from '../lib/utils';
10+
import {calibrateAndPrecisionRoundOptions, getFromLookup, getKey, isEndpoint, postfixWithEndpointName} from '../lib/utils';
1111

1212
const e = exposes.presets;
1313
const ea = exposes.access;
@@ -70,7 +70,8 @@ const fzLocal = {
7070
type: ['attributeReport', 'readResponse'],
7171
convert: (model, msg, publish, options, meta) => {
7272
// multi-endpoint version based on the stastard onverter 'fz.humidity'
73-
const humidity = parseFloat(msg.data['measuredValue']) / 100.0;
73+
let humidity = parseFloat(msg.data['measuredValue']) / 100.0;
74+
humidity = calibrateAndPrecisionRoundOptions(humidity, options, 'humidity');
7475

7576
// https://github.com/Koenkk/zigbee2mqtt/issues/798
7677
// Sometimes the sensor publishes non-realistic vales, it should only publish message
@@ -88,7 +89,8 @@ const fzLocal = {
8889
convert: (model, msg, publish, options, meta) => {
8990
// multi-endpoint version based on the stastard onverter 'fz.illuminance'
9091
const illuminance = msg.data['measuredValue'];
91-
const illuminanceLux = illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000);
92+
let illuminanceLux = illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000);
93+
illuminanceLux = calibrateAndPrecisionRoundOptions(illuminanceLux, options, 'illuminance');
9294
const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint;
9395
const property1 = multiEndpoint ? postfixWithEndpointName('illuminance', msg, model, meta) : 'illuminance';
9496
return {[property1]: illuminanceLux};
@@ -106,6 +108,7 @@ const fzLocal = {
106108
} else {
107109
pressure = parseFloat(msg.data['measuredValue']);
108110
}
111+
pressure = calibrateAndPrecisionRoundOptions(pressure, options, 'pressure');
109112
const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint;
110113
const property = multiEndpoint ? postfixWithEndpointName('pressure', msg, model, meta) : 'pressure';
111114
return {[property]: pressure};

0 commit comments

Comments
 (0)