Skip to content

Commit

Permalink
feat(log): log frame type and rssi of (Bridge)ApplicationCommands (#1541
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AlCalzone authored Jan 30, 2021
1 parent 12b148f commit 78ebbda
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core";
import {
MessageOrCCLogEntry,
MessageRecord,
ZWaveError,
ZWaveErrorCodes,
} from "@zwave-js/core";
import { CommandClass, SinglecastCC } from "../commandclass/CommandClass";
import type { ICommandClassContainer } from "../commandclass/ICommandClassContainer";
import type { Driver } from "../driver/Driver";
Expand Down Expand Up @@ -132,4 +137,15 @@ export class ApplicationCommandRequest

return super.serialize();
}

public toLogEntry(): MessageOrCCLogEntry {
const message: MessageRecord = {};
if (this.frameType !== "singlecast") {
message.type = this.frameType;
}
return {
...super.toLogEntry(),
message,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NODE_ID_BROADCAST } from "@zwave-js/core";
import {
MessageOrCCLogEntry,
MessageRecord,
NODE_ID_BROADCAST,
} from "@zwave-js/core";
import { getEnumMemberName } from "@zwave-js/shared";
import { CommandClass, SinglecastCC } from "../commandclass/CommandClass";
import type { ICommandClassContainer } from "../commandclass/ICommandClassContainer";
import type { Driver } from "../driver/Driver";
Expand Down Expand Up @@ -99,4 +104,30 @@ export class BridgeApplicationCommandRequest

// This needs to be writable or unwrapping MultiChannelCCs crashes
public command: SinglecastCC;

public toLogEntry(): MessageOrCCLogEntry {
const message: MessageRecord = {};
if (this.frameType !== "singlecast") {
message.type = this.frameType;
}
if (this.targetNodeId !== this.driver.controller.ownNodeId) {
message["target node"] =
typeof this.targetNodeId === "number"
? this.targetNodeId
: this.targetNodeId.join(", ");
}
switch (true) {
case this.rssi === RSSIValue.ReceiverSaturated:
case this.rssi === RSSIValue.NoSignalDetected:
message.rssi = getEnumMemberName(RSSIValue, this.rssi);
break;
case this.rssi < RSSI_RESERVED_START:
message.rssi = `${this.rssi} dBms`;
break;
}
return {
...super.toLogEntry(),
message,
};
}
}

0 comments on commit 78ebbda

Please sign in to comment.