Skip to content

Commit

Permalink
chore: Enforce no-floating-promises (or explicit disabling). (#896)
Browse files Browse the repository at this point in the history
* Enforce no-floating-promises (or explicit disabling).

* fix

---------

Co-authored-by: koenkk <[email protected]>
  • Loading branch information
Nerivec and Koenkk authored Feb 3, 2024
1 parent 8a477f2 commit 487996a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
"max-len": ["error", { "code": 150 }],
"no-return-await": "error",
"object-curly-spacing": ["error", "never"],
"@typescript-eslint/no-floating-promises": "error",
}
}
1 change: 1 addition & 0 deletions src/adapter/z-stack/adapter/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class ZnpAdapterManager {
*/
private async registerEndpoints(): Promise<void> {
const activeEpResponse = this.znp.waitFor(UnpiConstants.Type.AREQ, Subsystem.ZDO, 'activeEpRsp');
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.znp.request(Subsystem.ZDO, 'activeEpReq', {dstaddr: 0, nwkaddrofinterest: 0});
const activeEp = await activeEpResponse.start().promise;

Expand Down
1 change: 1 addition & 0 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ class ZStackAdapter extends Adapter {
// If a device announces multiple times in a very short time, it makes no sense
// to rediscover the route every time.
const debouncer = debounce(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.queue.execute<void>(async () => {
/* istanbul ignore next */
this.discoverRoute(payload.networkAddress, false).catch(() => {});
Expand Down
2 changes: 1 addition & 1 deletion src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ class Controller extends events.EventEmitter {


if (this.isZclDataPayload(dataPayload, dataType)) {
device.onZclData(dataPayload, endpoint);
await device.onZclData(dataPayload, endpoint);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/model/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,10 @@ class Device extends Entity {

await Entity.adapter.sendZclFrameToAll(242, frame, 242);
} else await Entity.adapter.removeDevice(this.networkAddress, this.ieeeAddr);
await this.removeFromDatabase();
this.removeFromDatabase();
}

public async removeFromDatabase(): Promise<void> {
public removeFromDatabase(): void {
Device.loadFromDatabaseIfNecessary();

for (const endpoint of this.endpoints) {
Expand Down
5 changes: 2 additions & 3 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ describe('Controller', () => {
linkquality: 52,
groupID: undefined,
});
await new Promise (process.nextTick);
await flushPromises();
expect(device._checkinInterval).toStrictEqual(51);
expect(device.pendingRequestTimeout).toStrictEqual(51000);
expect(mocksendZclFrameToEndpoint).toHaveBeenCalledTimes(3);
Expand Down Expand Up @@ -4870,7 +4870,6 @@ describe('Controller', () => {
await mockAdapterEvents['deviceJoined']({networkAddress: 174, ieeeAddr: '0x174'});
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
const device = controller.getDeviceByIeeeAddr('0x174');
const target = controller.getDeviceByIeeeAddr('0x129');
await device.interview();
const endpoint = device.getEndpoint(1);
mocksendZclFrameToEndpoint.mockClear();
Expand Down Expand Up @@ -4909,7 +4908,7 @@ describe('Controller', () => {
groupID: undefined,
});

expect(mocksendZclFrameToEndpoint).toHaveBeenCalledTimes(1);
expect(mocksendZclFrameToEndpoint).toHaveBeenCalledTimes(3);

const checkinrsp = mocksendZclFrameToEndpoint.mock.calls[0];
expect(checkinrsp[0]).toBe('0x174');
Expand Down

0 comments on commit 487996a

Please sign in to comment.