Skip to content

Commit

Permalink
remove description support
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfmartinez committed Oct 1, 2024
1 parent b6ac7ac commit 70a40ac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 81 deletions.
5 changes: 2 additions & 3 deletions lib/extension/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
77 changes: 2 additions & 75 deletions test/receive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions test/stub/zigbeeHerdsman.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 70a40ac

Please sign in to comment.