diff --git a/lib/controller.js b/lib/controller.js index 37cc0bd19..395fb506d 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -286,6 +286,9 @@ class Controller { } // filter mqtt message attributes + if (deviceOptions.filtered_attributes) { + deviceOptions.filtered_attributes.forEach((a) => delete messagePayload[a]); + } if (entity.settings.filtered_attributes) { entity.settings.filtered_attributes.forEach((a) => delete messagePayload[a]); } diff --git a/test/controller.test.js b/test/controller.test.js index ea33c879c..24140becd 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -427,6 +427,19 @@ describe('Controller', () => { expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb", '{"state":"ON","brightness":200}', {"qos": 0, "retain": true}, expect.any(Function)); }); + it('Publish entity state attribute_json output filtered (device_options)', async () => { + await controller.start(); + settings.set(['experimental', 'output'], 'attribute_and_json'); + settings.set(['device_options', 'filtered_attributes'], ['color_temp', 'linkquality']); + MQTT.publish.mockClear(); + await controller.publishEntityState('bulb', {state: 'ON', brightness: 200, color_temp: 370, linkquality: 99}); + await flushPromises(); + expect(MQTT.publish).toHaveBeenCalledTimes(3); + expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb/state", "ON", {"qos": 0, "retain": true}, expect.any(Function)); + expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb/brightness", "200", {"qos": 0, "retain": true}, expect.any(Function)); + expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb", '{"state":"ON","brightness":200}', {"qos": 0, "retain": true}, expect.any(Function)); + }); + it('Publish entity state with device information', async () => { await controller.start(); settings.set(['mqtt', 'include_device_information'], true);