query groups through MQTT bridge/config/groups (#1276)

* query groups through MQTT bridge/config/groups

* linter adjustments

* linter adjustments
This commit is contained in:
Martin Helff
2019-03-19 19:18:22 +01:00
committed by Koen Kanters
parent 4cb0c0bbb0
commit 789ec0cc90
3 changed files with 30 additions and 0 deletions
+6
View File
@@ -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);
@@ -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,
@@ -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()}`;
+1
View File
@@ -289,6 +289,7 @@ module.exports = {
getDevice,
getGroup,
getGroups,
getDevices,
addDevice: (ieeeAddr) => addDevice(ieeeAddr),
removeDevice: (ieeeAddr) => removeDevice(ieeeAddr),
+23
View File
@@ -7,6 +7,7 @@ const configurationFile = data.joinPath('configuration.yaml');
const mqtt = {
subscribe: (topic) => {},
log: (type, message) => {},
};
describe('BridgeConfig', () => {
@@ -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');
});
});