From dcb75b19d32b671eede77e68b92f80ba0ec19a49 Mon Sep 17 00:00:00 2001 From: Koenkk Date: Mon, 19 Nov 2018 20:29:35 +0100 Subject: [PATCH] Default postfix to empty string. https://github.com/Koenkk/zigbee2mqtt/issues/593 --- lib/extension/devicePublish.js | 2 +- test/devicePublish.test.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/extension/devicePublish.js b/lib/extension/devicePublish.js index cfd721ed..80024b33 100644 --- a/lib/extension/devicePublish.js +++ b/lib/extension/devicePublish.js @@ -53,7 +53,7 @@ class DevicePublish { topic = topic.replace(`/${type}`, ''); // Check if we have to deal with a postfix. - let postfix = null; + let postfix = ''; if (postfixes.find((p) => topic.endsWith(p))) { postfix = topic.substr(topic.lastIndexOf('/') + 1, topic.length); diff --git a/test/devicePublish.test.js b/test/devicePublish.test.js index 5c5ca5dc..1c771ca5 100644 --- a/test/devicePublish.test.js +++ b/test/devicePublish.test.js @@ -50,7 +50,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'set'); chai.assert.strictEqual(parsed.deviceID, 'my_device_id'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); }); it('Should parse get topic', () => { @@ -58,7 +58,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'get'); chai.assert.strictEqual(parsed.deviceID, 'my_device_id2'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); }); it('Should parse topic with when base topic has multiple slashes', () => { @@ -74,7 +74,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'get'); chai.assert.strictEqual(parsed.deviceID, 'my_device_id2'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); stub.restore(); }); @@ -83,7 +83,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'set'); chai.assert.strictEqual(parsed.deviceID, 'floor0/basement/my_device_id2'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); }); it('Should parse topic with when base and deviceID have multiple slashes', () => { @@ -99,7 +99,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'set'); chai.assert.strictEqual(parsed.deviceID, 'floor0/basement/my_device_id2'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); stub.restore(); }); @@ -108,7 +108,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'set'); chai.assert.strictEqual(parsed.deviceID, '0x12345689'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); }); it('Should parse set with postfix topic', () => { @@ -140,7 +140,7 @@ describe('DevicePublish', () => { const parsed = devicePublish.parseTopic(topic); chai.assert.strictEqual(parsed.type, 'set'); chai.assert.strictEqual(parsed.deviceID, '0x12345689/invalid'); - chai.assert.strictEqual(parsed.postfix, null); + chai.assert.strictEqual(parsed.postfix, ''); }); it('Should parse set with and slashes in base and deviceID postfix topic', () => {