Skip to content

Commit

Permalink
fix: a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 21, 2024
1 parent 678c476 commit 1d92664
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 181 deletions.
4 changes: 2 additions & 2 deletions packages/cc/src/cc/SecurityCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ export class SecurityCCNetworkKeySet extends SecurityCC {

// @publicAPI
export interface SecurityCCCommandsSupportedReportOptions {
reportsToFollow: number;
reportsToFollow?: number;
supportedCCs: CommandClasses[];
controlledCCs: CommandClasses[];
}
Expand All @@ -1014,7 +1014,7 @@ export class SecurityCCCommandsSupportedReport extends SecurityCC {
this.supportedCCs = options.supportedCCs;
this.controlledCCs = options.controlledCCs;
// TODO: properly split the CCs into multiple reports
this.reportsToFollow = 0;
this.reportsToFollow = options.reportsToFollow ?? 0;
}

public static from(
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/lib/CommandClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class CommandClass implements CCId {
// FIXME: Propagate frame type etc.
// FIXME: Refactor subclasses' parse() to override this
return new this({
nodeId: ctx.ownNodeId,
nodeId: ctx.sourceNodeId,
ccId: raw.ccId,
ccCommand: raw.ccCommand,
payload: raw.payload,
Expand Down Expand Up @@ -558,7 +558,7 @@ export class CommandClass implements CCId {
if (Constructor) {
return new Constructor({
nodeId: endpoint.nodeId,
endpoint: endpoint.index,
endpointIndex: endpoint.index,
}) as T;
}
}
Expand Down
18 changes: 17 additions & 1 deletion packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,23 @@ export class Driver extends TypedEventEmitter<DriverEventCallbacks>
},
};
this.messageEncodingContext = {
...this.messageParsingContext,
getHighestSecurityClass: (nodeId) =>
this.getHighestSecurityClass(nodeId),
hasSecurityClass: (nodeId, securityClass) =>
this.hasSecurityClass(nodeId, securityClass),
setSecurityClass: (nodeId, securityClass, granted) =>
this.setSecurityClass(nodeId, securityClass, granted),
getDeviceConfig: (nodeId) => this.getDeviceConfig(nodeId),
// These are evaluated lazily, so we cannot spread messageParsingContext unfortunately
get securityManager() {
return self.securityManager;
},
get securityManager2() {
return self.securityManager2;
},
get securityManagerLR() {
return self.securityManagerLR;
},
getSupportedCCVersion: (cc, nodeId, endpointIndex) =>
this.getSupportedCCVersion(cc, nodeId, endpointIndex),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ integrationTest(
});
cc = new MultiChannelCCCommandEncapsulation({
nodeId: mockController.ownNodeId,
endpoint: 1,
endpointIndex: 1,
destination: 0,
encapsulated: cc,
});
Expand All @@ -64,7 +64,7 @@ integrationTest(
});
cc = new MultiChannelCCCommandEncapsulation({
nodeId: mockController.ownNodeId,
endpoint: 1,
endpointIndex: 1,
destination: 0,
encapsulated: cc,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/src/lib/test/cc/BasicCC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test("deserializing an unsupported command should return an unspecified version
t.is(basicCC.constructor, BasicCC);
});

test.only("getDefinedValueIDs() should include the target value for all endpoints except the node itself", (t) => {
test("getDefinedValueIDs() should include the target value for all endpoints except the node itself", (t) => {
// Repro for GH#377
const commandClasses: CreateTestNodeOptions["commandClasses"] = {
[CommandClasses.Basic]: {
Expand Down
48 changes: 23 additions & 25 deletions packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CommandClass,
HumidityControlMode,
HumidityControlModeCCGet,
HumidityControlModeCCReport,
Expand Down Expand Up @@ -57,11 +58,11 @@ test("the Report command should be deserialized correctly", (t) => {
HumidityControlMode.Auto, // current value
]),
);
const cc = new HumidityControlModeCCReport({
nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlModeCCReport;
t.is(cc.constructor, HumidityControlModeCCReport);

t.is(cc.mode, HumidityControlMode.Auto);
});
Expand All @@ -73,11 +74,10 @@ test("the Report command should set the correct value", (t) => {
HumidityControlMode.Auto, // current value
]),
);
const report = new HumidityControlModeCCReport({
nodeId,
data: ccData,
context: {} as any,
});
const report = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlModeCCReport;
report.persistValues(host);

const currentValue = host.getValueDB(nodeId).getValue({
Expand All @@ -94,11 +94,10 @@ test("the Report command should set the correct metadata", (t) => {
HumidityControlMode.Auto, // current value
]),
);
const cc = new HumidityControlModeCCReport({
nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlModeCCReport;
cc.persistValues(host);

const currentValueMeta = host
Expand Down Expand Up @@ -130,11 +129,11 @@ test("the SupportedReport command should be deserialized correctly", (t) => {
(1 << HumidityControlMode.Off) | (1 << HumidityControlMode.Auto),
]),
);
const cc = new HumidityControlModeCCSupportedReport({
nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlModeCCSupportedReport;
t.is(cc.constructor, HumidityControlModeCCSupportedReport);

t.deepEqual(cc.supportedModes, [
HumidityControlMode.Off,
Expand All @@ -149,11 +148,10 @@ test("the SupportedReport command should set the correct metadata", (t) => {
(1 << HumidityControlMode.Off) | (1 << HumidityControlMode.Auto),
]),
);
const cc = new HumidityControlModeCCSupportedReport({
nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlModeCCSupportedReport;
cc.persistValues(host);

const currentValueMeta = host
Expand Down
77 changes: 37 additions & 40 deletions packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CommandClass,
HumidityControlSetpointCCCapabilitiesGet,
HumidityControlSetpointCCCapabilitiesReport,
HumidityControlSetpointCCGet,
Expand Down Expand Up @@ -70,11 +71,11 @@ test("the Report command should be deserialized correctly", (t) => {
encodeFloatWithScale(12, 1),
]),
);
const cc = new HumidityControlSetpointCCReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCReport;
t.is(cc.constructor, HumidityControlSetpointCCReport);

t.deepEqual(cc.type, HumidityControlSetpointType.Humidifier);
t.is(cc.scale, 1);
Expand All @@ -96,11 +97,10 @@ test("the Report command should set the correct value", (t) => {
encodeFloatWithScale(12, 1),
]),
);
const report = new HumidityControlSetpointCCReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const report = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCReport;
report.persistValues(host);

const currentValue = host.getValueDB(nodeId).getValue({
Expand Down Expand Up @@ -128,11 +128,10 @@ test("the Report command should set the correct metadata", (t) => {
encodeFloatWithScale(12, 1),
]),
);
const report = new HumidityControlSetpointCCReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const report = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCReport;
report.persistValues(host);

const setpointMeta = host.getValueDB(nodeId).getMetadata({
Expand Down Expand Up @@ -168,11 +167,11 @@ test("the SupportedReport command should be deserialized correctly", (t) => {
| (1 << HumidityControlSetpointType.Auto),
]),
);
const cc = new HumidityControlSetpointCCSupportedReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCSupportedReport;
t.is(cc.constructor, HumidityControlSetpointCCSupportedReport);

t.deepEqual(cc.supportedSetpointTypes, [
HumidityControlSetpointType.Humidifier,
Expand All @@ -188,11 +187,10 @@ test("the SupportedReport command should set the correct value", (t) => {
| (1 << HumidityControlSetpointType.Auto),
]),
);
const report = new HumidityControlSetpointCCSupportedReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const report = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCSupportedReport;
report.persistValues(host);

const currentValue = host.getValueDB(nodeId).getValue({
Expand Down Expand Up @@ -226,11 +224,11 @@ test("the ScaleSupportedReport command should be deserialized correctly", (t) =>
0b11, // percent + absolute
]),
);
const cc = new HumidityControlSetpointCCScaleSupportedReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCScaleSupportedReport;
t.is(cc.constructor, HumidityControlSetpointCCScaleSupportedReport);

t.deepEqual(cc.supportedScales, [0, 1]);
// new Scale(0, {
Expand Down Expand Up @@ -269,11 +267,11 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => {
encodeFloatWithScale(90, 1),
]),
);
const cc = new HumidityControlSetpointCCCapabilitiesReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const cc = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCCapabilitiesReport;
t.is(cc.constructor, HumidityControlSetpointCCCapabilitiesReport);

t.deepEqual(cc.type, HumidityControlSetpointType.Humidifier);
t.deepEqual(cc.minValue, 10);
Expand All @@ -293,11 +291,10 @@ test("the CapabilitiesReport command should set the correct metadata", (t) => {
encodeFloatWithScale(90, 1),
]),
);
const report = new HumidityControlSetpointCCCapabilitiesReport({
nodeId: nodeId,
data: ccData,
context: {} as any,
});
const report = CommandClass.parse(
ccData,
{ sourceNodeId: nodeId } as any,
) as HumidityControlSetpointCCCapabilitiesReport;
report.persistValues(host);

const setpointMeta = host.getValueDB(nodeId).getMetadata({
Expand Down
4 changes: 2 additions & 2 deletions packages/zwave-js/src/lib/test/cc/MeterCC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ test("the Report command should validate that a known meter type is given", (t)
ccData,
{ sourceNodeId: 1 } as any,
) as MeterCCReport;
t.is(cc.constructor, MeterCCReport);
t.is(report.constructor, MeterCCReport);

// Meter type 31 (does not exist)
assertZWaveError(t, () => report.persistValues(host), {
Expand All @@ -299,7 +299,7 @@ test("the Report command should validate that a known meter scale is given", (t)
ccData,
{ sourceNodeId: 1 } as any,
) as MeterCCReport;
t.is(cc.constructor, MeterCCReport);
t.is(report.constructor, MeterCCReport);

// Meter type 4, Scale 8 (does not exist)
assertZWaveError(t, () => report.persistValues(host), {
Expand Down
Loading

0 comments on commit 1d92664

Please sign in to comment.