Skip to content

Commit

Permalink
query groups through MQTT bridge/config/groups (Koenkk#1276)
Browse files Browse the repository at this point in the history
* query groups through MQTT bridge/config/groups

* linter adjustments

* linter adjustments
  • Loading branch information
mhelff authored and Koenkk committed Mar 19, 2019
1 parent fc1fdf5 commit 17fc03c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/extension/bridgeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BridgeConfig {
this.reset = this.reset.bind(this);
this.logLevel = this.logLevel.bind(this);
this.devices = this.devices.bind(this);
this.groups = this.groups.bind(this);
this.rename = this.rename.bind(this);
this.remove = this.remove.bind(this);
this.ban = this.ban.bind(this);
Expand All @@ -35,6 +36,7 @@ class BridgeConfig {
'reset': this.reset,
'log_level': this.logLevel,
'devices': this.devices,
'groups': this.groups,
'rename': this.rename,
'remove': this.remove,
'ban': this.ban,
Expand Down Expand Up @@ -141,6 +143,10 @@ class BridgeConfig {
this.mqtt.log('devices', devices);
}

groups(topic, message) {
this.mqtt.log('groups', settings.getGroups());
}

rename(topic, message) {
const invalid = `Invalid rename message format expected {old: 'friendly_name', new: 'new_name} ` +
`got ${message.toString()}`;
Expand Down
1 change: 1 addition & 0 deletions lib/util/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ module.exports = {

getDevice,
getGroup,
getGroups,
getDevices,
addDevice: (ieeeAddr) => addDevice(ieeeAddr),
removeDevice: (ieeeAddr) => removeDevice(ieeeAddr),
Expand Down
23 changes: 23 additions & 0 deletions test/bridgeConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const configurationFile = data.joinPath('configuration.yaml');

const mqtt = {
subscribe: (topic) => {},
log: (type, message) => {},
};

describe('BridgeConfig', () => {
Expand Down Expand Up @@ -114,4 +115,26 @@ describe('BridgeConfig', () => {

expect(read(configurationFile)).toStrictEqual(expected);
});

it('Get groups', async () => {
jest.spyOn(mqtt, 'log').mockImplementation((type, message) => {
expect(type).toBe('groups');
expect(Object.keys(message)).toHaveLength(2);
expect(message['1'].friendly_name).toBe('test1');
expect(message['4711'].friendly_name).toBe('test42');
});

write(configurationFile, {
groups: {
'1': {
friendly_name: 'test1',
},
'4711': {
friendly_name: 'test42',
},
},
});

bridgeConfig.onMQTTMessage('zigbee2mqtt/bridge/config/groups', 'whatever');
});
});

0 comments on commit 17fc03c

Please sign in to comment.