Skip to content

Commit

Permalink
fix: Remove deprecated options.sendWhen (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
slugzero authored Jan 20, 2024
1 parent 25bfae6 commit 2d3a5d1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
15 changes: 1 addition & 14 deletions src/controller/model/endpoint.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,7 +34,6 @@ interface Options {
transactionSequenceNumber?: number;
disableRecovery?: boolean;
writeUndiv?: boolean;
sendWhen?: SendRequestWhen;
sendPolicy?: SendPolicy;
}

Expand Down Expand Up @@ -277,17 +276,6 @@ class Endpoint extends Entity {
options.disableResponse, options.disableRecovery, options.srcEndpoint) as Promise<Type>;
}): Promise<Type> {
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') {
Expand Down Expand Up @@ -830,7 +818,6 @@ class Endpoint extends Entity {
): Options {
const providedOptions = options || {};
return {
sendWhen: undefined,
timeout: 10000,
disableResponse: false,
disableRecovery: false,
Expand Down
3 changes: 1 addition & 2 deletions src/controller/tstype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -42,5 +41,5 @@ interface GreenPowerDeviceJoinedPayload {

export {
KeyValue, DatabaseEntry, EntityType, DeviceType, GreenPowerEvents, GreenPowerDeviceJoinedPayload,
SendRequestWhen, SendPolicy
SendPolicy
};
11 changes: 1 addition & 10 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2d3a5d1

Please sign in to comment.