diff --git a/lib/extension/bind.js b/lib/extension/bind.js index 60cfbc73..04c26d54 100644 --- a/lib/extension/bind.js +++ b/lib/extension/bind.js @@ -146,6 +146,7 @@ class Bind extends Extension { async onMQTTMessage(topic, message) { const {type, sourceKey, targetKey, clusters} = this.parseMQTTMessage(topic, message); if (!type) return null; + message = utils.parseJSON(message, message); let error = null; const source = this.zigbee.resolveEntity(sourceKey); diff --git a/lib/extension/groups.js b/lib/extension/groups.js index 7b427454..8353f549 100644 --- a/lib/extension/groups.js +++ b/lib/extension/groups.js @@ -237,6 +237,7 @@ class Groups extends Extension { groupKey, deviceKey, } = this.parseMQTTMessage(topic, message); if (!type) return; + message = utils.parseJSON(message, message); const responseData = {device: deviceKey}; if (groupKey) { diff --git a/test/bind.test.js b/test/bind.test.js index 4c1e6079..368769e8 100644 --- a/test/bind.test.js +++ b/test/bind.test.js @@ -53,7 +53,7 @@ describe('Bind', () => { mockClear(device); target.configureReporting.mockImplementationOnce(() => {throw new Error("timeout")}); - MQTT.events.message('zigbee2mqtt/bridge/request/device/bind', stringify({from: 'remote', to: 'bulb_color'})); + MQTT.events.message('zigbee2mqtt/bridge/request/device/bind', stringify({transaction: "1234", from: 'remote', to: 'bulb_color'})); await flushPromises(); expect(target.read).toHaveBeenCalledWith('lightingColorCtrl', [ 'colorCapabilities' ]); expect(endpoint.bind).toHaveBeenCalledTimes(4); @@ -67,7 +67,7 @@ describe('Bind', () => { expect(target.configureReporting).toHaveBeenCalledWith("lightingColorCtrl",[{"attribute":"colorTemperature","minimumReportInterval":5,"maximumReportInterval":3600,"reportableChange":1},{"attribute":"currentX","minimumReportInterval":5,"maximumReportInterval":3600,"reportableChange":1},{"attribute":"currentY","minimumReportInterval":5,"maximumReportInterval":3600,"reportableChange":1}]); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/bridge/response/device/bind', - stringify({"data":{"from":"remote","to":"bulb_color","clusters":["genScenes","genOnOff","genLevelCtrl", "lightingColorCtrl"],"failed":[]},"status":"ok"}), + stringify({"transaction": "1234","data":{"from":"remote","to":"bulb_color","clusters":["genScenes","genOnOff","genLevelCtrl", "lightingColorCtrl"],"failed":[]},"status":"ok"}), {retain: false, qos: 0}, expect.any(Function) ); diff --git a/test/group.test.js b/test/group.test.js index dd0370c3..89b20c98 100644 --- a/test/group.test.js +++ b/test/group.test.js @@ -569,14 +569,14 @@ describe('Groups', () => { await controller.start(); await flushPromises(); MQTT.publish.mockClear(); - MQTT.events.message('zigbee2mqtt/bridge/request/group/members/add', stringify({group: 'group_1', device: 'bulb_color'})); + MQTT.events.message('zigbee2mqtt/bridge/request/group/members/add', stringify({transaction: "123", group: 'group_1', device: 'bulb_color'})); await flushPromises(); expect(group.members).toStrictEqual([endpoint]); expect(settings.getGroup('group_1').devices).toStrictEqual([`${device.ieeeAddr}/1`]); expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/bridge/groups', expect.any(String), expect.any(Object), expect.any(Function)); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/bridge/response/group/members/add', - stringify({"data":{"device":"bulb_color","group":"group_1"},"status":"ok"}), + stringify({"data":{"device":"bulb_color","group":"group_1"},"transaction": "123", "status":"ok"}), {retain: false, qos: 0}, expect.any(Function) ); });