Skip to content

Commit

Permalink
fix: keep separate supervision session ID counters for each node
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Aug 16, 2023
1 parent 9d9407f commit aa5afbd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/cc/src/cc/SupervisionCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class SupervisionCCGet extends SupervisionCC {
origin: options.origin,
});
} else {
this.sessionId = host.getNextSupervisionSessionId();
this.sessionId = host.getNextSupervisionSessionId(this.nodeId);
this.requestStatusUpdates = options.requestStatusUpdates;
this.encapsulated = options.encapsulated;
options.encapsulated.encapsulatingCC = this as any;
Expand Down
2 changes: 1 addition & 1 deletion packages/host/src/ZWaveHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface ZWaveHost {
/**
* Returns the next session ID for supervised communication
*/
getNextSupervisionSessionId(): number;
getNextSupervisionSessionId(nodeId: number): number;

getDeviceConfig?: (nodeId: number) => DeviceConfig | undefined;

Expand Down
13 changes: 10 additions & 3 deletions packages/host/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function createTestingHost(
const valuesStorage = new Map();
const metadataStorage = new Map();
const valueDBCache = new Map<number, ValueDB>();
const supervisionSessionIDs = new Map<number, () => number>();

const ret: TestingHost = {
homeId: options.homeId ?? 0x7e570001,
Expand Down Expand Up @@ -76,9 +77,15 @@ export function createTestingHost(
options.getSafeCCVersion ??
(() => 100),
getNextCallbackId: createWrappingCounter(0xff),
getNextSupervisionSessionId: createWrappingCounter(
MAX_SUPERVISION_SESSION_ID,
),
getNextSupervisionSessionId: (nodeId) => {
if (!supervisionSessionIDs.has(nodeId)) {
supervisionSessionIDs.set(
nodeId,
createWrappingCounter(MAX_SUPERVISION_SESSION_ID, true),
);
}
return supervisionSessionIDs.get(nodeId)!();
},
getValueDB: (nodeId) => {
if (!valueDBCache.has(nodeId)) {
valueDBCache.set(
Expand Down
13 changes: 10 additions & 3 deletions packages/testing/src/MockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class MockController {
// const valuesStorage = new Map();
// const metadataStorage = new Map();
// const valueDBCache = new Map<number, ValueDB>();
const supervisionSessionIDs = new Map<number, () => number>();

this.host = {
ownNodeId: options.ownNodeId ?? 1,
Expand All @@ -56,9 +57,15 @@ export class MockController {
securityManager2: undefined,
// nodes: this.nodes as any,
getNextCallbackId: () => 1,
getNextSupervisionSessionId: createWrappingCounter(
MAX_SUPERVISION_SESSION_ID,
),
getNextSupervisionSessionId: (nodeId) => {
if (!supervisionSessionIDs.has(nodeId)) {
supervisionSessionIDs.set(
nodeId,
createWrappingCounter(MAX_SUPERVISION_SESSION_ID, true),
);
}
return supervisionSessionIDs.get(nodeId)!();
},
getSafeCCVersion: () => 100,
getSupportedCCVersion: (cc, nodeId, endpointIndex = 0) => {
if (!this.nodes.has(nodeId)) {
Expand Down
14 changes: 10 additions & 4 deletions packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4103,13 +4103,19 @@ ${handlers.length} left`,
*/
public readonly getNextCallbackId = createWrappingCounter(0xff);

private readonly supervisionSessionIDs = new Map<number, () => number>();
/**
* Returns the next session ID for Supervision CC
*/
public readonly getNextSupervisionSessionId = createWrappingCounter(
MAX_SUPERVISION_SESSION_ID,
true,
);
public getNextSupervisionSessionId(nodeId: number): number {
if (!this.supervisionSessionIDs.has(nodeId)) {
this.supervisionSessionIDs.set(
nodeId,
createWrappingCounter(MAX_SUPERVISION_SESSION_ID, true),
);
}
return this.supervisionSessionIDs.get(nodeId)!();
}

/**
* Returns the next session ID for Transport Service CC
Expand Down

0 comments on commit aa5afbd

Please sign in to comment.