Skip to content

Commit

Permalink
refactor: remove deprecated neighbors property and interview stage (#…
Browse files Browse the repository at this point in the history
…3002)

fixes: #2554
  • Loading branch information
AlCalzone committed Jul 13, 2021
1 parent e6ee291 commit cf9782b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 58 deletions.
4 changes: 4 additions & 0 deletions docs/getting-started/migrating-to-v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ interface ZWaveOptions {
};
}
```

## Removed `neighbors` property from `ZWaveNode` class and removed `InterviewStage.Neighbors`

The static `neighbors` property was deprecated in `v7.9.0` and is now removed. Use `controller.getNodeNeighbors` to retrieve the neighbor lists on demand instead of accessing stale data. Furthermore, the interview stage `Neighbors` was removed too, because the information is no longer stored.
19 changes: 2 additions & 17 deletions packages/zwave-js/src/lib/node/Node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,12 @@ class TestNode extends ZWaveNode {
public async interviewCCs(): Promise<boolean> {
return super.interviewCCs();
}
// public async queryManufacturerSpecific(): Promise<void> {
// return super.queryManufacturerSpecific();
// }
// public async queryCCVersions(): Promise<void> {
// return super.queryCCVersions();
// }
// public async queryEndpoints(): Promise<void> {
// return super.queryEndpoints();
// }
// public async configureWakeup(): Promise<void> {
// return super.configureWakeup();
// }
// public async requestStaticValues(): Promise<void> {
// return super.requestStaticValues();
// }
public async queryNeighbors(): Promise<void> {
return super["queryNeighbors"]();
}
public get implementedCommandClasses(): Map<
CommandClasses,
CommandClassInfo
Expand Down Expand Up @@ -512,7 +500,6 @@ describe("lib/node/Node", () => {
queryProtocolInfo: InterviewStage.ProtocolInfo,
queryNodeInfo: InterviewStage.NodeInfo,
interviewCCs: InterviewStage.CommandClasses,
queryNeighbors: InterviewStage.Neighbors,
};
const returnValues: Partial<Record<keyof TestNode, any>> = {
ping: true,
Expand All @@ -522,7 +509,6 @@ describe("lib/node/Node", () => {
queryProtocolInfo: node["queryProtocolInfo"].bind(node),
queryNodeInfo: node["queryNodeInfo"].bind(node),
interviewCCs: node["interviewCCs"].bind(node),
queryNeighbors: node["queryNeighbors"].bind(node),
};
for (const method of Object.keys(
originalMethods,
Expand Down Expand Up @@ -979,7 +965,6 @@ describe("lib/node/Node", () => {
supportsBeaming: true,
protocolVersion: 3,
nodeType: "Controller",
neighbors: [2, 3, 4],
commandClasses: {
"0x25": {
name: "Binary Switch",
Expand Down Expand Up @@ -1098,11 +1083,11 @@ describe("lib/node/Node", () => {
it("deserialize() should also accept numbers for the interview stage", () => {
const input = {
...serializedTestNode,
interviewStage: InterviewStage.Neighbors,
interviewStage: InterviewStage.Complete,
};
const node = new ZWaveNode(1, fakeDriver);
node.deserialize(input);
expect(node.interviewStage).toBe(InterviewStage.Neighbors);
expect(node.interviewStage).toBe(InterviewStage.Complete);
node.destroy();
});

Expand Down
38 changes: 0 additions & 38 deletions packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
getCCName,
isTransmissionError,
isZWaveError,
MAX_NODES,
Maybe,
MetadataUpdatedArgs,
NodeUpdatePayload,
Expand Down Expand Up @@ -623,15 +622,6 @@ export class ZWaveNode extends Endpoint {
}
}

private _neighbors: readonly number[] = [];
/**
* The IDs of all direct neighbors of this node
* @deprecated Request the current known neighbors using `controller.getNodeNeighbors` instead.
*/
public get neighbors(): readonly number[] {
return this._neighbors;
}

private _valueDB: ValueDB;
/**
* Provides access to this node's values
Expand Down Expand Up @@ -1121,7 +1111,6 @@ export class ZWaveNode extends Endpoint {
this._supportsSecurity = undefined;
this._supportsBeaming = undefined;
this._deviceConfig = undefined;
this._neighbors = [];
this._hasEmittedNoNetworkKeyError = false;
this._valueDB.clear({ noEvent: true });
this._endpointInstances.clear();
Expand Down Expand Up @@ -1229,14 +1218,6 @@ export class ZWaveNode extends Endpoint {
await this.overwriteConfig();
}

if (this.interviewStage === InterviewStage.OverwriteConfig) {
// Request a list of this node's neighbors
// wotan-disable-next-line no-unstable-api-use
if (!(await tryInterviewStage(() => this.queryNeighbors()))) {
return false;
}
}

await this.setInterviewStage(InterviewStage.Complete);
this.readyMachine.send("INTERVIEW_DONE");

Expand Down Expand Up @@ -1955,17 +1936,6 @@ protocol version: ${this._protocolVersion}`;
await this.setInterviewStage(InterviewStage.OverwriteConfig);
}

/**
* Queries the controller for a node's neighbor nodes during the node interview
* @deprecated This should be done on demand, not once
*/
protected async queryNeighbors(): Promise<void> {
this._neighbors = await this.driver.controller.getNodeNeighbors(
this.id,
);
await this.setInterviewStage(InterviewStage.Neighbors);
}

/**
* @internal
* Handles a CommandClass that was received from this node
Expand Down Expand Up @@ -3277,7 +3247,6 @@ protocol version: ${this._protocolVersion}`;
generic: this.deviceClass.generic.key,
specific: this.deviceClass.specific.key,
},
neighbors: [...this._neighbors].sort(),
isListening: this.isListening,
isFrequentListening: this.isFrequentListening,
isRouting: this.isRouting,
Expand Down Expand Up @@ -3398,13 +3367,6 @@ protocol version: ${this._protocolVersion}`;
this._supportedDataRates = obj.supportedDataRates;
}

if (isArray(obj.neighbors)) {
// parse only valid node IDs
this._neighbors = obj.neighbors.filter(
(n: any) => typeof n === "number" && n > 0 && n <= MAX_NODES,
);
}

function enforceType(
val: any,
type: "boolean" | "number" | "string",
Expand Down
3 changes: 0 additions & 3 deletions packages/zwave-js/src/lib/node/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ export enum InterviewStage {
*/
OverwriteConfig,

/** The node has been queried for its current neighbor list */
Neighbors,

/** The interview process has finished */
Complete,
}
Expand Down

0 comments on commit cf9782b

Please sign in to comment.