Retrieve default ep from mapping. #1662

This commit is contained in:
Koenkk
2019-06-25 19:13:59 +02:00
parent 362b910e48
commit 5a132ad34b
3 changed files with 63 additions and 0 deletions
+3
View File
@@ -68,6 +68,9 @@ function getEndpointByEntityID(zigbee, entityID, epName) {
logger.error(`Device ${mappedDevice.model} doesn't have ep named '${epName}'`);
return;
}
} else if (mappedDevice.hasOwnProperty('ep')) {
const eps = mappedDevice.ep(device);
epID = eps[''] || null;
}
const endpoint = zigbee.getEndpoint(entityID, epID);
+19
View File
@@ -28,6 +28,11 @@ const devices = {
return {inClusterList: [5, 6]};
},
},
occupancy_sensor: {
getSimpleDesc: () => {
return {outClusterList: [5, 6]};
},
},
};
const zigbee = {
@@ -46,12 +51,15 @@ const zigbee = {
return devices.switch_ep2;
} else if (ep == 3 && ID === 'switch_ep3') {
return devices.switch_ep3;
} else if (ep == 2 && ID == 'occupancy_sensor') {
return devices.occupancy_sensor;
}
throw new Error(`No mock for ${ID} and ep ${ep}`);
},
getDevice: (ID) => {
const lookup = {
'occupancy_sensor': 'SML002',
'switch_ep2': 'lumi.sensor_86sw2.es1',
'switch_ep3': 'DNCKAT_S003',
'bulb': 'TRADFRI bulb E27 WS opal 980lm',
@@ -154,6 +162,17 @@ describe('DeviceBind', () => {
expect.any(Function)
);
});
it('Bind default ep when mapped', async () => {
deviceBind.onMQTTMessage('zigbee2mqtt/bridge/bind/occupancy_sensor', 'bulb');
expect(zigbee.bind).toHaveBeenCalledTimes(1);
expect(zigbee.bind).toHaveBeenNthCalledWith(1,
devices.occupancy_sensor,
6,
devices.bulb,
expect.any(Function)
);
});
});
describe('Unbind devices', () => {
+41
View File
@@ -34,4 +34,45 @@ describe('Utils', () => {
expect('EndDevice').toBe(utils.correctDeviceType(device));
});
});
describe('Get endpoint by id', () => {
it('Pick default ep', () => {
const zigbee = {
getDevice: (entityID) => {
return {modelId: 'TRADFRI on/off switch'};
},
getEndpoint: (entityID, epId) => {
return {epId: epId == null ? 1 : 0};
},
};
const endpoint = utils.getEndpointByEntityID(zigbee, '0x12345678', null);
expect(endpoint.epId).toBe(1);
});
it('Pick default ep from mapping when default defined', () => {
const zigbee = {
getDevice: (entityID) => {
return {modelId: 'SML002'};
},
getEndpoint: (entityID, epId) => {
return {epId};
},
};
const endpoint = utils.getEndpointByEntityID(zigbee, '0x12345678', null);
expect(endpoint.epId).toBe(2);
});
it('Pick default ep from mapping when not defined', () => {
const zigbee = {
getDevice: (entityID) => {
return {modelId: 'lumi.sensor_86sw2.es1'};
},
getEndpoint: (entityID, epId) => {
return {epId: epId == null ? 1 : 0};
},
};
const endpoint = utils.getEndpointByEntityID(zigbee, '0x12345678', null);
expect(endpoint.epId).toBe(1);
});
});
});