From b9c724711246312e01587b3b7a81614cd293083a Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 11 Dec 2024 13:43:01 +0100 Subject: [PATCH] refactor: rename bindings to host --- packages/host/src/mocks.ts | 54 ++----------------- packages/zwave-js/src/lib/driver/Driver.ts | 6 +-- .../zwave-js/src/lib/driver/ZWaveOptions.ts | 15 +++--- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 8 +-- 4 files changed, 18 insertions(+), 65 deletions(-) diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 73f27fe0d05..25c09d37cb0 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -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 = @@ -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); }, @@ -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)) { @@ -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; } diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 488f5fe537c..a7785132efb 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -1316,10 +1316,10 @@ export class Driver extends TypedEventTarget } /** - * 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>; + private bindings!: Required>; private _wasStarted: boolean = false; private _isOpen: boolean = false; @@ -1339,7 +1339,7 @@ export class Driver extends TypedEventTarget // 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, }; diff --git a/packages/zwave-js/src/lib/driver/ZWaveOptions.ts b/packages/zwave-js/src/lib/driver/ZWaveOptions.ts index 29227350670..a31dba76443 100644 --- a/packages/zwave-js/src/lib/driver/ZWaveOptions.ts +++ b/packages/zwave-js/src/lib/driver/ZWaveOptions.ts @@ -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, @@ -125,12 +125,13 @@ 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: { @@ -138,7 +139,7 @@ export interface ZWaveOptions { * 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; /** @@ -406,7 +407,7 @@ export type PartialZWaveOptions = Expand< | "joinNetworkUserCallbacks" | "logConfig" | "testingHooks" - | "bindings" + | "host" > > & Partial< @@ -414,7 +415,7 @@ export type PartialZWaveOptions = Expand< ZWaveOptions, | "testingHooks" | "vendor" - | "bindings" + | "host" > > & { diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 0ec957b4c54..27be639e877 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -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. @@ -278,10 +278,10 @@ export class Zniffer extends TypedEventTarget { 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>; + private bindings!: Required>; private serialFactory: ZnifferSerialStreamFactory | undefined; /** The serial port instance */ @@ -353,7 +353,7 @@ export class Zniffer extends TypedEventTarget { // 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, };