Skip to content

Commit

Permalink
refactor: rename bindings to host
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Dec 11, 2024
1 parent 42ce16f commit b9c7247
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 65 deletions.
54 changes: 3 additions & 51 deletions packages/host/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
} from "@zwave-js/core";
import { createThrowingMap } from "@zwave-js/shared";

// FIXME: At some points this module should be moved into @zwave-js/testing,
// but this doesn't work right now due to circular dependencies

export interface CreateTestingHostOptions extends HostIDs, GetDeviceConfig {}

export type BaseTestEndpoint =
Expand Down Expand Up @@ -71,36 +74,7 @@ export function createTestingHost(
homeId: options.homeId ?? 0x7e570001,
ownNodeId: options.ownNodeId ?? 1,
getDeviceConfig: options.getDeviceConfig ?? (() => undefined),
// securityManager: undefined,
// securityManager2: undefined,
// securityManagerLR: undefined,
// getDeviceConfig: () => undefined,
// lookupManufacturer: () => undefined,
logNode: () => {},
// options: {
// attempts: {
// nodeInterview: 1,
// // openSerialPort: 1,
// sendData: 3,
// controller: 3,
// },
// timeouts: {
// refreshValue: 5000,
// refreshValueAfterTransition: 1000,
// },
// },
// getInterviewOptions() {
// return {};
// },
// getUserPreferences() {
// return undefined;
// },
// getCommunicationTimeouts() {
// return {
// refreshValue: 5000,
// refreshValueAfterTransition: 1000,
// };
// },
getNode(nodeId) {
return nodes.get(nodeId);
},
Expand All @@ -113,14 +87,10 @@ export function createTestingHost(
setNode(nodeId, node) {
nodes.set(nodeId, node);
},
// getSafeCCVersion: options.getSafeCCVersion ?? (() => 100),
getSupportedCCVersion: (cc, nodeId, endpoint) => {
return nodes.get(nodeId)?.getEndpoint(endpoint ?? 0)?.getCCVersion(
cc,
) ?? 0;
// return options.getSupportedCCVersion?.(cc, nodeId, endpoint)
// ?? options.getSafeCCVersion?.(cc, nodeId, endpoint)
// ?? 100;
},
getValueDB: (nodeId) => {
if (!valueDBCache.has(nodeId)) {
Expand All @@ -138,24 +108,6 @@ export function createTestingHost(
tryGetValueDB: (nodeId) => {
return ret.getValueDB(nodeId);
},
// getHighestSecurityClass: (nodeId) => {
// const node = nodes.getOrThrow(nodeId);
// return node.getHighestSecurityClass();
// },
// hasSecurityClass: (nodeId, securityClass) => {
// const node = nodes.getOrThrow(nodeId);
// return node.hasSecurityClass(securityClass);
// },
// setSecurityClass: (nodeId, securityClass, granted) => {
// const node = nodes.getOrThrow(nodeId);
// node.setSecurityClass(securityClass, granted);
// },
// sendCommand: async (_command, _options) => {
// return undefined as any;
// },
// schedulePoll: (_nodeId, _valueId, _options) => {
// return false;
// },
};
return ret;
}
6 changes: 3 additions & 3 deletions packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,10 @@ export class Driver extends TypedEventTarget<DriverEventCallbacks>
}

/**
* The bindings used to access file system etc.
* The host bindings used to access file system etc.
*/
// This is set during `start()` and should not be accessed before
private bindings!: Required<NonNullable<ZWaveOptions["bindings"]>>;
private bindings!: Required<NonNullable<ZWaveOptions["host"]>>;

private _wasStarted: boolean = false;
private _isOpen: boolean = false;
Expand All @@ -1339,7 +1339,7 @@ export class Driver extends TypedEventTarget<DriverEventCallbacks>
// Populate default bindings. This has to happen asynchronously, so the driver does not have a hard dependency
// on Node.js internals
this.bindings = {
fs: this._options.bindings?.fs
fs: this._options.host?.fs
?? (await import("@zwave-js/core/bindings/fs/node")).fs,
};

Expand Down
15 changes: 8 additions & 7 deletions packages/zwave-js/src/lib/driver/ZWaveOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {
FileSystem,
FileSystem as LegacyFileSystemBindings,
LogConfig,
LongRangeChannel,
RFRegion,
} from "@zwave-js/core";
import { type ZWaveSerialStream } from "@zwave-js/serial";
import { type DeepPartial, type Expand } from "@zwave-js/shared";
import type { FileSystem as FileSystemBindings } from "@zwave-js/shared/bindings";
import type { FileSystem } from "@zwave-js/shared/bindings";
import type {
InclusionUserCallbacks,
JoinNetworkUserCallbacks,
Expand Down Expand Up @@ -125,20 +125,21 @@ export interface ZWaveOptions {
disableOnNodeAdded?: boolean;
};

bindings?: {
/** Host abstractions allowing Z-Wave JS to run on different platforms */
host?: {
/**
* Specifies which bindings are used to access the file system when
* reading or writing the cache, or loading device configuration files.
*/
fs?: FileSystemBindings;
fs?: FileSystem;
};

storage: {
/**
* Allows you to replace the default file system driver used to store and read the cache
* @deprecated Use `bindings.fs` instead.
*/
driver?: FileSystem;
driver?: LegacyFileSystemBindings;
/** Allows you to specify a different cache directory */
cacheDir: string;
/**
Expand Down Expand Up @@ -406,15 +407,15 @@ export type PartialZWaveOptions = Expand<
| "joinNetworkUserCallbacks"
| "logConfig"
| "testingHooks"
| "bindings"
| "host"
>
>
& Partial<
Pick<
ZWaveOptions,
| "testingHooks"
| "vendor"
| "bindings"
| "host"
>
>
& {
Expand Down
8 changes: 4 additions & 4 deletions packages/zwave-js/src/lib/zniffer/Zniffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface ZnifferOptions {
/** Security keys for decrypting Z-Wave Long Range traffic */
securityKeysLongRange?: ZWaveOptions["securityKeysLongRange"];

bindings?: ZWaveOptions["bindings"];
host?: ZWaveOptions["host"];

/**
* The RSSI values reported by the Zniffer are not actual RSSI values.
Expand Down Expand Up @@ -278,10 +278,10 @@ export class Zniffer extends TypedEventTarget<ZnifferEventCallbacks> {
private _options: ZnifferOptions;

/**
* The bindings used to access file system etc.
* The host bindings used to access file system etc.
*/
// This is set during `init()` and should not be accessed before
private bindings!: Required<NonNullable<ZWaveOptions["bindings"]>>;
private bindings!: Required<NonNullable<ZWaveOptions["host"]>>;

private serialFactory: ZnifferSerialStreamFactory | undefined;
/** The serial port instance */
Expand Down Expand Up @@ -353,7 +353,7 @@ export class Zniffer extends TypedEventTarget<ZnifferEventCallbacks> {
// Populate default bindings. This has to happen asynchronously, so the driver does not have a hard dependency
// on Node.js internals
this.bindings = {
fs: this._options.bindings?.fs
fs: this._options.host?.fs
?? (await import("@zwave-js/core/bindings/fs/node")).fs,
};

Expand Down

0 comments on commit b9c7247

Please sign in to comment.