Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved devicePublish topic parsing #1373

Merged
merged 5 commits into from
Apr 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added more testing of attribute
  • Loading branch information
Zagitta committed Apr 4, 2019
commit 5f7d7e5583d2e15059ba337c0de06d33304957c8
30 changes: 30 additions & 0 deletions test/devicePublish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('my_device_id');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse get topic', () => {
Expand All @@ -733,6 +734,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('get');
expect(parsed.ID).toBe('my_device_id2');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});


Expand Down Expand Up @@ -768,6 +770,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('get');
expect(parsed.ID).toBe('my_device_id2');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse topic with when deviceID has multiple slashes', () => {
Expand All @@ -776,6 +779,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('floor0/basement/my_device_id2');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse topic with when base and deviceID have multiple slashes', () => {
Expand All @@ -790,15 +794,26 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('floor0/basement/my_device_id2');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
}
);

it('Should parse set with attribute topic', () => {
const topic = 'zigbee2mqtt/0x12345689/set/foobar';
const parsed = devicePublish.parseTopic(topic);
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBe('foobar');
});

it('Should parse set with ieeAddr topic', () => {
const topic = 'zigbee2mqtt/0x12345689/set';
const parsed = devicePublish.parseTopic(topic);
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse set with postfix topic', () => {
Expand All @@ -807,6 +822,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689');
expect(parsed.postfix).toBe('left');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse set with almost postfix topic', () => {
Expand All @@ -815,6 +831,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('wohnzimmer.light.wall.right');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse set with postfix topic', () => {
Expand All @@ -823,6 +840,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689');
expect(parsed.postfix).toBe('right');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse set with postfix topic', () => {
Expand All @@ -831,6 +849,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689');
expect(parsed.postfix).toBe('bottom_left');
expect(parsed.attribute).toBeUndefined();
});

it('Shouldnt parse set with invalid postfix topic', () => {
Expand All @@ -839,6 +858,16 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689/invalid');
expect(parsed.postfix).toBe('');
expect(parsed.attribute).toBeUndefined();
});

it('Should parse set with postfix topic and attribute', () => {
const topic = 'zigbee2mqtt/0x12345689/bottom_left/set/foobar';
const parsed = devicePublish.parseTopic(topic);
expect(parsed.type).toBe('set');
expect(parsed.ID).toBe('0x12345689');
expect(parsed.postfix).toBe('bottom_left');
expect(parsed.attribute).toBe('foobar');
});

it('Should parse set with and slashes in base and deviceID postfix topic', () => {
Expand All @@ -853,6 +882,7 @@ describe('DevicePublish', () => {
expect(parsed.type).toBe('get');
expect(parsed.ID).toBe('my/device/in/basement/sensor');
expect(parsed.postfix).toBe('bottom_left');
expect(parsed.attribute).toBeUndefined();
}
);
});
Expand Down