Skip to content

Commit

Permalink
Prevent identification on zigbeeModel with undefined zigbeeModel. Koe…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Jul 22, 2020
1 parent 8278cf7 commit eaa0a3f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function findByDevice(device) {
const candidates = getFromLookup(device.modelID);
if (!candidates) {
return null;
} else if (candidates.length === 1) {
} else if (candidates.length === 1 && candidates[0].hasOwnProperty('zigbeeModel')) {
return candidates[0];
} else {
// Multiple candidates possible, first try to match based on fingerprint, return the first matching one.
Expand All @@ -93,6 +93,8 @@ function findByDevice(device) {
}
}
}

return null;
}

function fingerprintMatch(fingerprint, device) {
Expand Down
34 changes: 34 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('index.js', () => {
const device = {
type: 'Router',
manufacturerID: 4126,
modelID: undefined,
endpoints,
getEndpoint: (ID) => endpoints.find((e) => e.ID === ID),
};
Expand All @@ -58,6 +59,39 @@ describe('index.js', () => {
expect(definition.model).toBe('XBee');
});


it('Find device by using findDevice shoudlnt match when modelID is null and there is no fingerprint match', () => {
const endpoints = [
{ID: 1, profileID: undefined, deviceID: undefined, inputClusters: [], outputClusters: []},
];
const device = {
type: undefined,
manufacturerID: undefined,
modelID: undefined,
endpoints,
getEndpoint: (ID) => endpoints.find((e) => e.ID === ID),
};

const definition = index.findByDevice(device);
expect(definition).toBeNull();
});

it('Find device by using findDevice when device has modelID should match', () => {
const endpoints = [
{ID: 1, profileID: undefined, deviceID: undefined, inputClusters: [], outputClusters: []},
];
const device = {
type: undefined,
manufacturerID: undefined,
modelID: "lumi.sensor_motion",
endpoints,
getEndpoint: (ID) => endpoints.find((e) => e.ID === ID),
};

const definition = index.findByDevice(device);
expect(definition.model).toBe("RTCGQ01LM");
});

it('Find device by fingerprint prefer over zigbeeModel', () => {
const mullerEndpoints = [
{ID: 1, profileID: 49246, deviceID: 544, inputClusters: [0, 3, 4, 5, 6, 8, 768, 2821, 4096], outputClusters: [25]},
Expand Down

0 comments on commit eaa0a3f

Please sign in to comment.