Skip to content

Commit

Permalink
Fix invalid match on zigbeeModel when device has fingerprint containi…
Browse files Browse the repository at this point in the history
…ng that zigbeeModel. #1449
  • Loading branch information
Koenkk committed Aug 7, 2020
1 parent 0036112 commit caff55b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function findByDevice(device) {

// Match based on fingerprint failed, return first matching definition based on zigbeeModel
for (const candidate of candidates) {
if (candidate.hasOwnProperty('zigbeeModel')) {
if (candidate.hasOwnProperty('zigbeeModel') && candidate.zigbeeModel.includes(device.modelID)) {
return candidate;
}
}
Expand Down
37 changes: 37 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,43 @@ describe('index.js', () => {
expect(index.findByDevice(muller).model).toBe('404031');
});

it('Find by device when fingerprint has zigbeeModel of other definition', () => {
// https://github.com/Koenkk/zigbee-herdsman-converters/issues/1449
const endpoints = [
{ID: 1, profileID: 260, deviceID: 1026, inputClusters: [0,3,1280,1], outputClusters: [3]},
];
const device = {
type: 'EndDevice',
manufacturerID: 0,
manufacturerName: 'eWeLink',
modelID: 'TH01',
powerSource: 'Battery',
endpoints: endpoints,
getEndpoint: (ID) => endpoints.find((e) => e.ID === ID),
};

const definition = index.findByDevice(device);
expect(definition.model).toBe("SNZB-04");
});

it('onlythis Find by device when fingerprint has zigbeeModel of other definition shouln\'t match when fingerprint doesn\t match', () => {
const endpoints = [
{ID: 1, profileID: 260, deviceID: 770, inputClusters: [0,3,1026,1029,1], outputClusters: [3]},
];
const device = {
type: 'EndDevice',
manufacturerID: 0,
manufacturerName: 'eWeLink',
modelID: 'TH01',
powerSource: 'Battery',
endpoints: endpoints,
getEndpoint: (ID) => endpoints.find((e) => e.ID === ID),
};

const definition = index.findByDevice(device);
expect(definition.model).toBe("SNZB-02");
});

it('Verify devices.js definitions', () => {
function verifyKeys(expected, actual, id) {
expected.forEach((key) => {
Expand Down

0 comments on commit caff55b

Please sign in to comment.