Skip to content

Commit

Permalink
Fix incorrect options for some Xiaomi Aqara devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Feb 4, 2022
1 parent 0a46663 commit a562283
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions converters/fromZigbee.js
Expand Up @@ -5168,8 +5168,16 @@ const converters = {
aqara_opple: {
cluster: 'aqaraOpple',
type: ['attributeReport', 'readResponse'],
options: [exposes.options.precision('temperature'), exposes.options.calibration('temperature'),
exposes.options.precision('illuminance'), exposes.options.calibration('illuminance', 'percentual')],
options: (definition) => {
const result = [];
if (definition.exposes.find((e) => e.name === 'temperature')) {
result.push(exposes.options.precision('temperature'), exposes.options.calibration('temperature'));
}
if (definition.exposes.find((e) => e.name === 'illuminance')) {
result.push(exposes.options.precision('illuminance'), exposes.options.calibration('illuminance', 'percentual'));
}
return result;
},
convert: (model, msg, publish, options, meta) => {
const payload = {};
if (msg.data.hasOwnProperty('247')) {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -89,7 +89,8 @@ function addDefinition(definition) {
const optionKeys = definition.options.map((o) => o.name);
for (const converter of [...definition.toZigbee, ...definition.fromZigbee]) {
if (converter.options) {
for (const option of converter.options) {
const options = typeof converter.options === 'function' ? converter.options(definition) : converter.options;
for (const option of options) {
if (!optionKeys.includes(option.name)) {
definition.options.push(option);
optionKeys.push(option.name);
Expand Down
7 changes: 7 additions & 0 deletions test/index.test.js
Expand Up @@ -475,4 +475,11 @@ describe('index.js', () => {
}
});
});

it('Verify options filter', () => {
const ZNJLBL01LM = index.definitions.find((d) => d.model == 'ZNJLBL01LM');
expect(ZNJLBL01LM.options.length).toBe(1);
const ZNCZ04LM = index.definitions.find((d) => d.model == 'ZNCZ04LM');
expect(ZNCZ04LM.options.length).toBe(2);
});
});

0 comments on commit a562283

Please sign in to comment.