Skip to content

Commit 43a54f7

Browse files
authored
Refactor Shell and remove legacy leftovers (#1975)
1 parent a8bcd61 commit 43a54f7

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

packages/nodejs-shell/src/MatterNode.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// Include this first to auto-register Crypto, Network and Time Node.js implementations
88
import { Environment, Logger, StorageContext, StorageService } from "@matter/general";
99
import { ControllerStore } from "@matter/node";
10-
import { StorageBackendDisk } from "@matter/nodejs";
1110
import { EndpointInterface } from "@matter/protocol";
1211
import { NodeId } from "@matter/types";
1312
import { CommissioningController } from "@project-chip/matter.js";
@@ -18,19 +17,18 @@ const logger = Logger.get("Node");
1817

1918
export class MatterNode {
2019
#storageLocation?: string;
21-
private storage?: StorageBackendDisk;
22-
private storageContext?: StorageContext;
23-
24-
#environment?: Environment;
20+
#storageContext?: StorageContext;
21+
readonly #environment?: Environment;
2522
commissioningController?: CommissioningController;
26-
private started = false;
23+
#started = false;
24+
readonly #nodeNum: number;
25+
readonly #netInterface?: string;
2726

28-
constructor(
29-
private readonly nodeNum: number,
30-
private readonly netInterface?: string,
31-
) {
27+
constructor(nodeNum: number, netInterface?: string) {
3228
this.#environment = Environment.default;
3329
this.#environment.runtime.add(this);
30+
this.#nodeNum = nodeNum;
31+
this.#netInterface = netInterface;
3432
}
3533

3634
get storageLocation() {
@@ -46,11 +44,11 @@ export class MatterNode {
4644
*/
4745

4846
if (this.#environment) {
49-
if (this.netInterface !== undefined) {
50-
this.#environment.vars.set("mdns.networkinterface", this.netInterface);
47+
if (this.#netInterface !== undefined) {
48+
this.#environment.vars.set("mdns.networkinterface", this.#netInterface);
5149
}
5250
// Build up the "Not-so-legacy" Controller
53-
const id = `shell-${this.nodeNum.toString()}`;
51+
const id = `shell-${this.#nodeNum.toString()}`;
5452
this.commissioningController = new CommissioningController({
5553
environment: {
5654
environment: this.#environment,
@@ -65,7 +63,7 @@ export class MatterNode {
6563
if (resetStorage) {
6664
await controllerStore.erase();
6765
}
68-
this.storageContext = controllerStore.storage.createContext("Node");
66+
this.#storageContext = controllerStore.storage.createContext("Node");
6967

7068
const storageService = this.#environment.get(StorageService);
7169
const baseLocation = storageService.location;
@@ -81,26 +79,21 @@ export class MatterNode {
8179
}
8280

8381
get Store() {
84-
if (!this.storageContext) {
82+
if (!this.#storageContext) {
8583
throw new Error("Storage uninitialized");
8684
}
87-
return this.storageContext;
85+
return this.#storageContext;
8886
}
8987

9088
async close() {
9189
await this.commissioningController?.close();
92-
return await this.closeStorage();
93-
}
94-
95-
async closeStorage() {
96-
await this.storage?.close();
9790
}
9891

9992
async start() {
100-
if (this.started) {
93+
if (this.#started) {
10194
return;
10295
}
103-
logger.info(`matter.js shell controller started for node ${this.nodeNum}`);
96+
logger.info(`matter.js shell controller started for node ${this.#nodeNum}`);
10497

10598
if (this.commissioningController !== undefined) {
10699
await this.commissioningController.start();
@@ -113,7 +106,7 @@ export class MatterNode {
113106
} else {
114107
throw new Error("No controller initialized");
115108
}
116-
this.started = true;
109+
this.#started = true;
117110
}
118111

119112
async connectAndGetNodes(nodeIdStr?: string, connectOptions?: CommissioningControllerNodeOptions) {

0 commit comments

Comments
 (0)