Skip to content

Commit

Permalink
Fix zigbee2mqtt.isUsed function (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Dec 16, 2022
1 parent fefb9cf commit 06d878e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/services/zigbee2mqtt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function Zigbee2mqttService(gladys, serviceId) {
* const used = await gladys.services.zigbee2mqtt.isUsed();
*/
async function isUsed() {
return zigbee2mqttManager.gladysConnected && zigbee2mqttManager.z2mEnabled;
return zigbee2mqttManager.gladysConnected && zigbee2mqttManager.zigbee2mqttConnected;
}

return Object.freeze({
Expand Down
15 changes: 13 additions & 2 deletions server/test/services/zigbee2mqtt/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const { assert, fake } = sinon;

const Zigbee2MqttService = require('../../../services/zigbee2mqtt');

const gladys = {};
const gladys = {
event: {
emit: fake.returns,
},
};

describe('zigbee2mqtt service', () => {
// PREPARE
Expand Down Expand Up @@ -35,8 +39,15 @@ describe('zigbee2mqtt service', () => {
assert.calledOnce(zigbee2MqttService.device.disconnect);
assert.notCalled(zigbee2MqttService.device.init);
});
it('should return if service is used', async () => {
it('isUsed: should return false, service not used', async () => {
const used = await zigbee2MqttService.isUsed();
expect(used).to.equal(false);
});
it('isUsed: should return true, service is used', async () => {
zigbee2MqttService.device.gladysConnected = true;
// handle one message so that zigbee2mqtt connected is true
await zigbee2MqttService.device.handleMqttMessage('zigbee2mqtt/bridge/devices', JSON.stringify([]));
const used = await zigbee2MqttService.isUsed();
expect(used).to.equal(true);
});
});

0 comments on commit 06d878e

Please sign in to comment.