Skip to content

Commit

Permalink
feat: add ZWaveNode.createDump() method (#6906)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jun 7, 2024
1 parent 25c5cbb commit ef28407
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 10 deletions.
9 changes: 6 additions & 3 deletions packages/cc/src/lib/CommandClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,10 @@ export class CommandClass implements ICommandClass {
}

/** Returns a list of all value names that are defined for this CommandClass */
public getDefinedValueIDs(applHost: ZWaveApplicationHost): ValueID[] {
public getDefinedValueIDs(
applHost: ZWaveApplicationHost,
includeInternal: boolean = false,
): ValueID[] {
// In order to compare value ids, we need them to be strings
const ret = new Map<string, ValueID>();

Expand Down Expand Up @@ -844,7 +847,7 @@ export class CommandClass implements ICommandClass {
}

// Skip internal values
if (value.options.internal) continue;
if (value.options.internal && !includeInternal) continue;

// And determine if this value should be automatically "created"
if (!this.shouldAutoCreateValue(applHost, value)) continue;
Expand All @@ -864,7 +867,7 @@ export class CommandClass implements ICommandClass {
// ... which don't have a CC value definition
// ... or one that does not mark the value ID as internal
const ccValue = ccValues.find((value) => value.is(valueId));
if (!ccValue || !ccValue.options.internal) {
if (!ccValue || !ccValue.options.internal || includeInternal) {
addValueId(valueId.property, valueId.propertyKey);
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/security/SecurityClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export function securityClassIsS2(
);
}

/** Tests if the given security class is valid for use with Z-Wave LR */
export function securityClassIsLongRange(
secClass: SecurityClass | undefined,
): secClass is S2SecurityClass {
return (
secClass === SecurityClass.S2_AccessControl
|| secClass === SecurityClass.S2_Authenticated
);
}

/** An array of security classes, ordered from high (index 0) to low (index > 0) */
export const securityClassOrder = [
SecurityClass.S2_AccessControl,
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/values/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import type { ValueMetadata } from "./Metadata";
import type { ValueID } from "./_Types";

// export type SerializableValue = number | string | boolean | Map<string | number, any> | JSONObject;
type SerializedValue = number | string | boolean | JSONObject | undefined;
export type SerializedValue =
| number
| string
| boolean
| JSONObject
| undefined;

export interface CacheValue
extends Pick<ValueID, "endpoint" | "property" | "propertyKey">
Expand Down
79 changes: 79 additions & 0 deletions packages/zwave-js/src/lib/node/Dump.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type {
CommandClassInfo,
DataRate,
FLiRS,
SerializedValue,
ValueMetadata,
} from "@zwave-js/core/safe";
import { type JSONObject } from "@zwave-js/shared";

export interface DeviceClassDump {
key: number;
label: string;
}

export interface DeviceClassesDump {
basic: DeviceClassDump;
generic: DeviceClassDump;
specific: DeviceClassDump;
}

export interface CommandClassDump extends CommandClassInfo {
values: ValueDump[];
}

export interface ValueDump {
property: string | number;
propertyKey?: string | number;
metadata?: ValueMetadata;
value?: SerializedValue;
timestamp?: string;
internal?: boolean;
}

export interface EndpointDump {
index: number;
deviceClass: DeviceClassesDump | "unknown";
maySupportBasicCC: boolean;
commandClasses: Record<string, CommandClassDump>;
}

export interface NodeDump {
id: number;
manufacturer?: string;
label?: string;
description?: string;
fingerprint: {
// Hex representation:
manufacturerId: string;
productType: string;
productId: string;
firmwareVersion: string;
hardwareVersion?: number;
};
interviewStage: string;
ready: boolean;

dsk?: string;
securityClasses: Record<string, boolean | "unknown">;

isListening: boolean | "unknown";
isFrequentListening: FLiRS | "unknown";
isRouting: boolean | "unknown";
supportsBeaming: boolean | "unknown";
supportsSecurity: boolean | "unknown";
protocol: string;
supportedProtocols?: string[];
protocolVersion: string;
sdkVersion: string;
supportedDataRates: DataRate[] | "unknown";

deviceClass: DeviceClassesDump | "unknown";
maySupportBasicCC: boolean;
commandClasses: Record<string, CommandClassDump>;

endpoints?: Record<number, EndpointDump>;

configFileName?: string;
compatFlags?: JSONObject;
}
42 changes: 42 additions & 0 deletions packages/zwave-js/src/lib/node/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { isDeepStrictEqual } from "node:util";
import type { Driver } from "../driver/Driver";
import { cacheKeys } from "../driver/NetworkCache";
import type { DeviceClass } from "./DeviceClass";
import type { EndpointDump } from "./Dump";
import type { ZWaveNode } from "./Node";

/**
Expand Down Expand Up @@ -487,4 +488,45 @@ export class Endpoint implements IZWaveEndpoint {
ZWavePlusCCValues.userIcon.endpoint(this.index),
);
}

/**
* @internal
* Returns a dump of this endpoint's information for debugging purposes
*/
public createEndpointDump(): EndpointDump {
const ret: EndpointDump = {
index: this.index,
deviceClass: "unknown",
commandClasses: {},
maySupportBasicCC: this.maySupportBasicCC(),
};

if (this.deviceClass) {
ret.deviceClass = {
basic: {
key: this.deviceClass.basic.key,
label: this.deviceClass.basic.label,
},
generic: {
key: this.deviceClass.generic.key,
label: this.deviceClass.generic.label,
},
specific: {
key: this.deviceClass.specific.key,
label: this.deviceClass.specific.label,
},
};
}

for (const [ccId, info] of this._implementedCommandClasses) {
ret.commandClasses[getCCName(ccId)] = { ...info, values: [] };
}

for (const [prop, value] of Object.entries(ret)) {
// @ts-expect-error
if (value === undefined) delete ret[prop];
}

return ret;
}
}
Loading

0 comments on commit ef28407

Please sign in to comment.