From 70a40ac79e71a3b118cba5dbc92d2b0d39faabb1 Mon Sep 17 00:00:00 2001 From: Ivan Martinez Date: Tue, 1 Oct 2024 07:08:16 -0300 Subject: [PATCH] remove description support --- lib/extension/receive.ts | 5 +-- test/receive.test.js | 77 +------------------------------------ test/stub/zigbeeHerdsman.js | 5 +-- 3 files changed, 6 insertions(+), 81 deletions(-) diff --git a/lib/extension/receive.ts b/lib/extension/receive.ts index 038c84d488..2d8dc23a3a 100755 --- a/lib/extension/receive.ts +++ b/lib/extension/receive.ts @@ -149,9 +149,8 @@ export default class Receive extends Extension { // Check if we have to debounce or throttle if (data.device.options.debounce) { this.publishDebounce(data.device, payload, data.device.options.debounce, data.device.options.debounce_ignore); - } else if (data.device.options.throttle || (data.device.options.description && data.device.options.description.includes('SPAMMER'))) { - const throttleTime = data.device.options.throttle || 30; - await this.publishThrottle(data.device, payload, throttleTime); + } else if (data.device.options.throttle) { + await this.publishThrottle(data.device, payload, data.device.options.throttle); } else { await this.publishEntityState(data.device, payload); } diff --git a/test/receive.test.js b/test/receive.test.js index 522cde95bc..2064aaa10a 100755 --- a/test/receive.test.js +++ b/test/receive.test.js @@ -355,8 +355,8 @@ describe('Receive', () => { expect(JSON.parse(MQTT.publish.mock.calls[2][1])).toStrictEqual({temperature: 0.09, humidity: 0.01, pressure: 2}); }); - it('Should ignore multiple messages from spamming devices', async () => { - const device = zigbeeHerdsman.devices.SPAMMER1; + it('Should throttle multiple messages from spamming devices', async () => { + const device = zigbeeHerdsman.devices.SPAMMER; const throttle_for_testing = 1; settings.set(['device_options', 'throttle'], throttle_for_testing); settings.set(['device_options', 'retain'], true); @@ -428,79 +428,6 @@ describe('Receive', () => { expect(MQTT.publish.mock.calls[2][2]).toStrictEqual({qos: 0, retain: true}); }); - it('Should ignore multiple messages from spamming devices defined by description', async () => { - const device = zigbeeHerdsman.devices.SPAMMER2; - const throttle_for_testing = 50; - settings.set(['device_options', 'retain'], true); - settings.set(['devices', device.ieeeAddr, 'description'], 'this is a SPAMMER device'); - settings.set(['devices', device.ieeeAddr, 'friendly_name'], 'spammer2'); - const data1 = {measuredValue: 1}; - const payload1 = { - data: data1, - cluster: 'msTemperatureMeasurement', - device, - endpoint: device.getEndpoint(1), - type: 'attributeReport', - linkquality: 10, - }; - await zigbeeHerdsman.events.message(payload1); - const data2 = {measuredValue: 2}; - const payload2 = { - data: data2, - cluster: 'msTemperatureMeasurement', - device, - endpoint: device.getEndpoint(1), - type: 'attributeReport', - linkquality: 10, - }; - await zigbeeHerdsman.events.message(payload2); - const data3 = {measuredValue: 3}; - const payload3 = { - data: data3, - cluster: 'msTemperatureMeasurement', - device, - endpoint: device.getEndpoint(1), - type: 'attributeReport', - linkquality: 10, - }; - await zigbeeHerdsman.events.message(payload3); - await flushPromises(); - - expect(MQTT.publish).toHaveBeenCalledTimes(1); - await flushPromises(); - jest.advanceTimersByTime(throttle_for_testing * 1000); - expect(MQTT.publish).toHaveBeenCalledTimes(2); - - expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/spammer2'); - expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({temperature: 0.01}); - expect(MQTT.publish.mock.calls[0][2]).toStrictEqual({qos: 0, retain: true}); - - expect(MQTT.publish.mock.calls[1][0]).toStrictEqual('zigbee2mqtt/spammer2'); - expect(JSON.parse(MQTT.publish.mock.calls[1][1])).toStrictEqual({temperature: 0.03}); - expect(MQTT.publish.mock.calls[1][2]).toStrictEqual({qos: 0, retain: true}); - - // Now we try again after elapsed time to see if it publishes - const timeshift = throttle_for_testing * 2000; - jest.advanceTimersByTime(timeshift); - - const data4 = {measuredValue: 4}; - const payload4 = { - data: data4, - cluster: 'msTemperatureMeasurement', - device, - endpoint: device.getEndpoint(1), - type: 'attributeReport', - linkquality: 10, - }; - await zigbeeHerdsman.events.message(payload4); - await flushPromises(); - - expect(MQTT.publish).toHaveBeenCalledTimes(3); - expect(MQTT.publish.mock.calls[2][0]).toStrictEqual('zigbee2mqtt/spammer2'); - expect(JSON.parse(MQTT.publish.mock.calls[2][1])).toStrictEqual({temperature: 0.04}); - expect(MQTT.publish.mock.calls[2][2]).toStrictEqual({qos: 0, retain: true}); - }); - it('Shouldnt republish old state', async () => { // https://github.com/Koenkk/zigbee2mqtt/issues/3572 const device = zigbeeHerdsman.devices.bulb; diff --git a/test/stub/zigbeeHerdsman.js b/test/stub/zigbeeHerdsman.js index 366ae05db2..5cdfe3c563 100644 --- a/test/stub/zigbeeHerdsman.js +++ b/test/stub/zigbeeHerdsman.js @@ -503,9 +503,8 @@ const devices = { 'lumi.sensor_86sw2.es1', ), WSDCGQ11LM: new Device('EndDevice', '0x0017880104e45522', 6539, 4151, [new Endpoint(1, [0], [])], true, 'Battery', 'lumi.weather'), - // These are not a real spammer devices, just copy of previous to test the spam filter - SPAMMER1: new Device('EndDevice', '0x0017880104e455fe', 6539, 4151, [new Endpoint(1, [0], [])], true, 'Battery', 'lumi.weather'), - SPAMMER2: new Device('EndDevice', '0x0017880104e455ff', 6539, 4151, [new Endpoint(1, [0], [])], true, 'Battery', 'lumi.weather'), + // This are not a real spammer device, just copy of previous to test the throttle filter + SPAMMER: new Device('EndDevice', '0x0017880104e455fe', 6539, 4151, [new Endpoint(1, [0], [])], true, 'Battery', 'lumi.weather'), RTCGQ11LM: new Device('EndDevice', '0x0017880104e45523', 6540, 4151, [new Endpoint(1, [0], [])], true, 'Battery', 'lumi.sensor_motion.aq2'), ZNCZ02LM: ZNCZ02LM, E1743: new Device('Router', '0x0017880104e45540', 6540, 4476, [new Endpoint(1, [0], [])], true, 'Mains (single phase)', 'TRADFRI on/off switch'),