Skip to content

Commit

Permalink
fix: parsing of BridgeApplicationCommandRequest w/o RSSI (#4337)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Mar 8, 2022
1 parent a546be6 commit 4ba281c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ConfigManager } from "@zwave-js/config";
import "../commandclass/index";
import type { Driver } from "../driver/Driver";
import { Message } from "../message/Message";
import { createEmptyMockDriver } from "../test/mocks";

const fakeDriver = createEmptyMockDriver() as unknown as Driver;

describe("BridgeApplicationCommandRequest", () => {
beforeAll(async () => {
const configManager = new ConfigManager();
await configManager.loadMeters();
(fakeDriver as any).configManager = configManager;
(fakeDriver as any).controller = {
ownNodeId: 1,
nodes: {
get() {
return {
valueDB: {
hasMetadata: () => false,
setMetadata() {},
getMetadata() {},
setValue() {},
getValue() {},
},
isCCSecure: () => true,
getEndpoint() {},
};
},
},
};
});

describe("regression tests", () => {
it("parsing without RSSI", async () => {
// Repro for https://github.com/zwave-js/node-zwave-js/issues/4335
Message.from(
fakeDriver,
Buffer.from("011200a80001020a320221340000000000000069", "hex"),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
priority,
} from "../message/Message";
import { ApplicationCommandStatusFlags } from "./ApplicationCommandRequest";
import { parseRSSI, RSSI, RssiError } from "./SendDataShared";
import { RSSI, RssiError, tryParseRSSI } from "./SendDataShared";

@messageTypes(MessageType.Request, FunctionType.BridgeApplicationCommand)
// This does not expect a response. The controller sends us this when a node sends a command
Expand Down Expand Up @@ -78,7 +78,7 @@ export class BridgeApplicationCommandRequest
}
offset += multicastNodesLength;

this.rssi = parseRSSI(this.payload, offset);
this.rssi = tryParseRSSI(this.payload, offset);
}

public readonly routedBusy: boolean;
Expand All @@ -87,7 +87,7 @@ export class BridgeApplicationCommandRequest
public readonly isExploreFrame: boolean;
public readonly isForeignFrame: boolean;
public readonly fromForeignHomeId: boolean;
public readonly rssi: RSSI;
public readonly rssi?: RSSI;

// This needs to be writable or unwrapping MultiChannelCCs crashes
public command: SinglecastCC;
Expand All @@ -103,15 +103,17 @@ export class BridgeApplicationCommandRequest
? this.targetNodeId
: this.targetNodeId.join(", ");
}
switch (true) {
case this.rssi === RssiError.ReceiverSaturated:
case this.rssi === RssiError.NoSignalDetected:
message.RSSI = getEnumMemberName(RssiError, this.rssi);
break;
// case this.rssi < RSSI_RESERVED_START:
default:
message.RSSI = `${this.rssi} dBm`;
break;
if (this.rssi !== undefined) {
switch (true) {
case this.rssi === RssiError.ReceiverSaturated:
case this.rssi === RssiError.NoSignalDetected:
message.RSSI = getEnumMemberName(RssiError, this.rssi);
break;
// case this.rssi < RSSI_RESERVED_START:
default:
message.RSSI = `${this.rssi} dBm`;
break;
}
}
return {
...super.toLogEntry(),
Expand Down

0 comments on commit 4ba281c

Please sign in to comment.