From 2d3a5d1d25f45360e253946d26f4e8b95ea75e26 Mon Sep 17 00:00:00 2001 From: slugzero <2014249+slugzero@users.noreply.github.com> Date: Sat, 20 Jan 2024 08:36:50 +0100 Subject: [PATCH] fix: Remove deprecated `options.sendWhen` (#879) --- src/controller/model/endpoint.ts | 15 +-------------- src/controller/tstype.ts | 3 +-- test/controller.test.ts | 11 +---------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/controller/model/endpoint.ts b/src/controller/model/endpoint.ts index d314436381..93e87479ba 100644 --- a/src/controller/model/endpoint.ts +++ b/src/controller/model/endpoint.ts @@ -1,5 +1,5 @@ import Entity from './entity'; -import {KeyValue, SendRequestWhen, SendPolicy} from '../tstype'; +import {KeyValue, SendPolicy} from '../tstype'; import * as Zcl from '../../zcl'; import ZclTransactionSequenceNumber from '../helpers/zclTransactionSequenceNumber'; import * as ZclFrameConverter from '../helpers/zclFrameConverter'; @@ -34,7 +34,6 @@ interface Options { transactionSequenceNumber?: number; disableRecovery?: boolean; writeUndiv?: boolean; - sendWhen?: SendRequestWhen; sendPolicy?: SendPolicy; } @@ -277,17 +276,6 @@ class Endpoint extends Entity { options.disableResponse, options.disableRecovery, options.srcEndpoint) as Promise; }): Promise { const logPrefix = `Request Queue (${this.deviceIeeeAddress}/${this.ID}): `; - - if(options.sendWhen) { - if ((options.sendWhen === 'immediate') && (this.getDevice().pendingRequestTimeout > 0)) { - debug.info (logPrefix - + "sendWhen is deprecated. Interpreting sendwhen='immediate' as sendPolicy='immediate'"); - options.sendPolicy = 'immediate'; - } else { - debug.info (logPrefix + "sendWhen is deprecated and will be ignored."); - } - } - const request = new Request(func, frame, this.getDevice().pendingRequestTimeout, options.sendPolicy); if (request.sendPolicy !== 'bulk') { @@ -830,7 +818,6 @@ class Endpoint extends Entity { ): Options { const providedOptions = options || {}; return { - sendWhen: undefined, timeout: 10000, disableResponse: false, disableRecovery: false, diff --git a/src/controller/tstype.ts b/src/controller/tstype.ts index 7b00673abe..b1b01f8bb2 100644 --- a/src/controller/tstype.ts +++ b/src/controller/tstype.ts @@ -18,7 +18,6 @@ interface KeyValue {[s: string]: any}; set of command IDs. */ type SendPolicy = 'bulk' | 'queue' | 'immediate' | 'keep-payload' | 'keep-command' | 'keep-cmd-undiv'; -type SendRequestWhen = 'immediate' | 'fastpoll' | 'active'; type DeviceType = 'Coordinator' | 'Router' | 'EndDevice' | 'Unknown' | 'GreenPower'; type EntityType = DeviceType | 'Group'; @@ -42,5 +41,5 @@ interface GreenPowerDeviceJoinedPayload { export { KeyValue, DatabaseEntry, EntityType, DeviceType, GreenPowerEvents, GreenPowerDeviceJoinedPayload, - SendRequestWhen, SendPolicy + SendPolicy }; \ No newline at end of file diff --git a/test/controller.test.ts b/test/controller.test.ts index 47b09165d6..82d0c6492c 100755 --- a/test/controller.test.ts +++ b/test/controller.test.ts @@ -4599,15 +4599,6 @@ describe('Controller', () => { } expect(mocksendZclFrameToEndpoint).toHaveBeenCalledTimes(1); expect(endpoint.pendingRequests.size).toStrictEqual(1); - - // sendWhen=immediate should be interpreted as sendPolicy=immediate and treated the same way - try { - await endpoint.write('genOnOff', {onOff: 1}, {disableResponse: true, sendWhen: 'immediate'}); - } catch (error) { - expect(error.message).toStrictEqual(`Write 0x129/1 genOnOff({"onOff":1}, {"sendWhen":"immediate","timeout":10000,"disableResponse":true,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Cats barking too hard)`); - } - expect(mocksendZclFrameToEndpoint).toHaveBeenCalledTimes(2); - expect(endpoint.pendingRequests.size).toStrictEqual(1); }); @@ -4834,7 +4825,7 @@ describe('Controller', () => { }; endpoint.pendingRequests.add(new Request(async () => {}, [], 100)); - const result = endpoint.write('genOnOff', {onOff: 10}, {disableResponse: true, sendWhen: 'active'}); + const result = endpoint.write('genOnOff', {onOff: 10}, {disableResponse: true}); expect(mocksendZclFrameToEndpoint).toHaveBeenCalledTimes(1); Date.now.mockReturnValue(1001000);