mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-02 01:51:38 +00:00
Default postfix to empty string. https://github.com/Koenkk/zigbee2mqtt/issues/593
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user