From 03ac9e51dc02bab4baa6374facc4f04b12458c2b Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 14:32:57 +0200 Subject: [PATCH 01/60] refactor: split ZWaveNode class into "mixins" --- packages/cc/src/lib/CommandClass.ts | 3 +- .../core/src/abstractions/IZWaveEndpoint.ts | 8 +- packages/zwave-js/src/lib/driver/Driver.ts | 17 +- packages/zwave-js/src/lib/node/Endpoint.ts | 4 +- packages/zwave-js/src/lib/node/Node.ts | 1784 +---------------- .../src/lib/node/NodeStatusMachine.test.ts | 27 +- .../src/lib/node/NodeStatusMachine.ts | 7 +- .../src/lib/node/mixins/00_NetworkRole.ts | 144 ++ .../zwave-js/src/lib/node/mixins/10_Events.ts | 41 + .../zwave-js/src/lib/node/mixins/20_Status.ts | 180 ++ .../zwave-js/src/lib/node/mixins/30_Wakeup.ts | 76 + .../zwave-js/src/lib/node/mixins/40_Values.ts | 234 +++ .../src/lib/node/mixins/50_Endpoints.ts | 180 ++ .../src/lib/node/mixins/60_ScheduledPoll.ts | 139 ++ .../src/lib/node/mixins/70_FirmwareUpdate.ts | 977 +++++++++ .../zwave-js/src/lib/node/mixins/README.md | 3 + .../zwave-js/src/lib/node/mixins/index.ts | 3 + packages/zwave-js/src/lib/node/utils.ts | 84 +- 18 files changed, 2161 insertions(+), 1750 deletions(-) create mode 100644 packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/10_Events.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/20_Status.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/30_Wakeup.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/40_Values.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts create mode 100644 packages/zwave-js/src/lib/node/mixins/README.md create mode 100644 packages/zwave-js/src/lib/node/mixins/index.ts diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index c8674e77243d..c0ac1b928d23 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -2,6 +2,7 @@ import { type BroadcastCC, CommandClasses, EncapsulationFlags, + type EndpointId, type FrameType, type ICommandClass, type IZWaveEndpoint, @@ -449,7 +450,7 @@ export class CommandClass implements ICommandClass { */ public static createInstanceUnchecked( host: ZWaveHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, cc: CommandClasses | CCConstructor, ): T | undefined { const Constructor = typeof cc === "number" ? getCCConstructor(cc) : cc; diff --git a/packages/core/src/abstractions/IZWaveEndpoint.ts b/packages/core/src/abstractions/IZWaveEndpoint.ts index 46e2c5ee20aa..1cd832902b47 100644 --- a/packages/core/src/abstractions/IZWaveEndpoint.ts +++ b/packages/core/src/abstractions/IZWaveEndpoint.ts @@ -5,10 +5,14 @@ import type { import type { MulticastDestination } from "../consts"; import type { IVirtualNode, IZWaveNode } from "./IZWaveNode"; -/** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ -export interface IZWaveEndpoint { +/** Identifies an endpoint */ +export interface EndpointId { readonly nodeId: number; readonly index: number; +} + +/** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ +export interface IZWaveEndpoint extends EndpointId { readonly virtual: false; getCCVersion(cc: CommandClasses): number; addCC(cc: CommandClasses, info: Partial): void; diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index ace5128f2ff0..f8fd1fd1452a 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -167,7 +167,7 @@ import { ZWaveController } from "../controller/Controller"; import { InclusionState, RemoveNodeReason } from "../controller/Inclusion"; import { DriverLogger } from "../log/Driver"; import type { Endpoint } from "../node/Endpoint"; -import type { ZWaveNode } from "../node/Node"; +import type { ZWaveNode, ZWaveNodeBase } from "../node/Node"; import { InterviewStage, NodeStatus, @@ -203,6 +203,9 @@ import { isTransmitReport, } from "../serialapi/transport/SendDataShared"; +import { type NodeWakeup } from "../node/mixins/30_Wakeup"; +import { type NodeValues } from "../node/mixins/40_Values"; +import { type SchedulePoll } from "../node/mixins/60_ScheduledPoll"; import { SendTestFrameRequest, SendTestFrameTransmitReport, @@ -2687,7 +2690,7 @@ export class Driver extends TypedEventEmitter }; /** Checks if there are any pending messages for the given node */ - private hasPendingMessages(node: ZWaveNode): boolean { + private hasPendingMessages(node: ZWaveNodeBase & SchedulePoll): boolean { // First check if there are messages in the queue if ( this.hasPendingTransactions( @@ -2698,7 +2701,7 @@ export class Driver extends TypedEventEmitter } // Then check if there are scheduled polls - return node.scheduledPolls.size > 0; + return node.hasScheduledPolls(); } /** Checks if there are any pending transactions that match the given predicate */ @@ -6830,7 +6833,9 @@ ${handlers.length} left`, * @internal * Marks a node for a later sleep command. Every call refreshes the period until the node actually goes to sleep */ - public debounceSendNodeToSleep(node: ZWaveNode): void { + public debounceSendNodeToSleep( + node: ZWaveNodeBase & SchedulePoll & NodeValues & NodeWakeup, + ): void { // TODO: This should be a single command to the send thread // Delete old timers if any exist if (this.sendNodeToSleepTimers.has(node.id)) { @@ -6838,7 +6843,9 @@ ${handlers.length} left`, } // Sends a node to sleep if it has no more messages. - const sendNodeToSleep = (node: ZWaveNode): void => { + const sendNodeToSleep = ( + node: ZWaveNodeBase & SchedulePoll & NodeWakeup, + ): void => { this.sendNodeToSleepTimers.delete(node.id); if (!this.hasPendingMessages(node)) { void node.sendNoMoreInformation().catch(() => { diff --git a/packages/zwave-js/src/lib/node/Endpoint.ts b/packages/zwave-js/src/lib/node/Endpoint.ts index 7fc66014b838..3786f49f3fea 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.ts @@ -10,7 +10,7 @@ import { normalizeCCNameOrId, } from "@zwave-js/cc"; import { ZWavePlusCCValues } from "@zwave-js/cc/ZWavePlusCC"; -import type { IZWaveEndpoint, MaybeNotKnown } from "@zwave-js/core"; +import type { EndpointId, IZWaveEndpoint, MaybeNotKnown } from "@zwave-js/core"; import { BasicDeviceClass, CacheBackedMap, @@ -36,7 +36,7 @@ import type { ZWaveNode } from "./Node"; * * Each endpoint may have different capabilities (device class/supported CCs) */ -export class Endpoint implements IZWaveEndpoint { +export class Endpoint implements EndpointId, IZWaveEndpoint { public constructor( /** The id of the node this endpoint belongs to */ public readonly nodeId: number, diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index c623b2dda576..cbdbccee2064 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -1,7 +1,6 @@ import { AssociationGroupInfoProfile, type CCAPI, - type CCValueOptions, CentralSceneKeys, ClockCommand, CommandClass, @@ -10,13 +9,6 @@ import { DoorLockMode, EntryControlDataTypes, type FirmwareUpdateCapabilities, - type FirmwareUpdateInitResult, - type FirmwareUpdateMetaData, - type FirmwareUpdateOptions, - type FirmwareUpdateProgress, - FirmwareUpdateRequestStatus, - type FirmwareUpdateResult, - FirmwareUpdateStatus, InclusionControllerCCInitiate, InclusionControllerStep, IndicatorCCDescriptionGet, @@ -44,9 +36,7 @@ import { type ValueIDProperties, ZWavePlusNodeType, ZWavePlusRoleType, - defaultCCValueOptions, entryControlEventTypeLabels, - getCCValues, getImplementedVersion, isCommandClassContainer, utils as ccUtils, @@ -83,11 +73,8 @@ import { ClockCCReport } from "@zwave-js/cc/ClockCC"; import { DoorLockCCValues } from "@zwave-js/cc/DoorLockCC"; import { EntryControlCCNotification } from "@zwave-js/cc/EntryControlCC"; import { - FirmwareUpdateMetaDataCC, FirmwareUpdateMetaDataCCGet, FirmwareUpdateMetaDataCCMetaDataGet, - FirmwareUpdateMetaDataCCReport, - FirmwareUpdateMetaDataCCStatusReport, FirmwareUpdateMetaDataCCValues, } from "@zwave-js/cc/FirmwareUpdateMetaDataCC"; import { HailCC } from "@zwave-js/cc/HailCC"; @@ -96,7 +83,6 @@ import { ManufacturerSpecificCCGet, ManufacturerSpecificCCValues, } from "@zwave-js/cc/ManufacturerSpecificCC"; -import { MultiChannelCCValues } from "@zwave-js/cc/MultiChannelCC"; import { MultilevelSwitchCC, MultilevelSwitchCCSet, @@ -155,18 +141,15 @@ import { import { type DeviceConfig, embeddedDevicesDir } from "@zwave-js/config"; import { BasicDeviceClass, - CRC16_CCITT, CacheBackedMap, CommandClasses, - type DataRate, Duration, EncapsulationFlags, type FLiRS, - type Firmware, + type IZWaveEndpoint, type IZWaveNode, type MaybeNotKnown, MessagePriority, - type MetadataUpdatedArgs, NOT_KNOWN, NodeType, type NodeUpdatePayload, @@ -187,7 +170,7 @@ import { TransmitOptions, ValueDB, type ValueID, - ValueMetadata, + type ValueMetadata, type ValueMetadataNumeric, type ValueRemovedArgs, type ValueUpdatedArgs, @@ -203,7 +186,6 @@ import { getDSTInfo, getNotification, getNotificationValue, - isLongRangeNodeId, isRssiError, isSupervisionResult, isTransmissionError, @@ -218,15 +200,12 @@ import { serializeCacheValue, supervisedCommandFailed, supervisedCommandSucceeded, - timespan, topologicalSort, valueIdToString, } from "@zwave-js/core"; -import type { NodeSchedulePollOptions } from "@zwave-js/host"; import { FunctionType, type Message } from "@zwave-js/serial"; import { Mixin, - ObjectKeyMap, type TypedEventEmitter, cloneDeep, discreteLinearSearch, @@ -236,9 +215,7 @@ import { noop, pick, stringify, - throttle, } from "@zwave-js/shared"; -import { distinct } from "alcalzone-shared/arrays"; import { wait } from "alcalzone-shared/async"; import { type DeferredPromise, @@ -247,18 +224,14 @@ import { import { roundTo } from "alcalzone-shared/math"; import { padStart } from "alcalzone-shared/strings"; import { isArray, isObject } from "alcalzone-shared/typeguards"; -import { randomBytes } from "node:crypto"; import { EventEmitter } from "node:events"; import path from "node:path"; -import { isDeepStrictEqual } from "node:util"; import semver from "semver"; import { RemoveNodeReason } from "../controller/Inclusion"; import { determineNIF } from "../controller/NodeInformationFrame"; import { type Driver, libVersion } from "../driver/Driver"; import { cacheKeys } from "../driver/NetworkCache"; -import { type Extended, interpretEx } from "../driver/StateMachineShared"; import type { StatisticsEventCallbacksWithSelf } from "../driver/Statistics"; -import { type TaskBuilder, TaskPriority } from "../driver/Task"; import type { Transaction } from "../driver/Transaction"; import { type ApplicationUpdateRequest, @@ -281,21 +254,12 @@ import { formatRouteHealthCheckSummary, healthCheckTestFrameCount, } from "./HealthCheck"; -import { - type NodeReadyInterpreter, - createNodeReadyMachine, -} from "./NodeReadyMachine"; import { type NodeStatistics, NodeStatisticsHost, type RouteStatistics, routeStatisticsEquals, } from "./NodeStatistics"; -import { - type NodeStatusInterpreter, - createNodeStatusMachine, - nodeStatusMachineStateToNodeStatus, -} from "./NodeStatusMachine"; import { type DateAndTime, type LifelineHealthCheckResult, @@ -307,34 +271,56 @@ import { type RouteHealthCheckResult, type RouteHealthCheckSummary, type ZWaveNodeEventCallbacks, - type ZWaveNodeValueEventCallbacks, } from "./_Types"; import { InterviewStage, NodeStatus } from "./_Types"; +import { ZWaveNodeMixins } from "./mixins"; import * as nodeUtils from "./utils"; -interface ScheduledPoll { - timeout: NodeJS.Timeout; - expectedValue?: unknown; -} +const MAX_ASSOCIATIONS = 1; -interface AbortFirmwareUpdateContext { - abort: boolean; - tooLateToAbort: boolean; - abortPromise: DeferredPromise; -} +export abstract class ZWaveNodeBase extends Endpoint implements IZWaveNode { + abstract isListening: MaybeNotKnown; + abstract isFrequentListening: MaybeNotKnown; + abstract canSleep: MaybeNotKnown; + abstract status: NodeStatus; + abstract interviewStage: InterviewStage; + abstract getEndpoint(index: 0): IZWaveEndpoint; + abstract getEndpoint(index: number): IZWaveEndpoint | undefined; + abstract getEndpoint(index: unknown): IZWaveEndpoint | undefined; -type PartialFirmwareUpdateResult = - & Pick - & { success: boolean }; + abstract getEndpointOrThrow(index: number): IZWaveEndpoint; -const MAX_ASSOCIATIONS = 1; + abstract getAllEndpoints(): IZWaveEndpoint[]; + + abstract isSecure: MaybeNotKnown; + abstract getHighestSecurityClass(): MaybeNotKnown; + + abstract hasSecurityClass( + securityClass: SecurityClass, + ): MaybeNotKnown; + + abstract setSecurityClass( + securityClass: SecurityClass, + granted: boolean, + ): void; + + /** + * Whether the node should be kept awake when there are no pending messages. + */ + public keepAwake: boolean = false; + + /** The ID of this node */ + public get id(): number { + return this.nodeId; + } +} + +type AllNodeEvents = + & ZWaveNodeEventCallbacks + & StatisticsEventCallbacksWithSelf; -export interface ZWaveNode extends - TypedEventEmitter< - & ZWaveNodeEventCallbacks - & StatisticsEventCallbacksWithSelf - >, - NodeStatisticsHost +export interface ZWaveNode + extends TypedEventEmitter, NodeStatisticsHost {} /** @@ -342,21 +328,49 @@ export interface ZWaveNode extends * of its root endpoint (index 0) */ @Mixin([EventEmitter, NodeStatisticsHost]) -export class ZWaveNode extends Endpoint +export class ZWaveNode extends ZWaveNodeMixins implements SecurityClassOwner, IZWaveNode { + protected _emit( + event: TEvent, + ...args: Parameters + ): boolean { + return this.emit(event, ...args); + } + + protected _on( + event: TEvent, + callback: AllNodeEvents[TEvent], + ): this { + return this.on(event, callback); + } + + protected _once( + event: TEvent, + callback: AllNodeEvents[TEvent], + ): this { + return this.once(event, callback); + } + public constructor( - public readonly id: number, + id: number, driver: Driver, deviceClass?: DeviceClass, supportedCCs: CommandClasses[] = [], controlledCCs: CommandClasses[] = [], valueDB?: ValueDB, ) { - // Define this node's intrinsic endpoint as the root device (0) - super(id, driver, 0, deviceClass, supportedCCs); - this._valueDB = valueDB - ?? new ValueDB(id, driver.valueDB!, driver.metadataDB!); + super( + id, + driver, + // Define this node's intrinsic endpoint as the root device (0) + + 0, + deviceClass, + supportedCCs, + valueDB + ?? new ValueDB(id, driver.valueDB!, driver.metadataDB!), + ); // Pass value events to our listeners for ( const event of [ @@ -410,25 +424,6 @@ export class ZWaveNode extends Endpoint // Add optional controlled CCs - endpoints don't have this for (const cc of controlledCCs) this.addCC(cc, { isControlled: true }); - - // Create and hook up the status machine - this.statusMachine = interpretEx(createNodeStatusMachine(this)); - this.statusMachine.onTransition((state) => { - if (state.changed) { - this.onStatusChange( - nodeStatusMachineStateToNodeStatus(state.value as any), - ); - } - }); - this.statusMachine.start(); - - this.readyMachine = interpretEx(createNodeReadyMachine()); - this.readyMachine.onTransition((state) => { - if (state.changed) { - this.onReadyChange(state.value === "ready"); - } - }); - this.readyMachine.start(); } /** @@ -453,287 +448,7 @@ export class ZWaveNode extends Endpoint this.removeAllListeners(); // Clear all scheduled polls that would interfere with the interview - for (const valueId of this.scheduledPolls.keys()) { - this.cancelScheduledPoll(valueId); - } - } - - /** - * Enhances the raw event args of the ValueDB so it can be consumed better by applications - */ - private translateValueEvent( - eventName: keyof ZWaveNodeValueEventCallbacks, - arg: T, - ): void { - // Try to retrieve the speaking CC name - const outArg = nodeUtils.translateValueID(this.driver, this, arg); - // This can happen for value updated events - if ("source" in outArg) delete outArg.source; - - const loglevel = this.driver.getLogConfig().level; - - // If this is a metadata event, make sure we return the merged metadata - if ("metadata" in outArg) { - (outArg as unknown as MetadataUpdatedArgs).metadata = this - .getValueMetadata(arg); - } - - const ccInstance = CommandClass.createInstanceUnchecked( - this.driver, - this, - arg.commandClass, - ); - const isInternalValue = !!ccInstance?.isInternalValue(arg); - // Check whether this value change may be logged - const isSecretValue = !!ccInstance?.isSecretValue(arg); - - if (loglevel === "silly") { - this.driver.controllerLog.logNode(this.id, { - message: `[translateValueEvent: ${eventName}] - commandClass: ${getCCName(arg.commandClass)} - endpoint: ${arg.endpoint} - property: ${arg.property} - propertyKey: ${arg.propertyKey} - internal: ${isInternalValue} - secret: ${isSecretValue} - event source: ${(arg as any as ValueUpdatedArgs).source}`, - level: "silly", - }); - } - - if ( - !isSecretValue - && (arg as any as ValueUpdatedArgs).source !== "driver" - ) { - // Log the value change, except for updates caused by the driver itself - // I don't like the splitting and any but its the easiest solution here - const [changeTarget, changeType] = eventName.split(" "); - const logArgument = { - ...outArg, - nodeId: this.id, - internal: isInternalValue, - }; - if (changeTarget === "value") { - this.driver.controllerLog.value( - changeType as any, - logArgument as any, - ); - } else if (changeTarget === "metadata") { - this.driver.controllerLog.metadataUpdated(logArgument); - } - } - - // Don't expose value events for internal value IDs... - if (isInternalValue) return; - - if (loglevel === "silly") { - this.driver.controllerLog.logNode(this.id, { - message: `[translateValueEvent: ${eventName}] - is root endpoint: ${!arg.endpoint} - is application CC: ${applicationCCs.includes(arg.commandClass)} - should hide root values: ${ - nodeUtils.shouldHideRootApplicationCCValues( - this.driver, - this, - ) - }`, - level: "silly", - }); - } - - // ... and root values ID that mirrors endpoint functionality - if ( - // Only root endpoint values need to be filtered - !arg.endpoint - // Only application CCs need to be filtered - && applicationCCs.includes(arg.commandClass) - // and only if the endpoints are not unnecessary and the root values mirror them - && nodeUtils.shouldHideRootApplicationCCValues(this.driver, this) - ) { - // Iterate through all possible non-root endpoints of this node and - // check if there is a value ID that mirrors root endpoint functionality - for (const endpoint of this.getEndpointIndizes()) { - const possiblyMirroredValueID: ValueID = { - // same CC, property and key - ...pick(arg, ["commandClass", "property", "propertyKey"]), - // but different endpoint - endpoint, - }; - if (this.valueDB.hasValue(possiblyMirroredValueID)) { - if (loglevel === "silly") { - this.driver.controllerLog.logNode(this.id, { - message: - `[translateValueEvent: ${eventName}] found mirrored value ID on different endpoint, ignoring event: - commandClass: ${getCCName(possiblyMirroredValueID.commandClass)} - endpoint: ${possiblyMirroredValueID.endpoint} - property: ${possiblyMirroredValueID.property} - propertyKey: ${possiblyMirroredValueID.propertyKey}`, - level: "silly", - }); - } - - return; - } - } - } - // And pass the translated event to our listeners - this.emit(eventName, this, outArg as any); - } - - private statusMachine: Extended; - private _status: NodeStatus = NodeStatus.Unknown; - - private onStatusChange(newStatus: NodeStatus) { - // Ignore duplicate events - if (newStatus === this._status) return; - - const oldStatus = this._status; - this._status = newStatus; - if (this._status === NodeStatus.Asleep) { - this.emit("sleep", this, oldStatus); - } else if (this._status === NodeStatus.Awake) { - this.emit("wake up", this, oldStatus); - } else if (this._status === NodeStatus.Dead) { - this.emit("dead", this, oldStatus); - } else if (this._status === NodeStatus.Alive) { - this.emit("alive", this, oldStatus); - } - - // To be marked ready, a node must be known to be not dead. - // This means that listening nodes must have communicated with us and - // sleeping nodes are assumed to be ready - this.readyMachine.send( - this._status !== NodeStatus.Unknown - && this._status !== NodeStatus.Dead - ? "NOT_DEAD" - : "MAYBE_DEAD", - ); - } - - /** - * Which status the node is believed to be in - */ - public get status(): NodeStatus { - return this._status; - } - - /** - * @internal - * Marks this node as dead (if applicable) - */ - public markAsDead(): void { - this.statusMachine.send("DEAD"); - } - - /** - * @internal - * Marks this node as alive (if applicable) - */ - public markAsAlive(): void { - this.statusMachine.send("ALIVE"); - } - - /** - * @internal - * Marks this node as asleep (if applicable) - */ - public markAsAsleep(): void { - this.statusMachine.send("ASLEEP"); - } - - /** - * @internal - * Marks this node as awake (if applicable) - */ - public markAsAwake(): void { - this.statusMachine.send("AWAKE"); - } - - /** Returns a promise that resolves when the node wakes up the next time or immediately if the node is already awake. */ - public waitForWakeup(): Promise { - if (!this.canSleep || !this.supportsCC(CommandClasses["Wake Up"])) { - throw new ZWaveError( - `Node ${this.id} does not support wakeup!`, - ZWaveErrorCodes.CC_NotSupported, - ); - } else if (this._status === NodeStatus.Awake) { - return Promise.resolve(); - } - - return new Promise((resolve) => { - this.once("wake up", () => resolve()); - }); - } - - // The node is only ready when the interview has been completed - // to a certain degree - - private readyMachine: Extended; - private _ready: boolean = false; - - private onReadyChange(ready: boolean) { - // Ignore duplicate events - if (ready === this._ready) return; - - this._ready = ready; - if (ready) this.emit("ready", this); - } - - /** - * Whether the node is ready to be used - */ - public get ready(): boolean { - return this._ready; - } - - /** Whether this node is always listening or not */ - public get isListening(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).isListening); - } - private set isListening(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).isListening, value); - } - - /** Indicates the wakeup interval if this node is a FLiRS node. `false` if it isn't. */ - public get isFrequentListening(): MaybeNotKnown { - return this.driver.cacheGet( - cacheKeys.node(this.id).isFrequentListening, - ); - } - private set isFrequentListening(value: MaybeNotKnown) { - this.driver.cacheSet( - cacheKeys.node(this.id).isFrequentListening, - value, - ); - } - - public get canSleep(): MaybeNotKnown { - // The controller node can never sleep (apparently it can report otherwise though) - if (this.isControllerNode) return false; - if (this.isListening == NOT_KNOWN) return NOT_KNOWN; - if (this.isFrequentListening == NOT_KNOWN) return NOT_KNOWN; - return !this.isListening && !this.isFrequentListening; - } - - /** Whether the node supports routing/forwarding messages. */ - public get isRouting(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).isRouting); - } - private set isRouting(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).isRouting, value); - } - - public get supportedDataRates(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).supportedDataRates); - } - private set supportedDataRates(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).supportedDataRates, value); - } - - public get maxDataRate(): MaybeNotKnown { - if (this.supportedDataRates) { - return Math.max(...this.supportedDataRates) as DataRate; - } + this.cancelAllScheduledPolls(); } /** @internal */ @@ -788,41 +503,6 @@ export class ZWaveNode extends Endpoint return missingSome ? NOT_KNOWN : SecurityClass.None; } - /** The Z-Wave protocol version this node implements */ - public get protocolVersion(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).protocolVersion); - } - private set protocolVersion(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).protocolVersion, value); - } - - /** Whether this node is a controller (can calculate routes) or an end node (relies on route info) */ - public get nodeType(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).nodeType); - } - private set nodeType(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).nodeType, value); - } - - /** - * Whether this node supports security (S0 or S2). - * **WARNING:** Nodes often report this incorrectly - do not blindly trust it. - */ - public get supportsSecurity(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).supportsSecurity); - } - private set supportsSecurity(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).supportsSecurity, value); - } - - /** Whether this node can issue wakeup beams to FLiRS nodes */ - public get supportsBeaming(): MaybeNotKnown { - return this.driver.cacheGet(cacheKeys.node(this.id).supportsBeaming); - } - private set supportsBeaming(value: MaybeNotKnown) { - this.driver.cacheSet(cacheKeys.node(this.id).supportsBeaming, value); - } - public get manufacturerId(): MaybeNotKnown { return this.getValue(ManufacturerSpecificCCValues.manufacturerId.id); } @@ -932,13 +612,6 @@ export class ZWaveNode extends Endpoint } } - /** Which protocol is used to communicate with this node */ - public get protocol(): Protocols { - return isLongRangeNodeId(this.id) - ? Protocols.ZWaveLongRange - : Protocols.ZWave; - } - /** Whether a SUC return route was configured for this node */ public get hasSUCReturnRoute(): boolean { return !!this.driver.cacheGet( @@ -1040,61 +713,6 @@ export class ZWaveNode extends Endpoint this.driver.cacheSet(cacheKeys.node(this.id).deviceConfigHash, value); } - private _valueDB: ValueDB; - /** - * Provides access to this node's values - * @internal - */ - public get valueDB(): ValueDB { - return this._valueDB; - } - - /** - * Retrieves a stored value for a given value id. - * This does not request an updated value from the node! - */ - public getValue(valueId: ValueID): MaybeNotKnown { - return this._valueDB.getValue(valueId); - } - - /** - * Returns when the given value id was last updated by an update from the node. - */ - public getValueTimestamp(valueId: ValueID): MaybeNotKnown { - return this._valueDB.getTimestamp(valueId); - } - - /** - * Retrieves metadata for a given value id. - * This can be used to enhance the user interface of an application - */ - public getValueMetadata(valueId: ValueID): ValueMetadata { - // Check if a corresponding CC value is defined for this value ID - // so we can extend the returned metadata - const definedCCValues = getCCValues(valueId.commandClass); - let valueOptions: Required | undefined; - let meta: ValueMetadata | undefined; - if (definedCCValues) { - const value = Object.values(definedCCValues) - .find((v) => v?.is(valueId)); - if (value) { - if (typeof value !== "function") { - meta = value.meta; - } - valueOptions = value.options; - } - } - - const existingMetadata = this._valueDB.getMetadata(valueId); - return { - // The priority for returned metadata is valueDB > defined value > Any (default) - ...(existingMetadata ?? meta ?? ValueMetadata.Any), - // ...except for these flags, which are taken from defined values: - stateful: valueOptions?.stateful ?? defaultCCValueOptions.stateful, - secret: valueOptions?.secret ?? defaultCCValueOptions.secret, - }; - } - /** Returns a list of all value names that are defined on all endpoints of this node */ public getDefinedValueIDs(): TranslatedValueID[] { return nodeUtils.getDefinedValueIDs(this.driver, this); @@ -1396,267 +1014,40 @@ export class ZWaveNode extends Endpoint } /** - * @internal - * All polls that are currently scheduled for this node - */ - public scheduledPolls = new ObjectKeyMap(); - - /** - * @internal - * Schedules a value to be polled after a given time. Only one schedule can be active for a given value ID. - * @returns `true` if the poll was scheduled, `false` otherwise + * This tells us which interview stage was last completed */ - public schedulePoll( - valueId: ValueID, - options: NodeSchedulePollOptions = {}, - ): boolean { - const { - timeoutMs = this.driver.options.timeouts.refreshValue, - expectedValue, - } = options; - - // Avoid false positives or false negatives due to a mis-formatted value ID - valueId = normalizeValueID(valueId); - - // Try to retrieve the corresponding CC API - const endpointInstance = this.getEndpoint(valueId.endpoint || 0); - if (!endpointInstance) return false; - - const api = ( - (endpointInstance.commandClasses as any)[ - valueId.commandClass - ] as CCAPI - ).withOptions({ - // We do not want to delay more important communication by polling, so give it - // the lowest priority and don't retry unless overwritten by the options - maxSendAttempts: 1, - priority: MessagePriority.Poll, - }); - - // Check if the pollValue method is implemented - if (!api.pollValue) return false; - // make sure there is only one timeout instance per poll - this.cancelScheduledPoll(valueId); - const timeout = setTimeout(async () => { - // clean up after the timeout - this.cancelScheduledPoll(valueId); - try { - await api.pollValue!.call(api, valueId); - } catch { - /* ignore */ - } - }, timeoutMs).unref(); - this.scheduledPolls.set(valueId, { timeout, expectedValue }); + public get interviewStage(): InterviewStage { + return ( + this.driver.cacheGet(cacheKeys.node(this.id).interviewStage) + ?? InterviewStage.None + ); + } + public set interviewStage(value: InterviewStage) { + this.driver.cacheSet(cacheKeys.node(this.id).interviewStage, value); + } - return true; + private _interviewAttempts: number = 0; + /** How many attempts to interview this node have already been made */ + public get interviewAttempts(): number { + return this._interviewAttempts; } + private _hasEmittedNoS2NetworkKeyError: boolean = false; + private _hasEmittedNoS0NetworkKeyError: boolean = false; + /** - * @internal - * Cancels a poll that has been scheduled with schedulePoll. + * Starts or resumes a deferred initial interview of this node. + * + * **WARNING:** This is only allowed when the initial interview was deferred using the + * `interview.disableOnNodeAdded` option. Otherwise, this method will throw an error. * - * @param actualValue If given, this indicates the value that was received by a node, which triggered the poll to be canceled. - * If the scheduled poll expects a certain value and this matches the expected value for the scheduled poll, the poll will be canceled. + * **NOTE:** It is advised to NOT await this method as it can take a very long time (minutes to hours)! */ - public cancelScheduledPoll( - valueId: ValueID, - actualValue?: unknown, - ): boolean { - // Avoid false positives or false negatives due to a mis-formatted value ID - valueId = normalizeValueID(valueId); - - const poll = this.scheduledPolls.get(valueId); - if (!poll) return false; - - if ( - actualValue !== undefined - && poll.expectedValue !== undefined - && !isDeepStrictEqual(poll.expectedValue, actualValue) - ) { - return false; - } - - clearTimeout(poll.timeout); - this.scheduledPolls.delete(valueId); - - return true; - } - - public get endpointCountIsDynamic(): MaybeNotKnown { - return nodeUtils.endpointCountIsDynamic(this.driver, this); - } - - public get endpointsHaveIdenticalCapabilities(): MaybeNotKnown { - return nodeUtils.endpointsHaveIdenticalCapabilities(this.driver, this); - } - - public get individualEndpointCount(): MaybeNotKnown { - return nodeUtils.getIndividualEndpointCount(this.driver, this); - } - - public get aggregatedEndpointCount(): MaybeNotKnown { - return nodeUtils.getAggregatedEndpointCount(this.driver, this); - } - - /** Returns the device class of an endpoint. Falls back to the node's device class if the information is not known. */ - private getEndpointDeviceClass(index: number): MaybeNotKnown { - const deviceClass = this.getValue<{ - generic: number; - specific: number; - }>( - MultiChannelCCValues.endpointDeviceClass.endpoint( - this.endpointsHaveIdenticalCapabilities ? 1 : index, - ), - ); - if (deviceClass && this.deviceClass) { - return new DeviceClass( - this.deviceClass.basic, - deviceClass.generic, - deviceClass.specific, - ); - } - // fall back to the node's device class if it is known - return this.deviceClass; - } - - private getEndpointCCs(index: number): MaybeNotKnown { - const ret = this.getValue( - MultiChannelCCValues.endpointCCs.endpoint( - this.endpointsHaveIdenticalCapabilities ? 1 : index, - ), - ); - // Workaround for the change in #1977 - if (isArray(ret)) { - // The value is set up correctly, return it - return ret as CommandClasses[]; - } else if (isObject(ret) && "supportedCCs" in ret) { - return ret.supportedCCs as CommandClasses[]; - } - } - - /** - * Returns the current endpoint count of this node. - * - * If you want to enumerate the existing endpoints, use `getEndpointIndizes` instead. - * Some devices are known to contradict themselves. - */ - public getEndpointCount(): number { - return nodeUtils.getEndpointCount(this.driver, this); - } - - /** - * Returns indizes of all endpoints on the node. - */ - public getEndpointIndizes(): number[] { - return nodeUtils.getEndpointIndizes(this.driver, this); - } - - /** Whether the Multi Channel CC has been interviewed and all endpoint information is known */ - private get isMultiChannelInterviewComplete(): boolean { - return nodeUtils.isMultiChannelInterviewComplete(this.driver, this); - } - - /** Cache for this node's endpoint instances */ - private _endpointInstances = new Map(); - /** - * Returns an endpoint of this node with the given index. 0 returns the node itself. - */ - public getEndpoint(index: 0): Endpoint; - public getEndpoint(index: number): Endpoint | undefined; - public getEndpoint(index: number): Endpoint | undefined { - if (index < 0) { - throw new ZWaveError( - "The endpoint index must be positive!", - ZWaveErrorCodes.Argument_Invalid, - ); - } - // Zero is the root endpoint - i.e. this node - if (index === 0) return this; - // Check if the Multi Channel CC interview for this node is completed, - // because we don't have all the information before that - if (!this.isMultiChannelInterviewComplete) { - this.driver.driverLog.print( - `Node ${this.id}, Endpoint ${index}: Trying to access endpoint instance before Multi Channel interview`, - "error", - ); - return undefined; - } - // Check if the endpoint index is in the list of known endpoint indizes - if (!this.getEndpointIndizes().includes(index)) return undefined; - - // Create an endpoint instance if it does not exist - if (!this._endpointInstances.has(index)) { - this._endpointInstances.set( - index, - new Endpoint( - this.id, - this.driver, - index, - this.getEndpointDeviceClass(index), - this.getEndpointCCs(index), - ), - ); - } - return this._endpointInstances.get(index)!; - } - - public getEndpointOrThrow(index: number): Endpoint { - const ret = this.getEndpoint(index); - if (!ret) { - throw new ZWaveError( - `Endpoint ${index} does not exist on Node ${this.id}`, - ZWaveErrorCodes.Controller_EndpointNotFound, - ); - } - return ret; - } - - /** Returns a list of all endpoints of this node, including the root endpoint (index 0) */ - public getAllEndpoints(): Endpoint[] { - return nodeUtils.getAllEndpoints(this.driver, this) as Endpoint[]; - } - - /** - * This tells us which interview stage was last completed - */ - - public get interviewStage(): InterviewStage { - return ( - this.driver.cacheGet(cacheKeys.node(this.id).interviewStage) - ?? InterviewStage.None - ); - } - public set interviewStage(value: InterviewStage) { - this.driver.cacheSet(cacheKeys.node(this.id).interviewStage, value); - } - - private _interviewAttempts: number = 0; - /** How many attempts to interview this node have already been made */ - public get interviewAttempts(): number { - return this._interviewAttempts; - } - - private _hasEmittedNoS2NetworkKeyError: boolean = false; - private _hasEmittedNoS0NetworkKeyError: boolean = false; - - /** Returns whether this node is the controller */ - public get isControllerNode(): boolean { - return this.id === this.driver.controller.ownNodeId; - } - - /** - * Starts or resumes a deferred initial interview of this node. - * - * **WARNING:** This is only allowed when the initial interview was deferred using the - * `interview.disableOnNodeAdded` option. Otherwise, this method will throw an error. - * - * **NOTE:** It is advised to NOT await this method as it can take a very long time (minutes to hours)! - */ - public async interview(): Promise { - // The initial interview of the controller node is always done - // and cannot be deferred. - if (this.isControllerNode) return; + public async interview(): Promise { + // The initial interview of the controller node is always done + // and cannot be deferred. + if (this.isControllerNode) return; if (!this.driver.options.interview?.disableOnNodeAdded) { throw new ZWaveError( @@ -1736,7 +1127,7 @@ export class ZWaveNode extends Endpoint this._interviewAttempts = 0; this.interviewStage = InterviewStage.None; - this._ready = false; + this.ready = false; this.deviceClass = undefined; this.isListening = undefined; this.isFrequentListening = undefined; @@ -1762,9 +1153,7 @@ export class ZWaveNode extends Endpoint this.statusMachine.restart(); // Remove queued polls that would interfere with the interview - for (const valueId of this.scheduledPolls.keys()) { - this.cancelScheduledPoll(valueId); - } + this.cancelAllScheduledPolls(); // Restore the previously saved name/location if (name != undefined) this.name = name; @@ -5624,921 +5013,6 @@ protocol version: ${this.protocolVersion}`; }; } - private _abortFirmwareUpdate: (() => Promise) | undefined; - /** - * Aborts an active firmware update process - */ - public async abortFirmwareUpdate(): Promise { - if (!this._abortFirmwareUpdate) return; - await this._abortFirmwareUpdate(); - } - - // Stores the CRC of the previously transferred firmware image. - // Allows detecting whether resuming is supported and where to continue in a multi-file transfer. - private _previousFirmwareCRC: number | undefined; - - /** Is used to remember fragment requests that came in before they were able to be handled */ - private _firmwareUpdatePrematureRequest: - | FirmwareUpdateMetaDataCCGet - | undefined; - - /** - * Performs an OTA firmware upgrade of one or more chips on this node. - * - * This method will resolve after the process has **COMPLETED**. Failure to start any one of the provided updates will throw an error. - * - * **WARNING: Use at your own risk! We don't take any responsibility if your devices don't work after an update.** - * - * @param updates An array of firmware updates that will be done in sequence - * - * @returns Whether all of the given updates were successful. - */ - public async updateFirmware( - updates: Firmware[], - options: FirmwareUpdateOptions = {}, - ): Promise { - if (updates.length === 0) { - throw new ZWaveError( - `At least one update must be provided`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - - // Check that each update has a buffer with at least 1 byte - if (updates.some((u) => u.data.length === 0)) { - throw new ZWaveError( - `All firmware updates must have a non-empty data buffer`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - - // Check that the targets are not duplicates - if ( - distinct(updates.map((u) => u.firmwareTarget ?? 0)).length - !== updates.length - ) { - throw new ZWaveError( - `The target of all provided firmware updates must be unique`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - - // Don't start the process twice - if (this.driver.controller.isFirmwareUpdateInProgress()) { - throw new ZWaveError( - `Failed to start the update: An OTW upgrade of the controller is in progress!`, - ZWaveErrorCodes.FirmwareUpdateCC_Busy, - ); - } - - // Don't allow starting two firmware updates for the same node - const task = this.getUpdateFirmwareTask(updates, options); - if (task instanceof Promise) { - throw new ZWaveError( - `Failed to start the update: A firmware update is already in progress for this node!`, - ZWaveErrorCodes.FirmwareUpdateCC_Busy, - ); - } - - // Queue the task - return this.driver.scheduler.queueTask(task); - } - - /** - * Returns whether a firmware update is in progress for this node. - */ - public isFirmwareUpdateInProgress(): boolean { - return !!this.driver.scheduler.findTask( - nodeUtils.isFirmwareUpdateOTATask, - ); - } - - private getUpdateFirmwareTask( - updates: Firmware[], - options: FirmwareUpdateOptions = {}, - ): Promise | TaskBuilder { - const self = this; - - // This task should only run once at a time - const existingTask = this.driver.scheduler.findTask< - FirmwareUpdateResult - >((t) => - t.tag?.id === "firmware-update-ota" - && t.tag.nodeId === self.id - ); - if (existingTask) return existingTask; - - let keepAwake: boolean; - - return { - // Firmware updates cause a lot of traffic. Execute them in the background. - priority: TaskPriority.Lower, - tag: { id: "firmware-update-ota", nodeId: self.id }, - task: async function* firmwareUpdateTask() { - // Keep battery powered nodes awake during the process - keepAwake = self.keepAwake; - self.keepAwake = true; - - // Support aborting the update - const abortContext = { - abort: false, - tooLateToAbort: false, - abortPromise: createDeferredPromise(), - }; - - self._abortFirmwareUpdate = async () => { - if (abortContext.tooLateToAbort) { - throw new ZWaveError( - `The firmware update was transmitted completely, cannot abort anymore.`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToAbort, - ); - } - - self.driver.controllerLog.logNode(self.id, { - message: `Aborting firmware update...`, - direction: "outbound", - }); - - // Trigger the abort - abortContext.abort = true; - const aborted = await abortContext.abortPromise; - if (!aborted) { - throw new ZWaveError( - `The node did not acknowledge the aborted update`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToAbort, - ); - } - self.driver.controllerLog.logNode(self.id, { - message: `Firmware update aborted`, - direction: "inbound", - }); - }; - - // Prepare the firmware update - let fragmentSizeSecure: number; - let fragmentSizeNonSecure: number; - let meta: FirmwareUpdateMetaData; - try { - const prepareResult = await self - .prepareFirmwareUpdateInternal( - updates.map((u) => u.firmwareTarget ?? 0), - abortContext, - ); - - // Handle early aborts - if (abortContext.abort) { - const result: FirmwareUpdateResult = { - success: false, - status: FirmwareUpdateStatus - .Error_TransmissionFailed, - reInterview: false, - }; - self.emit( - "firmware update finished", - self, - result, - ); - return result; - } - - // If the firmware update was not aborted, prepareResult is definitely defined - ({ - fragmentSizeSecure, - fragmentSizeNonSecure, - ...meta - } = prepareResult!); - } catch { - // Not sure what the error is, but we'll label it "transmission failed" - const result: FirmwareUpdateResult = { - success: false, - status: FirmwareUpdateStatus.Error_TransmissionFailed, - reInterview: false, - }; - - return result; - } - - yield; // Give the task scheduler time to do something else - - // The resume and non-secure transfer features may not be supported by the node - // If not, disable them, even though the application requested them - if (!meta.supportsResuming) options.resume = false; - - const securityClass = self.getHighestSecurityClass(); - const isSecure = securityClass === SecurityClass.S0_Legacy - || securityClassIsS2(securityClass); - if (!isSecure) { - // The nonSecureTransfer option is only relevant for secure devices - options.nonSecureTransfer = false; - } else if (!meta.supportsNonSecureTransfer) { - options.nonSecureTransfer = false; - } - - // Throttle the progress emitter so applications can handle the load of events - const notifyProgress = throttle( - (progress) => - self.emit( - "firmware update progress", - self, - progress, - ), - 250, - true, - ); - - // If resuming is supported and desired, try to figure out with which file to continue - const updatesWithChecksum = updates.map((u) => ({ - ...u, - checksum: CRC16_CCITT(u.data), - })); - let skipFinishedFiles = -1; - let shouldResume = options.resume - && self._previousFirmwareCRC != undefined; - if (shouldResume) { - skipFinishedFiles = updatesWithChecksum.findIndex( - (u) => u.checksum === self._previousFirmwareCRC, - ); - if (skipFinishedFiles === -1) shouldResume = false; - } - - // Perform all firmware updates in sequence - let updateResult!: PartialFirmwareUpdateResult; - let conservativeWaitTime: number; - - const totalBytes: number = updatesWithChecksum.reduce( - (total, update) => total + update.data.length, - 0, - ); - let sentBytesOfPreviousFiles = 0; - - for (let i = 0; i < updatesWithChecksum.length; i++) { - const { firmwareTarget: target = 0, data, checksum } = - updatesWithChecksum[i]; - - if (i < skipFinishedFiles) { - // If we are resuming, skip this file since it was already done before - self.driver.controllerLog.logNode( - self.id, - `Skipping already completed firmware update (part ${ - i + 1 - } / ${updatesWithChecksum.length})...`, - ); - sentBytesOfPreviousFiles += data.length; - continue; - } - - self.driver.controllerLog.logNode( - self.id, - `Updating firmware (part ${ - i + 1 - } / ${updatesWithChecksum.length})...`, - ); - - // For determining the initial fragment size, assume the node respects our choice. - // If the node is not secure, these two values are identical anyways. - let fragmentSize = options.nonSecureTransfer - ? fragmentSizeNonSecure - : fragmentSizeSecure; - - // Tell the node to start requesting fragments - const { resume, nonSecureTransfer } = yield* self - .beginFirmwareUpdateInternal( - data, - target, - meta, - fragmentSize, - checksum, - shouldResume, - options.nonSecureTransfer, - ); - - // If the node did not accept non-secure transfer, revisit our choice of fragment size - if (options.nonSecureTransfer && !nonSecureTransfer) { - fragmentSize = fragmentSizeSecure; - } - - // Remember the checksum, so we can resume if necessary - self._previousFirmwareCRC = checksum; - - if (shouldResume) { - self.driver.controllerLog.logNode( - self.id, - `Node ${ - resume ? "accepted" : "did not accept" - } resuming the update...`, - ); - } - if (nonSecureTransfer) { - self.driver.controllerLog.logNode( - self.id, - `Firmware will be transferred without encryption...`, - ); - } - - yield; // Give the task scheduler time to do something else - - // Listen for firmware update fragment requests and handle them - updateResult = yield* self.doFirmwareUpdateInternal( - data, - fragmentSize, - nonSecureTransfer, - abortContext, - (fragment, total) => { - const progress: FirmwareUpdateProgress = { - currentFile: i + 1, - totalFiles: updatesWithChecksum.length, - sentFragments: fragment, - totalFragments: total, - progress: roundTo( - ( - (sentBytesOfPreviousFiles - + Math.min( - fragment * fragmentSize, - data.length, - )) - / totalBytes - ) * 100, - 2, - ), - }; - notifyProgress(progress); - - // When this file is done, add the fragments to the total, so we can compute the total progress correctly - if (fragment === total) { - sentBytesOfPreviousFiles += data.length; - } - }, - ); - - // If we wait, wait a bit longer than the device told us, so it is actually ready to use - conservativeWaitTime = self.driver - .getConservativeWaitTimeAfterFirmwareUpdate( - updateResult.waitTime, - ); - - if (!updateResult.success) { - self.driver.controllerLog.logNode(self.id, { - message: `Firmware update (part ${ - i + 1 - } / ${updatesWithChecksum.length}) failed with status ${ - getEnumMemberName( - FirmwareUpdateStatus, - updateResult.status, - ) - }`, - direction: "inbound", - }); - - const result: FirmwareUpdateResult = { - ...updateResult, - waitTime: undefined, - reInterview: false, - }; - self.emit( - "firmware update finished", - self, - result, - ); - - return result; - } else if (i < updatesWithChecksum.length - 1) { - // Update succeeded, but we're not done yet - - self.driver.controllerLog.logNode(self.id, { - message: `Firmware update (part ${ - i + 1 - } / ${updatesWithChecksum.length}) succeeded with status ${ - getEnumMemberName( - FirmwareUpdateStatus, - updateResult.status, - ) - }`, - direction: "inbound", - }); - - self.driver.controllerLog.logNode( - self.id, - `Continuing with next part in ${conservativeWaitTime} seconds...`, - ); - - // If we've resumed the previous file, there's no need to resume the next one too - shouldResume = false; - - yield () => wait(conservativeWaitTime * 1000, true); - } - } - - // We're done. No need to resume this update - self._previousFirmwareCRC = undefined; - - const result: FirmwareUpdateResult = { - ...updateResult, - waitTime: conservativeWaitTime!, - reInterview: true, - }; - - // After a successful firmware update, we want to interview sleeping nodes immediately, - // so don't send them to sleep when they wake up - keepAwake = true; - - self.emit("firmware update finished", self, result); - - return result; - }, - cleanup() { - self._abortFirmwareUpdate = undefined; - self._firmwareUpdatePrematureRequest = undefined; - - // Make sure that the keepAwake flag gets reset at the end - self.keepAwake = keepAwake; - if (!keepAwake) { - setImmediate(() => { - self.driver.debounceSendNodeToSleep(self); - }); - } - - return Promise.resolve(); - }, - }; - } - - /** Prepares the firmware update of a single target by collecting the necessary information */ - private async prepareFirmwareUpdateInternal( - targets: number[], - abortContext: AbortFirmwareUpdateContext, - ): Promise< - | undefined - | (FirmwareUpdateMetaData & { - fragmentSizeSecure: number; - fragmentSizeNonSecure: number; - }) - > { - const api = this.commandClasses["Firmware Update Meta Data"]; - - // ================================ - // STEP 1: - // Check if this update is possible - const meta = await api.getMetaData(); - if (!meta) { - throw new ZWaveError( - `Failed to start the update: The node did not respond in time!`, - ZWaveErrorCodes.Controller_NodeTimeout, - ); - } - - for (const target of targets) { - if (target === 0) { - if (!meta.firmwareUpgradable) { - throw new ZWaveError( - `Failed to start the update: The Z-Wave chip firmware is not upgradable!`, - ZWaveErrorCodes.FirmwareUpdateCC_NotUpgradable, - ); - } - } else { - if (api.version < 3) { - throw new ZWaveError( - `Failed to start the update: The node does not support upgrading a different firmware target than 0!`, - ZWaveErrorCodes.FirmwareUpdateCC_TargetNotFound, - ); - } else if ( - meta.additionalFirmwareIDs[target - 1] == undefined - ) { - throw new ZWaveError( - `Failed to start the update: Firmware target #${target} not found on this node!`, - ZWaveErrorCodes.FirmwareUpdateCC_TargetNotFound, - ); - } - } - } - - // ================================ - // STEP 2: - // Determine the fragment size - const fcc = new FirmwareUpdateMetaDataCC(this.driver, { - nodeId: this.id, - }); - const maxGrossPayloadSizeSecure = this.driver - .computeNetCCPayloadSize( - fcc, - ); - const maxGrossPayloadSizeNonSecure = this.driver - .computeNetCCPayloadSize(fcc, true); - - const maxNetPayloadSizeSecure = maxGrossPayloadSizeSecure - - 2 // report number - - (fcc.version >= 2 ? 2 : 0); // checksum - const maxNetPayloadSizeNonSecure = maxGrossPayloadSizeNonSecure - - 2 // report number - - (fcc.version >= 2 ? 2 : 0); // checksum - - // Use the smallest allowed payload - const fragmentSizeSecure = Math.min( - maxNetPayloadSizeSecure, - meta.maxFragmentSize ?? Number.POSITIVE_INFINITY, - ); - const fragmentSizeNonSecure = Math.min( - maxNetPayloadSizeNonSecure, - meta.maxFragmentSize ?? Number.POSITIVE_INFINITY, - ); - - if (abortContext.abort) { - abortContext.abortPromise.resolve(true); - return; - } else { - return { - ...meta, - fragmentSizeSecure, - fragmentSizeNonSecure, - }; - } - } - - protected async handleUnexpectedFirmwareUpdateGet( - command: FirmwareUpdateMetaDataCCGet, - ): Promise { - // This method will only be called under two circumstances: - // 1. The node is currently busy responding to a firmware update request -> remember the request - if (this.isFirmwareUpdateInProgress()) { - this._firmwareUpdatePrematureRequest = command; - return; - } - - // 2. No firmware update is in progress -> abort - this.driver.controllerLog.logNode(this.id, { - message: - `Received Firmware Update Get, but no firmware update is in progress. Forcing the node to abort...`, - direction: "inbound", - }); - - // Since no update is in progress, we need to determine the fragment size again - const fcc = new FirmwareUpdateMetaDataCC(this.driver, { - nodeId: this.id, - }); - const fragmentSize = this.driver.computeNetCCPayloadSize(fcc) - - 2 // report number - - (fcc.version >= 2 ? 2 : 0); // checksum - const fragment = randomBytes(fragmentSize); - try { - await this.sendCorruptedFirmwareUpdateReport( - command.reportNumber, - fragment, - ); - } catch { - // ignore - } - } - - /** Kicks off a firmware update of a single target. Returns whether the node accepted resuming and non-secure transfer */ - private *beginFirmwareUpdateInternal( - data: Buffer, - target: number, - meta: FirmwareUpdateMetaData, - fragmentSize: number, - checksum: number, - resume: boolean | undefined, - nonSecureTransfer: boolean | undefined, - ) { - const api = this.commandClasses["Firmware Update Meta Data"]; - - // ================================ - // STEP 3: - // Start the update - this.driver.controllerLog.logNode(this.id, { - message: `Starting firmware update...`, - direction: "outbound", - }); - - // Request the node to start the upgrade. Pause the task until this is done, - // since the call can block for a long time - const result: FirmwareUpdateInitResult = yield () => - api.requestUpdate({ - // TODO: Should manufacturer id and firmware id be provided externally? - manufacturerId: meta.manufacturerId, - firmwareId: target == 0 - ? meta.firmwareId - : meta.additionalFirmwareIDs[target - 1], - firmwareTarget: target, - fragmentSize, - checksum, - resume, - nonSecureTransfer, - }); - switch (result.status) { - case FirmwareUpdateRequestStatus.Error_AuthenticationExpected: - throw new ZWaveError( - `Failed to start the update: A manual authentication event (e.g. button push) was expected!`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, - ); - case FirmwareUpdateRequestStatus.Error_BatteryLow: - throw new ZWaveError( - `Failed to start the update: The battery level is too low!`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, - ); - case FirmwareUpdateRequestStatus - .Error_FirmwareUpgradeInProgress: - throw new ZWaveError( - `Failed to start the update: A firmware upgrade is already in progress!`, - ZWaveErrorCodes.FirmwareUpdateCC_Busy, - ); - case FirmwareUpdateRequestStatus - .Error_InvalidManufacturerOrFirmwareID: - throw new ZWaveError( - `Failed to start the update: Invalid manufacturer or firmware id!`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, - ); - case FirmwareUpdateRequestStatus.Error_InvalidHardwareVersion: - throw new ZWaveError( - `Failed to start the update: Invalid hardware version!`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, - ); - case FirmwareUpdateRequestStatus.Error_NotUpgradable: - throw new ZWaveError( - `Failed to start the update: Firmware target #${target} is not upgradable!`, - ZWaveErrorCodes.FirmwareUpdateCC_NotUpgradable, - ); - case FirmwareUpdateRequestStatus.Error_FragmentSizeTooLarge: - throw new ZWaveError( - `Failed to start the update: The chosen fragment size is too large!`, - ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, - ); - case FirmwareUpdateRequestStatus.OK: - // All good, we have started! - // Keep the node awake until the update is done. - this.keepAwake = true; - } - - return { - resume: !!result.resume, - nonSecureTransfer: !!result.nonSecureTransfer, - }; - } - - protected async handleFirmwareUpdateMetaDataGet( - command: FirmwareUpdateMetaDataCCMetaDataGet, - ): Promise { - const endpoint = this.getEndpoint(command.endpointIndex) - ?? this; - - // We are being queried, so the device may actually not support the CC, just control it. - // Using the commandClasses property would throw in that case - const api = endpoint - .createAPI(CommandClasses["Firmware Update Meta Data"], false) - .withOptions({ - // Answer with the same encapsulation as asked, but omit - // Supervision as it shouldn't be used for Get-Report flows - encapsulationFlags: command.encapsulationFlags - & ~EncapsulationFlags.Supervision, - }); - - // We do not support the firmware to be upgraded. - await api.reportMetaData({ - manufacturerId: this.driver.options.vendor?.manufacturerId - ?? 0xffff, - firmwareUpgradable: false, - hardwareVersion: this.driver.options.vendor?.hardwareVersion - ?? 0, - }); - } - - private async sendCorruptedFirmwareUpdateReport( - reportNum: number, - fragment: Buffer, - nonSecureTransfer: boolean = false, - ): Promise { - try { - await this.commandClasses["Firmware Update Meta Data"] - .withOptions({ - // Only encapsulate if the transfer is secure - autoEncapsulate: !nonSecureTransfer, - }) - .sendFirmwareFragment(reportNum, true, fragment); - } catch { - // ignore - } - } - - private hasPendingFirmwareUpdateFragment( - fragmentNumber: number, - ): boolean { - // Avoid queuing duplicate fragments - const isCurrentFirmwareFragment = (t: Transaction) => - t.message.getNodeId() === this.id - && isCommandClassContainer(t.message) - && t.message.command instanceof FirmwareUpdateMetaDataCCReport - && t.message.command.reportNumber === fragmentNumber; - - return this.driver.hasPendingTransactions( - isCurrentFirmwareFragment, - ); - } - - private async *doFirmwareUpdateInternal( - data: Buffer, - fragmentSize: number, - nonSecureTransfer: boolean, - abortContext: AbortFirmwareUpdateContext, - onProgress: (fragment: number, total: number) => void, - ): AsyncGenerator< - any, - PartialFirmwareUpdateResult, - any - > { - const numFragments = Math.ceil(data.length / fragmentSize); - - // Make sure we're not responding to an outdated request immediately - this._firmwareUpdatePrematureRequest = undefined; - - // ================================ - // STEP 4: - // Respond to fragment requests from the node - update: while (true) { - yield; // Give the task scheduler time to do something else - - // During ongoing firmware updates, it can happen that the next request is received before the callback for the previous response - // is back. In that case we can immediately handle the premature request. Otherwise wait for the next request. - let fragmentRequest: FirmwareUpdateMetaDataCCGet; - if (this._firmwareUpdatePrematureRequest) { - fragmentRequest = this._firmwareUpdatePrematureRequest; - this._firmwareUpdatePrematureRequest = undefined; - } else { - try { - fragmentRequest = yield () => - this.driver - .waitForCommand( - (cc) => - cc.nodeId === this.id - && cc - instanceof FirmwareUpdateMetaDataCCGet, - // Wait up to 2 minutes for each fragment request. - // Some users try to update devices with unstable connections, where 30s can be too short. - timespan.minutes(2), - ); - } catch { - // In some cases it can happen that the device stops requesting update frames - // We need to timeout the update in this case so it can be restarted - this.driver.controllerLog.logNode(this.id, { - message: `Firmware update timed out`, - direction: "none", - level: "warn", - }); - - return { - success: false, - status: FirmwareUpdateStatus.Error_Timeout, - }; - } - } - - // When a node requests a firmware update fragment, it must be awake - this.markAsAwake(); - - if (fragmentRequest.reportNumber > numFragments) { - this.driver.controllerLog.logNode(this.id, { - message: - `Received Firmware Update Get for an out-of-bounds fragment. Forcing the node to abort...`, - direction: "inbound", - }); - await this.sendCorruptedFirmwareUpdateReport( - fragmentRequest.reportNumber, - randomBytes(fragmentSize), - nonSecureTransfer, - ); - // This will cause the node to abort the process, wait for that - break update; - } - - // Actually send the requested frames - request: for ( - let num = fragmentRequest.reportNumber; - num - < fragmentRequest.reportNumber - + fragmentRequest.numReports; - num++ - ) { - yield; // Give the task scheduler time to do something else - - // Check if the node requested more fragments than are left - if (num > numFragments) { - break; - } - const fragment = data.subarray( - (num - 1) * fragmentSize, - num * fragmentSize, - ); - - if (abortContext.abort) { - await this.sendCorruptedFirmwareUpdateReport( - fragmentRequest.reportNumber, - randomBytes(fragment.length), - nonSecureTransfer, - ); - // This will cause the node to abort the process, wait for that - break update; - } else { - // Avoid queuing duplicate fragments - if (this.hasPendingFirmwareUpdateFragment(num)) { - this.driver.controllerLog.logNode(this.id, { - message: `Firmware fragment ${num} already queued`, - level: "warn", - }); - continue request; - } - - this.driver.controllerLog.logNode(this.id, { - message: - `Sending firmware fragment ${num} / ${numFragments}`, - direction: "outbound", - }); - const isLast = num === numFragments; - - try { - await this - .commandClasses["Firmware Update Meta Data"] - .withOptions({ - // Only encapsulate if the transfer is secure - autoEncapsulate: !nonSecureTransfer, - }) - .sendFirmwareFragment(num, isLast, fragment); - - onProgress(num, numFragments); - - // If that was the last one wait for status report from the node and restart interview - if (isLast) { - abortContext.tooLateToAbort = true; - break update; - } - } catch { - // When transmitting fails, simply stop responding to this request and wait for the node to re-request the fragment - this.driver.controllerLog.logNode(this.id, { - message: - `Failed to send firmware fragment ${num} / ${numFragments}`, - direction: "outbound", - level: "warn", - }); - break request; - } - } - } - } - - yield; // Give the task scheduler time to do something else - - // ================================ - // STEP 5: - // Finalize the update process - - const statusReport: - | FirmwareUpdateMetaDataCCStatusReport - | undefined = yield () => - this.driver - .waitForCommand( - (cc) => - cc.nodeId === this.id - && cc - instanceof FirmwareUpdateMetaDataCCStatusReport, - // Wait up to 5 minutes. It should never take that long, but the specs - // don't say anything specific - 5 * 60000, - ) - .catch(() => undefined); - - if (abortContext.abort) { - abortContext.abortPromise.resolve( - // The error should be Error_TransmissionFailed, but some devices - // use the Error_Checksum error code instead - statusReport?.status - === FirmwareUpdateStatus.Error_TransmissionFailed - || statusReport?.status - === FirmwareUpdateStatus.Error_Checksum, - ); - } - - if (!statusReport) { - this.driver.controllerLog.logNode( - this.id, - `The node did not acknowledge the completed update`, - "warn", - ); - - return { - success: false, - status: FirmwareUpdateStatus.Error_Timeout, - }; - } - - const { status, waitTime } = statusReport; - - // Actually, OK_WaitingForActivation should never happen since we don't allow - // delayed activation in the RequestGet command - const success = status >= FirmwareUpdateStatus.OK_WaitingForActivation; - - return { - success, - status, - waitTime, - }; - } - private recentEntryControlNotificationSequenceNumbers: number[] = []; private handleEntryControlNotification( command: EntryControlCCNotification, @@ -6596,50 +5070,6 @@ protocol version: ${this.protocolVersion}`; } } - /** - * Whether the node should be kept awake when there are no pending messages. - */ - public keepAwake: boolean = false; - - private isSendingNoMoreInformation: boolean = false; - /** - * @internal - * Sends the node a WakeUpCCNoMoreInformation so it can go back to sleep - */ - public async sendNoMoreInformation(): Promise { - // Don't send the node back to sleep if it should be kept awake - if (this.keepAwake) return false; - - // Avoid calling this method more than once - if (this.isSendingNoMoreInformation) return false; - this.isSendingNoMoreInformation = true; - - let msgSent = false; - if ( - this.status === NodeStatus.Awake - && this.interviewStage === InterviewStage.Complete - ) { - this.driver.controllerLog.logNode(this.id, { - message: "Sending node back to sleep...", - direction: "outbound", - }); - try { - // it is important that we catch errors in this call - // otherwise, this method will not work anymore because - // isSendingNoMoreInformation is stuck on `true` - await this.commandClasses["Wake Up"].sendNoMoreInformation(); - msgSent = true; - } catch { - /* ignore */ - } finally { - this.markAsAsleep(); - } - } - - this.isSendingNoMoreInformation = false; - return msgSent; - } - /** * Instructs the node to send powerlevel test frames to the other node using the given powerlevel. Returns how many frames were acknowledged during the test. * diff --git a/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts b/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts index ef1f946fa623..097bb467b587 100644 --- a/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts +++ b/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts @@ -8,9 +8,6 @@ import { createNodeStatusMachine, } from "./NodeStatusMachine"; -const testNodeNonSleeping = { canSleep: false } as any; -const testNodeSleeping = { canSleep: true } as any; - function startMachine( t: ExecutionContext, machine: NodeStatusMachine, @@ -21,18 +18,14 @@ function startMachine( } test(`The node should start in the unknown state if it maybe cannot sleep`, (t) => { - const testMachine = createNodeStatusMachine({ - canSleep: false, - } as any); + const testMachine = createNodeStatusMachine(false); const service = startMachine(t, testMachine); t.is(service.getSnapshot().value, "unknown"); }); test(`The node should start in the unknown state if it can definitely sleep`, (t) => { - const testMachine = createNodeStatusMachine({ - canSleep: true, - } as any); + const testMachine = createNodeStatusMachine(true); const service = startMachine(t, testMachine); t.is(service.getSnapshot().value, "unknown"); @@ -171,15 +164,15 @@ for (const testCase of transitions) { test(name, (t) => { // For these tests, assume that the node does or does not support Wakeup, whatever fits - const testNode = testCase.canSleep == undefined + const canSleep = testCase.canSleep == undefined ? testCase.event === "ASLEEP" || testCase.event === "AWAKE" - ? testNodeSleeping - : testNodeNonSleeping + ? true + : false : testCase.canSleep - ? testNodeSleeping - : testNodeNonSleeping; + ? true + : false; - const testMachine = createNodeStatusMachine(testNode); + const testMachine = createNodeStatusMachine(canSleep); testMachine.initial = testCase.start; const service = startMachine(t, testMachine); @@ -189,7 +182,7 @@ for (const testCase of transitions) { } test("A transition from unknown to awake should not happen if the node cannot sleep", (t) => { - const testMachine = createNodeStatusMachine(testNodeNonSleeping); + const testMachine = createNodeStatusMachine(false); const service = startMachine(t, testMachine); service.send("AWAKE"); @@ -197,7 +190,7 @@ test("A transition from unknown to awake should not happen if the node cannot sl }); test("A transition from unknown to asleep should not happen if the node cannot sleep", (t) => { - const testMachine = createNodeStatusMachine(testNodeNonSleeping); + const testMachine = createNodeStatusMachine(false); const service = startMachine(t, testMachine); service.send("ASLEEP"); diff --git a/packages/zwave-js/src/lib/node/NodeStatusMachine.ts b/packages/zwave-js/src/lib/node/NodeStatusMachine.ts index 9bca75019308..0140de63acde 100644 --- a/packages/zwave-js/src/lib/node/NodeStatusMachine.ts +++ b/packages/zwave-js/src/lib/node/NodeStatusMachine.ts @@ -1,5 +1,4 @@ import { type InterpreterFrom, Machine, type StateMachine } from "xstate"; -import type { ZWaveNode } from "./Node"; import { NodeStatus } from "./_Types"; export interface NodeStatusStateSchema { @@ -44,7 +43,7 @@ export type NodeStatusMachine = StateMachine< >; export type NodeStatusInterpreter = InterpreterFrom; -export function createNodeStatusMachine(node: ZWaveNode): NodeStatusMachine { +export function createNodeStatusMachine(canSleep: boolean): NodeStatusMachine { return Machine( { id: "nodeStatus", @@ -104,8 +103,8 @@ export function createNodeStatusMachine(node: ZWaveNode): NodeStatusMachine { }, { guards: { - canSleep: () => !!node.canSleep, - cannotSleep: () => !node.canSleep, + canSleep: () => !!canSleep, + cannotSleep: () => !canSleep, }, }, ); diff --git a/packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts b/packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts new file mode 100644 index 000000000000..3095f57b9166 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts @@ -0,0 +1,144 @@ +import { + type DataRate, + type FLiRS, + type MaybeNotKnown, + NOT_KNOWN, + type NodeType, + type ProtocolVersion, + Protocols, + isLongRangeNodeId, +} from "@zwave-js/core"; +import { cacheKeys } from "../../driver/NetworkCache"; +import { ZWaveNodeBase } from "../Node"; + +export interface NodeNetworkRole { + /** Whether this node is always listening or not */ + readonly isListening: MaybeNotKnown; + + /** Indicates the wakeup interval if this node is a FLiRS node. `false` if it isn't. */ + readonly isFrequentListening: MaybeNotKnown; + + /** Whether this node can sleep */ + readonly canSleep: MaybeNotKnown; + + /** Whether the node supports routing/forwarding messages. */ + readonly isRouting: MaybeNotKnown; + + /** All supported data rates of this node */ + readonly supportedDataRates: MaybeNotKnown; + + /** The maximum data rate supported by this node */ + readonly maxDataRate: MaybeNotKnown; + + /** The Z-Wave protocol version this node implements */ + readonly protocolVersion: MaybeNotKnown; + + /** Whether this node is a controller (can calculate routes) or an end node (relies on route info) */ + readonly nodeType: MaybeNotKnown; + + /** + * Whether this node supports security (S0 or S2). + * **WARNING:** Nodes often report this incorrectly - do not blindly trust it. + */ + readonly supportsSecurity: MaybeNotKnown; + + /** Whether this node can issue wakeup beams to FLiRS nodes */ + readonly supportsBeaming: MaybeNotKnown; + + /** Which protocol is used to communicate with this node */ + readonly protocol: Protocols; + + /** Returns whether this node is the controller */ + readonly isControllerNode: boolean; +} + +export abstract class NetworkRoleMixin extends ZWaveNodeBase + implements NodeNetworkRole +{ + public get isListening(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).isListening); + } + protected set isListening(value: MaybeNotKnown) { + this.driver.cacheSet(cacheKeys.node(this.id).isListening, value); + } + + public get isFrequentListening(): MaybeNotKnown { + return this.driver.cacheGet( + cacheKeys.node(this.id).isFrequentListening, + ); + } + protected set isFrequentListening(value: MaybeNotKnown) { + this.driver.cacheSet( + cacheKeys.node(this.id).isFrequentListening, + value, + ); + } + + public get canSleep(): MaybeNotKnown { + // The controller node can never sleep (apparently it can report otherwise though) + if (this.isControllerNode) return false; + if (this.isListening == NOT_KNOWN) return NOT_KNOWN; + if (this.isFrequentListening == NOT_KNOWN) return NOT_KNOWN; + return !this.isListening && !this.isFrequentListening; + } + + public get isRouting(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).isRouting); + } + protected set isRouting(value: MaybeNotKnown) { + this.driver.cacheSet(cacheKeys.node(this.id).isRouting, value); + } + + public get supportedDataRates(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).supportedDataRates); + } + protected set supportedDataRates( + value: MaybeNotKnown, + ) { + this.driver.cacheSet(cacheKeys.node(this.id).supportedDataRates, value); + } + + public get maxDataRate(): MaybeNotKnown { + if (this.supportedDataRates) { + return Math.max(...this.supportedDataRates) as DataRate; + } + } + + public get protocolVersion(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).protocolVersion); + } + protected set protocolVersion(value: MaybeNotKnown) { + this.driver.cacheSet(cacheKeys.node(this.id).protocolVersion, value); + } + + public get nodeType(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).nodeType); + } + protected set nodeType(value: MaybeNotKnown) { + this.driver.cacheSet(cacheKeys.node(this.id).nodeType, value); + } + + public get supportsSecurity(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).supportsSecurity); + } + protected set supportsSecurity(value: MaybeNotKnown) { + this.driver.cacheSet(cacheKeys.node(this.id).supportsSecurity, value); + } + + public get supportsBeaming(): MaybeNotKnown { + return this.driver.cacheGet(cacheKeys.node(this.id).supportsBeaming); + } + protected set supportsBeaming(value: MaybeNotKnown) { + this.driver.cacheSet(cacheKeys.node(this.id).supportsBeaming, value); + } + + public get protocol(): Protocols { + return isLongRangeNodeId(this.id) + ? Protocols.ZWaveLongRange + : Protocols.ZWave; + } + + public get isControllerNode(): boolean { + return this.id === this.driver.controller.ownNodeId; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/10_Events.ts b/packages/zwave-js/src/lib/node/mixins/10_Events.ts new file mode 100644 index 000000000000..76a0fb4aeacb --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/10_Events.ts @@ -0,0 +1,41 @@ +import { type EventHandler } from "@zwave-js/shared"; +import { type StatisticsEventCallbacksWithSelf } from "../../driver/Statistics"; +import { type ZWaveNode } from "../Node"; +import { type NodeStatistics } from "../NodeStatistics"; +import { type ZWaveNodeEventCallbacks } from "../_Types"; +import { NetworkRoleMixin } from "./00_NetworkRole"; + +// This mixin is a slightly ugly workaround to allow other mixins to +// interact with events which would normally take an instance of ZWaveNode + +type ReplaceNodeWithThis = { + [K in keyof T]: T[K] extends ZWaveNode ? TThis : T[K]; +}; + +export type EventsToAbstract> = { + [K in keyof T]: ( + ...args: ReplaceNodeWithThis> + ) => void; +}; + +type AbstractNodeEvents = EventsToAbstract< + TThis, + & ZWaveNodeEventCallbacks + & StatisticsEventCallbacksWithSelf +>; + +export abstract class NodeEventsMixin extends NetworkRoleMixin { + protected abstract _emit>( + event: TEvent, + ...args: Parameters[TEvent]> + ): boolean; + + protected abstract _on>( + event: TEvent, + callback: AbstractNodeEvents[TEvent], + ): this; + protected abstract _once>( + event: TEvent, + callback: AbstractNodeEvents[TEvent], + ): this; +} diff --git a/packages/zwave-js/src/lib/node/mixins/20_Status.ts b/packages/zwave-js/src/lib/node/mixins/20_Status.ts new file mode 100644 index 000000000000..8376449b6689 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/20_Status.ts @@ -0,0 +1,180 @@ +import { type CommandClasses } from "@zwave-js/core"; +import { type Driver } from "../../driver/Driver"; +import { type Extended, interpretEx } from "../../driver/StateMachineShared"; +import { type DeviceClass } from "../DeviceClass"; +import { + type NodeReadyInterpreter, + createNodeReadyMachine, +} from "../NodeReadyMachine"; +import { + type NodeStatusInterpreter, + createNodeStatusMachine, + nodeStatusMachineStateToNodeStatus, +} from "../NodeStatusMachine"; +import { NodeStatus } from "../_Types"; +import { NodeEventsMixin } from "./10_Events"; + +export interface NodeWithStatus { + /** + * Which status the node is believed to be in + */ + status: NodeStatus; + + /** + * Whether the node is ready to be used + */ + ready: boolean; + + /** + * @internal + * Marks this node as dead (if applicable) + */ + markAsDead(): void; + + /** + * @internal + * Marks this node as alive (if applicable) + */ + markAsAlive(): void; + + /** + * @internal + * Marks this node as asleep (if applicable) + */ + markAsAsleep(): void; + + /** + * @internal + * Marks this node as awake (if applicable) + */ + markAsAwake(): void; +} + +export abstract class NodeStatusMixin extends NodeEventsMixin + implements NodeWithStatus +{ + public constructor( + nodeId: number, + driver: Driver, + index: number, + deviceClass?: DeviceClass, + supportedCCs?: CommandClasses[], + ) { + super(nodeId, driver, index, deviceClass, supportedCCs); + + // Create and hook up the status machine + this.statusMachine = interpretEx( + createNodeStatusMachine(this.canSleep ?? false), + ); + this.statusMachine.onTransition((state) => { + if (state.changed) { + this.onStatusChange( + nodeStatusMachineStateToNodeStatus(state.value as any), + ); + } + }); + this.statusMachine.start(); + + this.readyMachine = interpretEx(createNodeReadyMachine()); + this.readyMachine.onTransition((state) => { + if (state.changed) { + this.onReadyChange(state.value === "ready"); + } + }); + this.readyMachine.start(); + } + + protected statusMachine: Extended; + + private _status: NodeStatus = NodeStatus.Unknown; + + /** + * Which status the node is believed to be in + */ + public get status(): NodeStatus { + return this._status; + } + + private onStatusChange(newStatus: NodeStatus) { + // Ignore duplicate events + if (newStatus === this._status) return; + + const oldStatus = this._status; + this._status = newStatus; + if (this._status === NodeStatus.Asleep) { + this._emit("sleep", this, oldStatus); + } else if (this._status === NodeStatus.Awake) { + this._emit("wake up", this, oldStatus); + } else if (this._status === NodeStatus.Dead) { + this._emit("dead", this, oldStatus); + } else if (this._status === NodeStatus.Alive) { + this._emit("alive", this, oldStatus); + } + + // To be marked ready, a node must be known to be not dead. + // This means that listening nodes must have communicated with us and + // sleeping nodes are assumed to be ready + this.readyMachine.send( + this._status !== NodeStatus.Unknown + && this._status !== NodeStatus.Dead + ? "NOT_DEAD" + : "MAYBE_DEAD", + ); + } + + /** + * @internal + * Marks this node as dead (if applicable) + */ + public markAsDead(): void { + this.statusMachine.send("DEAD"); + } + + /** + * @internal + * Marks this node as alive (if applicable) + */ + public markAsAlive(): void { + this.statusMachine.send("ALIVE"); + } + + /** + * @internal + * Marks this node as asleep (if applicable) + */ + public markAsAsleep(): void { + this.statusMachine.send("ASLEEP"); + } + + /** + * @internal + * Marks this node as awake (if applicable) + */ + public markAsAwake(): void { + this.statusMachine.send("AWAKE"); + } + + // The node is only ready when the interview has been completed + // to a certain degree + + protected readyMachine: Extended; + private _ready: boolean = false; + + private onReadyChange(ready: boolean) { + // Ignore duplicate events + if (ready === this._ready) return; + + this._ready = ready; + if (ready) this._emit("ready", this); + } + + /** + * Whether the node is ready to be used + */ + public get ready(): boolean { + return this._ready; + } + protected set ready(ready: boolean) { + this._ready = ready; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/30_Wakeup.ts b/packages/zwave-js/src/lib/node/mixins/30_Wakeup.ts new file mode 100644 index 000000000000..1c2df3059705 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/30_Wakeup.ts @@ -0,0 +1,76 @@ +import { + CommandClasses, + InterviewStage, + NodeStatus, + ZWaveError, + ZWaveErrorCodes, +} from "@zwave-js/core"; +import { NodeStatusMixin } from "./20_Status"; + +/** + * Interface for NodeWakeupMixin + */ +export interface NodeWakeup { + /** Returns a promise that resolves when the node wakes up the next time or immediately if the node is already awake. */ + waitForWakeup(): Promise; + + /** + * Sends the node a WakeUpCCNoMoreInformation so it can go back to sleep + * @internal + */ + sendNoMoreInformation(): Promise; +} + +export abstract class NodeWakeupMixin extends NodeStatusMixin + implements NodeWakeup +{ + public waitForWakeup(): Promise { + if (!this.canSleep || !this.supportsCC(CommandClasses["Wake Up"])) { + throw new ZWaveError( + `Node ${this.id} does not support wakeup!`, + ZWaveErrorCodes.CC_NotSupported, + ); + } else if (this.status === NodeStatus.Awake) { + return Promise.resolve(); + } + + return new Promise((resolve) => { + this._once("wake up", () => resolve()); + }); + } + + private isSendingNoMoreInformation: boolean = false; + public async sendNoMoreInformation(): Promise { + // Don't send the node back to sleep if it should be kept awake + if (this.keepAwake) return false; + + // Avoid calling this method more than once + if (this.isSendingNoMoreInformation) return false; + this.isSendingNoMoreInformation = true; + + let msgSent = false; + if ( + this.status === NodeStatus.Awake + && this.interviewStage === InterviewStage.Complete + ) { + this.driver.controllerLog.logNode(this.id, { + message: "Sending node back to sleep...", + direction: "outbound", + }); + try { + // it is important that we catch errors in this call + // otherwise, this method will not work anymore because + // isSendingNoMoreInformation is stuck on `true` + await this.commandClasses["Wake Up"].sendNoMoreInformation(); + msgSent = true; + } catch { + /* ignore */ + } finally { + this.markAsAsleep(); + } + } + + this.isSendingNoMoreInformation = false; + return msgSent; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/40_Values.ts b/packages/zwave-js/src/lib/node/mixins/40_Values.ts new file mode 100644 index 000000000000..09809fb09319 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/40_Values.ts @@ -0,0 +1,234 @@ +import { + type CCValueOptions, + CommandClass, + defaultCCValueOptions, + getCCValues, +} from "@zwave-js/cc"; +import { + type CommandClasses, + type MaybeNotKnown, + type MetadataUpdatedArgs, + ValueDB, + type ValueID, + ValueMetadata, + type ValueUpdatedArgs, + applicationCCs, + getCCName, +} from "@zwave-js/core"; +import { pick } from "@zwave-js/shared"; +import { type Driver } from "../../driver/Driver"; +import { type DeviceClass } from "../DeviceClass"; +import { type ZWaveNodeValueEventCallbacks } from "../_Types"; +import * as nodeUtils from "../utils"; +import { NodeWakeupMixin } from "./30_Wakeup"; + +/** Defines functionality of Z-Wave nodes related to the value DB */ +export interface NodeValues { + /** + * Provides access to this node's values + * @internal + */ + readonly valueDB: ValueDB; + + /** + * Retrieves a stored value for a given value id. + * This does not request an updated value from the node! + */ + getValue(valueId: ValueID): MaybeNotKnown; + + /** + * Returns when the given value id was last updated by an update from the node. + */ + getValueTimestamp(valueId: ValueID): MaybeNotKnown; + + /** + * Retrieves metadata for a given value id. + * This can be used to enhance the user interface of an application + */ + getValueMetadata(valueId: ValueID): ValueMetadata; +} + +export abstract class NodeValuesMixin extends NodeWakeupMixin + implements NodeValues +{ + public constructor( + nodeId: number, + driver: Driver, + endpointIndex: number, + deviceClass?: DeviceClass, + supportedCCs?: CommandClasses[], + valueDB?: ValueDB, + ) { + // Define this node's intrinsic endpoint as the root device (0) + super(nodeId, driver, endpointIndex, deviceClass, supportedCCs); + this._valueDB = valueDB + ?? new ValueDB(nodeId, driver.valueDB!, driver.metadataDB!); + } + + protected _valueDB: ValueDB; + public get valueDB(): ValueDB { + return this._valueDB; + } + + public getValue(valueId: ValueID): MaybeNotKnown { + return this._valueDB.getValue(valueId); + } + + public getValueTimestamp(valueId: ValueID): MaybeNotKnown { + return this._valueDB.getTimestamp(valueId); + } + + public getValueMetadata(valueId: ValueID): ValueMetadata { + // Check if a corresponding CC value is defined for this value ID + // so we can extend the returned metadata + const definedCCValues = getCCValues(valueId.commandClass); + let valueOptions: Required | undefined; + let meta: ValueMetadata | undefined; + if (definedCCValues) { + const value = Object.values(definedCCValues) + .find((v) => v?.is(valueId)); + if (value) { + if (typeof value !== "function") { + meta = value.meta; + } + valueOptions = value.options; + } + } + + const existingMetadata = this._valueDB.getMetadata(valueId); + return { + // The priority for returned metadata is valueDB > defined value > Any (default) + ...(existingMetadata ?? meta ?? ValueMetadata.Any), + // ...except for these flags, which are taken from defined values: + stateful: valueOptions?.stateful ?? defaultCCValueOptions.stateful, + secret: valueOptions?.secret ?? defaultCCValueOptions.secret, + }; + } + + /** + * Enhances the raw event args of the ValueDB so it can be consumed better by applications + */ + protected translateValueEvent( + eventName: keyof ZWaveNodeValueEventCallbacks, + arg: T, + ): void { + // Try to retrieve the speaking CC name + const outArg = nodeUtils.translateValueID(this.driver, this, arg); + // This can happen for value updated events + if ("source" in outArg) delete outArg.source; + + const loglevel = this.driver.getLogConfig().level; + + // If this is a metadata event, make sure we return the merged metadata + if ("metadata" in outArg) { + (outArg as unknown as MetadataUpdatedArgs).metadata = this + .getValueMetadata(arg); + } + + const ccInstance = CommandClass.createInstanceUnchecked( + this.driver, + this, + arg.commandClass, + ); + const isInternalValue = !!ccInstance?.isInternalValue(arg); + // Check whether this value change may be logged + const isSecretValue = !!ccInstance?.isSecretValue(arg); + + if (loglevel === "silly") { + this.driver.controllerLog.logNode(this.id, { + message: `[translateValueEvent: ${eventName}] + commandClass: ${getCCName(arg.commandClass)} + endpoint: ${arg.endpoint} + property: ${arg.property} + propertyKey: ${arg.propertyKey} + internal: ${isInternalValue} + secret: ${isSecretValue} + event source: ${(arg as any as ValueUpdatedArgs).source}`, + level: "silly", + }); + } + + if ( + !isSecretValue + && (arg as any as ValueUpdatedArgs).source !== "driver" + ) { + // Log the value change, except for updates caused by the driver itself + // I don't like the splitting and any but its the easiest solution here + const [changeTarget, changeType] = eventName.split(" "); + const logArgument = { + ...outArg, + nodeId: this.id, + internal: isInternalValue, + }; + if (changeTarget === "value") { + this.driver.controllerLog.value( + changeType as any, + logArgument as any, + ); + } else if (changeTarget === "metadata") { + this.driver.controllerLog.metadataUpdated(logArgument); + } + } + + // Don't expose value events for internal value IDs... + if (isInternalValue) return; + + if (loglevel === "silly") { + this.driver.controllerLog.logNode(this.id, { + message: `[translateValueEvent: ${eventName}] + is root endpoint: ${!arg.endpoint} + is application CC: ${applicationCCs.includes(arg.commandClass)} + should hide root values: ${ + nodeUtils.shouldHideRootApplicationCCValues( + this.driver, + this.id, + ) + }`, + level: "silly", + }); + } + + // ... and root values ID that mirrors endpoint functionality + if ( + // Only root endpoint values need to be filtered + !arg.endpoint + // Only application CCs need to be filtered + && applicationCCs.includes(arg.commandClass) + // and only if the endpoints are not unnecessary and the root values mirror them + && nodeUtils.shouldHideRootApplicationCCValues(this.driver, this.id) + ) { + // Iterate through all possible non-root endpoints of this node and + // check if there is a value ID that mirrors root endpoint functionality + for ( + const endpoint of nodeUtils.getEndpointIndizes( + this.driver, + this.id, + ) + ) { + const possiblyMirroredValueID: ValueID = { + // same CC, property and key + ...pick(arg, ["commandClass", "property", "propertyKey"]), + // but different endpoint + endpoint, + }; + if (this.valueDB.hasValue(possiblyMirroredValueID)) { + if (loglevel === "silly") { + this.driver.controllerLog.logNode(this.id, { + message: + `[translateValueEvent: ${eventName}] found mirrored value ID on different endpoint, ignoring event: + commandClass: ${getCCName(possiblyMirroredValueID.commandClass)} + endpoint: ${possiblyMirroredValueID.endpoint} + property: ${possiblyMirroredValueID.property} + propertyKey: ${possiblyMirroredValueID.propertyKey}`, + level: "silly", + }); + } + + return; + } + } + } + // And pass the translated event to our listeners + this._emit(eventName, this, outArg as any); + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts new file mode 100644 index 000000000000..a3966f536fd0 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts @@ -0,0 +1,180 @@ +import { MultiChannelCCValues } from "@zwave-js/cc"; +import { + type CommandClasses, + type MaybeNotKnown, + ZWaveError, + ZWaveErrorCodes, +} from "@zwave-js/core"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; +import { DeviceClass } from "../DeviceClass"; +import { Endpoint } from "../Endpoint"; +import * as nodeUtils from "../utils"; +import { NodeValuesMixin } from "./40_Values"; + +/** Defines functionality of Z-Wave nodes related to accessing endpoints and their capabilities */ +export interface Endpoints { + /** Whether the endpoint count is dynamic */ + readonly endpointCountIsDynamic: MaybeNotKnown; + /** Whether all endpoints have identical capabilities */ + readonly endpointsHaveIdenticalCapabilities: MaybeNotKnown; + /** The number of individual endpoints */ + readonly individualEndpointCount: MaybeNotKnown; + /** The number of aggregated endpoints */ + readonly aggregatedEndpointCount: MaybeNotKnown; + /** Returns the current endpoint count of this node. + * + * If you want to enumerate the existing endpoints, use `getEndpointIndizes` instead. + * Some devices are known to contradict themselves. + */ + getEndpointCount(): number; + /** Returns indizes of all endpoints on the node. */ + getEndpointIndizes(): number[]; + /** Returns an endpoint of this node with the given index. 0 returns the node itself. */ + getEndpoint(index: 0): Endpoint; + getEndpoint(index: number): Endpoint | undefined; + /** Returns an endpoint of this node with the given index. Throws if the endpoint does not exist. */ + getEndpointOrThrow(index: number): Endpoint; + /** Returns a list of all endpoints of this node, including the root endpoint (index 0) */ + getAllEndpoints(): Endpoint[]; +} + +export abstract class EndpointsMixin extends NodeValuesMixin + implements Endpoints +{ + public get endpointCountIsDynamic(): MaybeNotKnown { + return nodeUtils.endpointCountIsDynamic(this.driver, this.id); + } + + public get endpointsHaveIdenticalCapabilities(): MaybeNotKnown { + return nodeUtils.endpointsHaveIdenticalCapabilities( + this.driver, + this.id, + ); + } + + public get individualEndpointCount(): MaybeNotKnown { + return nodeUtils.getIndividualEndpointCount(this.driver, this.id); + } + + public get aggregatedEndpointCount(): MaybeNotKnown { + return nodeUtils.getAggregatedEndpointCount(this.driver, this.id); + } + + /** Returns the device class of an endpoint. Falls back to the node's device class if the information is not known. */ + private getEndpointDeviceClass(index: number): MaybeNotKnown { + const deviceClass = this.getValue<{ + generic: number; + specific: number; + }>( + MultiChannelCCValues.endpointDeviceClass.endpoint( + this.endpointsHaveIdenticalCapabilities ? 1 : index, + ), + ); + if (deviceClass && this.deviceClass) { + return new DeviceClass( + this.deviceClass.basic, + deviceClass.generic, + deviceClass.specific, + ); + } + // fall back to the node's device class if it is known + return this.deviceClass; + } + + private getEndpointCCs(index: number): MaybeNotKnown { + const ret = this.getValue( + MultiChannelCCValues.endpointCCs.endpoint( + this.endpointsHaveIdenticalCapabilities ? 1 : index, + ), + ); + // Workaround for the change in #1977 + if (isArray(ret)) { + // The value is set up correctly, return it + return ret as CommandClasses[]; + } else if (isObject(ret) && "supportedCCs" in ret) { + return ret.supportedCCs as CommandClasses[]; + } + } + + /** + * Returns the current endpoint count of this node. + * + * If you want to enumerate the existing endpoints, use `getEndpointIndizes` instead. + * Some devices are known to contradict themselves. + */ + public getEndpointCount(): number { + return nodeUtils.getEndpointCount(this.driver, this.id); + } + + /** + * Returns indizes of all endpoints on the node. + */ + public getEndpointIndizes(): number[] { + return nodeUtils.getEndpointIndizes(this.driver, this.id); + } + + /** Whether the Multi Channel CC has been interviewed and all endpoint information is known */ + private get isMultiChannelInterviewComplete(): boolean { + return nodeUtils.isMultiChannelInterviewComplete(this.driver, this.id); + } + + /** Cache for this node's endpoint instances */ + protected _endpointInstances = new Map(); + /** + * Returns an endpoint of this node with the given index. 0 returns the node itself. + */ + public getEndpoint(index: 0): Endpoint; + public getEndpoint(index: number): Endpoint | undefined; + public getEndpoint(index: number): Endpoint | undefined { + if (index < 0) { + throw new ZWaveError( + "The endpoint index must be positive!", + ZWaveErrorCodes.Argument_Invalid, + ); + } + // Zero is the root endpoint - i.e. this node + if (index === 0) return this; + // Check if the Multi Channel CC interview for this node is completed, + // because we don't have all the information before that + if (!this.isMultiChannelInterviewComplete) { + this.driver.driverLog.print( + `Node ${this.id}, Endpoint ${index}: Trying to access endpoint instance before Multi Channel interview`, + "error", + ); + return undefined; + } + // Check if the endpoint index is in the list of known endpoint indizes + if (!this.getEndpointIndizes().includes(index)) return undefined; + + // Create an endpoint instance if it does not exist + if (!this._endpointInstances.has(index)) { + this._endpointInstances.set( + index, + new Endpoint( + this.id, + this.driver, + index, + this.getEndpointDeviceClass(index), + this.getEndpointCCs(index), + ), + ); + } + return this._endpointInstances.get(index)!; + } + + public getEndpointOrThrow(index: number): Endpoint { + const ret = this.getEndpoint(index); + if (!ret) { + throw new ZWaveError( + `Endpoint ${index} does not exist on Node ${this.id}`, + ZWaveErrorCodes.Controller_EndpointNotFound, + ); + } + return ret; + } + + /** Returns a list of all endpoints of this node, including the root endpoint (index 0) */ + public getAllEndpoints(): Endpoint[] { + return nodeUtils.getAllEndpoints(this.driver, this) as Endpoint[]; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts b/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts new file mode 100644 index 000000000000..744cd867146c --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts @@ -0,0 +1,139 @@ +import { type CCAPI } from "@zwave-js/cc"; +import { normalizeValueID } from "@zwave-js/core"; +import { MessagePriority, type ValueID } from "@zwave-js/core/safe"; +import { type NodeSchedulePollOptions } from "@zwave-js/host"; +import { ObjectKeyMap } from "@zwave-js/shared"; +import { isDeepStrictEqual } from "node:util"; +import { EndpointsMixin } from "./50_Endpoints"; + +export interface ScheduledPoll { + timeout: NodeJS.Timeout; + expectedValue?: unknown; +} + +/** Defines functionality of Z-Wave nodes for scheduling polls for a later time and canceling scheduled polls */ +export interface SchedulePoll { + /** + * @internal + * Returns whether a poll is currently scheduled for this node + */ + hasScheduledPolls(): boolean; + + /** + * @internal + * Schedules a value to be polled after a given time. Only one schedule can be active for a given value ID. + * @returns `true` if the poll was scheduled, `false` otherwise + */ + schedulePoll( + valueId: ValueID, + options: NodeSchedulePollOptions, + ): boolean; + + /** + * @internal + * Cancels a poll that has been scheduled with schedulePoll. + * + * @param actualValue If given, this indicates the value that was received by a node, which triggered the poll to be canceled. + * If the scheduled poll expects a certain value and this matches the expected value for the scheduled poll, the poll will be canceled. + */ + cancelScheduledPoll( + valueId: ValueID, + actualValue?: unknown, + ): boolean; + + /** + * @internal + * Cancels all polls that have been scheduled with schedulePoll. + */ + cancelAllScheduledPolls(): void; +} + +export abstract class SchedulePollMixin extends EndpointsMixin + implements SchedulePoll +{ + /** + * All polls that are currently scheduled for this node + */ + private _scheduledPolls = new ObjectKeyMap(); + + public hasScheduledPolls(): boolean { + return this._scheduledPolls.size > 0; + } + + public schedulePoll( + valueId: ValueID, + options: NodeSchedulePollOptions = {}, + ): boolean { + const { + timeoutMs = this.driver.options.timeouts.refreshValue, + expectedValue, + } = options; + + // Avoid false positives or false negatives due to a mis-formatted value ID + valueId = normalizeValueID(valueId); + + // Try to retrieve the corresponding CC API + const endpointInstance = this.getEndpoint(valueId.endpoint || 0); + if (!endpointInstance) return false; + + const api = ( + (endpointInstance.commandClasses as any)[ + valueId.commandClass + ] as CCAPI + ).withOptions({ + // We do not want to delay more important communication by polling, so give it + // the lowest priority and don't retry unless overwritten by the options + maxSendAttempts: 1, + priority: MessagePriority.Poll, + }); + + // Check if the pollValue method is implemented + if (!api.pollValue) return false; + + // make sure there is only one timeout instance per poll + this.cancelScheduledPoll(valueId); + const timeout = setTimeout(async () => { + // clean up after the timeout + this.cancelScheduledPoll(valueId); + try { + await api.pollValue!.call(api, valueId); + } catch { + /* ignore */ + } + }, timeoutMs).unref(); + this._scheduledPolls.set(valueId, { timeout, expectedValue }); + + return true; + } + + public cancelScheduledPoll( + valueId: ValueID, + actualValue?: unknown, + ): boolean { + // Avoid false positives or false negatives due to a mis-formatted value ID + valueId = normalizeValueID(valueId); + + const poll = this._scheduledPolls.get(valueId); + if (!poll) return false; + + if ( + actualValue !== undefined + && poll.expectedValue !== undefined + && !isDeepStrictEqual(poll.expectedValue, actualValue) + ) { + return false; + } + + clearTimeout(poll.timeout); + this._scheduledPolls.delete(valueId); + + return true; + } + + public cancelAllScheduledPolls(): void { + // Remove queued polls that would interfere with the interview + for (const valueId of this._scheduledPolls.keys()) { + this.cancelScheduledPoll(valueId); + } + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts new file mode 100644 index 000000000000..25ebcdd48f2d --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts @@ -0,0 +1,977 @@ +import { + type FirmwareUpdateInitResult, + type FirmwareUpdateMetaData, + FirmwareUpdateMetaDataCC, + FirmwareUpdateMetaDataCCGet, + type FirmwareUpdateMetaDataCCMetaDataGet, + FirmwareUpdateMetaDataCCReport, + FirmwareUpdateMetaDataCCStatusReport, + type FirmwareUpdateOptions, + type FirmwareUpdateProgress, + FirmwareUpdateRequestStatus, + type FirmwareUpdateResult, + FirmwareUpdateStatus, + isCommandClassContainer, +} from "@zwave-js/cc"; +import { + CRC16_CCITT, + CommandClasses, + EncapsulationFlags, + type Firmware, + SecurityClass, + ZWaveError, + ZWaveErrorCodes, + securityClassIsS2, + timespan, +} from "@zwave-js/core"; +import { getEnumMemberName, throttle } from "@zwave-js/shared"; +import { distinct } from "alcalzone-shared/arrays"; +import { wait } from "alcalzone-shared/async"; +import { + type DeferredPromise, + createDeferredPromise, +} from "alcalzone-shared/deferred-promise"; +import { roundTo } from "alcalzone-shared/math"; +import { randomBytes } from "node:crypto"; +import { type Task, type TaskBuilder, TaskPriority } from "../../driver/Task"; +import { type Transaction } from "../../driver/Transaction"; +import { SchedulePollMixin } from "./60_ScheduledPoll"; + +interface AbortFirmwareUpdateContext { + abort: boolean; + tooLateToAbort: boolean; + abortPromise: DeferredPromise; +} + +type PartialFirmwareUpdateResult = + & Pick + & { success: boolean }; + +/** Checks if a task belongs to a route rebuilding process */ +export function isFirmwareUpdateOTATask(t: Task): boolean { + return t.tag?.id === "firmware-update-ota"; +} + +export interface NodeFirmwareUpdate { + /** + * Aborts an active firmware update process + */ + abortFirmwareUpdate(): Promise; + + /** + * Performs an OTA firmware upgrade of one or more chips on this node. + * + * This method will resolve after the process has **COMPLETED**. Failure to start any one of the provided updates will throw an error. + * + * **WARNING: Use at your own risk! We don't take any responsibility if your devices don't work after an update.** + * + * @param updates An array of firmware updates that will be done in sequence + * + * @returns Whether all of the given updates were successful. + */ + updateFirmware( + updates: Firmware[], + options?: FirmwareUpdateOptions, + ): Promise; + + /** + * Returns whether a firmware update is in progress for this node. + */ + isFirmwareUpdateInProgress(): boolean; +} + +export abstract class FirmwareUpdateMixin extends SchedulePollMixin + implements NodeFirmwareUpdate +{ + private _abortFirmwareUpdate: (() => Promise) | undefined; + public async abortFirmwareUpdate(): Promise { + if (!this._abortFirmwareUpdate) return; + await this._abortFirmwareUpdate(); + } + + // Stores the CRC of the previously transferred firmware image. + // Allows detecting whether resuming is supported and where to continue in a multi-file transfer. + private _previousFirmwareCRC: number | undefined; + + /** Is used to remember fragment requests that came in before they were able to be handled */ + private _firmwareUpdatePrematureRequest: + | FirmwareUpdateMetaDataCCGet + | undefined; + + public async updateFirmware( + updates: Firmware[], + options: FirmwareUpdateOptions = {}, + ): Promise { + if (updates.length === 0) { + throw new ZWaveError( + `At least one update must be provided`, + ZWaveErrorCodes.Argument_Invalid, + ); + } + + // Check that each update has a buffer with at least 1 byte + if (updates.some((u) => u.data.length === 0)) { + throw new ZWaveError( + `All firmware updates must have a non-empty data buffer`, + ZWaveErrorCodes.Argument_Invalid, + ); + } + + // Check that the targets are not duplicates + if ( + distinct(updates.map((u) => u.firmwareTarget ?? 0)).length + !== updates.length + ) { + throw new ZWaveError( + `The target of all provided firmware updates must be unique`, + ZWaveErrorCodes.Argument_Invalid, + ); + } + + // Don't start the process twice + if (this.driver.controller.isFirmwareUpdateInProgress()) { + throw new ZWaveError( + `Failed to start the update: An OTW upgrade of the controller is in progress!`, + ZWaveErrorCodes.FirmwareUpdateCC_Busy, + ); + } + + // Don't allow starting two firmware updates for the same node + const task = this.getUpdateFirmwareTask(updates, options); + if (task instanceof Promise) { + throw new ZWaveError( + `Failed to start the update: A firmware update is already in progress for this node!`, + ZWaveErrorCodes.FirmwareUpdateCC_Busy, + ); + } + + // Queue the task + return this.driver.scheduler.queueTask(task); + } + + public isFirmwareUpdateInProgress(): boolean { + return !!this.driver.scheduler.findTask(isFirmwareUpdateOTATask); + } + + private getUpdateFirmwareTask( + updates: Firmware[], + options: FirmwareUpdateOptions = {}, + ): Promise | TaskBuilder { + const self = this; + + // This task should only run once at a time + const existingTask = this.driver.scheduler.findTask< + FirmwareUpdateResult + >((t) => + t.tag?.id === "firmware-update-ota" + && t.tag.nodeId === self.id + ); + if (existingTask) return existingTask; + + let keepAwake: boolean; + + return { + // Firmware updates cause a lot of traffic. Execute them in the background. + priority: TaskPriority.Lower, + tag: { id: "firmware-update-ota", nodeId: self.id }, + task: async function* firmwareUpdateTask() { + // Keep battery powered nodes awake during the process + keepAwake = self.keepAwake; + self.keepAwake = true; + + // Support aborting the update + const abortContext = { + abort: false, + tooLateToAbort: false, + abortPromise: createDeferredPromise(), + }; + + self._abortFirmwareUpdate = async () => { + if (abortContext.tooLateToAbort) { + throw new ZWaveError( + `The firmware update was transmitted completely, cannot abort anymore.`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToAbort, + ); + } + + self.driver.controllerLog.logNode(self.id, { + message: `Aborting firmware update...`, + direction: "outbound", + }); + + // Trigger the abort + abortContext.abort = true; + const aborted = await abortContext.abortPromise; + if (!aborted) { + throw new ZWaveError( + `The node did not acknowledge the aborted update`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToAbort, + ); + } + self.driver.controllerLog.logNode(self.id, { + message: `Firmware update aborted`, + direction: "inbound", + }); + }; + + // Prepare the firmware update + let fragmentSizeSecure: number; + let fragmentSizeNonSecure: number; + let meta: FirmwareUpdateMetaData; + try { + const prepareResult = await self + .prepareFirmwareUpdateInternal( + updates.map((u) => u.firmwareTarget ?? 0), + abortContext, + ); + + // Handle early aborts + if (abortContext.abort) { + const result: FirmwareUpdateResult = { + success: false, + status: FirmwareUpdateStatus + .Error_TransmissionFailed, + reInterview: false, + }; + self._emit( + "firmware update finished", + self, + result, + ); + return result; + } + + // If the firmware update was not aborted, prepareResult is definitely defined + ({ + fragmentSizeSecure, + fragmentSizeNonSecure, + ...meta + } = prepareResult!); + } catch { + // Not sure what the error is, but we'll label it "transmission failed" + const result: FirmwareUpdateResult = { + success: false, + status: FirmwareUpdateStatus.Error_TransmissionFailed, + reInterview: false, + }; + + return result; + } + + yield; // Give the task scheduler time to do something else + + // The resume and non-secure transfer features may not be supported by the node + // If not, disable them, even though the application requested them + if (!meta.supportsResuming) options.resume = false; + + const securityClass = self.getHighestSecurityClass(); + const isSecure = securityClass === SecurityClass.S0_Legacy + || securityClassIsS2(securityClass); + if (!isSecure) { + // The nonSecureTransfer option is only relevant for secure devices + options.nonSecureTransfer = false; + } else if (!meta.supportsNonSecureTransfer) { + options.nonSecureTransfer = false; + } + + // Throttle the progress emitter so applications can handle the load of events + const notifyProgress = throttle( + (progress) => + self._emit( + "firmware update progress", + self, + progress, + ), + 250, + true, + ); + + // If resuming is supported and desired, try to figure out with which file to continue + const updatesWithChecksum = updates.map((u) => ({ + ...u, + checksum: CRC16_CCITT(u.data), + })); + let skipFinishedFiles = -1; + let shouldResume = options.resume + && self._previousFirmwareCRC != undefined; + if (shouldResume) { + skipFinishedFiles = updatesWithChecksum.findIndex( + (u) => u.checksum === self._previousFirmwareCRC, + ); + if (skipFinishedFiles === -1) shouldResume = false; + } + + // Perform all firmware updates in sequence + let updateResult!: PartialFirmwareUpdateResult; + let conservativeWaitTime: number; + + const totalBytes: number = updatesWithChecksum.reduce( + (total, update) => total + update.data.length, + 0, + ); + let sentBytesOfPreviousFiles = 0; + + for (let i = 0; i < updatesWithChecksum.length; i++) { + const { firmwareTarget: target = 0, data, checksum } = + updatesWithChecksum[i]; + + if (i < skipFinishedFiles) { + // If we are resuming, skip this file since it was already done before + self.driver.controllerLog.logNode( + self.id, + `Skipping already completed firmware update (part ${ + i + 1 + } / ${updatesWithChecksum.length})...`, + ); + sentBytesOfPreviousFiles += data.length; + continue; + } + + self.driver.controllerLog.logNode( + self.id, + `Updating firmware (part ${ + i + 1 + } / ${updatesWithChecksum.length})...`, + ); + + // For determining the initial fragment size, assume the node respects our choice. + // If the node is not secure, these two values are identical anyways. + let fragmentSize = options.nonSecureTransfer + ? fragmentSizeNonSecure + : fragmentSizeSecure; + + // Tell the node to start requesting fragments + const { resume, nonSecureTransfer } = yield* self + .beginFirmwareUpdateInternal( + data, + target, + meta, + fragmentSize, + checksum, + shouldResume, + options.nonSecureTransfer, + ); + + // If the node did not accept non-secure transfer, revisit our choice of fragment size + if (options.nonSecureTransfer && !nonSecureTransfer) { + fragmentSize = fragmentSizeSecure; + } + + // Remember the checksum, so we can resume if necessary + self._previousFirmwareCRC = checksum; + + if (shouldResume) { + self.driver.controllerLog.logNode( + self.id, + `Node ${ + resume ? "accepted" : "did not accept" + } resuming the update...`, + ); + } + if (nonSecureTransfer) { + self.driver.controllerLog.logNode( + self.id, + `Firmware will be transferred without encryption...`, + ); + } + + yield; // Give the task scheduler time to do something else + + // Listen for firmware update fragment requests and handle them + updateResult = yield* self.doFirmwareUpdateInternal( + data, + fragmentSize, + nonSecureTransfer, + abortContext, + (fragment, total) => { + const progress: FirmwareUpdateProgress = { + currentFile: i + 1, + totalFiles: updatesWithChecksum.length, + sentFragments: fragment, + totalFragments: total, + progress: roundTo( + ( + (sentBytesOfPreviousFiles + + Math.min( + fragment * fragmentSize, + data.length, + )) + / totalBytes + ) * 100, + 2, + ), + }; + notifyProgress(progress); + + // When this file is done, add the fragments to the total, so we can compute the total progress correctly + if (fragment === total) { + sentBytesOfPreviousFiles += data.length; + } + }, + ); + + // If we wait, wait a bit longer than the device told us, so it is actually ready to use + conservativeWaitTime = self.driver + .getConservativeWaitTimeAfterFirmwareUpdate( + updateResult.waitTime, + ); + + if (!updateResult.success) { + self.driver.controllerLog.logNode(self.id, { + message: `Firmware update (part ${ + i + 1 + } / ${updatesWithChecksum.length}) failed with status ${ + getEnumMemberName( + FirmwareUpdateStatus, + updateResult.status, + ) + }`, + direction: "inbound", + }); + + const result: FirmwareUpdateResult = { + ...updateResult, + waitTime: undefined, + reInterview: false, + }; + self._emit( + "firmware update finished", + self, + result, + ); + + return result; + } else if (i < updatesWithChecksum.length - 1) { + // Update succeeded, but we're not done yet + + self.driver.controllerLog.logNode(self.id, { + message: `Firmware update (part ${ + i + 1 + } / ${updatesWithChecksum.length}) succeeded with status ${ + getEnumMemberName( + FirmwareUpdateStatus, + updateResult.status, + ) + }`, + direction: "inbound", + }); + + self.driver.controllerLog.logNode( + self.id, + `Continuing with next part in ${conservativeWaitTime} seconds...`, + ); + + // If we've resumed the previous file, there's no need to resume the next one too + shouldResume = false; + + yield () => wait(conservativeWaitTime * 1000, true); + } + } + + // We're done. No need to resume this update + self._previousFirmwareCRC = undefined; + + const result: FirmwareUpdateResult = { + ...updateResult, + waitTime: conservativeWaitTime!, + reInterview: true, + }; + + // After a successful firmware update, we want to interview sleeping nodes immediately, + // so don't send them to sleep when they wake up + keepAwake = true; + + self._emit("firmware update finished", self, result); + + return result; + }, + cleanup() { + self._abortFirmwareUpdate = undefined; + self._firmwareUpdatePrematureRequest = undefined; + + // Make sure that the keepAwake flag gets reset at the end + self.keepAwake = keepAwake; + if (!keepAwake) { + setImmediate(() => { + self.driver.debounceSendNodeToSleep(self); + }); + } + + return Promise.resolve(); + }, + }; + } + + /** Prepares the firmware update of a single target by collecting the necessary information */ + private async prepareFirmwareUpdateInternal( + targets: number[], + abortContext: AbortFirmwareUpdateContext, + ): Promise< + | undefined + | (FirmwareUpdateMetaData & { + fragmentSizeSecure: number; + fragmentSizeNonSecure: number; + }) + > { + const api = this.commandClasses["Firmware Update Meta Data"]; + + // ================================ + // STEP 1: + // Check if this update is possible + const meta = await api.getMetaData(); + if (!meta) { + throw new ZWaveError( + `Failed to start the update: The node did not respond in time!`, + ZWaveErrorCodes.Controller_NodeTimeout, + ); + } + + for (const target of targets) { + if (target === 0) { + if (!meta.firmwareUpgradable) { + throw new ZWaveError( + `Failed to start the update: The Z-Wave chip firmware is not upgradable!`, + ZWaveErrorCodes.FirmwareUpdateCC_NotUpgradable, + ); + } + } else { + if (api.version < 3) { + throw new ZWaveError( + `Failed to start the update: The node does not support upgrading a different firmware target than 0!`, + ZWaveErrorCodes.FirmwareUpdateCC_TargetNotFound, + ); + } else if ( + meta.additionalFirmwareIDs[target - 1] == undefined + ) { + throw new ZWaveError( + `Failed to start the update: Firmware target #${target} not found on this node!`, + ZWaveErrorCodes.FirmwareUpdateCC_TargetNotFound, + ); + } + } + } + + // ================================ + // STEP 2: + // Determine the fragment size + const fcc = new FirmwareUpdateMetaDataCC(this.driver, { + nodeId: this.id, + }); + const maxGrossPayloadSizeSecure = this.driver + .computeNetCCPayloadSize( + fcc, + ); + const maxGrossPayloadSizeNonSecure = this.driver + .computeNetCCPayloadSize(fcc, true); + + const maxNetPayloadSizeSecure = maxGrossPayloadSizeSecure + - 2 // report number + - (fcc.version >= 2 ? 2 : 0); // checksum + const maxNetPayloadSizeNonSecure = maxGrossPayloadSizeNonSecure + - 2 // report number + - (fcc.version >= 2 ? 2 : 0); // checksum + + // Use the smallest allowed payload + const fragmentSizeSecure = Math.min( + maxNetPayloadSizeSecure, + meta.maxFragmentSize ?? Number.POSITIVE_INFINITY, + ); + const fragmentSizeNonSecure = Math.min( + maxNetPayloadSizeNonSecure, + meta.maxFragmentSize ?? Number.POSITIVE_INFINITY, + ); + + if (abortContext.abort) { + abortContext.abortPromise.resolve(true); + return; + } else { + return { + ...meta, + fragmentSizeSecure, + fragmentSizeNonSecure, + }; + } + } + + protected async handleUnexpectedFirmwareUpdateGet( + command: FirmwareUpdateMetaDataCCGet, + ): Promise { + // This method will only be called under two circumstances: + // 1. The node is currently busy responding to a firmware update request -> remember the request + if (this.isFirmwareUpdateInProgress()) { + this._firmwareUpdatePrematureRequest = command; + return; + } + + // 2. No firmware update is in progress -> abort + this.driver.controllerLog.logNode(this.id, { + message: + `Received Firmware Update Get, but no firmware update is in progress. Forcing the node to abort...`, + direction: "inbound", + }); + + // Since no update is in progress, we need to determine the fragment size again + const fcc = new FirmwareUpdateMetaDataCC(this.driver, { + nodeId: this.id, + }); + const fragmentSize = this.driver.computeNetCCPayloadSize(fcc) + - 2 // report number + - (fcc.version >= 2 ? 2 : 0); // checksum + const fragment = randomBytes(fragmentSize); + try { + await this.sendCorruptedFirmwareUpdateReport( + command.reportNumber, + fragment, + ); + } catch { + // ignore + } + } + + /** Kicks off a firmware update of a single target. Returns whether the node accepted resuming and non-secure transfer */ + private *beginFirmwareUpdateInternal( + data: Buffer, + target: number, + meta: FirmwareUpdateMetaData, + fragmentSize: number, + checksum: number, + resume: boolean | undefined, + nonSecureTransfer: boolean | undefined, + ) { + const api = this.commandClasses["Firmware Update Meta Data"]; + + // ================================ + // STEP 3: + // Start the update + this.driver.controllerLog.logNode(this.id, { + message: `Starting firmware update...`, + direction: "outbound", + }); + + // Request the node to start the upgrade. Pause the task until this is done, + // since the call can block for a long time + const result: FirmwareUpdateInitResult = yield () => + api.requestUpdate({ + // TODO: Should manufacturer id and firmware id be provided externally? + manufacturerId: meta.manufacturerId, + firmwareId: target == 0 + ? meta.firmwareId + : meta.additionalFirmwareIDs[target - 1], + firmwareTarget: target, + fragmentSize, + checksum, + resume, + nonSecureTransfer, + }); + switch (result.status) { + case FirmwareUpdateRequestStatus.Error_AuthenticationExpected: + throw new ZWaveError( + `Failed to start the update: A manual authentication event (e.g. button push) was expected!`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, + ); + case FirmwareUpdateRequestStatus.Error_BatteryLow: + throw new ZWaveError( + `Failed to start the update: The battery level is too low!`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, + ); + case FirmwareUpdateRequestStatus + .Error_FirmwareUpgradeInProgress: + throw new ZWaveError( + `Failed to start the update: A firmware upgrade is already in progress!`, + ZWaveErrorCodes.FirmwareUpdateCC_Busy, + ); + case FirmwareUpdateRequestStatus + .Error_InvalidManufacturerOrFirmwareID: + throw new ZWaveError( + `Failed to start the update: Invalid manufacturer or firmware id!`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, + ); + case FirmwareUpdateRequestStatus.Error_InvalidHardwareVersion: + throw new ZWaveError( + `Failed to start the update: Invalid hardware version!`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, + ); + case FirmwareUpdateRequestStatus.Error_NotUpgradable: + throw new ZWaveError( + `Failed to start the update: Firmware target #${target} is not upgradable!`, + ZWaveErrorCodes.FirmwareUpdateCC_NotUpgradable, + ); + case FirmwareUpdateRequestStatus.Error_FragmentSizeTooLarge: + throw new ZWaveError( + `Failed to start the update: The chosen fragment size is too large!`, + ZWaveErrorCodes.FirmwareUpdateCC_FailedToStart, + ); + case FirmwareUpdateRequestStatus.OK: + // All good, we have started! + // Keep the node awake until the update is done. + this.keepAwake = true; + } + + return { + resume: !!result.resume, + nonSecureTransfer: !!result.nonSecureTransfer, + }; + } + + protected async handleFirmwareUpdateMetaDataGet( + command: FirmwareUpdateMetaDataCCMetaDataGet, + ): Promise { + const endpoint = this.getEndpoint(command.endpointIndex) + ?? this; + + // We are being queried, so the device may actually not support the CC, just control it. + // Using the commandClasses property would throw in that case + const api = endpoint + .createAPI(CommandClasses["Firmware Update Meta Data"], false) + .withOptions({ + // Answer with the same encapsulation as asked, but omit + // Supervision as it shouldn't be used for Get-Report flows + encapsulationFlags: command.encapsulationFlags + & ~EncapsulationFlags.Supervision, + }); + + // We do not support the firmware to be upgraded. + await api.reportMetaData({ + manufacturerId: this.driver.options.vendor?.manufacturerId + ?? 0xffff, + firmwareUpgradable: false, + hardwareVersion: this.driver.options.vendor?.hardwareVersion + ?? 0, + }); + } + + private async sendCorruptedFirmwareUpdateReport( + reportNum: number, + fragment: Buffer, + nonSecureTransfer: boolean = false, + ): Promise { + try { + await this.commandClasses["Firmware Update Meta Data"] + .withOptions({ + // Only encapsulate if the transfer is secure + autoEncapsulate: !nonSecureTransfer, + }) + .sendFirmwareFragment(reportNum, true, fragment); + } catch { + // ignore + } + } + + private hasPendingFirmwareUpdateFragment( + fragmentNumber: number, + ): boolean { + // Avoid queuing duplicate fragments + const isCurrentFirmwareFragment = (t: Transaction) => + t.message.getNodeId() === this.id + && isCommandClassContainer(t.message) + && t.message.command instanceof FirmwareUpdateMetaDataCCReport + && t.message.command.reportNumber === fragmentNumber; + + return this.driver.hasPendingTransactions( + isCurrentFirmwareFragment, + ); + } + + private async *doFirmwareUpdateInternal( + data: Buffer, + fragmentSize: number, + nonSecureTransfer: boolean, + abortContext: AbortFirmwareUpdateContext, + onProgress: (fragment: number, total: number) => void, + ): AsyncGenerator< + any, + PartialFirmwareUpdateResult, + any + > { + const numFragments = Math.ceil(data.length / fragmentSize); + + // Make sure we're not responding to an outdated request immediately + this._firmwareUpdatePrematureRequest = undefined; + + // ================================ + // STEP 4: + // Respond to fragment requests from the node + update: while (true) { + yield; // Give the task scheduler time to do something else + + // During ongoing firmware updates, it can happen that the next request is received before the callback for the previous response + // is back. In that case we can immediately handle the premature request. Otherwise wait for the next request. + let fragmentRequest: FirmwareUpdateMetaDataCCGet; + if (this._firmwareUpdatePrematureRequest) { + fragmentRequest = this._firmwareUpdatePrematureRequest; + this._firmwareUpdatePrematureRequest = undefined; + } else { + try { + fragmentRequest = yield () => + this.driver + .waitForCommand( + (cc) => + cc.nodeId === this.id + && cc + instanceof FirmwareUpdateMetaDataCCGet, + // Wait up to 2 minutes for each fragment request. + // Some users try to update devices with unstable connections, where 30s can be too short. + timespan.minutes(2), + ); + } catch { + // In some cases it can happen that the device stops requesting update frames + // We need to timeout the update in this case so it can be restarted + this.driver.controllerLog.logNode(this.id, { + message: `Firmware update timed out`, + direction: "none", + level: "warn", + }); + + return { + success: false, + status: FirmwareUpdateStatus.Error_Timeout, + }; + } + } + + // When a node requests a firmware update fragment, it must be awake + this.markAsAwake(); + + if (fragmentRequest.reportNumber > numFragments) { + this.driver.controllerLog.logNode(this.id, { + message: + `Received Firmware Update Get for an out-of-bounds fragment. Forcing the node to abort...`, + direction: "inbound", + }); + await this.sendCorruptedFirmwareUpdateReport( + fragmentRequest.reportNumber, + randomBytes(fragmentSize), + nonSecureTransfer, + ); + // This will cause the node to abort the process, wait for that + break update; + } + + // Actually send the requested frames + request: for ( + let num = fragmentRequest.reportNumber; + num + < fragmentRequest.reportNumber + + fragmentRequest.numReports; + num++ + ) { + yield; // Give the task scheduler time to do something else + + // Check if the node requested more fragments than are left + if (num > numFragments) { + break; + } + const fragment = data.subarray( + (num - 1) * fragmentSize, + num * fragmentSize, + ); + + if (abortContext.abort) { + await this.sendCorruptedFirmwareUpdateReport( + fragmentRequest.reportNumber, + randomBytes(fragment.length), + nonSecureTransfer, + ); + // This will cause the node to abort the process, wait for that + break update; + } else { + // Avoid queuing duplicate fragments + if (this.hasPendingFirmwareUpdateFragment(num)) { + this.driver.controllerLog.logNode(this.id, { + message: `Firmware fragment ${num} already queued`, + level: "warn", + }); + continue request; + } + + this.driver.controllerLog.logNode(this.id, { + message: + `Sending firmware fragment ${num} / ${numFragments}`, + direction: "outbound", + }); + const isLast = num === numFragments; + + try { + await this + .commandClasses["Firmware Update Meta Data"] + .withOptions({ + // Only encapsulate if the transfer is secure + autoEncapsulate: !nonSecureTransfer, + }) + .sendFirmwareFragment(num, isLast, fragment); + + onProgress(num, numFragments); + + // If that was the last one wait for status report from the node and restart interview + if (isLast) { + abortContext.tooLateToAbort = true; + break update; + } + } catch { + // When transmitting fails, simply stop responding to this request and wait for the node to re-request the fragment + this.driver.controllerLog.logNode(this.id, { + message: + `Failed to send firmware fragment ${num} / ${numFragments}`, + direction: "outbound", + level: "warn", + }); + break request; + } + } + } + } + + yield; // Give the task scheduler time to do something else + + // ================================ + // STEP 5: + // Finalize the update process + + const statusReport: + | FirmwareUpdateMetaDataCCStatusReport + | undefined = yield () => + this.driver + .waitForCommand( + (cc) => + cc.nodeId === this.id + && cc + instanceof FirmwareUpdateMetaDataCCStatusReport, + // Wait up to 5 minutes. It should never take that long, but the specs + // don't say anything specific + 5 * 60000, + ) + .catch(() => undefined); + + if (abortContext.abort) { + abortContext.abortPromise.resolve( + statusReport?.status + === FirmwareUpdateStatus.Error_TransmissionFailed, + ); + } + + if (!statusReport) { + this.driver.controllerLog.logNode( + this.id, + `The node did not acknowledge the completed update`, + "warn", + ); + + return { + success: false, + status: FirmwareUpdateStatus.Error_Timeout, + }; + } + + const { status, waitTime } = statusReport; + + // Actually, OK_WaitingForActivation should never happen since we don't allow + // delayed activation in the RequestGet command + const success = status >= FirmwareUpdateStatus.OK_WaitingForActivation; + + return { + success, + status, + waitTime, + }; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/README.md b/packages/zwave-js/src/lib/node/mixins/README.md new file mode 100644 index 000000000000..e5519f2b9e61 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/README.md @@ -0,0 +1,3 @@ +This folder contains "mixins" to compose the full functionality of the `ZWaveNode` class. They are not really mixins in the traditional sense, but rather "partial" classes that are extended in a fixed order to compose the full `ZWaveNode` class from manageable chunks. + +Files should be prefixed with numbers to indicate the order in which the inheritance is done. Each file should export a class that extends the previous one. diff --git a/packages/zwave-js/src/lib/node/mixins/index.ts b/packages/zwave-js/src/lib/node/mixins/index.ts new file mode 100644 index 000000000000..0843bf7efb64 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/index.ts @@ -0,0 +1,3 @@ +import { FirmwareUpdateMixin } from "./70_FirmwareUpdate"; + +export abstract class ZWaveNodeMixins extends FirmwareUpdateMixin {} diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index fc542fa2e1b6..5f508c9c67f7 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -2,6 +2,7 @@ import { CommandClass } from "@zwave-js/cc"; import { MultiChannelCCValues } from "@zwave-js/cc/MultiChannelCC"; import { CommandClasses, + type EndpointId, type IZWaveEndpoint, type IZWaveNode, type MaybeNotKnown, @@ -15,88 +16,87 @@ import { getCCName, } from "@zwave-js/core"; import type { ZWaveApplicationHost } from "@zwave-js/host"; -import { type Task } from "../driver/Task"; function getValue( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, valueId: ValueID, ): T | undefined { - return applHost.getValueDB(node.id).getValue(valueId); + return applHost.getValueDB(nodeId).getValue(valueId); } function setValue( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, valueId: ValueID, value: unknown, options?: SetValueOptions, ): void { - return applHost.getValueDB(node.id).setValue(valueId, value, options); + return applHost.getValueDB(nodeId).setValue(valueId, value, options); } export function endpointCountIsDynamic( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): MaybeNotKnown { return getValue( applHost, - node, + nodeId, MultiChannelCCValues.endpointCountIsDynamic.id, ); } export function endpointsHaveIdenticalCapabilities( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): MaybeNotKnown { return getValue( applHost, - node, + nodeId, MultiChannelCCValues.endpointsHaveIdenticalCapabilities.id, ); } export function getIndividualEndpointCount( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): MaybeNotKnown { return getValue( applHost, - node, + nodeId, MultiChannelCCValues.individualEndpointCount.id, ); } export function getAggregatedEndpointCount( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): MaybeNotKnown { return getValue( applHost, - node, + nodeId, MultiChannelCCValues.aggregatedEndpointCount.id, ); } export function getEndpointCount( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): number { return ( - (getIndividualEndpointCount(applHost, node) || 0) - + (getAggregatedEndpointCount(applHost, node) || 0) + (getIndividualEndpointCount(applHost, nodeId) || 0) + + (getAggregatedEndpointCount(applHost, nodeId) || 0) ); } export function setIndividualEndpointCount( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, count: number, ): void { setValue( applHost, - node, + nodeId, MultiChannelCCValues.individualEndpointCount.id, count, ); @@ -104,12 +104,12 @@ export function setIndividualEndpointCount( export function setAggregatedEndpointCount( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, count: number, ): void { setValue( applHost, - node, + nodeId, MultiChannelCCValues.aggregatedEndpointCount.id, count, ); @@ -117,17 +117,17 @@ export function setAggregatedEndpointCount( export function getEndpointIndizes( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): number[] { let ret = getValue( applHost, - node, + nodeId, MultiChannelCCValues.endpointIndizes.id, ); if (!ret) { // Endpoint indizes not stored, assume sequential endpoints ret = []; - for (let i = 1; i <= getEndpointCount(applHost, node); i++) { + for (let i = 1; i <= getEndpointCount(applHost, nodeId); i++) { ret.push(i); } } @@ -136,17 +136,22 @@ export function getEndpointIndizes( export function setEndpointIndizes( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, indizes: number[], ): void { - setValue(applHost, node, MultiChannelCCValues.endpointIndizes.id, indizes); + setValue( + applHost, + nodeId, + MultiChannelCCValues.endpointIndizes.id, + indizes, + ); } export function isMultiChannelInterviewComplete( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): boolean { - return !!getValue(applHost, node, { + return !!getValue(applHost, nodeId, { commandClass: CommandClasses["Multi Channel"], endpoint: 0, property: "interviewComplete", @@ -155,12 +160,12 @@ export function isMultiChannelInterviewComplete( export function setMultiChannelInterviewComplete( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, complete: boolean, ): void { setValue( applHost, - node, + nodeId, { commandClass: CommandClasses["Multi Channel"], endpoint: 0, @@ -177,8 +182,8 @@ export function getAllEndpoints( const ret: IZWaveEndpoint[] = [node]; // Check if the Multi Channel CC interview for this node is completed, // because we don't have all the endpoint information before that - if (isMultiChannelInterviewComplete(applHost, node)) { - for (const i of getEndpointIndizes(applHost, node)) { + if (isMultiChannelInterviewComplete(applHost, node.id)) { + for (const i of getEndpointIndizes(applHost, node.id)) { const endpoint = node.getEndpoint(i); if (endpoint) ret.push(endpoint); } @@ -189,14 +194,14 @@ export function getAllEndpoints( /** Determines whether the root application CC values should be hidden in favor of endpoint values */ export function shouldHideRootApplicationCCValues( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, ): boolean { // This is not the case when the root values should explicitly be preserved - const compatConfig = applHost.getDeviceConfig?.(node.id)?.compat; + const compatConfig = applHost.getDeviceConfig?.(nodeId)?.compat; if (compatConfig?.preserveRootApplicationCCValueIDs) return false; // This is not the case when there are no endpoints - const endpointIndizes = getEndpointIndizes(applHost, node); + const endpointIndizes = getEndpointIndizes(applHost, nodeId); if (endpointIndizes.length === 0) return false; // This is not the case when only individual endpoints should be preserved in addition to the root @@ -218,7 +223,7 @@ export function shouldHideRootApplicationCCValues( */ export function translateValueID( applHost: ZWaveApplicationHost, - node: IZWaveNode, + endpoint: EndpointId, valueId: T, ): T & TranslatedValueID { // Try to retrieve the speaking CC name @@ -229,7 +234,7 @@ export function translateValueID( }; const ccInstance = CommandClass.createInstanceUnchecked( applHost, - node, + endpoint, valueId.commandClass, ); if (!ccInstance) { @@ -352,15 +357,10 @@ export function getDefinedValueIDsInternal( // via service discovery mechanisms like mDNS or to users in a GUI. // We do this when there are endpoints that were explicitly preserved - if (shouldHideRootApplicationCCValues(applHost, node)) { + if (shouldHideRootApplicationCCValues(applHost, node.id)) { ret = filterRootApplicationCCValueIDs(ret); } // Translate the remaining value IDs before exposing them to applications return ret.map((id) => translateValueID(applHost, node, id)); } - -/** Checks if a task belongs to a route rebuilding process */ -export function isFirmwareUpdateOTATask(t: Task): boolean { - return t.tag?.id === "firmware-update-ota"; -} From b56cbb762095541b11b4ccdb219e35412b6bc268 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 14:40:12 +0200 Subject: [PATCH 02/60] fix: import loop --- packages/zwave-js/src/lib/driver/Driver.ts | 3 +- packages/zwave-js/src/lib/node/Node.ts | 41 +--------------- .../zwave-js/src/lib/node/mixins/00_Base.ts | 47 +++++++++++++++++++ .../{00_NetworkRole.ts => 01_NetworkRole.ts} | 2 +- .../zwave-js/src/lib/node/mixins/10_Events.ts | 2 +- 5 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 packages/zwave-js/src/lib/node/mixins/00_Base.ts rename packages/zwave-js/src/lib/node/mixins/{00_NetworkRole.ts => 01_NetworkRole.ts} (99%) diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index f8fd1fd1452a..03d3a5cd3322 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -167,7 +167,7 @@ import { ZWaveController } from "../controller/Controller"; import { InclusionState, RemoveNodeReason } from "../controller/Inclusion"; import { DriverLogger } from "../log/Driver"; import type { Endpoint } from "../node/Endpoint"; -import type { ZWaveNode, ZWaveNodeBase } from "../node/Node"; +import type { ZWaveNode } from "../node/Node"; import { InterviewStage, NodeStatus, @@ -203,6 +203,7 @@ import { isTransmitReport, } from "../serialapi/transport/SendDataShared"; +import { type ZWaveNodeBase } from "../node/mixins/00_Base"; import { type NodeWakeup } from "../node/mixins/30_Wakeup"; import { type NodeValues } from "../node/mixins/40_Values"; import { type SchedulePoll } from "../node/mixins/60_ScheduledPoll"; diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index cbdbccee2064..0523df241f6b 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -145,8 +145,6 @@ import { CommandClasses, Duration, EncapsulationFlags, - type FLiRS, - type IZWaveEndpoint, type IZWaveNode, type MaybeNotKnown, MessagePriority, @@ -248,7 +246,7 @@ import { } from "../serialapi/network-mgmt/RequestNodeInfoMessages"; import { DeviceClass } from "./DeviceClass"; import { type NodeDump, type ValueDump } from "./Dump"; -import { Endpoint } from "./Endpoint"; +import { type Endpoint } from "./Endpoint"; import { formatLifelineHealthCheckSummary, formatRouteHealthCheckSummary, @@ -278,43 +276,6 @@ import * as nodeUtils from "./utils"; const MAX_ASSOCIATIONS = 1; -export abstract class ZWaveNodeBase extends Endpoint implements IZWaveNode { - abstract isListening: MaybeNotKnown; - abstract isFrequentListening: MaybeNotKnown; - abstract canSleep: MaybeNotKnown; - abstract status: NodeStatus; - abstract interviewStage: InterviewStage; - abstract getEndpoint(index: 0): IZWaveEndpoint; - abstract getEndpoint(index: number): IZWaveEndpoint | undefined; - abstract getEndpoint(index: unknown): IZWaveEndpoint | undefined; - - abstract getEndpointOrThrow(index: number): IZWaveEndpoint; - - abstract getAllEndpoints(): IZWaveEndpoint[]; - - abstract isSecure: MaybeNotKnown; - abstract getHighestSecurityClass(): MaybeNotKnown; - - abstract hasSecurityClass( - securityClass: SecurityClass, - ): MaybeNotKnown; - - abstract setSecurityClass( - securityClass: SecurityClass, - granted: boolean, - ): void; - - /** - * Whether the node should be kept awake when there are no pending messages. - */ - public keepAwake: boolean = false; - - /** The ID of this node */ - public get id(): number { - return this.nodeId; - } -} - type AllNodeEvents = & ZWaveNodeEventCallbacks & StatisticsEventCallbacksWithSelf; diff --git a/packages/zwave-js/src/lib/node/mixins/00_Base.ts b/packages/zwave-js/src/lib/node/mixins/00_Base.ts new file mode 100644 index 000000000000..1080ce6ab05d --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/00_Base.ts @@ -0,0 +1,47 @@ +import { + type FLiRS, + type IZWaveEndpoint, + type IZWaveNode, + type InterviewStage, + type MaybeNotKnown, + type NodeStatus, + type SecurityClass, +} from "@zwave-js/core"; +import { Endpoint } from "../Endpoint"; + +export abstract class ZWaveNodeBase extends Endpoint implements IZWaveNode { + abstract isListening: MaybeNotKnown; + abstract isFrequentListening: MaybeNotKnown; + abstract canSleep: MaybeNotKnown; + abstract status: NodeStatus; + abstract interviewStage: InterviewStage; + abstract getEndpoint(index: 0): IZWaveEndpoint; + abstract getEndpoint(index: number): IZWaveEndpoint | undefined; + abstract getEndpoint(index: unknown): IZWaveEndpoint | undefined; + + abstract getEndpointOrThrow(index: number): IZWaveEndpoint; + + abstract getAllEndpoints(): IZWaveEndpoint[]; + + abstract isSecure: MaybeNotKnown; + abstract getHighestSecurityClass(): MaybeNotKnown; + + abstract hasSecurityClass( + securityClass: SecurityClass, + ): MaybeNotKnown; + + abstract setSecurityClass( + securityClass: SecurityClass, + granted: boolean, + ): void; + + /** + * Whether the node should be kept awake when there are no pending messages. + */ + public keepAwake: boolean = false; + + /** The ID of this node */ + public get id(): number { + return this.nodeId; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts b/packages/zwave-js/src/lib/node/mixins/01_NetworkRole.ts similarity index 99% rename from packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts rename to packages/zwave-js/src/lib/node/mixins/01_NetworkRole.ts index 3095f57b9166..f43478ad7dba 100644 --- a/packages/zwave-js/src/lib/node/mixins/00_NetworkRole.ts +++ b/packages/zwave-js/src/lib/node/mixins/01_NetworkRole.ts @@ -9,7 +9,7 @@ import { isLongRangeNodeId, } from "@zwave-js/core"; import { cacheKeys } from "../../driver/NetworkCache"; -import { ZWaveNodeBase } from "../Node"; +import { ZWaveNodeBase } from "./00_Base"; export interface NodeNetworkRole { /** Whether this node is always listening or not */ diff --git a/packages/zwave-js/src/lib/node/mixins/10_Events.ts b/packages/zwave-js/src/lib/node/mixins/10_Events.ts index 76a0fb4aeacb..8f24cccdc6e1 100644 --- a/packages/zwave-js/src/lib/node/mixins/10_Events.ts +++ b/packages/zwave-js/src/lib/node/mixins/10_Events.ts @@ -3,7 +3,7 @@ import { type StatisticsEventCallbacksWithSelf } from "../../driver/Statistics"; import { type ZWaveNode } from "../Node"; import { type NodeStatistics } from "../NodeStatistics"; import { type ZWaveNodeEventCallbacks } from "../_Types"; -import { NetworkRoleMixin } from "./00_NetworkRole"; +import { NetworkRoleMixin } from "./01_NetworkRole"; // This mixin is a slightly ugly workaround to allow other mixins to // interact with events which would normally take an instance of ZWaveNode From 7510a382e9abdd376d7f6dfbcc2630419682c83f Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 14:55:38 +0200 Subject: [PATCH 03/60] refactor: replace some instances of IZWaveNode --- packages/cc/src/cc/AssociationGroupInfoCC.ts | 3 ++- packages/cc/src/cc/MultiChannelCC.ts | 7 +++---- packages/cc/src/cc/NotificationCC.ts | 4 ++-- packages/cc/src/lib/utils.ts | 6 ++++-- packages/zwave-js/src/lib/node/utils.ts | 3 +++ 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index c01890008cc9..2a2707a37bf8 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -1,5 +1,6 @@ import { CommandClasses, + type EndpointId, type IZWaveEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -271,7 +272,7 @@ export class AssociationGroupInfoCC extends CommandClass { /** Returns the association profile for an association group */ public static getGroupProfileCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, groupId: number, ): MaybeNotKnown { return applHost.getValueDB(endpoint.nodeId).getValue<{ diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 23a327e99cb0..fd13c2a6aed9 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -2,7 +2,6 @@ import { type ApplicationNodeInformation, CommandClasses, type GenericDeviceClass, - type IZWaveNode, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -130,7 +129,7 @@ export const MultiChannelCCValues = Object.freeze({ */ function areEndpointsUnnecessary( applHost: ZWaveApplicationHost, - node: IZWaveNode, + nodeId: number, endpointIndizes: number[], ): boolean { // Gather all device classes @@ -144,7 +143,7 @@ function areEndpointsUnnecessary( for (const endpoint of endpointIndizes) { const devClassValueId = MultiChannelCCValues.endpointDeviceClass .endpoint(endpoint); - const deviceClass = applHost.getValueDB(node.id).getValue<{ + const deviceClass = applHost.getValueDB(nodeId).getValue<{ generic: number; specific: number; }>(devClassValueId); @@ -674,7 +673,7 @@ supported CCs:`; // But first figure out if they seem unnecessary and if they do, which ones should be preserved if ( !multiResponse.identicalCapabilities - && areEndpointsUnnecessary(applHost, node, allEndpoints) + && areEndpointsUnnecessary(applHost, node.id, allEndpoints) ) { const preserve = applHost.getDeviceConfig?.(node.id)?.compat ?.preserveEndpoints; diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index f05ac12c7d0e..374e84228b1c 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -13,7 +13,6 @@ import { CommandClasses, Duration, type IZWaveEndpoint, - type IZWaveNode, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -552,7 +551,8 @@ export class NotificationCC extends CommandClass { /** Whether the node implements push or pull notifications */ public static getNotificationMode( applHost: ZWaveApplicationHost, - node: IZWaveNode, + // FIXME: GH#7261 Change to nodeId + node: { id: number }, ): MaybeNotKnown<"push" | "pull"> { return applHost .getValueDB(node.id) diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index 3ed1b4ada4a6..d32452a0e306 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -88,6 +88,7 @@ export function getAssociations( export function getAllAssociations( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough node: IZWaveNode, ): ReadonlyObjectKeyMap< AssociationAddress, @@ -339,6 +340,7 @@ export function getAssociationGroups( export function getAllAssociationGroups( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough node: IZWaveNode, ): ReadonlyMap> { const ret = new Map>(); @@ -636,7 +638,6 @@ export function getLifelineGroupIds( ): number[] { // For now only support this for the root endpoint - i.e. node if (endpoint.index > 0) return []; - const node = endpoint as IZWaveNode; // Some nodes define multiple lifeline groups, so we need to assign us to // all of them @@ -649,7 +650,7 @@ export function getLifelineGroupIds( // We have a device config file that tells us which (additional) association to assign let associations: ReadonlyMap | undefined; - const deviceConfig = applHost.getDeviceConfig?.(node.id); + const deviceConfig = applHost.getDeviceConfig?.(endpoint.nodeId); if (endpoint.index === 0) { // The root endpoint's associations may be configured separately or as part of "endpoints" associations = deviceConfig?.associations @@ -1234,6 +1235,7 @@ export async function assignLifelineIssueingCommand( export function doesAnyLifelineSendActuatorOrSensorReports( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough node: IZWaveNode, ): MaybeNotKnown { // No association support means no unsolicited reports diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index 5f508c9c67f7..4f62334719c0 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -177,6 +177,7 @@ export function setMultiChannelInterviewComplete( export function getAllEndpoints( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough node: IZWaveNode, ): IZWaveEndpoint[] { const ret: IZWaveEndpoint[] = [node]; @@ -303,6 +304,7 @@ export function filterRootApplicationCCValueIDs( /** Returns a list of all value names that are defined on all endpoints of this node */ export function getDefinedValueIDs( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough node: IZWaveNode, ): TranslatedValueID[] { return getDefinedValueIDsInternal(applHost, node, false); @@ -314,6 +316,7 @@ export function getDefinedValueIDs( */ export function getDefinedValueIDsInternal( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough node: IZWaveNode, includeInternal: boolean = false, ): TranslatedValueID[] { From be65623cef99bbc586feb936dea5fab5c7068a34 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 15:04:35 +0200 Subject: [PATCH 04/60] refactor: replace some instances of IZWaveEndpoint --- packages/cc/src/cc/AlarmSensorCC.ts | 4 +-- packages/cc/src/cc/AssociationCC.ts | 8 +++--- packages/cc/src/cc/AssociationGroupInfoCC.ts | 6 +++-- packages/cc/src/cc/BinarySensorCC.ts | 4 +-- packages/cc/src/cc/ConfigurationCC.ts | 3 +++ packages/cc/src/cc/DoorLockCC.ts | 16 +++++------ packages/cc/src/cc/IndicatorCC.ts | 4 +-- packages/cc/src/cc/IrrigationCC.ts | 8 +++--- packages/cc/src/cc/MeterCC.ts | 10 +++---- .../cc/src/cc/MultiChannelAssociationCC.ts | 8 +++--- packages/cc/src/cc/MultilevelSensorCC.ts | 6 ++--- packages/cc/src/cc/NotificationCC.ts | 4 +-- .../src/cc/SceneControllerConfigurationCC.ts | 4 +-- packages/cc/src/cc/ScheduleEntryLockCC.ts | 27 +++++++++---------- packages/cc/src/cc/SupervisionCC.ts | 6 ++--- packages/cc/src/cc/TimeParametersCC.ts | 1 + packages/cc/src/cc/UserCodeCC.ts | 20 +++++++------- packages/cc/src/lib/utils.ts | 12 +++++++-- 18 files changed, 82 insertions(+), 69 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 5e4fcf8f4ea8..29fdaedfdfda 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -1,6 +1,6 @@ import { CommandClasses, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -289,7 +289,7 @@ duration: ${currentValue.duration}`; */ public static getSupportedSensorTypesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index b65b01750b44..97dbfbb6775c 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -1,5 +1,5 @@ import type { - IZWaveEndpoint, + EndpointId, MaybeNotKnown, MessageRecord, SupervisionResult, @@ -307,7 +307,7 @@ export class AssociationCC extends CommandClass { */ public static getGroupCountCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): number { return ( applHost @@ -324,7 +324,7 @@ export class AssociationCC extends CommandClass { */ public static getMaxNodesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, groupId: number, ): number { return ( @@ -351,7 +351,7 @@ export class AssociationCC extends CommandClass { */ public static getAllDestinationsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): ReadonlyMap { const ret = new Map(); const groupCount = this.getGroupCountCached(applHost, endpoint); diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 2a2707a37bf8..0550413ab64b 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -257,7 +257,7 @@ export class AssociationGroupInfoCC extends CommandClass { /** Returns the name of an association group */ public static getGroupNameCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, groupId: number, ): MaybeNotKnown { return applHost @@ -288,7 +288,7 @@ export class AssociationGroupInfoCC extends CommandClass { /** Returns the dictionary of all commands issued by the given association group */ public static getIssuedCommandsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, groupId: number, ): MaybeNotKnown> { return applHost @@ -302,6 +302,7 @@ export class AssociationGroupInfoCC extends CommandClass { public static findGroupsForIssuedCommand( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, ccId: CommandClasses, command: number, @@ -332,6 +333,7 @@ export class AssociationGroupInfoCC extends CommandClass { private static getAssociationGroupCountCached( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, ): number { // The association group count is either determined by the diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 45fa98d6bb11..c30b7e29ce92 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -1,6 +1,6 @@ import { CommandClasses, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -308,7 +308,7 @@ export class BinarySensorCC extends CommandClass { */ public static getSupportedSensorTypesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 851850340327..c6e74742edb1 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -145,6 +145,7 @@ type NormalizedConfigurationCCAPISetOptions = function createConfigurationCCInstance( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and index should be enough endpoint: IZWaveEndpoint | IVirtualEndpoint, ): ConfigurationCC { return CommandClass.createInstanceUnchecked( @@ -156,6 +157,7 @@ function createConfigurationCCInstance( function normalizeConfigurationCCAPISetOptions( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and index should be enough endpoint: IZWaveEndpoint | IVirtualEndpoint, options: ConfigurationCCAPISetOptions, ): NormalizedConfigurationCCAPISetOptions { @@ -213,6 +215,7 @@ function normalizeConfigurationCCAPISetOptions( function bulkMergePartialParamValues( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and index should be enough endpoint: IZWaveEndpoint | IVirtualEndpoint, options: NormalizedConfigurationCCAPISetOptions[], ): (NormalizedConfigurationCCAPISetOptions & { bitMask?: undefined })[] { diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 58e393219bd2..8ccdd5bbadf0 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -1,7 +1,7 @@ import { CommandClasses, Duration, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -254,7 +254,7 @@ export const DoorLockCCValues = Object.freeze({ function shouldAutoCreateLatchStatusValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; @@ -265,7 +265,7 @@ function shouldAutoCreateLatchStatusValue( function shouldAutoCreateBoltStatusValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; @@ -276,7 +276,7 @@ function shouldAutoCreateBoltStatusValue( function shouldAutoCreateDoorStatusValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; @@ -287,7 +287,7 @@ function shouldAutoCreateDoorStatusValue( function shouldAutoCreateTwistAssistConfigValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; @@ -298,7 +298,7 @@ function shouldAutoCreateTwistAssistConfigValue( function shouldAutoCreateBlockToBlockConfigValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; @@ -309,7 +309,7 @@ function shouldAutoCreateBlockToBlockConfigValue( function shouldAutoCreateAutoRelockConfigValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; @@ -320,7 +320,7 @@ function shouldAutoCreateAutoRelockConfigValue( function shouldAutoCreateHoldAndReleaseConfigValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 15387e8f8278..025066610a35 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -1,7 +1,7 @@ import type { ConfigManager } from "@zwave-js/config"; import { CommandClasses, - type IZWaveEndpoint, + type EndpointId, Indicator, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -850,7 +850,7 @@ export class IndicatorCC extends CommandClass { public static getSupportedPropertyIDsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, indicatorId: number, ): MaybeNotKnown { return applHost diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 3d880b26e894..d82979ca1a5b 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1,6 +1,6 @@ import { CommandClasses, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -1119,7 +1119,7 @@ export class IrrigationCC extends CommandClass { */ public static getMaxValveTableSizeCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -1134,7 +1134,7 @@ export class IrrigationCC extends CommandClass { */ public static getNumValvesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -1147,7 +1147,7 @@ export class IrrigationCC extends CommandClass { */ public static supportsMasterValveCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { return !!applHost .getValueDB(endpoint.nodeId) diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 3c0519351bb4..c230f8cbfa1e 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -1,6 +1,5 @@ import { type FloatParameters, - type IZWaveEndpoint, type MaybeUnknown, encodeBitMask, encodeFloatWithScale, @@ -13,6 +12,7 @@ import { } from "@zwave-js/core"; import { CommandClasses, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -782,7 +782,7 @@ supports reset: ${suppResp.supportsReset}`; */ public static getMeterTypeCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -795,7 +795,7 @@ supports reset: ${suppResp.supportsReset}`; */ public static getSupportedScalesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -808,7 +808,7 @@ supports reset: ${suppResp.supportsReset}`; */ public static supportsResetCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -821,7 +821,7 @@ supports reset: ${suppResp.supportsReset}`; */ public static getSupportedRateTypesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 4909baab2baa..ed6cad335aca 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -1,5 +1,5 @@ import type { - IZWaveEndpoint, + EndpointId, MessageRecord, SupervisionResult, } from "@zwave-js/core/safe"; @@ -371,7 +371,7 @@ export class MultiChannelAssociationCC extends CommandClass { */ public static getGroupCountCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): number { return ( applHost @@ -390,7 +390,7 @@ export class MultiChannelAssociationCC extends CommandClass { */ public static getMaxNodesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, groupId: number, ): number { return ( @@ -410,7 +410,7 @@ export class MultiChannelAssociationCC extends CommandClass { */ public static getAllDestinationsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): ReadonlyMap { const ret = new Map(); const groupCount = this.getGroupCountCached(applHost, endpoint); diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index c6977ffbe6f9..34afed7957f2 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -7,7 +7,7 @@ import { timespan, } from "@zwave-js/core"; import type { - IZWaveEndpoint, + EndpointId, MessageOrCCLogEntry, MessageRecord, Scale, @@ -568,7 +568,7 @@ value: ${mlsResponse.value}${ */ public static getSupportedSensorTypesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -585,7 +585,7 @@ value: ${mlsResponse.value}${ */ public static getSupportedScalesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, sensorType: number, ): MaybeNotKnown { return applHost diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index 374e84228b1c..584577942a5f 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -12,7 +12,7 @@ import { import { CommandClasses, Duration, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -213,7 +213,7 @@ export const NotificationCCValues = Object.freeze({ function shouldAutoCreateSimpleDoorSensorValue( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 077051654a73..79893901c00d 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -1,7 +1,7 @@ import { CommandClasses, Duration, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -465,7 +465,7 @@ dimming duration: ${group.dimmingDuration.toString()}`; */ public static getGroupCountCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): number { return ( applHost.getDeviceConfig?.(endpoint.nodeId)?.compat diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index b3c047476c5d..04ee0b394920 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -1,6 +1,5 @@ import { CommandClasses, - type IZWaveEndpoint, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, @@ -13,7 +12,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { type EndpointId, type MaybeNotKnown } from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -143,7 +142,7 @@ function persistSchedule( /** Updates the schedule kind assumed to be active for user in the cache */ function setUserCodeScheduleKindCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, userId: number, scheduleKind: ScheduleEntryLockScheduleKind, ): void { @@ -160,7 +159,7 @@ function setUserCodeScheduleKindCached( /** Updates whether scheduling is active for one or all user(s) in the cache */ function setUserCodeScheduleEnabledCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, userId: number | undefined, enabled: boolean, ): void { @@ -766,7 +765,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; */ public static getNumWeekDaySlotsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): number { return ( applHost @@ -785,7 +784,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; */ public static getNumYearDaySlotsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): number { return ( applHost @@ -804,7 +803,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; */ public static getNumDailyRepeatingSlotsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): number { return ( applHost @@ -827,7 +826,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; */ public static getUserCodeScheduleEnabledCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, userId: number, ): boolean { return !!applHost @@ -849,7 +848,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; */ public static getUserCodeScheduleKindCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, userId: number, ): MaybeNotKnown { return applHost @@ -863,7 +862,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; public static getScheduleCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind.WeekDay, userId: number, slotId: number, @@ -871,7 +870,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; public static getScheduleCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind.YearDay, userId: number, slotId: number, @@ -879,7 +878,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; public static getScheduleCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind.DailyRepeating, userId: number, slotId: number, @@ -888,7 +887,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; // Catch-all overload for applications which haven't narrowed `scheduleKind` public static getScheduleCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind, userId: number, slotId: number, @@ -909,7 +908,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; */ public static getScheduleCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind, userId: number, slotId: number, diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 10f6d69c4a77..8ce2d74082db 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -2,7 +2,7 @@ import { CommandClasses, Duration, EncapsulationFlags, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -196,7 +196,7 @@ export class SupervisionCC extends CommandClass { */ public static getCCSupportedWithSupervision( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ccId: CommandClasses, ): boolean { // By default assume supervision is supported for all CCs, unless we've remembered one not to be @@ -216,7 +216,7 @@ export class SupervisionCC extends CommandClass { */ public static setCCSupportedWithSupervision( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ccId: CommandClasses, supported: boolean, ): void { diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 496a6bf9f8f7..07a4189d86d2 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -60,6 +60,7 @@ export const TimeParametersCCValues = Object.freeze({ */ function shouldUseLocalTime( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, ): boolean { // GH#311 Some nodes have no way to determine the time zone offset, diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index d264ffafe671..559ad41bdd99 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -1,6 +1,6 @@ import { CommandClasses, - type IZWaveEndpoint, + type EndpointId, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -1052,7 +1052,7 @@ export class UserCodeCC extends CommandClass { */ public static getSupportedUsersCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -1065,7 +1065,7 @@ export class UserCodeCC extends CommandClass { */ public static getSupportedKeypadModesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -1080,7 +1080,7 @@ export class UserCodeCC extends CommandClass { */ public static getSupportedUserIDStatusesCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -1097,7 +1097,7 @@ export class UserCodeCC extends CommandClass { */ public static getSupportedASCIICharsCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): MaybeNotKnown { return applHost .getValueDB(endpoint.nodeId) @@ -1112,7 +1112,7 @@ export class UserCodeCC extends CommandClass { */ public static supportsAdminCodeCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost .getValueDB(endpoint.nodeId); @@ -1133,7 +1133,7 @@ export class UserCodeCC extends CommandClass { */ public static supportsAdminCodeDeactivationCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { const valueDB = applHost .getValueDB(endpoint.nodeId); @@ -1155,7 +1155,7 @@ export class UserCodeCC extends CommandClass { */ public static supportsMultipleUserCodeSetCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean { return !!applHost .getValueDB(endpoint.nodeId) @@ -1172,7 +1172,7 @@ export class UserCodeCC extends CommandClass { */ public static getUserIdStatusCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, userId: number, ): MaybeNotKnown { return applHost @@ -1188,7 +1188,7 @@ export class UserCodeCC extends CommandClass { */ public static getUserCodeCached( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, userId: number, ): MaybeNotKnown { return applHost diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index d32452a0e306..d2f704624dc2 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -1,6 +1,7 @@ import type { AssociationConfig } from "@zwave-js/config"; import { CommandClasses, + type EndpointId, type IZWaveEndpoint, type IZWaveNode, type MaybeNotKnown, @@ -35,6 +36,7 @@ import { export function getAssociations( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, ): ReadonlyMap { const ret = new Map(); @@ -112,6 +114,7 @@ export function getAllAssociations( export function checkAssociation( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, group: number, destination: AssociationAddress, @@ -239,6 +242,7 @@ export function checkAssociation( export function getAssociationGroups( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, ): ReadonlyMap { // Check whether we have multi channel support or not @@ -354,6 +358,7 @@ export function getAllAssociationGroups( export async function addAssociations( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, group: number, destinations: AssociationAddress[], @@ -524,6 +529,7 @@ export async function addAssociations( export async function removeAssociations( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, group: number, destinations: AssociationAddress[], @@ -634,6 +640,7 @@ export async function removeAssociations( export function getLifelineGroupIds( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and endpoint capabilities would be enough endpoint: IZWaveEndpoint, ): number[] { // For now only support this for the root endpoint - i.e. node @@ -808,7 +815,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, // Figure out which associations exist and may need to be removed const isAssignedAsNodeAssociation = ( - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean => { if (groupSupportsMultiChannelAssociation && mcInstance) { if ( @@ -845,7 +852,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, }; const isAssignedAsEndpointAssociation = ( - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ): boolean => { if (mcInstance) { if ( @@ -1188,6 +1195,7 @@ must use node association: ${rootMustUseNodeAssociation}`, export async function assignLifelineIssueingCommand( applHost: ZWaveApplicationHost, + // FIXME: GH#7261 ID and node+endpoint capabilities would be enough endpoint: IZWaveEndpoint, ccId: CommandClasses, ccCommand: number, From bf5f13a8c2355950593d73711987065edb3440d2 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 15:07:59 +0200 Subject: [PATCH 05/60] refactor: autoCreate needs only the EndpointId --- packages/cc/src/lib/CommandClass.ts | 5 ++++- packages/cc/src/lib/Values.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index c0ac1b928d23..2d14d935cc9e 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -807,7 +807,10 @@ export class CommandClass implements ICommandClass { || (typeof value.options.autoCreate === "function" && value.options.autoCreate( applHost, - this.getEndpoint(applHost)!, + { + nodeId: this.nodeId as number, + index: this.endpointIndex, + }, )) ); } diff --git a/packages/cc/src/lib/Values.ts b/packages/cc/src/lib/Values.ts index 8335e79a1ae2..8215fcc922c8 100644 --- a/packages/cc/src/lib/Values.ts +++ b/packages/cc/src/lib/Values.ts @@ -1,6 +1,6 @@ import { type CommandClasses, - type IZWaveEndpoint, + type EndpointId, type ValueID, ValueMetadata, } from "@zwave-js/core"; @@ -49,7 +49,7 @@ export interface CCValueOptions { | boolean | (( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: EndpointId, ) => boolean); } From 7cb90ea61d307945cfc6cfe03a9c9b5350c9b04f Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 15:33:51 +0200 Subject: [PATCH 06/60] refactor: constructors, use live binding for status machine --- packages/zwave-js/src/lib/node/Node.ts | 86 +++++-------------- .../src/lib/node/NodeStatusMachine.ts | 9 +- .../zwave-js/src/lib/node/mixins/20_Status.ts | 2 +- .../zwave-js/src/lib/node/mixins/40_Values.ts | 13 +++ .../src/lib/node/mixins/60_ScheduledPoll.ts | 54 +++++++++++- 5 files changed, 95 insertions(+), 69 deletions(-) diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index 0523df241f6b..34c608f2a8db 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -166,12 +166,10 @@ import { type TXReport, type TranslatedValueID, TransmitOptions, - ValueDB, + type ValueDB, type ValueID, type ValueMetadata, type ValueMetadataNumeric, - type ValueRemovedArgs, - type ValueUpdatedArgs, ZWaveError, ZWaveErrorCodes, ZWaveLibraryTypes, @@ -292,27 +290,6 @@ export interface ZWaveNode export class ZWaveNode extends ZWaveNodeMixins implements SecurityClassOwner, IZWaveNode { - protected _emit( - event: TEvent, - ...args: Parameters - ): boolean { - return this.emit(event, ...args); - } - - protected _on( - event: TEvent, - callback: AllNodeEvents[TEvent], - ): this { - return this.on(event, callback); - } - - protected _once( - event: TEvent, - callback: AllNodeEvents[TEvent], - ): this { - return this.once(event, callback); - } - public constructor( id: number, driver: Driver, @@ -325,49 +302,11 @@ export class ZWaveNode extends ZWaveNodeMixins id, driver, // Define this node's intrinsic endpoint as the root device (0) - 0, deviceClass, supportedCCs, - valueDB - ?? new ValueDB(id, driver.valueDB!, driver.metadataDB!), + valueDB, ); - // Pass value events to our listeners - for ( - const event of [ - "value added", - "value updated", - "value removed", - "value notification", - "metadata updated", - ] as const - ) { - this._valueDB.on(event, this.translateValueEvent.bind(this, event)); - } - - // Also avoid verifying a value change for which we recently received an update - for (const event of ["value updated", "value removed"] as const) { - this._valueDB.on( - event, - (args: ValueUpdatedArgs | ValueRemovedArgs) => { - // Value updates caused by the driver should never cancel a scheduled poll - if ("source" in args && args.source === "driver") return; - - if ( - this.cancelScheduledPoll( - args, - (args as ValueUpdatedArgs).newValue, - ) - ) { - this.driver.controllerLog.logNode( - this.id, - "Scheduled poll canceled because expected value was received", - "verbose", - ); - } - }, - ); - } this.securityClasses = new CacheBackedMap(this.driver.networkCache, { prefix: cacheKeys.node(this.id)._securityClassBaseKey + ".", @@ -6558,4 +6497,25 @@ ${formatRouteHealthCheckSummary(this.id, otherNode.id, summary)}`, return ret; } + + protected _emit( + event: TEvent, + ...args: Parameters + ): boolean { + return this.emit(event, ...args); + } + + protected _on( + event: TEvent, + callback: AllNodeEvents[TEvent], + ): this { + return this.on(event, callback); + } + + protected _once( + event: TEvent, + callback: AllNodeEvents[TEvent], + ): this { + return this.once(event, callback); + } } diff --git a/packages/zwave-js/src/lib/node/NodeStatusMachine.ts b/packages/zwave-js/src/lib/node/NodeStatusMachine.ts index 0140de63acde..6823866e1295 100644 --- a/packages/zwave-js/src/lib/node/NodeStatusMachine.ts +++ b/packages/zwave-js/src/lib/node/NodeStatusMachine.ts @@ -1,5 +1,6 @@ import { type InterpreterFrom, Machine, type StateMachine } from "xstate"; import { NodeStatus } from "./_Types"; +import { type NodeNetworkRole } from "./mixins/01_NetworkRole"; export interface NodeStatusStateSchema { states: { @@ -43,7 +44,9 @@ export type NodeStatusMachine = StateMachine< >; export type NodeStatusInterpreter = InterpreterFrom; -export function createNodeStatusMachine(canSleep: boolean): NodeStatusMachine { +export function createNodeStatusMachine( + node: NodeNetworkRole, +): NodeStatusMachine { return Machine( { id: "nodeStatus", @@ -103,8 +106,8 @@ export function createNodeStatusMachine(canSleep: boolean): NodeStatusMachine { }, { guards: { - canSleep: () => !!canSleep, - cannotSleep: () => !canSleep, + canSleep: () => !!node.canSleep, + cannotSleep: () => !node.canSleep, }, }, ); diff --git a/packages/zwave-js/src/lib/node/mixins/20_Status.ts b/packages/zwave-js/src/lib/node/mixins/20_Status.ts index 8376449b6689..ebe8f8624d20 100644 --- a/packages/zwave-js/src/lib/node/mixins/20_Status.ts +++ b/packages/zwave-js/src/lib/node/mixins/20_Status.ts @@ -64,7 +64,7 @@ export abstract class NodeStatusMixin extends NodeEventsMixin // Create and hook up the status machine this.statusMachine = interpretEx( - createNodeStatusMachine(this.canSleep ?? false), + createNodeStatusMachine(this), ); this.statusMachine.onTransition((state) => { if (state.changed) { diff --git a/packages/zwave-js/src/lib/node/mixins/40_Values.ts b/packages/zwave-js/src/lib/node/mixins/40_Values.ts index 09809fb09319..d6737aa484df 100644 --- a/packages/zwave-js/src/lib/node/mixins/40_Values.ts +++ b/packages/zwave-js/src/lib/node/mixins/40_Values.ts @@ -63,6 +63,19 @@ export abstract class NodeValuesMixin extends NodeWakeupMixin super(nodeId, driver, endpointIndex, deviceClass, supportedCCs); this._valueDB = valueDB ?? new ValueDB(nodeId, driver.valueDB!, driver.metadataDB!); + + // Pass value events to our listeners + for ( + const event of [ + "value added", + "value updated", + "value removed", + "value notification", + "metadata updated", + ] as const + ) { + this._valueDB.on(event, this.translateValueEvent.bind(this, event)); + } } protected _valueDB: ValueDB; diff --git a/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts b/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts index 744cd867146c..32166745a973 100644 --- a/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts +++ b/packages/zwave-js/src/lib/node/mixins/60_ScheduledPoll.ts @@ -1,9 +1,17 @@ import { type CCAPI } from "@zwave-js/cc"; -import { normalizeValueID } from "@zwave-js/core"; -import { MessagePriority, type ValueID } from "@zwave-js/core/safe"; +import { type ValueDB, normalizeValueID } from "@zwave-js/core"; +import { + type CommandClasses, + MessagePriority, + type ValueID, + type ValueRemovedArgs, + type ValueUpdatedArgs, +} from "@zwave-js/core/safe"; import { type NodeSchedulePollOptions } from "@zwave-js/host"; import { ObjectKeyMap } from "@zwave-js/shared"; import { isDeepStrictEqual } from "node:util"; +import { type Driver } from "../../driver/Driver"; +import { type DeviceClass } from "../DeviceClass"; import { EndpointsMixin } from "./50_Endpoints"; export interface ScheduledPoll { @@ -51,6 +59,48 @@ export interface SchedulePoll { export abstract class SchedulePollMixin extends EndpointsMixin implements SchedulePoll { + public constructor( + nodeId: number, + driver: Driver, + endpointIndex: number, + deviceClass?: DeviceClass, + supportedCCs?: CommandClasses[], + valueDB?: ValueDB, + ) { + super( + nodeId, + driver, + endpointIndex, + deviceClass, + supportedCCs, + valueDB, + ); + + // Avoid verifying a value change for which we recently received an update + for (const event of ["value updated", "value removed"] as const) { + this.valueDB.on( + event, + (args: ValueUpdatedArgs | ValueRemovedArgs) => { + // Value updates caused by the driver should never cancel a scheduled poll + if ("source" in args && args.source === "driver") return; + + if ( + this.cancelScheduledPoll( + args, + (args as ValueUpdatedArgs).newValue, + ) + ) { + this.driver.controllerLog.logNode( + this.id, + "Scheduled poll canceled because expected value was received", + "verbose", + ); + } + }, + ); + } + } + /** * All polls that are currently scheduled for this node */ From 8983591e01ad30507e52889b8ca8644c23c591cc Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 16:22:44 +0200 Subject: [PATCH 07/60] refactor: move security classes to "mixin" --- packages/zwave-js/src/lib/node/Node.ts | 68 -------------- .../src/lib/node/NodeStatusMachine.test.ts | 27 +++--- .../zwave-js/src/lib/node/mixins/00_Base.ts | 36 +------- .../src/lib/node/mixins/05_Security.ts | 90 +++++++++++++++++++ .../zwave-js/src/lib/node/mixins/10_Events.ts | 4 +- .../zwave-js/src/lib/node/mixins/20_Status.ts | 18 +++- .../src/lib/node/mixins/50_Endpoints.ts | 4 +- 7 files changed, 130 insertions(+), 117 deletions(-) create mode 100644 packages/zwave-js/src/lib/node/mixins/05_Security.ts diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index 34c608f2a8db..a62197d3e4f5 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -141,7 +141,6 @@ import { import { type DeviceConfig, embeddedDevicesDir } from "@zwave-js/config"; import { BasicDeviceClass, - CacheBackedMap, CommandClasses, Duration, EncapsulationFlags, @@ -308,20 +307,6 @@ export class ZWaveNode extends ZWaveNodeMixins valueDB, ); - this.securityClasses = new CacheBackedMap(this.driver.networkCache, { - prefix: cacheKeys.node(this.id)._securityClassBaseKey + ".", - suffixSerializer: (value: SecurityClass) => - getEnumMemberName(SecurityClass, value), - suffixDeserializer: (key: string) => { - if ( - key in SecurityClass - && typeof (SecurityClass as any)[key] === "number" - ) { - return (SecurityClass as any)[key]; - } - }, - }); - // Add optional controlled CCs - endpoints don't have this for (const cc of controlledCCs) this.addCC(cc, { isControlled: true }); } @@ -351,10 +336,6 @@ export class ZWaveNode extends ZWaveNodeMixins this.cancelAllScheduledPolls(); } - /** @internal */ - // This a CacheBackedMap that's assigned in the constructor - public readonly securityClasses: Map; - /** * The device specific key (DSK) of this node in binary format. * This is only set if included with Security S2. @@ -368,41 +349,6 @@ export class ZWaveNode extends ZWaveNodeMixins this.driver.cacheSet(cacheKey, value); } - /** Whether the node was granted at least one security class */ - public get isSecure(): MaybeNotKnown { - const securityClass = this.getHighestSecurityClass(); - if (securityClass == undefined) return NOT_KNOWN; - if (securityClass === SecurityClass.None) return false; - return true; - } - - public hasSecurityClass( - securityClass: SecurityClass, - ): MaybeNotKnown { - return this.securityClasses.get(securityClass); - } - - public setSecurityClass( - securityClass: SecurityClass, - granted: boolean, - ): void { - this.securityClasses.set(securityClass, granted); - } - - /** Returns the highest security class this node was granted or `undefined` if that information isn't known yet */ - public getHighestSecurityClass(): MaybeNotKnown { - if (this.securityClasses.size === 0) return undefined; - let missingSome = false; - for (const secClass of securityClassOrder) { - if (this.securityClasses.get(secClass) === true) return secClass; - if (!this.securityClasses.has(secClass)) { - missingSome = true; - } - } - // If we don't have the info for every security class, we don't know the highest one yet - return missingSome ? NOT_KNOWN : SecurityClass.None; - } - public get manufacturerId(): MaybeNotKnown { return this.getValue(ManufacturerSpecificCCValues.manufacturerId.id); } @@ -913,20 +859,6 @@ export class ZWaveNode extends ZWaveNodeMixins }); } - /** - * This tells us which interview stage was last completed - */ - - public get interviewStage(): InterviewStage { - return ( - this.driver.cacheGet(cacheKeys.node(this.id).interviewStage) - ?? InterviewStage.None - ); - } - public set interviewStage(value: InterviewStage) { - this.driver.cacheSet(cacheKeys.node(this.id).interviewStage, value); - } - private _interviewAttempts: number = 0; /** How many attempts to interview this node have already been made */ public get interviewAttempts(): number { diff --git a/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts b/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts index 097bb467b587..ef1f946fa623 100644 --- a/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts +++ b/packages/zwave-js/src/lib/node/NodeStatusMachine.test.ts @@ -8,6 +8,9 @@ import { createNodeStatusMachine, } from "./NodeStatusMachine"; +const testNodeNonSleeping = { canSleep: false } as any; +const testNodeSleeping = { canSleep: true } as any; + function startMachine( t: ExecutionContext, machine: NodeStatusMachine, @@ -18,14 +21,18 @@ function startMachine( } test(`The node should start in the unknown state if it maybe cannot sleep`, (t) => { - const testMachine = createNodeStatusMachine(false); + const testMachine = createNodeStatusMachine({ + canSleep: false, + } as any); const service = startMachine(t, testMachine); t.is(service.getSnapshot().value, "unknown"); }); test(`The node should start in the unknown state if it can definitely sleep`, (t) => { - const testMachine = createNodeStatusMachine(true); + const testMachine = createNodeStatusMachine({ + canSleep: true, + } as any); const service = startMachine(t, testMachine); t.is(service.getSnapshot().value, "unknown"); @@ -164,15 +171,15 @@ for (const testCase of transitions) { test(name, (t) => { // For these tests, assume that the node does or does not support Wakeup, whatever fits - const canSleep = testCase.canSleep == undefined + const testNode = testCase.canSleep == undefined ? testCase.event === "ASLEEP" || testCase.event === "AWAKE" - ? true - : false + ? testNodeSleeping + : testNodeNonSleeping : testCase.canSleep - ? true - : false; + ? testNodeSleeping + : testNodeNonSleeping; - const testMachine = createNodeStatusMachine(canSleep); + const testMachine = createNodeStatusMachine(testNode); testMachine.initial = testCase.start; const service = startMachine(t, testMachine); @@ -182,7 +189,7 @@ for (const testCase of transitions) { } test("A transition from unknown to awake should not happen if the node cannot sleep", (t) => { - const testMachine = createNodeStatusMachine(false); + const testMachine = createNodeStatusMachine(testNodeNonSleeping); const service = startMachine(t, testMachine); service.send("AWAKE"); @@ -190,7 +197,7 @@ test("A transition from unknown to awake should not happen if the node cannot sl }); test("A transition from unknown to asleep should not happen if the node cannot sleep", (t) => { - const testMachine = createNodeStatusMachine(false); + const testMachine = createNodeStatusMachine(testNodeNonSleeping); const service = startMachine(t, testMachine); service.send("ASLEEP"); diff --git a/packages/zwave-js/src/lib/node/mixins/00_Base.ts b/packages/zwave-js/src/lib/node/mixins/00_Base.ts index 1080ce6ab05d..f6c176a25530 100644 --- a/packages/zwave-js/src/lib/node/mixins/00_Base.ts +++ b/packages/zwave-js/src/lib/node/mixins/00_Base.ts @@ -1,40 +1,6 @@ -import { - type FLiRS, - type IZWaveEndpoint, - type IZWaveNode, - type InterviewStage, - type MaybeNotKnown, - type NodeStatus, - type SecurityClass, -} from "@zwave-js/core"; import { Endpoint } from "../Endpoint"; -export abstract class ZWaveNodeBase extends Endpoint implements IZWaveNode { - abstract isListening: MaybeNotKnown; - abstract isFrequentListening: MaybeNotKnown; - abstract canSleep: MaybeNotKnown; - abstract status: NodeStatus; - abstract interviewStage: InterviewStage; - abstract getEndpoint(index: 0): IZWaveEndpoint; - abstract getEndpoint(index: number): IZWaveEndpoint | undefined; - abstract getEndpoint(index: unknown): IZWaveEndpoint | undefined; - - abstract getEndpointOrThrow(index: number): IZWaveEndpoint; - - abstract getAllEndpoints(): IZWaveEndpoint[]; - - abstract isSecure: MaybeNotKnown; - abstract getHighestSecurityClass(): MaybeNotKnown; - - abstract hasSecurityClass( - securityClass: SecurityClass, - ): MaybeNotKnown; - - abstract setSecurityClass( - securityClass: SecurityClass, - granted: boolean, - ): void; - +export abstract class ZWaveNodeBase extends Endpoint { /** * Whether the node should be kept awake when there are no pending messages. */ diff --git a/packages/zwave-js/src/lib/node/mixins/05_Security.ts b/packages/zwave-js/src/lib/node/mixins/05_Security.ts new file mode 100644 index 000000000000..c576bde42707 --- /dev/null +++ b/packages/zwave-js/src/lib/node/mixins/05_Security.ts @@ -0,0 +1,90 @@ +import { + CacheBackedMap, + type CommandClasses, + type MaybeNotKnown, + NOT_KNOWN, + SecurityClass, + securityClassOrder, +} from "@zwave-js/core"; +import { getEnumMemberName } from "@zwave-js/shared"; +import { type Driver } from "../../driver/Driver"; +import { cacheKeys } from "../../driver/NetworkCache"; +import { type DeviceClass } from "../DeviceClass"; +import { NetworkRoleMixin } from "./01_NetworkRole"; + +export interface NodeSecurity { + /** Whether the node was granted at least one security class */ + readonly isSecure: MaybeNotKnown; + + hasSecurityClass(securityClass: SecurityClass): MaybeNotKnown; + + setSecurityClass(securityClass: SecurityClass, granted: boolean): void; + + /** Returns the highest security class this node was granted or `undefined` if that information isn't known yet */ + getHighestSecurityClass(): MaybeNotKnown; +} + +export abstract class NodeSecurityMixin extends NetworkRoleMixin + implements NodeSecurity +{ + public constructor( + nodeId: number, + driver: Driver, + index: number, + deviceClass?: DeviceClass, + supportedCCs?: CommandClasses[], + ) { + super(nodeId, driver, index, deviceClass, supportedCCs); + + this.securityClasses = new CacheBackedMap(this.driver.networkCache, { + prefix: cacheKeys.node(this.id)._securityClassBaseKey + ".", + suffixSerializer: (value: SecurityClass) => + getEnumMemberName(SecurityClass, value), + suffixDeserializer: (key: string) => { + if ( + key in SecurityClass + && typeof (SecurityClass as any)[key] === "number" + ) { + return (SecurityClass as any)[key]; + } + }, + }); + } + + /** @internal */ + // This a CacheBackedMap that's assigned in the constructor + public readonly securityClasses: Map; + + public get isSecure(): MaybeNotKnown { + const securityClass = this.getHighestSecurityClass(); + if (securityClass == undefined) return NOT_KNOWN; + if (securityClass === SecurityClass.None) return false; + return true; + } + + public hasSecurityClass( + securityClass: SecurityClass, + ): MaybeNotKnown { + return this.securityClasses.get(securityClass); + } + + public setSecurityClass( + securityClass: SecurityClass, + granted: boolean, + ): void { + this.securityClasses.set(securityClass, granted); + } + + public getHighestSecurityClass(): MaybeNotKnown { + if (this.securityClasses.size === 0) return undefined; + let missingSome = false; + for (const secClass of securityClassOrder) { + if (this.securityClasses.get(secClass) === true) return secClass; + if (!this.securityClasses.has(secClass)) { + missingSome = true; + } + } + // If we don't have the info for every security class, we don't know the highest one yet + return missingSome ? NOT_KNOWN : SecurityClass.None; + } +} diff --git a/packages/zwave-js/src/lib/node/mixins/10_Events.ts b/packages/zwave-js/src/lib/node/mixins/10_Events.ts index 8f24cccdc6e1..92909e3713e9 100644 --- a/packages/zwave-js/src/lib/node/mixins/10_Events.ts +++ b/packages/zwave-js/src/lib/node/mixins/10_Events.ts @@ -3,7 +3,7 @@ import { type StatisticsEventCallbacksWithSelf } from "../../driver/Statistics"; import { type ZWaveNode } from "../Node"; import { type NodeStatistics } from "../NodeStatistics"; import { type ZWaveNodeEventCallbacks } from "../_Types"; -import { NetworkRoleMixin } from "./01_NetworkRole"; +import { NodeSecurityMixin } from "./05_Security"; // This mixin is a slightly ugly workaround to allow other mixins to // interact with events which would normally take an instance of ZWaveNode @@ -24,7 +24,7 @@ type AbstractNodeEvents = EventsToAbstract< & StatisticsEventCallbacksWithSelf >; -export abstract class NodeEventsMixin extends NetworkRoleMixin { +export abstract class NodeEventsMixin extends NodeSecurityMixin { protected abstract _emit>( event: TEvent, ...args: Parameters[TEvent]> diff --git a/packages/zwave-js/src/lib/node/mixins/20_Status.ts b/packages/zwave-js/src/lib/node/mixins/20_Status.ts index ebe8f8624d20..7a4e08693af9 100644 --- a/packages/zwave-js/src/lib/node/mixins/20_Status.ts +++ b/packages/zwave-js/src/lib/node/mixins/20_Status.ts @@ -1,5 +1,6 @@ -import { type CommandClasses } from "@zwave-js/core"; +import { type CommandClasses, InterviewStage } from "@zwave-js/core"; import { type Driver } from "../../driver/Driver"; +import { cacheKeys } from "../../driver/NetworkCache"; import { type Extended, interpretEx } from "../../driver/StateMachineShared"; import { type DeviceClass } from "../DeviceClass"; import { @@ -48,6 +49,11 @@ export interface NodeWithStatus { * Marks this node as awake (if applicable) */ markAsAwake(): void; + + /** + * Which interview stage was last completed + */ + interviewStage: InterviewStage; } export abstract class NodeStatusMixin extends NodeEventsMixin @@ -177,4 +183,14 @@ export abstract class NodeStatusMixin extends NodeEventsMixin protected set ready(ready: boolean) { this._ready = ready; } + + public get interviewStage(): InterviewStage { + return ( + this.driver.cacheGet(cacheKeys.node(this.id).interviewStage) + ?? InterviewStage.None + ); + } + public set interviewStage(value: InterviewStage) { + this.driver.cacheSet(cacheKeys.node(this.id).interviewStage, value); + } } diff --git a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts index a3966f536fd0..b31a2b5e7e9b 100644 --- a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts +++ b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts @@ -1,6 +1,7 @@ import { MultiChannelCCValues } from "@zwave-js/cc"; import { type CommandClasses, + type IZWaveNode, type MaybeNotKnown, ZWaveError, ZWaveErrorCodes, @@ -39,7 +40,7 @@ export interface Endpoints { } export abstract class EndpointsMixin extends NodeValuesMixin - implements Endpoints + implements Endpoints, IZWaveNode { public get endpointCountIsDynamic(): MaybeNotKnown { return nodeUtils.endpointCountIsDynamic(this.driver, this.id); @@ -175,6 +176,7 @@ export abstract class EndpointsMixin extends NodeValuesMixin /** Returns a list of all endpoints of this node, including the root endpoint (index 0) */ public getAllEndpoints(): Endpoint[] { + // FIXME: GH#7261 we should not need to cast here return nodeUtils.getAllEndpoints(this.driver, this) as Endpoint[]; } } From cf13ee0e091fd228472fed137258de2095b0b1db Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 20:05:56 +0200 Subject: [PATCH 08/60] fix: broken test --- packages/zwave-js/src/lib/test/mocks.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/zwave-js/src/lib/test/mocks.ts b/packages/zwave-js/src/lib/test/mocks.ts index b25f320ef62c..a1ee4c838aa6 100644 --- a/packages/zwave-js/src/lib/test/mocks.ts +++ b/packages/zwave-js/src/lib/test/mocks.ts @@ -343,9 +343,13 @@ export function createTestNode( // If the number of endpoints are given, use them as the individual endpoint count if (options.numEndpoints != undefined) { - nodeUtils.setIndividualEndpointCount(host, ret, options.numEndpoints); - nodeUtils.setAggregatedEndpointCount(host, ret, 0); - nodeUtils.setMultiChannelInterviewComplete(host, ret, true); + nodeUtils.setIndividualEndpointCount( + host, + ret.id, + options.numEndpoints, + ); + nodeUtils.setAggregatedEndpointCount(host, ret.id, 0); + nodeUtils.setMultiChannelInterviewComplete(host, ret.id, true); } return ret; From a0a7584257257089742aef387386b7f30abfb429 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 9 Oct 2024 21:22:41 +0200 Subject: [PATCH 09/60] refactor: further reduce dependency on IZWaveNode and IZWaveEndpoint --- packages/cc/src/cc/AssociationGroupInfoCC.ts | 8 ++- packages/cc/src/cc/ConfigurationCC.ts | 12 ++--- .../cc/src/cc/ManufacturerProprietaryCC.ts | 6 +-- packages/cc/src/cc/TimeParametersCC.ts | 11 ++-- packages/cc/src/lib/API.ts | 49 ++++++++++++++---- packages/cc/src/lib/CommandClass.ts | 1 + packages/cc/src/lib/utils.ts | 14 +++-- .../core/src/abstractions/IZWaveEndpoint.ts | 51 ++++++++++++++----- packages/core/src/abstractions/IZWaveNode.ts | 51 ++++++++++++++----- .../zwave-js/src/lib/node/VirtualEndpoint.ts | 3 +- 10 files changed, 143 insertions(+), 63 deletions(-) diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 0550413ab64b..2c68764e7583 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -1,11 +1,11 @@ import { CommandClasses, type EndpointId, - type IZWaveEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type SupportsCC, encodeCCId, getCCName, parseCCId, @@ -302,8 +302,7 @@ export class AssociationGroupInfoCC extends CommandClass { public static findGroupsForIssuedCommand( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + endpoint: EndpointId & SupportsCC, ccId: CommandClasses, command: number, ): number[] { @@ -333,8 +332,7 @@ export class AssociationGroupInfoCC extends CommandClass { private static getAssociationGroupCountCached( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + endpoint: EndpointId & SupportsCC, ): number { // The association group count is either determined by the // Association CC or the Multi Channel Association CC diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index c6e74742edb1..6cd1c063ecc1 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -3,8 +3,6 @@ import { CommandClasses, ConfigValueFormat, type ConfigurationMetadata, - type IVirtualEndpoint, - type IZWaveEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -38,6 +36,7 @@ import { composeObject } from "alcalzone-shared/objects"; import { padStart } from "alcalzone-shared/strings"; import { CCAPI, + type CCAPIEndpoint, POLL_VALUE, type PollValueImplementation, SET_VALUE, @@ -145,8 +144,7 @@ type NormalizedConfigurationCCAPISetOptions = function createConfigurationCCInstance( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and index should be enough - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, ): ConfigurationCC { return CommandClass.createInstanceUnchecked( applHost, @@ -157,8 +155,7 @@ function createConfigurationCCInstance( function normalizeConfigurationCCAPISetOptions( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and index should be enough - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, options: ConfigurationCCAPISetOptions, ): NormalizedConfigurationCCAPISetOptions { if ("bitMask" in options && options.bitMask) { @@ -215,8 +212,7 @@ function normalizeConfigurationCCAPISetOptions( function bulkMergePartialParamValues( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and index should be enough - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, options: NormalizedConfigurationCCAPISetOptions[], ): (NormalizedConfigurationCCAPISetOptions & { bitMask?: undefined })[] { // Merge partial parameters before doing anything else. Therefore, take the non-partials, ... diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index 8b71365c3f11..c53b6372c7dc 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -1,7 +1,5 @@ import { CommandClasses, - type IVirtualEndpoint, - type IZWaveEndpoint, ZWaveError, ZWaveErrorCodes, validatePayload, @@ -9,7 +7,7 @@ import { import type { ZWaveApplicationHost, ZWaveHost } from "@zwave-js/host/safe"; import { staticExtends } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { CCAPI } from "../lib/API"; +import { CCAPI, type CCAPIEndpoint } from "../lib/API"; import { type CCCommandOptions, CommandClass, @@ -41,7 +39,7 @@ export type ManufacturerProprietaryCCConstructor< export class ManufacturerProprietaryCCAPI extends CCAPI { public constructor( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, ) { super(applHost, endpoint); diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 07a4189d86d2..53f949260652 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -1,6 +1,5 @@ import { CommandClasses, - type IZWaveEndpoint, type MessageOrCCLogEntry, MessagePriority, type SupervisionResult, @@ -8,7 +7,12 @@ import { formatDate, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type ControlsCC, + type EndpointId, + type MaybeNotKnown, + type SupportsCC, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -60,8 +64,7 @@ export const TimeParametersCCValues = Object.freeze({ */ function shouldUseLocalTime( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + endpoint: EndpointId & SupportsCC & ControlsCC, ): boolean { // GH#311 Some nodes have no way to determine the time zone offset, // so they need to interpret the set time as local time instead of UTC. diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index 9c9d7aad6e54..4ad5ce219b30 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -1,7 +1,10 @@ import { type CompatOverrideQueries } from "@zwave-js/config"; import { CommandClasses, + type ControlsCC, type Duration, + type EndpointId, + type GetEndpoint, type IVirtualEndpoint, type IZWaveEndpoint, type IZWaveNode, @@ -9,12 +12,15 @@ import { NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, NOT_KNOWN, + type PhysicalNodes, type SendCommandOptions, type SupervisionResult, + type SupportsCC, type TXReport, type ValueChangeOptions, type ValueDB, type ValueID, + type VirtualEndpointId, ZWaveError, ZWaveErrorCodes, getCCName, @@ -148,6 +154,31 @@ export interface SchedulePollOptions { transition?: "fast" | "slow"; } +// Defines the necessary traits an endpoint passed to a CC API must have +export type CCAPIEndpoint = + & ( + | ( + // Physical endpoints must let us query their controlled CCs + EndpointId & ControlsCC + ) + | ( + // Virtual endpoints must let us query their physical nodes, + // the CCs those nodes implement, and access the endpoints of those + // physical nodes + VirtualEndpointId & { + node: PhysicalNodes< + & SupportsCC + & ControlsCC + & GetEndpoint + >; + } + ) + ) + & SupportsCC; + +export type PhysicalCCAPIEndpoint = CCAPIEndpoint & EndpointId; +export type VirtualCCAPIEndpoint = CCAPIEndpoint & VirtualEndpointId; + /** * The base class for all CC APIs exposed via `Node.commandClasses.` * @publicAPI @@ -155,7 +186,7 @@ export interface SchedulePollOptions { export class CCAPI { public constructor( protected readonly applHost: ZWaveApplicationHost, - protected readonly endpoint: IZWaveEndpoint | IVirtualEndpoint, + protected readonly endpoint: CCAPIEndpoint, ) { this.ccId = getCommandClass(this); } @@ -163,7 +194,7 @@ export class CCAPI { public static create( ccId: T, applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, requireSupport?: boolean, ): CommandClasses extends T ? CCAPI : CCToAPI { const APIConstructor = getAPI(ccId); @@ -312,7 +343,7 @@ export class CCAPI { const timeoutMs = durationMs + additionalDelay; if (this.isSinglecast()) { - const node = this.endpoint.getNodeUnsafe(); + const node = this.getNodeUnsafe(); if (!node) return false; return this.applHost.schedulePoll( @@ -416,8 +447,8 @@ export class CCAPI { } protected assertPhysicalEndpoint( - endpoint: IZWaveEndpoint | IVirtualEndpoint, - ): asserts endpoint is IZWaveEndpoint { + endpoint: EndpointId | VirtualEndpointId, + ): asserts endpoint is EndpointId { if (endpoint.virtual) { throw new ZWaveError( `This method is not supported for virtual nodes!`, @@ -602,7 +633,7 @@ export class CCAPI { function overrideQueriesWrapper( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + endpoint: PhysicalCCAPIEndpoint, ccId: CommandClasses, method: string, overrides: CompatOverrideQueries, @@ -742,18 +773,18 @@ function overrideQueriesWrapper( export class PhysicalCCAPI extends CCAPI { public constructor( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, ) { super(applHost, endpoint); this.assertPhysicalEndpoint(endpoint); } - declare protected readonly endpoint: IZWaveEndpoint; + declare protected readonly endpoint: PhysicalCCAPIEndpoint; } export type APIConstructor = new ( applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint | IVirtualEndpoint, + endpoint: CCAPIEndpoint, ) => T; // This type is auto-generated by maintenance/generateCCAPIInterface.ts diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 2d14d935cc9e..2b68a2bad357 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -808,6 +808,7 @@ export class CommandClass implements ICommandClass { && value.options.autoCreate( applHost, { + virtual: false, nodeId: this.nodeId as number, index: this.endpointIndex, }, diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index d2f704624dc2..20b19dad0344 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -6,7 +6,9 @@ import { type IZWaveNode, type MaybeNotKnown, NOT_KNOWN, + type NodeId, SecurityClass, + type SupportsCC, ZWaveError, ZWaveErrorCodes, actuatorCCs, @@ -36,8 +38,7 @@ import { export function getAssociations( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + endpoint: EndpointId & SupportsCC, ): ReadonlyMap { const ret = new Map(); @@ -242,8 +243,7 @@ export function checkAssociation( export function getAssociationGroups( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + endpoint: EndpointId & SupportsCC, ): ReadonlyMap { // Check whether we have multi channel support or not let assocInstance: typeof AssociationCC; @@ -640,8 +640,7 @@ export async function removeAssociations( export function getLifelineGroupIds( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + endpoint: EndpointId & SupportsCC, ): number[] { // For now only support this for the root endpoint - i.e. node if (endpoint.index > 0) return []; @@ -1243,8 +1242,7 @@ export async function assignLifelineIssueingCommand( export function doesAnyLifelineSendActuatorOrSensorReports( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - node: IZWaveNode, + node: NodeId & SupportsCC, ): MaybeNotKnown { // No association support means no unsolicited reports if ( diff --git a/packages/core/src/abstractions/IZWaveEndpoint.ts b/packages/core/src/abstractions/IZWaveEndpoint.ts index 1cd832902b47..cb9ca6e3bf92 100644 --- a/packages/core/src/abstractions/IZWaveEndpoint.ts +++ b/packages/core/src/abstractions/IZWaveEndpoint.ts @@ -7,29 +7,56 @@ import type { IVirtualNode, IZWaveNode } from "./IZWaveNode"; /** Identifies an endpoint */ export interface EndpointId { + readonly virtual: false; readonly nodeId: number; readonly index: number; } -/** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ -export interface IZWaveEndpoint extends EndpointId { - readonly virtual: false; +/** Allows querying if a CC is supported and in which version */ +export interface SupportsCC { + supportsCC(cc: CommandClasses): boolean; getCCVersion(cc: CommandClasses): number; +} + +/** Allows querying if a CC is controlled */ +export interface ControlsCC { + controlsCC(cc: CommandClasses): boolean; +} + +/** Allows querying if a CC is supported or controlled only securely */ +export interface IsCCSecure { + isCCSecure(cc: CommandClasses): boolean; +} + +/** Allows modifying the list of supported/controlled CCs */ +export interface ModifyCCs { addCC(cc: CommandClasses, info: Partial): void; removeCC(cc: CommandClasses): void; +} + +/** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ +export interface IZWaveEndpoint + extends EndpointId, SupportsCC, ControlsCC, IsCCSecure, ModifyCCs +{ getCCs(): Iterable<[ccId: CommandClasses, info: CommandClassInfo]>; - supportsCC(cc: CommandClasses): boolean; - controlsCC(cc: CommandClasses): boolean; - isCCSecure(cc: CommandClasses): boolean; getNodeUnsafe(): IZWaveNode | undefined; } -/** A basic abstraction of an endpoint of a virtual node (multicast or broadcast) providing access to the relevant functionality */ -export interface IVirtualEndpoint { +/** Identifies a virtual endpoint */ +export interface VirtualEndpointId { + readonly virtual: true; readonly nodeId: number | MulticastDestination; - readonly node: IVirtualNode; readonly index: number; - readonly virtual: true; - getCCVersion(cc: CommandClasses): number; - supportsCC(cc: CommandClasses): boolean; } + +/** A basic abstraction of an endpoint of a virtual node (multicast or broadcast) providing access to the relevant functionality */ +export interface IVirtualEndpoint extends VirtualEndpointId, SupportsCC { + readonly node: IVirtualNode; +} + +// TODO: Use cases in CCAPI implementations: +// - EndpointId or VirtualEndpointId +// - SupportsCC +// - VirtualEndpoint: +// - physical nodes -> NodeId +// - physical nodes -> Endpoint -> SupportsCC,ControlsCC diff --git a/packages/core/src/abstractions/IZWaveNode.ts b/packages/core/src/abstractions/IZWaveNode.ts index b24420db58b5..1684a448936b 100644 --- a/packages/core/src/abstractions/IZWaveNode.ts +++ b/packages/core/src/abstractions/IZWaveNode.ts @@ -2,30 +2,57 @@ import type { FLiRS } from "../capabilities/NodeInfo"; import type { InterviewStage, NodeStatus } from "../consts"; import type { SecurityClassOwner } from "../security/SecurityClass"; import { type MaybeNotKnown } from "../values/Primitive"; -import type { IVirtualEndpoint, IZWaveEndpoint } from "./IZWaveEndpoint"; +import type { + EndpointId, + IVirtualEndpoint, + IZWaveEndpoint, + VirtualEndpointId, +} from "./IZWaveEndpoint"; -/** A basic abstraction of a Z-Wave node providing access to the relevant functionality */ -export interface IZWaveNode extends IZWaveEndpoint, SecurityClassOwner { +export interface NodeId extends EndpointId { readonly id: number; + // FIXME: GH#7261 this should have type 0 + readonly index: number; +} + +export interface GetEndpoint { + getEndpoint(index: 0): T; + getEndpoint(index: number): T | undefined; + getEndpointOrThrow(index: number): T; +} + +/** A basic abstraction of a Z-Wave node providing access to the relevant functionality */ +export interface IZWaveNode + extends + IZWaveEndpoint, + NodeId, + GetEndpoint, + SecurityClassOwner +{ isListening: MaybeNotKnown; isFrequentListening: MaybeNotKnown; readonly canSleep: MaybeNotKnown; readonly status: NodeStatus; interviewStage: InterviewStage; - getEndpoint(index: 0): IZWaveEndpoint; - getEndpoint(index: number): IZWaveEndpoint | undefined; - getEndpointOrThrow(index: number): IZWaveEndpoint; getAllEndpoints(): IZWaveEndpoint[]; readonly isSecure: MaybeNotKnown; } -/** A basic abstraction of a virtual node (multicast or broadcast) providing access to the relevant functionality */ -export interface IVirtualNode extends IVirtualEndpoint { +export interface VirtualNodeId extends VirtualEndpointId { readonly id: number | undefined; - readonly physicalNodes: readonly IZWaveNode[]; +} - getEndpoint(index: 0): IVirtualEndpoint; - getEndpoint(index: number): IVirtualEndpoint | undefined; - getEndpointOrThrow(index: number): IVirtualEndpoint; +export interface PhysicalNodes { + readonly physicalNodes: readonly (NodeId & T)[]; +} + +/** A basic abstraction of a virtual node (multicast or broadcast) providing access to the relevant functionality */ +export interface IVirtualNode + extends + IVirtualEndpoint, + VirtualNodeId, + GetEndpoint, + PhysicalNodes +{ } diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts index 71223ea3d7b1..079544b76f75 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts @@ -4,6 +4,7 @@ import { type CCAPIs, type CCNameOrId, PhysicalCCAPI, + type VirtualCCAPIEndpoint, getAPI, normalizeCCNameOrId, } from "@zwave-js/cc"; @@ -91,7 +92,7 @@ export class VirtualEndpoint implements IVirtualEndpoint { */ public createAPI(ccId: CommandClasses): CCAPI { const createCCAPI = ( - endpoint: IVirtualEndpoint, + endpoint: VirtualCCAPIEndpoint, secClass: SecurityClass, ) => { if ( From cbec3d41d1ffec03917460f11605cac2f9dec5e9 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 10 Oct 2024 13:15:26 +0200 Subject: [PATCH 10/60] refactor: more traits, less IZWaveNode --- .vscode/typescript.code-snippets | 7 ++- packages/cc/src/cc/AlarmSensorCC.ts | 13 ++-- packages/cc/src/cc/AssociationCC.ts | 9 ++- packages/cc/src/cc/AssociationGroupInfoCC.ts | 13 ++-- packages/cc/src/cc/BarrierOperatorCC.ts | 11 +++- packages/cc/src/cc/BasicCC.ts | 13 ++-- packages/cc/src/cc/BatteryCC.ts | 15 +++-- packages/cc/src/cc/BinarySensorCC.ts | 11 +++- packages/cc/src/cc/BinarySwitchCC.ts | 9 ++- packages/cc/src/cc/CRC16CC.ts | 1 + packages/cc/src/cc/CentralSceneCC.ts | 9 ++- .../cc/src/cc/ClimateControlScheduleCC.ts | 1 + packages/cc/src/cc/ClockCC.ts | 9 ++- packages/cc/src/cc/ColorSwitchCC.ts | 11 +++- packages/cc/src/cc/ConfigurationCC.ts | 19 +++--- packages/cc/src/cc/DoorLockCC.ts | 13 ++-- packages/cc/src/cc/DoorLockLoggingCC.ts | 9 ++- packages/cc/src/cc/EnergyProductionCC.ts | 11 +++- packages/cc/src/cc/EntryControlCC.ts | 11 +++- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 5 +- packages/cc/src/cc/HumidityControlModeCC.ts | 11 +++- .../src/cc/HumidityControlOperatingStateCC.ts | 9 ++- .../cc/src/cc/HumidityControlSetpointCC.ts | 13 ++-- packages/cc/src/cc/InclusionControllerCC.ts | 1 + packages/cc/src/cc/IndicatorCC.ts | 15 +++-- packages/cc/src/cc/IrrigationCC.ts | 13 ++-- packages/cc/src/cc/LanguageCC.ts | 9 ++- packages/cc/src/cc/LockCC.ts | 9 ++- .../cc/src/cc/ManufacturerProprietaryCC.ts | 13 ++-- packages/cc/src/cc/ManufacturerSpecificCC.ts | 5 +- packages/cc/src/cc/MeterCC.ts | 15 +++-- .../cc/src/cc/MultiChannelAssociationCC.ts | 9 ++- packages/cc/src/cc/MultiChannelCC.ts | 11 +++- packages/cc/src/cc/MultiCommandCC.ts | 1 + packages/cc/src/cc/MultilevelSensorCC.ts | 13 ++-- packages/cc/src/cc/MultilevelSwitchCC.ts | 11 +++- packages/cc/src/cc/NodeNamingCC.ts | 9 ++- packages/cc/src/cc/NotificationCC.ts | 21 ++++--- packages/cc/src/cc/PowerlevelCC.ts | 2 +- packages/cc/src/cc/ProtectionCC.ts | 11 +++- packages/cc/src/cc/SceneActivationCC.ts | 1 + .../cc/src/cc/SceneActuatorConfigurationCC.ts | 9 ++- .../src/cc/SceneControllerConfigurationCC.ts | 11 +++- packages/cc/src/cc/ScheduleEntryLockCC.ts | 11 ++-- packages/cc/src/cc/Security2CC.ts | 5 +- packages/cc/src/cc/SecurityCC.ts | 5 +- packages/cc/src/cc/SoundSwitchCC.ts | 5 +- packages/cc/src/cc/SupervisionCC.ts | 7 ++- packages/cc/src/cc/ThermostatFanModeCC.ts | 11 +++- packages/cc/src/cc/ThermostatFanStateCC.ts | 9 ++- packages/cc/src/cc/ThermostatModeCC.ts | 13 ++-- .../cc/src/cc/ThermostatOperatingStateCC.ts | 9 ++- packages/cc/src/cc/ThermostatSetbackCC.ts | 9 ++- packages/cc/src/cc/ThermostatSetpointCC.ts | 13 ++-- packages/cc/src/cc/TimeCC.ts | 5 +- packages/cc/src/cc/TimeParametersCC.ts | 9 ++- packages/cc/src/cc/UserCodeCC.ts | 15 +++-- packages/cc/src/cc/VersionCC.ts | 5 +- packages/cc/src/cc/WakeUpCC.ts | 7 ++- packages/cc/src/cc/WindowCoveringCC.ts | 5 +- packages/cc/src/cc/ZWavePlusCC.ts | 5 +- packages/cc/src/cc/ZWaveProtocolCC.ts | 1 + .../cc/manufacturerProprietary/FibaroCC.ts | 52 +++++++++------- packages/cc/src/lib/API.ts | 45 ++++---------- packages/cc/src/lib/CommandClass.ts | 54 +++++++++++++---- packages/cc/src/lib/utils.ts | 59 +++++++++++-------- .../core/src/abstractions/IZWaveEndpoint.ts | 15 ++--- packages/core/src/abstractions/IZWaveNode.ts | 53 +++++++++++++---- packages/core/src/security/SecurityClass.ts | 16 ++++- packages/host/src/ZWaveHost.ts | 21 +++++-- packages/host/src/mocks.ts | 42 +++++++------ packages/serial/src/message/Message.ts | 10 ++-- packages/zwave-js/src/lib/driver/Driver.ts | 24 ++++---- packages/zwave-js/src/lib/node/Endpoint.ts | 22 ++++++- packages/zwave-js/src/lib/node/Node.ts | 4 +- .../zwave-js/src/lib/node/VirtualEndpoint.ts | 6 +- .../zwave-js/src/lib/node/mixins/00_Base.ts | 3 +- .../src/lib/node/mixins/05_Security.ts | 16 +---- .../src/lib/node/mixins/50_Endpoints.ts | 10 +++- packages/zwave-js/src/lib/node/utils.ts | 40 ++++++++----- .../network-mgmt/AddNodeToNetworkRequest.ts | 8 ++- 81 files changed, 717 insertions(+), 354 deletions(-) diff --git a/.vscode/typescript.code-snippets b/.vscode/typescript.code-snippets index a6d55319776e..5799ddeb1af3 100644 --- a/.vscode/typescript.code-snippets +++ b/.vscode/typescript.code-snippets @@ -664,7 +664,7 @@ "scope": "typescript", "prefix": "zwccpv", "body": [ - "public persistValues(applHost: ZWaveApplicationHost): boolean {", + "public persistValues(applHost: ZWaveApplicationHost): boolean {", "\tif (!super.persistValues(applHost)) return false;", "\tconst valueDB = this.getValueDB(applHost);", "", @@ -682,6 +682,7 @@ "\tCommandClass,", "\tgotDeserializationOptions,", "\ttype CCCommandOptions,", + "\ttype CCNode,", "\ttype CommandClassDeserializationOptions,", "} from \"../lib/CommandClass\";", "import {", @@ -951,7 +952,7 @@ "scope": "typescript", "prefix": "zwccinterview", "body": [ - "public async interview(applHost: ZWaveApplicationHost): Promise {", + "public async interview(applHost: ZWaveApplicationHost): Promise {", "\tconst node = this.getNode(applHost)!;", "\tconst endpoint = this.getEndpoint(applHost)!;", "\tconst api = CCAPI.create(", @@ -1003,7 +1004,7 @@ "scope": "typescript", "prefix": "zwccrefval", "body": [ - "public async refreshValues(applHost: ZWaveApplicationHost): Promise {", + "public async refreshValues(applHost: ZWaveApplicationHost): Promise {", "\tconst node = this.getNode(applHost)!;", "\tconst endpoint = this.getEndpoint(applHost)!;", "\tconst api = CCAPI.create(", diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 29fdaedfdfda..f4cbdf1b6d51 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -21,6 +21,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -168,7 +169,9 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI { export class AlarmSensorCC extends CommandClass { declare ccCommand: AlarmSensorCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; @@ -234,7 +237,9 @@ export class AlarmSensorCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -362,7 +367,7 @@ export class AlarmSensorCCReport extends AlarmSensorCC { }; } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Create metadata if it does not exist this.createMetadataForSensorType(applHost, this.sensorType); @@ -456,7 +461,7 @@ export class AlarmSensorCCSupportedReport extends AlarmSensorCC { return this._supportedSensorTypes; } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Create metadata for each sensor type for (const type of this._supportedSensorTypes) { diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 97dbfbb6775c..8720af022624 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -23,6 +23,7 @@ import { distinct } from "alcalzone-shared/arrays"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -371,7 +372,9 @@ export class AssociationCC extends CommandClass { return ret; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -437,7 +440,9 @@ export class AssociationCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 2c68764e7583..f4d23b575e84 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -21,6 +21,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -352,7 +353,9 @@ export class AssociationGroupInfoCC extends CommandClass { ); } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -409,7 +412,9 @@ export class AssociationGroupInfoCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -494,7 +499,7 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC { public readonly groupId: number; public readonly name: string; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const valueDB = this.getValueDB(applHost); @@ -626,7 +631,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { public readonly groups: readonly AssociationGroupInfo[]; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; for (const group of this.groups) { diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index f7b245eb941f..5ceb87941903 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -41,6 +41,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -422,7 +423,9 @@ export class BarrierOperatorCCAPI extends CCAPI { export class BarrierOperatorCC extends CommandClass { declare ccCommand: BarrierOperatorCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -485,7 +488,9 @@ export class BarrierOperatorCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -742,7 +747,7 @@ export class BarrierOperatorCCEventSignalingReport extends BarrierOperatorCC { this.subsystemState = this.payload[1]; } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const signalingStateValue = BarrierOperatorCCValues.signalingState( diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 832be1af0264..5e870e330fb4 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -33,6 +33,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -251,7 +252,9 @@ export class BasicCCAPI extends CCAPI { export class BasicCC extends CommandClass { declare ccCommand: BasicCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; @@ -288,7 +291,9 @@ export class BasicCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -324,7 +329,7 @@ remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; } public override getDefinedValueIDs( - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, ): ValueID[] { const ret: ValueID[] = []; const endpoint = this.getEndpoint(applHost)!; @@ -437,7 +442,7 @@ export class BasicCCReport extends BasicCC { @ccValue(BasicCCValues.duration) public readonly duration: Duration | undefined; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { // Basic CC Report persists its values itself, since there are some // specific rules when which value may be persisted. // These rules are essentially encoded in the getDefinedValueIDs overload, diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index eb96dc960623..1e3591111e3f 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -28,6 +28,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -276,7 +277,9 @@ export class BatteryCCAPI extends PhysicalCCAPI { export class BatteryCC extends CommandClass { declare ccCommand: BatteryCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -292,7 +295,9 @@ export class BatteryCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -361,7 +366,7 @@ temperature: ${batteryHealth.temperature} °C`; public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, ): boolean { // Check when the battery state was last updated const valueDB = applHost.tryGetValueDB(this.nodeId); @@ -454,7 +459,7 @@ export class BatteryCCReport extends BatteryCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Naïve heuristic for a full battery @@ -615,7 +620,7 @@ export class BatteryCCHealthReport extends BatteryCC { this.temperatureScale = scale; } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Update the temperature unit in the value DB diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index c30b7e29ce92..5cf8c3d33e93 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -26,6 +26,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -189,7 +190,9 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { export class BinarySensorCC extends CommandClass { declare ccCommand: BinarySensorCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -245,7 +248,9 @@ export class BinarySensorCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -361,7 +366,7 @@ export class BinarySensorCCReport extends BinarySensorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Workaround for devices reporting with sensor type Any -> find first supported sensor type and use that diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 9674ec342873..fd6bb109e293 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -34,6 +34,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -239,7 +240,9 @@ export class BinarySwitchCCAPI extends CCAPI { export class BinarySwitchCC extends CommandClass { declare ccCommand: BinarySwitchCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -254,7 +257,9 @@ export class BinarySwitchCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index 22d490ac013e..189ab3e13d2f 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -10,6 +10,7 @@ import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index d50422e5a3f7..04a55bd64ed7 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -33,6 +33,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -218,7 +219,9 @@ export class CentralSceneCC extends CommandClass { return true; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -318,7 +321,7 @@ export class CentralSceneCCNotification extends CentralSceneCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // In case the interview is not yet completed, we still create some basic metadata @@ -395,7 +398,7 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Create/extend metadata for all scenes diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index e7c4d610276c..c2d922b88192 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -16,6 +16,7 @@ import { padStart } from "alcalzone-shared/strings"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 3c1ffcf09a4f..6c3f679effa9 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -21,6 +21,7 @@ import { padStart } from "alcalzone-shared/strings"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -90,7 +91,9 @@ export class ClockCCAPI extends CCAPI { export class ClockCC extends CommandClass { declare ccCommand: ClockCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -105,7 +108,9 @@ export class ClockCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 9d215ea13e3f..7a1160ef3e15 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -44,6 +44,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -543,7 +544,9 @@ export class ColorSwitchCCAPI extends CCAPI { export class ColorSwitchCC extends CommandClass { declare ccCommand: ColorSwitchCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -625,7 +628,9 @@ export class ColorSwitchCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -766,7 +771,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { // Duration is stored globally instead of per component if (!super.persistValues(applHost)) return false; diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 6cd1c063ecc1..c455f9100e22 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -47,6 +47,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -1039,7 +1040,9 @@ export class ConfigurationCCAPI extends CCAPI { export class ConfigurationCC extends CommandClass { declare ccCommand: ConfigurationCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1197,7 +1200,9 @@ alters capabilities: ${!!properties.altersCapabilities}`; this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1633,7 +1638,7 @@ export class ConfigurationCCReport extends ConfigurationCC { public valueSize: number; private valueFormat?: ConfigValueFormat; // only used for serialization - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // This parameter may be a partial param in the following cases: @@ -2148,7 +2153,7 @@ export class ConfigurationCCBulkReport extends ConfigurationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Store every received parameter @@ -2329,7 +2334,7 @@ export class ConfigurationCCNameReport extends ConfigurationCC { public name: string; public readonly reportsToFollow: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Bitfield parameters that are not documented in a config file @@ -2476,7 +2481,7 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { public info: string; public readonly reportsToFollow: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Bitfield parameters that are not documented in a config file @@ -2715,7 +2720,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // If we actually received parameter info, store it diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 8ccdd5bbadf0..e11c652631ce 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -35,6 +35,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -594,7 +595,9 @@ export class DoorLockCCAPI extends PhysicalCCAPI { export class DoorLockCC extends CommandClass { declare ccCommand: DoorLockCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -719,7 +722,9 @@ supports block to block: ${resp.blockToBlockSupported}`; if (!hadCriticalTimeout) this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -903,7 +908,7 @@ export class DoorLockCCOperationReport extends DoorLockCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Only store the door/bolt/latch status if the lock supports it @@ -1065,7 +1070,7 @@ export class DoorLockCCConfigurationReport extends DoorLockCC { public readonly twistAssist?: boolean; public readonly blockToBlock?: boolean; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Only store the autoRelockTime etc. params if the lock supports it diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index a88bd9585c9b..b9b284f66955 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -18,6 +18,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -170,7 +171,9 @@ export class DoorLockLoggingCCAPI extends PhysicalCCAPI { export class DoorLockLoggingCC extends CommandClass { declare ccCommand: DoorLockLoggingCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -185,7 +188,9 @@ export class DoorLockLoggingCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index 2871a514a9e2..d43934b4a0a7 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -23,6 +23,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -132,7 +133,9 @@ export class EnergyProductionCCAPI extends CCAPI { export class EnergyProductionCC extends CommandClass { declare ccCommand: EnergyProductionCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -148,7 +151,9 @@ export class EnergyProductionCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -218,7 +223,7 @@ export class EnergyProductionCCReport extends EnergyProductionCC { public readonly scale: EnergyProductionScale; public readonly value: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const valueValue = EnergyProductionCCValues.value(this.parameter); diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index b47a03500c76..eca66d6e4c38 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -31,6 +31,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -269,7 +270,9 @@ export class EntryControlCC extends CommandClass { ]; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -358,7 +361,9 @@ max key cache timeout: ${eventCapabilities.maxKeyCacheTimeout} seconds`, this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -566,7 +571,7 @@ export class EntryControlCCEventSupportedReport extends EntryControlCC { this.maxKeyCacheTimeout = this.payload[offset + 3]; } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Store min/max cache size and timeout as metadata diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index c9725d40feaf..908bc9bcca74 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -24,6 +24,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -263,7 +264,9 @@ export class FirmwareUpdateMetaDataCC extends CommandClass { return true; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index b096e6617b9a..ad166fa122f5 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -30,6 +30,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -185,7 +186,9 @@ export class HumidityControlModeCCAPI extends CCAPI { export class HumidityControlModeCC extends CommandClass { declare ccCommand: HumidityControlModeCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -242,7 +245,9 @@ export class HumidityControlModeCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -364,7 +369,7 @@ export class HumidityControlModeCCSupportedReport } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Use this information to create the metadata for the mode property diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index b04db8898b98..4c93b6085bfa 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -20,6 +20,7 @@ import { throwUnsupportedProperty, } from "../lib/API"; import { + type CCNode, CommandClass, type CommandClassDeserializationOptions, } from "../lib/CommandClass"; @@ -111,7 +112,9 @@ export class HumidityControlOperatingStateCCAPI extends CCAPI { export class HumidityControlOperatingStateCC extends CommandClass { declare ccCommand: HumidityControlOperatingStateCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -126,7 +129,9 @@ export class HumidityControlOperatingStateCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 2705a39ecb22..76ba80ee0e05 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -35,6 +35,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -350,7 +351,9 @@ export class HumidityControlSetpointCC extends CommandClass { } } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -465,7 +468,9 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -591,7 +596,7 @@ export class HumidityControlSetpointCCReport extends HumidityControlSetpointCC { this.scale = scale; } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const scale = getScale(this.scale); @@ -861,7 +866,7 @@ export class HumidityControlSetpointCCCapabilitiesReport parseFloatWithScale(this.payload.subarray(1 + bytesRead))); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Predefine the metadata diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index 5efbd3665974..1e4ddb87301f 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -9,6 +9,7 @@ import { getEnumMemberName } from "@zwave-js/shared"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 025066610a35..225bb888f621 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -36,6 +36,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -676,7 +677,9 @@ export class IndicatorCCAPI extends CCAPI { export class IndicatorCC extends CommandClass { declare ccCommand: IndicatorCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -762,7 +765,9 @@ export class IndicatorCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1068,7 +1073,7 @@ export class IndicatorCCReport extends IndicatorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; if (this.indicator0Value != undefined) { @@ -1281,7 +1286,7 @@ export class IndicatorCCSupportedReport extends IndicatorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; if (this.indicatorId !== 0x00) { @@ -1418,7 +1423,7 @@ export class IndicatorCCDescriptionReport extends IndicatorCC { public indicatorId: number; public description: string; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; if (this.description) { diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index d82979ca1a5b..3dd8423f3cc2 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -36,6 +36,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -1156,7 +1157,9 @@ export class IrrigationCC extends CommandClass { ); } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1220,7 +1223,9 @@ max. valve table size: ${systemInfo.maxValveTableSize}`; this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1726,7 +1731,7 @@ export class IrrigationCCValveInfoReport extends IrrigationCC { public readonly errorHighFlow?: boolean; public readonly errorLowFlow?: boolean; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // connected @@ -2014,7 +2019,7 @@ export class IrrigationCCValveConfigReport extends IrrigationCC { this.useMoistureSensor = !!(this.payload[offset] & 0b10); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // nominalCurrentHighThreshold diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 02ce9f2c0dee..77befb25bd14 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -22,6 +22,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -113,7 +114,9 @@ export class LanguageCCAPI extends CCAPI { export class LanguageCC extends CommandClass { declare ccCommand: LanguageCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -128,7 +131,9 @@ export class LanguageCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index c7cf5b0095f3..80952dbcb3b5 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -28,6 +28,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -137,7 +138,9 @@ export class LockCCAPI extends PhysicalCCAPI { export class LockCC extends CommandClass { declare ccCommand: LockCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -152,7 +155,9 @@ export class LockCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index c53b6372c7dc..2d93ef32dc29 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -7,9 +7,10 @@ import { import type { ZWaveApplicationHost, ZWaveHost } from "@zwave-js/host/safe"; import { staticExtends } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { CCAPI, type CCAPIEndpoint } from "../lib/API"; +import { CCAPI, type CCAPIEndpoint, type CCAPINode } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -38,7 +39,7 @@ export type ManufacturerProprietaryCCConstructor< @API(CommandClasses["Manufacturer Proprietary"]) export class ManufacturerProprietaryCCAPI extends CCAPI { public constructor( - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, endpoint: CCAPIEndpoint, ) { super(applHost, endpoint); @@ -221,7 +222,9 @@ export class ManufacturerProprietaryCC extends CommandClass { } } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; // Read the manufacturer ID from Manufacturer Specific CC @@ -244,7 +247,9 @@ export class ManufacturerProprietaryCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; if (this.manufacturerId == undefined) { diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 0abea0a049c4..6dec47054712 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -18,6 +18,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -178,7 +179,9 @@ export class ManufacturerSpecificCC extends CommandClass { return []; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index c230f8cbfa1e..420d53b7cd23 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -53,6 +53,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -628,7 +629,9 @@ export class MeterCCAPI extends PhysicalCCAPI { export class MeterCC extends CommandClass { declare ccCommand: MeterCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -696,7 +699,9 @@ supports reset: ${suppResp.supportsReset}`; this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -756,7 +761,7 @@ supports reset: ${suppResp.supportsReset}`; public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, ): boolean { // Poll the device when all of the supported values were last updated longer than 6 hours ago. // This may lead to some values not being updated, but the user may have disabled some unnecessary @@ -925,7 +930,7 @@ export class MeterCCReport extends MeterCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const meter = getMeter(this.type); @@ -1246,7 +1251,7 @@ export class MeterCCSupportedReport extends MeterCC { @ccValue(MeterCCValues.supportedRateTypes) public readonly supportedRateTypes: readonly RateType[]; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; if (!this.supportsReset) return true; diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index ed6cad335aca..e47530799326 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -25,6 +25,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -462,7 +463,9 @@ export class MultiChannelAssociationCC extends CommandClass { return ret; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const mcAPI = CCAPI.create( @@ -511,7 +514,9 @@ export class MultiChannelAssociationCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const mcAPI = CCAPI.create( diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index fd13c2a6aed9..fe00f5b30418 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -28,6 +28,7 @@ import { distinct } from "alcalzone-shared/arrays"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -441,7 +442,9 @@ export class MultiChannelCC extends CommandClass { return true; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const removeEndpoints = applHost.getDeviceConfig?.(node.id)?.compat @@ -712,7 +715,9 @@ supported CCs:`; this.setInterviewComplete(applHost, true); } - private async interviewV1(applHost: ZWaveApplicationHost): Promise { + private async interviewV1( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -934,7 +939,7 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const deviceClassValue = MultiChannelCCValues.endpointDeviceClass; diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index 039c4050c56f..4bb1678dd63a 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -10,6 +10,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 34afed7957f2..c2586fa999d3 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -41,6 +41,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, type CCResponsePredicate, CommandClass, type CommandClassDeserializationOptions, @@ -382,7 +383,9 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { export class MultilevelSensorCC extends CommandClass { declare ccCommand: MultilevelSensorCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -472,7 +475,9 @@ export class MultilevelSensorCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -542,7 +547,7 @@ value: ${mlsResponse.value}${ public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, ): boolean { // Poll the device when all of the supported values were last updated longer than 6 hours ago. // This may lead to some values not being updated, but the user may have disabled some unnecessary @@ -647,7 +652,7 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const sensor = getSensor(this.type); diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index ecbcf05f6aba..6991cc84ee79 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -33,6 +33,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -518,7 +519,9 @@ export class MultilevelSwitchCCAPI extends CCAPI { export class MultilevelSwitchCC extends CommandClass { declare ccCommand: MultilevelSwitchCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -567,7 +570,9 @@ export class MultilevelSwitchCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -861,7 +866,7 @@ export class MultilevelSwitchCCSupportedReport extends MultilevelSwitchCC { @ccValue(MultilevelSwitchCCValues.switchType) public readonly switchType: SwitchType; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; this.createMetadataForLevelChangeActions(applHost, this.switchType); return true; diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 53ebeb26d04a..e0de1b25eee7 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -27,6 +27,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -209,7 +210,9 @@ export class NodeNamingAndLocationCC extends CommandClass { return true; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -224,7 +227,9 @@ export class NodeNamingAndLocationCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index 584577942a5f..cb9e65fa2413 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -17,6 +17,7 @@ import { type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type NodeId, type SinglecastCC, type SupervisionResult, type ValueID, @@ -47,6 +48,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, InvalidCC, @@ -489,7 +491,7 @@ export class NotificationCC extends CommandClass { } private async determineNotificationMode( - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, api: NotificationCCAPI, supportedNotificationEvents: ReadonlyMap, ): Promise<"push" | "pull"> { @@ -551,15 +553,16 @@ export class NotificationCC extends CommandClass { /** Whether the node implements push or pull notifications */ public static getNotificationMode( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 Change to nodeId - node: { id: number }, + node: NodeId, ): MaybeNotKnown<"push" | "pull"> { return applHost .getValueDB(node.id) .getValue(NotificationCCValues.notificationMode.id); } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -825,7 +828,9 @@ export class NotificationCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; // Refreshing values only works on pull nodes if (NotificationCC.getNotificationMode(applHost, node) === "pull") { @@ -879,7 +884,7 @@ export class NotificationCC extends CommandClass { public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, ): boolean { // Pull-mode nodes must be polled regularly @@ -1023,7 +1028,7 @@ export class NotificationCCReport extends NotificationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Check if we need to re-interpret the alarm values somehow @@ -1633,7 +1638,7 @@ export class NotificationCCEventSupportedReport extends NotificationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Store which events this notification supports diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index 044a6876eee7..9a359f759b59 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -126,7 +126,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { ZWaveErrorCodes.Argument_Invalid, ); } - const testNode = this.applHost.nodes.getOrThrow(testNodeId); + const testNode = this.applHost.getNodeOrThrow(testNodeId); if (testNode.isFrequentListening) { throw new ZWaveError( `Node ${testNodeId} is FLiRS and therefore cannot be used for a powerlevel test.`, diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 4e2985238cff..235c8d8722c3 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -33,6 +33,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -355,7 +356,9 @@ export class ProtectionCCAPI extends CCAPI { export class ProtectionCC extends CommandClass { declare ccCommand: ProtectionCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -418,7 +421,9 @@ RF protection states: ${ if (!hadCriticalTimeout) this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -610,7 +615,7 @@ export class ProtectionCCSupportedReport extends ProtectionCC { ); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // update metadata (partially) for the local and rf values diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index f00677c62bac..9c26a98e432b 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -21,6 +21,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 1960150f7028..11dcfe854742 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -31,6 +31,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -297,7 +298,9 @@ export class SceneActuatorConfigurationCC extends CommandClass { declare ccCommand: SceneActuatorConfigurationCommand; // eslint-disable-next-line @typescript-eslint/require-await - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -323,7 +326,7 @@ export class SceneActuatorConfigurationCC extends CommandClass { // `refreshValues()` would create 255 `Get` commands to be issued to the node // Therefore, I think we should not implement it. Here is how it would be implemented // - // public async refreshValues(applHost: ZWaveApplicationHost): Promise { + // public async refreshValues(applHost: ZWaveApplicationHost): Promise { // const node = this.getNode(applHost)!; // const endpoint = this.getEndpoint(applHost)!; // const api = endpoint.commandClasses[ @@ -434,7 +437,7 @@ export class SceneActuatorConfigurationCCReport public readonly level?: number; public readonly dimmingDuration?: Duration; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Do not persist values for an inactive scene diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 79893901c00d..5c129dc87c62 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -32,6 +32,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -374,7 +375,9 @@ export class SceneControllerConfigurationCC extends CommandClass { } // eslint-disable-next-line @typescript-eslint/require-await - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; @@ -416,7 +419,9 @@ export class SceneControllerConfigurationCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -557,7 +562,7 @@ export class SceneControllerConfigurationCCReport public readonly sceneId: number; public readonly dimmingDuration: Duration; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // If groupId = 0, values are meaningless diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 04ee0b394920..0cf071c4291f 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -29,6 +29,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -701,7 +702,9 @@ export class ScheduleEntryLockCCAPI extends CCAPI { export class ScheduleEntryLockCC extends CommandClass { declare ccCommand: ScheduleEntryLockCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1258,7 +1261,7 @@ export class ScheduleEntryLockCCWeekDayScheduleReport public stopHour?: number; public stopMinute?: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; persistSchedule.call( @@ -1591,7 +1594,7 @@ export class ScheduleEntryLockCCYearDayScheduleReport public stopHour?: number; public stopMinute?: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; persistSchedule.call( @@ -2002,7 +2005,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport public durationHour?: number; public durationMinute?: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; persistSchedule.call( diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index f8b460c4097f..d8748a8e0636 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -46,6 +46,7 @@ import { isArray } from "alcalzone-shared/typeguards"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, type CCResponseRole, CommandClass, type CommandClassDeserializationOptions, @@ -614,7 +615,9 @@ export class Security2CCAPI extends CCAPI { export class Security2CC extends CommandClass { declare ccCommand: Security2Command; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index c3757a36b13a..b59babd5205e 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -32,6 +32,7 @@ import { randomBytes } from "node:crypto"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -338,7 +339,9 @@ export class SecurityCC extends CommandClass { securityManager: SecurityManager; }; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index 22e257341eb4..2b4874c526b2 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -30,6 +30,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, type CCResponsePredicate, CommandClass, type CommandClassDeserializationOptions, @@ -372,7 +373,9 @@ export class SoundSwitchCCAPI extends CCAPI { export class SoundSwitchCC extends CommandClass { declare ccCommand: SoundSwitchCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 8ce2d74082db..a20721ae44f3 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -3,13 +3,16 @@ import { Duration, EncapsulationFlags, type EndpointId, + type GetEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type NodeId, type SinglecastCC, type SupervisionResult, SupervisionStatus, + type SupportsCC, TransmitOptions, ZWaveError, ZWaveErrorCodes, @@ -230,7 +233,9 @@ export class SupervisionCC extends CommandClass { /** Returns whether this is a valid command to send supervised */ public static mayUseSupervision( - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost< + NodeId & SupportsCC & GetEndpoint + >, command: T, ): command is SinglecastCC { // Supervision may only be used for singlecast CCs that expect no response diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index 451d2739ae07..58f1366f8fe2 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -31,6 +31,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -237,7 +238,9 @@ export class ThermostatFanModeCCAPI extends CCAPI { export class ThermostatFanModeCC extends CommandClass { declare ccCommand: ThermostatFanModeCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -291,7 +294,9 @@ export class ThermostatFanModeCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -431,7 +436,7 @@ export class ThermostatFanModeCCSupportedReport extends ThermostatFanModeCC { ); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Remember which fan modes are supported diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index e3df7bbe73e3..7a459e45c5dc 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -21,6 +21,7 @@ import { throwUnsupportedProperty, } from "../lib/API"; import { + type CCNode, CommandClass, type CommandClassDeserializationOptions, } from "../lib/CommandClass"; @@ -103,7 +104,9 @@ export class ThermostatFanStateCCAPI extends CCAPI { export class ThermostatFanStateCC extends CommandClass { declare ccCommand: ThermostatFanStateCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -118,7 +121,9 @@ export class ThermostatFanStateCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index a045ae915be5..889785adb564 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -32,6 +32,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -218,7 +219,9 @@ export class ThermostatModeCCAPI extends CCAPI { export class ThermostatModeCC extends CommandClass { declare ccCommand: ThermostatModeCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -272,7 +275,9 @@ export class ThermostatModeCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -431,7 +436,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Update the supported modes if a mode is used that wasn't previously @@ -533,7 +538,7 @@ export class ThermostatModeCCSupportedReport extends ThermostatModeCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Use this information to create the metadata for the mode property diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index e593cbb502c1..5eaeef5dd98f 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -21,6 +21,7 @@ import { throwUnsupportedProperty, } from "../lib/API"; import { + type CCNode, CommandClass, type CommandClassDeserializationOptions, } from "../lib/CommandClass"; @@ -107,7 +108,9 @@ export class ThermostatOperatingStateCCAPI extends PhysicalCCAPI { export class ThermostatOperatingStateCC extends CommandClass { declare ccCommand: ThermostatOperatingStateCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -122,7 +125,9 @@ export class ThermostatOperatingStateCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 29860dee9d43..6aee139733fc 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -26,6 +26,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -149,7 +150,9 @@ export class ThermostatSetbackCCAPI extends CCAPI { export class ThermostatSetbackCC extends CommandClass { declare ccCommand: ThermostatSetbackCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -164,7 +167,9 @@ export class ThermostatSetbackCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 8e2bb4abf6d1..1ea7f07f79b9 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -36,6 +36,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -343,7 +344,9 @@ export class ThermostatSetpointCC extends CommandClass { } } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -562,7 +565,9 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -710,7 +715,7 @@ export class ThermostatSetpointCCReport extends ThermostatSetpointCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const scale = getScale(this.scale); @@ -864,7 +869,7 @@ export class ThermostatSetpointCCCapabilitiesReport } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Predefine the metadata diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index f6b3890413c5..313f515b9a19 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -22,6 +22,7 @@ import { padStart } from "alcalzone-shared/strings"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -191,7 +192,9 @@ export class TimeCCAPI extends CCAPI { export class TimeCC extends CommandClass { declare ccCommand: TimeCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 53f949260652..4dde6937e4d5 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -30,6 +30,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -221,7 +222,9 @@ export class TimeParametersCCAPI extends CCAPI { export class TimeParametersCC extends CommandClass { declare ccCommand: TimeParametersCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -274,7 +277,7 @@ export class TimeParametersCCReport extends TimeParametersCC { ); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { // If necessary, fix the date and time before persisting it const local = shouldUseLocalTime(applHost, this.getEndpoint(applHost)!); if (local) { @@ -353,7 +356,7 @@ export class TimeParametersCCSet extends TimeParametersCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { // We do not actually persist anything here, but we need access to the node // in order to interpret the date segments correctly diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 559ad41bdd99..0a695c9aafc2 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -42,6 +42,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -881,7 +882,9 @@ export class UserCodeCCAPI extends PhysicalCCAPI { export class UserCodeCC extends CommandClass { declare ccCommand: UserCodeCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -944,7 +947,9 @@ export class UserCodeCC extends CommandClass { this.setInterviewComplete(applHost, true); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -1369,7 +1374,7 @@ export class UserCodeCCReport extends UserCodeCC public readonly userIdStatus: UserIDStatus; public readonly userCode: string | Buffer; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; persistUserCode.call( @@ -1745,7 +1750,7 @@ export class UserCodeCCKeypadModeReport extends UserCodeCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; // Update the keypad modes metadata @@ -2025,7 +2030,7 @@ export class UserCodeCCExtendedUserCodeReport extends UserCodeCC { this.nextUserId = this.payload.readUInt16BE(offset); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; for (const { userId, userIdStatus, userCode } of this.userCodes) { diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 6fd9152fce95..e2507f3b6f28 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -25,6 +25,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -420,7 +421,9 @@ export class VersionCC extends CommandClass { return [CommandClasses["Manufacturer Specific"]]; } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; // SDS13782: In a Multi Channel device, the Version Command Class MUST be supported by the Root Device, while diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index a09cd31467a7..de909727c4c5 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -28,6 +28,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -222,7 +223,9 @@ export class WakeUpCCAPI extends CCAPI { export class WakeUpCC extends CommandClass { declare ccCommand: WakeUpCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -463,7 +466,7 @@ export class WakeUpCCIntervalCapabilitiesReport extends WakeUpCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const valueDB = this.getValueDB(applHost); diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 623f494b2088..89bc21460af0 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -33,6 +33,7 @@ import { } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -580,7 +581,9 @@ export class WindowCoveringCCAPI extends CCAPI { export class WindowCoveringCC extends CommandClass { declare ccCommand: WindowCoveringCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index 1716268b7440..2d69fea59d7a 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -15,6 +15,7 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -121,7 +122,9 @@ export class ZWavePlusCCAPI extends PhysicalCCAPI { export class ZWavePlusCC extends CommandClass { declare ccCommand: ZWavePlusCommand; - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( diff --git a/packages/cc/src/cc/ZWaveProtocolCC.ts b/packages/cc/src/cc/ZWaveProtocolCC.ts index 12d48da99957..35517512bb2d 100644 --- a/packages/cc/src/cc/ZWaveProtocolCC.ts +++ b/packages/cc/src/cc/ZWaveProtocolCC.ts @@ -23,6 +23,7 @@ import { import type { ZWaveHost } from "@zwave-js/host"; import { type CCCommandOptions, + type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 01ff2bccef2d..1fdb364fbd63 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -30,6 +30,7 @@ import { } from "../../lib/API"; import { type CCCommandOptions, + type CCNode, type CommandClassDeserializationOptions, gotDeserializationOptions, } from "../../lib/CommandClass"; @@ -89,6 +90,20 @@ export function getFibaroVenetianBlindTiltMetadata(): ValueMetadata { }; } +function getSupportedFibaroCCIDs( + applHost: ZWaveApplicationHost, + nodeId: number, +): FibaroCCIDs[] { + const proprietaryConfig = applHost.getDeviceConfig?.( + nodeId, + )?.proprietary; + if (proprietaryConfig && isArray(proprietaryConfig.fibaroCCs)) { + return proprietaryConfig.fibaroCCs as FibaroCCIDs[]; + } + + return []; +} + export enum FibaroCCIDs { VenetianBlind = 0x26, } @@ -231,26 +246,13 @@ export class FibaroCC extends ManufacturerProprietaryCC { public fibaroCCId?: number; public fibaroCCCommand?: number; - private getSupportedFibaroCCIDs( - applHost: ZWaveApplicationHost, - ): FibaroCCIDs[] { - const node = this.getNode(applHost)!; - - const proprietaryConfig = applHost.getDeviceConfig?.( - node.id, - )?.proprietary; - if (proprietaryConfig && isArray(proprietaryConfig.fibaroCCs)) { - return proprietaryConfig.fibaroCCs as FibaroCCIDs[]; - } - - return []; - } - - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; // Iterate through all supported Fibaro CCs and interview them - const supportedFibaroCCIDs = this.getSupportedFibaroCCIDs(applHost); + const supportedFibaroCCIDs = getSupportedFibaroCCIDs(applHost, node.id); for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { @@ -262,11 +264,13 @@ export class FibaroCC extends ManufacturerProprietaryCC { } } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; // Iterate through all supported Fibaro CCs and let them refresh their values - const supportedFibaroCCIDs = this.getSupportedFibaroCCIDs(applHost); + const supportedFibaroCCIDs = getSupportedFibaroCCIDs(applHost, node.id); for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { @@ -326,7 +330,9 @@ export class FibaroVenetianBlindCC extends FibaroCC { } } - public async interview(applHost: ZWaveApplicationHost): Promise { + public async interview( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -339,7 +345,9 @@ export class FibaroVenetianBlindCC extends FibaroCC { await this.refreshValues(applHost); } - public async refreshValues(applHost: ZWaveApplicationHost): Promise { + public async refreshValues( + applHost: ZWaveApplicationHost, + ): Promise { const node = this.getNode(applHost)!; applHost.controllerLog.logNode(node.id, { @@ -453,7 +461,7 @@ export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; const valueDB = this.getValueDB(applHost); diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index 4ad5ce219b30..0c30f8daa87d 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -7,12 +7,14 @@ import { type GetEndpoint, type IVirtualEndpoint, type IZWaveEndpoint, - type IZWaveNode, + type ListenBehavior, type MaybeNotKnown, NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, NOT_KNOWN, + type NodeId, type PhysicalNodes, + type QueryNodeStatus, type SendCommandOptions, type SupervisionResult, type SupportsCC, @@ -24,7 +26,6 @@ import { ZWaveError, ZWaveErrorCodes, getCCName, - isZWaveError, stripUndefined, } from "@zwave-js/core"; import type { ZWaveApplicationHost } from "@zwave-js/host"; @@ -154,6 +155,9 @@ export interface SchedulePollOptions { transition?: "fast" | "slow"; } +// Defines the necessary traits a node passed to a CC API must have +export type CCAPINode = NodeId & ListenBehavior & QueryNodeStatus; + // Defines the necessary traits an endpoint passed to a CC API must have export type CCAPIEndpoint = & ( @@ -167,6 +171,7 @@ export type CCAPIEndpoint = // physical nodes VirtualEndpointId & { node: PhysicalNodes< + & NodeId & SupportsCC & ControlsCC & GetEndpoint @@ -185,7 +190,7 @@ export type VirtualCCAPIEndpoint = CCAPIEndpoint & VirtualEndpointId; */ export class CCAPI { public constructor( - protected readonly applHost: ZWaveApplicationHost, + protected readonly applHost: ZWaveApplicationHost, protected readonly endpoint: CCAPIEndpoint, ) { this.ccId = getCommandClass(this); @@ -193,7 +198,7 @@ export class CCAPI { public static create( ccId: T, - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, endpoint: CCAPIEndpoint, requireSupport?: boolean, ): CommandClasses extends T ? CCAPI : CCToAPI { @@ -343,7 +348,7 @@ export class CCAPI { const timeoutMs = durationMs + additionalDelay; if (this.isSinglecast()) { - const node = this.getNodeUnsafe(); + const node = this.applHost.getNode(this.endpoint.nodeId); if (!node) return false; return this.applHost.schedulePoll( @@ -576,32 +581,6 @@ export class CCAPI { ); } - /** - * Returns the node this CC API is linked to. Throws if the controller is not yet ready. - */ - public getNode(): IZWaveNode | undefined { - if (this.isSinglecast()) { - return this.applHost.nodes.get(this.endpoint.nodeId); - } - } - - /** - * @internal - * Returns the node this CC API is linked to (or undefined if the node doesn't exist) - */ - public getNodeUnsafe(): IZWaveNode | undefined { - try { - return this.getNode(); - } catch (e) { - // This was expected - if (isZWaveError(e) && e.code === ZWaveErrorCodes.Driver_NotReady) { - return undefined; - } - // Something else happened - throw e; - } - } - /** Returns the value DB for this CC API's node (if it can be safely accessed) */ protected tryGetValueDB(): ValueDB | undefined { if (!this.isSinglecast()) return; @@ -772,7 +751,7 @@ function overrideQueriesWrapper( /** A CC API that is only available for physical endpoints */ export class PhysicalCCAPI extends CCAPI { public constructor( - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, endpoint: CCAPIEndpoint, ) { super(applHost, endpoint); @@ -783,7 +762,7 @@ export class PhysicalCCAPI extends CCAPI { } export type APIConstructor = new ( - applHost: ZWaveApplicationHost, + applHost: ZWaveApplicationHost, endpoint: CCAPIEndpoint, ) => T; diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 2b68a2bad357..3404458f0616 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -1,19 +1,28 @@ import { type BroadcastCC, CommandClasses, + type ControlsCC, EncapsulationFlags, type EndpointId, type FrameType, + type GetAllEndpoints, + type GetCCs, + type GetEndpoint, type ICommandClass, - type IZWaveEndpoint, - type IZWaveNode, + type ListenBehavior, type MessageOrCCLogEntry, type MessageRecord, + type ModifyCCs, type MulticastCC, type MulticastDestination, NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, + type NodeId, + type QueryNodeStatus, + type QuerySecurityClasses, + type SetSecurityClass, type SinglecastCC, + type SupportsCC, type ValueDB, type ValueID, type ValueMetadata, @@ -110,6 +119,27 @@ export type CommandClassOptions = | CommandClassCreationOptions | CommandClassDeserializationOptions; +// Defines the necessary traits an endpoint passed to a CC instance must have +export type CCEndpoint = + & EndpointId + & SupportsCC + & ControlsCC + & GetCCs + & ModifyCCs; + +// Defines the necessary traits a node passed to a CC instance must have +export type CCNode = + & NodeId + & SupportsCC + & ControlsCC + & GetCCs + & GetEndpoint + & GetAllEndpoints + & QuerySecurityClasses + & SetSecurityClass + & ListenBehavior + & QueryNodeStatus; + // @publicAPI export class CommandClass implements ICommandClass { // empty constructor to parse messages @@ -606,9 +636,11 @@ export class CommandClass implements ICommandClass { /** * Returns the node this CC is linked to. Throws if the controller is not yet ready. */ - public getNode(applHost: ZWaveApplicationHost): IZWaveNode | undefined { + public getNode( + applHost: ZWaveApplicationHost, + ): T | undefined { if (this.isSinglecast()) { - return applHost.nodes.get(this.nodeId); + return applHost.getNode(this.nodeId); } } @@ -616,9 +648,9 @@ export class CommandClass implements ICommandClass { * @internal * Returns the node this CC is linked to (or undefined if the node doesn't exist) */ - public getNodeUnsafe( - applHost: ZWaveApplicationHost, - ): IZWaveNode | undefined { + public getNodeUnsafe( + applHost: ZWaveApplicationHost, + ): T | undefined { try { return this.getNode(applHost); } catch (e) { @@ -631,9 +663,9 @@ export class CommandClass implements ICommandClass { } } - public getEndpoint( - applHost: ZWaveApplicationHost, - ): IZWaveEndpoint | undefined { + public getEndpoint( + applHost: ZWaveApplicationHost>, + ): T | undefined { return this.getNode(applHost)?.getEndpoint(this.endpointIndex); } @@ -913,7 +945,7 @@ export class CommandClass implements ICommandClass { * Persists all values for this CC instance into the value DB which are annotated with @ccValue. * Returns `true` if the process succeeded, `false` if the value DB cannot be accessed. */ - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(applHost: ZWaveApplicationHost): boolean { let valueDB: ValueDB; try { valueDB = this.getValueDB(applHost); diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index 20b19dad0344..9fd28a70dc0a 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -1,12 +1,16 @@ import type { AssociationConfig } from "@zwave-js/config"; import { CommandClasses, + type ControlsCC, type EndpointId, - type IZWaveEndpoint, - type IZWaveNode, + type GetAllEndpoints, + type GetEndpoint, + type ListenBehavior, type MaybeNotKnown, NOT_KNOWN, type NodeId, + type QueryNodeStatus, + type QuerySecurityClasses, SecurityClass, type SupportsCC, ZWaveError, @@ -28,6 +32,7 @@ import { AssociationCC, AssociationCCValues } from "../cc/AssociationCC"; import { AssociationGroupInfoCC } from "../cc/AssociationGroupInfoCC"; import { MultiChannelAssociationCC } from "../cc/MultiChannelAssociationCC"; import { CCAPI } from "./API"; +import { type CCNode } from "./CommandClass"; import { type AssociationAddress, AssociationCheckResult, @@ -91,8 +96,7 @@ export function getAssociations( export function getAllAssociations( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - node: IZWaveNode, + node: NodeId & GetAllEndpoints, ): ReadonlyObjectKeyMap< AssociationAddress, ReadonlyMap @@ -114,14 +118,18 @@ export function getAllAssociations( } export function checkAssociation( - applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + applHost: ZWaveApplicationHost< + & NodeId + & SupportsCC + & GetEndpoint + & QuerySecurityClasses + >, + endpoint: EndpointId & SupportsCC & ControlsCC, group: number, destination: AssociationAddress, ): AssociationCheckResult { // Check that the target endpoint exists except when adding an association to the controller - const targetNode = applHost.nodes.getOrThrow(destination.nodeId); + const targetNode = applHost.getNodeOrThrow(destination.nodeId); const targetEndpoint = destination.nodeId === applHost.ownNodeId ? targetNode : targetNode.getEndpointOrThrow(destination.endpoint ?? 0); @@ -165,7 +173,7 @@ export function checkAssociation( // A controlling node MUST NOT associate Node A to a Node B destination // if Node A was not granted Node B’s highest Security Class. - const sourceNode = endpoint.getNodeUnsafe()!; + const sourceNode = applHost.getNode(endpoint.nodeId)!; let securityClassMustMatch: boolean; if (destination.endpoint == undefined) { // "normal" association @@ -344,8 +352,7 @@ export function getAssociationGroups( export function getAllAssociationGroups( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - node: IZWaveNode, + node: NodeId & GetAllEndpoints, ): ReadonlyMap> { const ret = new Map>(); for (const endpoint of node.getAllEndpoints()) { @@ -357,9 +364,8 @@ export function getAllAssociationGroups( } export async function addAssociations( - applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + applHost: ZWaveApplicationHost, + endpoint: EndpointId & SupportsCC & ControlsCC, group: number, destinations: AssociationAddress[], ): Promise { @@ -528,9 +534,8 @@ export async function addAssociations( } export async function removeAssociations( - applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + applHost: ZWaveApplicationHost, + endpoint: EndpointId & SupportsCC & ControlsCC, group: number, destinations: AssociationAddress[], ): Promise { @@ -680,12 +685,19 @@ export function getLifelineGroupIds( } export async function configureLifelineAssociations( - applHost: ZWaveApplicationHost, - endpoint: IZWaveEndpoint, + applHost: ZWaveApplicationHost< + & NodeId + & SupportsCC + & ControlsCC + & ListenBehavior + & QueryNodeStatus + & GetAllEndpoints + >, + endpoint: EndpointId & SupportsCC & ControlsCC, ): Promise { // Assign the controller to all lifeline groups const ownNodeId = applHost.ownNodeId; - const node = endpoint.getNodeUnsafe()!; + const node = applHost.getNodeOrThrow(endpoint.nodeId); const valueDB = applHost.getValueDB(node.id); const deviceConfig = applHost.getDeviceConfig?.(node.id); @@ -1193,13 +1205,12 @@ must use node association: ${rootMustUseNodeAssociation}`, } export async function assignLifelineIssueingCommand( - applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and node+endpoint capabilities would be enough - endpoint: IZWaveEndpoint, + applHost: ZWaveApplicationHost, + endpoint: EndpointId, ccId: CommandClasses, ccCommand: number, ): Promise { - const node = endpoint.getNodeUnsafe()!; + const node = applHost.getNodeOrThrow(endpoint.nodeId); if ( node.supportsCC(CommandClasses["Association Group Information"]) && (node.supportsCC(CommandClasses.Association) diff --git a/packages/core/src/abstractions/IZWaveEndpoint.ts b/packages/core/src/abstractions/IZWaveEndpoint.ts index cb9ca6e3bf92..8b3db82cbed2 100644 --- a/packages/core/src/abstractions/IZWaveEndpoint.ts +++ b/packages/core/src/abstractions/IZWaveEndpoint.ts @@ -28,6 +28,11 @@ export interface IsCCSecure { isCCSecure(cc: CommandClasses): boolean; } +/** Allows querying all implemented CCs and their information */ +export interface GetCCs { + getCCs(): Iterable<[ccId: CommandClasses, info: CommandClassInfo]>; +} + /** Allows modifying the list of supported/controlled CCs */ export interface ModifyCCs { addCC(cc: CommandClasses, info: Partial): void; @@ -36,9 +41,8 @@ export interface ModifyCCs { /** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ export interface IZWaveEndpoint - extends EndpointId, SupportsCC, ControlsCC, IsCCSecure, ModifyCCs + extends EndpointId, SupportsCC, ControlsCC, IsCCSecure, ModifyCCs, GetCCs { - getCCs(): Iterable<[ccId: CommandClasses, info: CommandClassInfo]>; getNodeUnsafe(): IZWaveNode | undefined; } @@ -53,10 +57,3 @@ export interface VirtualEndpointId { export interface IVirtualEndpoint extends VirtualEndpointId, SupportsCC { readonly node: IVirtualNode; } - -// TODO: Use cases in CCAPI implementations: -// - EndpointId or VirtualEndpointId -// - SupportsCC -// - VirtualEndpoint: -// - physical nodes -> NodeId -// - physical nodes -> Endpoint -> SupportsCC,ControlsCC diff --git a/packages/core/src/abstractions/IZWaveNode.ts b/packages/core/src/abstractions/IZWaveNode.ts index 1684a448936b..70c393ab18c5 100644 --- a/packages/core/src/abstractions/IZWaveNode.ts +++ b/packages/core/src/abstractions/IZWaveNode.ts @@ -1,6 +1,9 @@ import type { FLiRS } from "../capabilities/NodeInfo"; import type { InterviewStage, NodeStatus } from "../consts"; -import type { SecurityClassOwner } from "../security/SecurityClass"; +import type { + QuerySecurityClasses, + SetSecurityClass, +} from "../security/SecurityClass"; import { type MaybeNotKnown } from "../values/Primitive"; import type { EndpointId, @@ -9,42 +12,66 @@ import type { VirtualEndpointId, } from "./IZWaveEndpoint"; +/** Identifies a node */ export interface NodeId extends EndpointId { readonly id: number; - // FIXME: GH#7261 this should have type 0 - readonly index: number; + // // FIXME: GH#7261 this should have type 0 + // readonly index: number; } +/** Allows accessing a specific endpoint */ export interface GetEndpoint { getEndpoint(index: 0): T; getEndpoint(index: number): T | undefined; getEndpointOrThrow(index: number): T; } +/** Allows accessing all endpoints */ +export interface GetAllEndpoints { + getAllEndpoints(): T[]; +} + +/** Allows querying whether a node is a listening, FLiRS or sleeping device */ +export interface ListenBehavior { + /** Whether this node is always listening or not */ + readonly isListening: MaybeNotKnown; + + /** Indicates the wakeup interval if this node is a FLiRS node. `false` if it isn't. */ + readonly isFrequentListening: MaybeNotKnown; + + /** Whether this node can sleep */ + readonly canSleep: MaybeNotKnown; +} + +/** Allows querying whether a node's status */ +export interface QueryNodeStatus { + /** + * Which status the node is believed to be in + */ + readonly status: NodeStatus; +} + /** A basic abstraction of a Z-Wave node providing access to the relevant functionality */ export interface IZWaveNode extends IZWaveEndpoint, NodeId, + ListenBehavior, + QueryNodeStatus, GetEndpoint, - SecurityClassOwner + GetAllEndpoints, + QuerySecurityClasses, + SetSecurityClass { - isListening: MaybeNotKnown; - isFrequentListening: MaybeNotKnown; - readonly canSleep: MaybeNotKnown; - readonly status: NodeStatus; interviewStage: InterviewStage; - - getAllEndpoints(): IZWaveEndpoint[]; - readonly isSecure: MaybeNotKnown; } export interface VirtualNodeId extends VirtualEndpointId { readonly id: number | undefined; } -export interface PhysicalNodes { - readonly physicalNodes: readonly (NodeId & T)[]; +export interface PhysicalNodes { + readonly physicalNodes: readonly T[]; } /** A basic abstraction of a virtual node (multicast or broadcast) providing access to the relevant functionality */ diff --git a/packages/core/src/security/SecurityClass.ts b/packages/core/src/security/SecurityClass.ts index ed06e521a877..cc4e46795593 100644 --- a/packages/core/src/security/SecurityClass.ts +++ b/packages/core/src/security/SecurityClass.ts @@ -50,10 +50,20 @@ export const securityClassOrder = [ SecurityClass.S0_Legacy, ] as const; -export interface SecurityClassOwner { - readonly id: number; - getHighestSecurityClass(): MaybeNotKnown; +/** Allows querying the security classes of a node */ +export interface QuerySecurityClasses { + /** Whether the node was granted at least one security class */ + readonly isSecure: MaybeNotKnown; + + /** Returns whether a node was granted the given security class */ hasSecurityClass(securityClass: SecurityClass): MaybeNotKnown; + + /** Returns the highest security class this node was granted or `undefined` if that information isn't known yet */ + getHighestSecurityClass(): MaybeNotKnown; +} + +/** Allows modifying the security classes of a node */ +export interface SetSecurityClass { setSecurityClass(securityClass: SecurityClass, granted: boolean): void; } diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 23de183ef77e..2b7687ef4cdd 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -3,9 +3,9 @@ import type { CommandClasses, ControllerLogger, ICommandClass, - IZWaveNode, MaybeNotKnown, NodeIDType, + NodeId, SecurityClass, SecurityManager, SecurityManager2, @@ -14,7 +14,6 @@ import type { ValueDB, ValueID, } from "@zwave-js/core"; -import type { ReadonlyThrowingMap } from "@zwave-js/shared"; import type { ZWaveHostOptions } from "./ZWaveHostOptions"; /** Host application abstractions to be used in Serial API and CC implementations */ @@ -102,8 +101,21 @@ export interface ZWaveValueHost { tryGetValueDB(nodeId: number): ValueDB | undefined; } +/** Allows accessing a specific node */ +export interface GetNode { + getNode(nodeId: number): T | undefined; + getNodeOrThrow(nodeId: number): T; +} + +/** Allows accessing all nodes */ +export interface GetAllNodes { + getAllNodes(): T[]; +} + /** A more featureful version of the ZWaveHost interface, which is meant to be used on the controller application side. */ -export interface ZWaveApplicationHost extends ZWaveValueHost, ZWaveHost { +export interface ZWaveApplicationHost + extends ZWaveValueHost, ZWaveHost, GetNode, GetAllNodes +{ /** Gives access to the configuration files */ configManager: ConfigManager; @@ -112,9 +124,6 @@ export interface ZWaveApplicationHost extends ZWaveValueHost, ZWaveHost { // TODO: There's probably a better fitting name for this now controllerLog: ControllerLogger; - /** Readonly access to all node instances known to the host */ - nodes: ReadonlyThrowingMap; - /** Whether the node with the given ID is the controller */ isControllerNode(nodeId: number): boolean; diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index ca42be0f4850..bb618b237c6a 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -8,12 +8,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import { - type ThrowingMap, - createThrowingMap, - createWrappingCounter, -} from "@zwave-js/shared"; -import type { Overwrite } from "alcalzone-shared/types"; +import { createThrowingMap, createWrappingCounter } from "@zwave-js/shared"; import type { ZWaveApplicationHost, ZWaveHost } from "./ZWaveHost"; export interface CreateTestingHostOptions { @@ -23,9 +18,9 @@ export interface CreateTestingHostOptions { getSupportedCCVersion?: ZWaveHost["getSupportedCCVersion"]; } -export type TestingHost = Overwrite< - Omit, - { nodes: ThrowingMap } +export type TestingHost = Omit< + ZWaveApplicationHost, + "__internalIsMockNode" >; /** Creates a {@link ZWaveApplicationHost} that can be used for testing */ @@ -36,6 +31,12 @@ export function createTestingHost( const metadataStorage = new Map(); const valueDBCache = new Map(); const supervisionSessionIDs = new Map number>(); + const nodes = createThrowingMap((nodeId) => { + throw new ZWaveError( + `Node ${nodeId} was not found!`, + ZWaveErrorCodes.Controller_NodeNotFound, + ); + }); const ret: TestingHost = { homeId: options.homeId ?? 0x7e570001, @@ -66,12 +67,15 @@ export function createTestingHost( refreshValueAfterTransition: 1000, }, }, - nodes: createThrowingMap((nodeId) => { - throw new ZWaveError( - `Node ${nodeId} was not found!`, - ZWaveErrorCodes.Controller_NodeNotFound, - ); - }), + getNode(nodeId: number) { + return nodes.get(nodeId); + }, + getNodeOrThrow(nodeId: number) { + return nodes.getOrThrow(nodeId); + }, + getAllNodes() { + return [...nodes.values()]; + }, getSafeCCVersion: options.getSafeCCVersion ?? (() => 100), getSupportedCCVersion: options.getSupportedCCVersion ?? options.getSafeCCVersion @@ -103,7 +107,7 @@ export function createTestingHost( return ret.getValueDB(nodeId); }, isCCSecure: (ccId, nodeId, endpointIndex = 0) => { - const node = ret.nodes.get(nodeId); + const node = nodes.get(nodeId); const endpoint = node?.getEndpoint(endpointIndex); return ( node?.isSecure !== false @@ -112,15 +116,15 @@ export function createTestingHost( ); }, getHighestSecurityClass: (nodeId) => { - const node = ret.nodes.getOrThrow(nodeId); + const node = nodes.getOrThrow(nodeId); return node.getHighestSecurityClass(); }, hasSecurityClass: (nodeId, securityClass) => { - const node = ret.nodes.getOrThrow(nodeId); + const node = nodes.getOrThrow(nodeId); return node.hasSecurityClass(securityClass); }, setSecurityClass: (nodeId, securityClass, granted) => { - const node = ret.nodes.getOrThrow(nodeId); + const node = nodes.getOrThrow(nodeId); node.setSecurityClass(securityClass, granted); }, sendCommand: async (_command, _options) => { diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 1937cfbb78ce..f5e76b4ea85b 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -1,7 +1,7 @@ import { - type IZWaveNode, type MessageOrCCLogEntry, type MessagePriority, + type NodeId, ZWaveError, ZWaveErrorCodes, createReflectionDecorator, @@ -410,11 +410,11 @@ export class Message { /** * Returns the node this message is linked to or undefined */ - public getNodeUnsafe( - applHost: ZWaveApplicationHost, - ): IZWaveNode | undefined { + public getNodeUnsafe( + applHost: ZWaveApplicationHost, + ): T | undefined { const nodeId = this.getNodeId(); - if (nodeId != undefined) return applHost.nodes.get(nodeId); + if (nodeId != undefined) return applHost.getNode(nodeId); } private _transmissionTimestamp: number | undefined; diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 03d3a5cd3322..68a6af4a1502 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -134,7 +134,6 @@ import { } from "@zwave-js/serial"; import { AsyncQueue, - type ReadonlyThrowingMap, type ThrowingMap, TypedEventEmitter, buffer2hex, @@ -593,7 +592,7 @@ export type DriverEvents = Extract; * instance or its associated nodes. */ export class Driver extends TypedEventEmitter - implements ZWaveApplicationHost + implements ZWaveApplicationHost { public constructor( private port: string | ZWaveSerialPortImplementation, @@ -928,14 +927,19 @@ export class Driver extends TypedEventEmitter return this._controller?.nodeIdType ?? NodeIDType.Short; } - /** - * **!!! INTERNAL !!!** - * - * Not intended to be used by applications. Use `controller.nodes` instead! - */ - public get nodes(): ReadonlyThrowingMap { - // This is needed for the ZWaveHost interface - return this.controller.nodes; + /** @internal Used for compatibility with the ZWaveApplicationHost interface */ + public getNode(nodeId: number): ZWaveNode | undefined { + return this.controller.nodes.get(nodeId); + } + + /** @internal Used for compatibility with the ZWaveApplicationHost interface */ + public getNodeOrThrow(nodeId: number): ZWaveNode { + return this.controller.nodes.getOrThrow(nodeId); + } + + /** @internal Used for compatibility with the ZWaveApplicationHost interface */ + public getAllNodes(): ZWaveNode[] { + return [...this.controller.nodes.values()]; } public getNodeUnsafe(msg: Message): ZWaveNode | undefined { diff --git a/packages/zwave-js/src/lib/node/Endpoint.ts b/packages/zwave-js/src/lib/node/Endpoint.ts index 3786f49f3fea..17d58d8d27a1 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.ts @@ -10,7 +10,16 @@ import { normalizeCCNameOrId, } from "@zwave-js/cc"; import { ZWavePlusCCValues } from "@zwave-js/cc/ZWavePlusCC"; -import type { EndpointId, IZWaveEndpoint, MaybeNotKnown } from "@zwave-js/core"; +import type { + ControlsCC, + EndpointId, + GetCCs, + IZWaveEndpoint, + IsCCSecure, + MaybeNotKnown, + ModifyCCs, + SupportsCC, +} from "@zwave-js/core"; import { BasicDeviceClass, CacheBackedMap, @@ -36,7 +45,16 @@ import type { ZWaveNode } from "./Node"; * * Each endpoint may have different capabilities (device class/supported CCs) */ -export class Endpoint implements EndpointId, IZWaveEndpoint { +export class Endpoint + implements + EndpointId, + SupportsCC, + ControlsCC, + IsCCSecure, + ModifyCCs, + GetCCs, + IZWaveEndpoint +{ public constructor( /** The id of the node this endpoint belongs to */ public readonly nodeId: number, diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index a62197d3e4f5..cd5720dc7921 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -154,10 +154,10 @@ import { type NotificationState, ProtocolVersion, Protocols, + type QuerySecurityClasses, type RSSI, RssiError, SecurityClass, - type SecurityClassOwner, type SendCommandOptions, type SetValueOptions, type SinglecastCC, @@ -287,7 +287,7 @@ export interface ZWaveNode */ @Mixin([EventEmitter, NodeStatisticsHost]) export class ZWaveNode extends ZWaveNodeMixins - implements SecurityClassOwner, IZWaveNode + implements QuerySecurityClasses, IZWaveNode { public constructor( id: number, diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts index 079544b76f75..ebab4497a7d2 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts @@ -13,6 +13,8 @@ import { type IVirtualEndpoint, type MulticastDestination, type SecurityClass, + type SupportsCC, + type VirtualEndpointId, ZWaveError, ZWaveErrorCodes, getCCName, @@ -30,7 +32,9 @@ import { VirtualNode } from "./VirtualNode"; * * The endpoint's capabilities are determined by the capabilities of the individual nodes' endpoints. */ -export class VirtualEndpoint implements IVirtualEndpoint { +export class VirtualEndpoint + implements VirtualEndpointId, SupportsCC, IVirtualEndpoint +{ public constructor( /** The virtual node this endpoint belongs to (or undefined if it set later) */ node: VirtualNode | undefined, diff --git a/packages/zwave-js/src/lib/node/mixins/00_Base.ts b/packages/zwave-js/src/lib/node/mixins/00_Base.ts index f6c176a25530..fd114f1fd1c2 100644 --- a/packages/zwave-js/src/lib/node/mixins/00_Base.ts +++ b/packages/zwave-js/src/lib/node/mixins/00_Base.ts @@ -1,6 +1,7 @@ +import { type NodeId } from "@zwave-js/core/safe"; import { Endpoint } from "../Endpoint"; -export abstract class ZWaveNodeBase extends Endpoint { +export abstract class ZWaveNodeBase extends Endpoint implements NodeId { /** * Whether the node should be kept awake when there are no pending messages. */ diff --git a/packages/zwave-js/src/lib/node/mixins/05_Security.ts b/packages/zwave-js/src/lib/node/mixins/05_Security.ts index c576bde42707..326dc757449d 100644 --- a/packages/zwave-js/src/lib/node/mixins/05_Security.ts +++ b/packages/zwave-js/src/lib/node/mixins/05_Security.ts @@ -3,7 +3,9 @@ import { type CommandClasses, type MaybeNotKnown, NOT_KNOWN, + type QuerySecurityClasses, SecurityClass, + type SetSecurityClass, securityClassOrder, } from "@zwave-js/core"; import { getEnumMemberName } from "@zwave-js/shared"; @@ -12,20 +14,8 @@ import { cacheKeys } from "../../driver/NetworkCache"; import { type DeviceClass } from "../DeviceClass"; import { NetworkRoleMixin } from "./01_NetworkRole"; -export interface NodeSecurity { - /** Whether the node was granted at least one security class */ - readonly isSecure: MaybeNotKnown; - - hasSecurityClass(securityClass: SecurityClass): MaybeNotKnown; - - setSecurityClass(securityClass: SecurityClass, granted: boolean): void; - - /** Returns the highest security class this node was granted or `undefined` if that information isn't known yet */ - getHighestSecurityClass(): MaybeNotKnown; -} - export abstract class NodeSecurityMixin extends NetworkRoleMixin - implements NodeSecurity + implements QuerySecurityClasses, SetSecurityClass { public constructor( nodeId: number, diff --git a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts index b31a2b5e7e9b..0e29fe4716b4 100644 --- a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts +++ b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts @@ -1,6 +1,8 @@ import { MultiChannelCCValues } from "@zwave-js/cc"; import { type CommandClasses, + type GetAllEndpoints, + type GetEndpoint, type IZWaveNode, type MaybeNotKnown, ZWaveError, @@ -40,7 +42,11 @@ export interface Endpoints { } export abstract class EndpointsMixin extends NodeValuesMixin - implements Endpoints, IZWaveNode + implements + Endpoints, + GetEndpoint, + GetAllEndpoints, + IZWaveNode { public get endpointCountIsDynamic(): MaybeNotKnown { return nodeUtils.endpointCountIsDynamic(this.driver, this.id); @@ -177,6 +183,6 @@ export abstract class EndpointsMixin extends NodeValuesMixin /** Returns a list of all endpoints of this node, including the root endpoint (index 0) */ public getAllEndpoints(): Endpoint[] { // FIXME: GH#7261 we should not need to cast here - return nodeUtils.getAllEndpoints(this.driver, this) as Endpoint[]; + return nodeUtils.getAllEndpoints(this.driver, this); } } diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index 4f62334719c0..6c8e14e56443 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -2,11 +2,13 @@ import { CommandClass } from "@zwave-js/cc"; import { MultiChannelCCValues } from "@zwave-js/cc/MultiChannelCC"; import { CommandClasses, + type ControlsCC, type EndpointId, - type IZWaveEndpoint, - type IZWaveNode, + type GetEndpoint, type MaybeNotKnown, + type NodeId, type SetValueOptions, + type SupportsCC, type TranslatedValueID, type ValueID, ZWaveError, @@ -175,16 +177,15 @@ export function setMultiChannelInterviewComplete( ); } -export function getAllEndpoints( +export function getAllEndpoints( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - node: IZWaveNode, -): IZWaveEndpoint[] { - const ret: IZWaveEndpoint[] = [node]; + node: T & GetEndpoint, +): T[] { + const ret: T[] = [node]; // Check if the Multi Channel CC interview for this node is completed, // because we don't have all the endpoint information before that - if (isMultiChannelInterviewComplete(applHost, node.id)) { - for (const i of getEndpointIndizes(applHost, node.id)) { + if (isMultiChannelInterviewComplete(applHost, node.nodeId)) { + for (const i of getEndpointIndizes(applHost, node.nodeId)) { const endpoint = node.getEndpoint(i); if (endpoint) ret.push(endpoint); } @@ -304,8 +305,11 @@ export function filterRootApplicationCCValueIDs( /** Returns a list of all value names that are defined on all endpoints of this node */ export function getDefinedValueIDs( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - node: IZWaveNode, + node: + & NodeId + & SupportsCC + & ControlsCC + & GetEndpoint, ): TranslatedValueID[] { return getDefinedValueIDsInternal(applHost, node, false); } @@ -316,8 +320,11 @@ export function getDefinedValueIDs( */ export function getDefinedValueIDsInternal( applHost: ZWaveApplicationHost, - // FIXME: GH#7261 ID and endpoint capabilities would be enough - node: IZWaveNode, + node: + & NodeId + & SupportsCC + & ControlsCC + & GetEndpoint, includeInternal: boolean = false, ): TranslatedValueID[] { // The controller has no values. Even if some ended up in the cache somehow, do not return any. @@ -327,7 +334,12 @@ export function getDefinedValueIDsInternal( const allowControlled: CommandClasses[] = [ CommandClasses["Scene Activation"], ]; - for (const endpoint of getAllEndpoints(applHost, node)) { + for ( + const endpoint of getAllEndpoints( + applHost, + node, + ) + ) { for (const cc of allCCs) { if ( // Create values only for supported CCs diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts index 945b465b893a..f6f819e360cf 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts @@ -1,15 +1,17 @@ import { type BasicDeviceClass, type CommandClasses, + type ListenBehavior, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type NodeId, NodeType, Protocols, parseNodeID, parseNodeUpdatePayload, } from "@zwave-js/core"; -import type { ZWaveApplicationHost, ZWaveHost } from "@zwave-js/host"; +import type { GetAllNodes, ZWaveHost } from "@zwave-js/host"; import type { SuccessIndicator } from "@zwave-js/serial"; import { FunctionType, @@ -68,10 +70,10 @@ interface AddNodeDSKToNetworkRequestOptions extends MessageBaseOptions { } export function computeNeighborDiscoveryTimeout( - host: ZWaveApplicationHost, + host: GetAllNodes, nodeType: NodeType, ): number { - const allNodes = [...host.nodes.values()]; + const allNodes = [...host.getAllNodes()]; const numListeningNodes = allNodes.filter((n) => n.isListening).length; const numFlirsNodes = allNodes.filter((n) => n.isFrequentListening).length; const numNodes = allNodes.length; From 9b94e88f45d1be735c5f0ba53412501496821c77 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Fri, 11 Oct 2024 13:31:10 +0200 Subject: [PATCH 11/60] refactor: autosave :D --- ZWaveHost properties.txt | 16 +++ packages/cc/src/cc/AlarmSensorCC.ts | 5 +- packages/cc/src/cc/AssociationCC.ts | 25 ++-- packages/cc/src/cc/AssociationGroupInfoCC.ts | 25 ++-- packages/cc/src/cc/BarrierOperatorCC.ts | 13 ++- packages/cc/src/cc/BasicCC.ts | 9 +- packages/cc/src/cc/BatteryCC.ts | 5 +- packages/cc/src/cc/BinarySensorCC.ts | 13 ++- packages/cc/src/cc/BinarySwitchCC.ts | 9 +- packages/cc/src/cc/CRC16CC.ts | 10 +- packages/cc/src/cc/CentralSceneCC.ts | 5 +- .../cc/src/cc/ClimateControlScheduleCC.ts | 14 +-- packages/cc/src/cc/ClockCC.ts | 5 +- packages/cc/src/cc/ColorSwitchCC.ts | 30 ++--- packages/cc/src/cc/ConfigurationCC.ts | 45 +++---- packages/cc/src/cc/DoorLockCC.ts | 9 +- packages/cc/src/cc/DoorLockLoggingCC.ts | 5 +- packages/cc/src/cc/EnergyProductionCC.ts | 13 ++- packages/cc/src/cc/EntryControlCC.ts | 5 +- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 21 ++-- packages/cc/src/cc/HumidityControlModeCC.ts | 5 +- .../cc/src/cc/HumidityControlSetpointCC.ts | 17 +-- packages/cc/src/cc/InclusionControllerCC.ts | 14 ++- packages/cc/src/cc/IndicatorCC.ts | 29 ++--- packages/cc/src/cc/IrrigationCC.ts | 37 +++--- packages/cc/src/cc/LanguageCC.ts | 5 +- packages/cc/src/cc/LockCC.ts | 5 +- .../cc/src/cc/ManufacturerProprietaryCC.ts | 5 +- packages/cc/src/cc/ManufacturerSpecificCC.ts | 13 ++- packages/cc/src/cc/MeterCC.ts | 17 +-- .../cc/src/cc/MultiChannelAssociationCC.ts | 21 ++-- packages/cc/src/cc/MultiChannelCC.ts | 45 +++---- packages/cc/src/cc/MultiCommandCC.ts | 12 +- packages/cc/src/cc/MultilevelSensorCC.ts | 21 ++-- packages/cc/src/cc/MultilevelSwitchCC.ts | 13 ++- packages/cc/src/cc/NodeNamingCC.ts | 9 +- packages/cc/src/cc/NotificationCC.ts | 27 +++-- packages/cc/src/cc/PowerlevelCC.ts | 17 +-- packages/cc/src/cc/ProtectionCC.ts | 13 ++- packages/cc/src/cc/SceneActivationCC.ts | 6 +- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 9 +- .../src/cc/SceneControllerConfigurationCC.ts | 9 +- packages/cc/src/cc/ScheduleEntryLockCC.ts | 62 +++++----- packages/cc/src/cc/Security2CC.ts | 77 ++++++------ packages/cc/src/cc/SecurityCC.ts | 38 +++--- packages/cc/src/cc/SoundSwitchCC.ts | 25 ++-- packages/cc/src/cc/SupervisionCC.ts | 17 ++- packages/cc/src/cc/ThermostatFanModeCC.ts | 5 +- packages/cc/src/cc/ThermostatModeCC.ts | 13 ++- packages/cc/src/cc/ThermostatSetbackCC.ts | 11 +- packages/cc/src/cc/ThermostatSetpointCC.ts | 25 ++-- packages/cc/src/cc/TimeCC.ts | 21 ++-- packages/cc/src/cc/TimeParametersCC.ts | 5 +- packages/cc/src/cc/TransportServiceCC.ts | 24 ++-- packages/cc/src/cc/UserCodeCC.ts | 49 ++++---- packages/cc/src/cc/VersionCC.ts | 17 +-- packages/cc/src/cc/WakeUpCC.ts | 5 +- packages/cc/src/cc/WindowCoveringCC.ts | 25 ++-- packages/cc/src/cc/ZWavePlusCC.ts | 5 +- packages/cc/src/cc/ZWaveProtocolCC.ts | 110 +++++++++--------- .../cc/manufacturerProprietary/FibaroCC.ts | 9 +- packages/cc/src/lib/CommandClass.ts | 12 +- .../core/src/abstractions/ICommandClass.ts | 44 ++++++- packages/host/src/ZWaveHost.ts | 60 +++++----- packages/host/src/mocks.ts | 80 +++++++------ packages/serial/src/message/Message.test.ts | 26 +++-- packages/serial/src/message/Message.ts | 37 +++++- packages/testing/src/MockController.ts | 70 ++++++++--- packages/testing/src/MockNode.ts | 80 ++++++------- packages/testing/src/MockZWaveFrame.ts | 8 +- .../Controller.manageAssociations.test.ts | 4 +- .../lib/controller/MockControllerBehaviors.ts | 63 +++++----- packages/zwave-js/src/lib/driver/Driver.ts | 46 +++++++- .../src/lib/driver/MessageGenerators.ts | 61 +++++++--- .../src/lib/driver/SerialAPICommandMachine.ts | 5 +- .../application/ApplicationCommandRequest.ts | 13 ++- .../application/ApplicationUpdateRequest.ts | 9 +- .../BridgeApplicationCommandRequest.test.ts | 1 + .../BridgeApplicationCommandRequest.ts | 6 +- .../application/SerialAPIStartedRequest.ts | 5 +- .../GetControllerCapabilitiesMessages.ts | 5 +- .../GetControllerVersionMessages.ts | 5 +- .../capability/GetLongRangeNodesMessages.ts | 9 +- .../GetSerialApiCapabilitiesMessages.ts | 5 +- .../GetSerialApiInitDataMessages.ts | 5 +- .../serialapi/capability/HardResetRequest.ts | 5 +- .../capability/LongRangeChannelMessages.ts | 5 +- .../capability/SerialAPISetupMessages.test.ts | 12 +- .../capability/SerialAPISetupMessages.ts | 33 +++--- .../SetApplicationNodeInformationRequest.ts | 5 +- .../SetLongRangeShadowNodeIDsRequest.ts | 5 +- .../memory/GetControllerIdMessages.ts | 5 +- .../misc/SetRFReceiveModeMessages.ts | 9 +- .../misc/SetSerialApiTimeoutsMessages.ts | 5 +- .../network-mgmt/AddNodeToNetworkRequest.ts | 17 +-- .../AssignPriorityReturnRouteMessages.ts | 5 +- .../AssignPrioritySUCReturnRouteMessages.ts | 5 +- .../network-mgmt/AssignReturnRouteMessages.ts | 10 +- .../AssignSUCReturnRouteMessages.ts | 13 ++- .../network-mgmt/DeleteReturnRouteMessages.ts | 10 +- .../DeleteSUCReturnRouteMessages.ts | 18 +-- .../GetNodeProtocolInfoMessages.ts | 9 +- .../network-mgmt/GetPriorityRouteMessages.ts | 5 +- .../network-mgmt/GetRoutingInfoMessages.ts | 5 +- .../network-mgmt/GetSUCNodeIdMessages.ts | 5 +- .../network-mgmt/IsFailedNodeMessages.ts | 5 +- .../network-mgmt/RemoveFailedNodeMessages.ts | 9 +- .../RemoveNodeFromNetworkRequest.ts | 9 +- .../network-mgmt/ReplaceFailedNodeRequest.ts | 9 +- .../network-mgmt/RequestNodeInfoMessages.ts | 9 +- .../RequestNodeNeighborUpdateMessages.ts | 10 +- .../network-mgmt/SetLearnModeMessages.ts | 5 +- .../network-mgmt/SetPriorityRouteMessages.ts | 5 +- .../network-mgmt/SetSUCNodeIDMessages.ts | 9 +- .../nvm/ExtNVMReadLongBufferMessages.ts | 5 +- .../nvm/ExtNVMReadLongByteMessages.ts | 5 +- .../nvm/ExtNVMWriteLongBufferMessages.ts | 5 +- .../nvm/ExtNVMWriteLongByteMessages.ts | 5 +- .../nvm/ExtendedNVMOperationsMessages.ts | 17 +-- .../nvm/FirmwareUpdateNVMMessages.ts | 17 +-- .../serialapi/nvm/NVMOperationsMessages.ts | 15 +-- .../transport/SendDataBridgeMessages.ts | 26 +++-- .../serialapi/transport/SendDataMessages.ts | 48 +++++--- .../transport/SendTestFrameMessages.ts | 5 +- .../zwave-js/src/lib/test/cc/BasicCC.test.ts | 2 +- .../cc/SceneControllerConfigurationCC.test.ts | 2 +- .../invalidCallbackFunctionTypes.test.ts | 8 +- .../lib/test/driver/controllerJammed.test.ts | 12 +- .../driver/sendDataAbortAfterTimeout.test.ts | 8 +- .../sendDataMissingCallbackAbort.test.ts | 16 +-- .../driver/sendDataMissingResponse.test.ts | 6 +- packages/zwave-js/src/lib/test/mocks.ts | 14 +-- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 32 +++++ 133 files changed, 1376 insertions(+), 961 deletions(-) create mode 100644 ZWaveHost properties.txt diff --git a/ZWaveHost properties.txt b/ZWaveHost properties.txt new file mode 100644 index 000000000000..22d51fa65bc9 --- /dev/null +++ b/ZWaveHost properties.txt @@ -0,0 +1,16 @@ +ZWaveHost, properties used: + +getDeviceConfig +ownNodeId +homeId +nodeIdType +securityManager +__internalIsMockNode +getSafeCCVersion +getSupportedCCVersion +isCCSecure + +getNextCallbackId -> how did zwave-rs do this? + +for a specific node: getHighestSecurityClass, hasSecurityClass, setSecurityClass --> GetNode<...> ? +for a specific endpoint: isCCSecure ? diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index f4cbdf1b6d51..882cae2b90d8 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -421,9 +422,9 @@ export class AlarmSensorCCGet extends AlarmSensorCC { public sensorType: AlarmSensorType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sensorType]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 8720af022624..d562a8353434 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -5,6 +5,7 @@ import type { SupervisionResult, } from "@zwave-js/core/safe"; import { + type CCEncodingContext, CommandClasses, MAX_NODES, type MessageOrCCLogEntry, @@ -520,9 +521,9 @@ export class AssociationCCSet extends AssociationCC { public groupId: number; public nodeIds: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupId, ...this.nodeIds]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -590,12 +591,12 @@ export class AssociationCCRemove extends AssociationCC { public groupId?: number; public nodeIds?: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.groupId || 0, ...(this.nodeIds || []), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -679,14 +680,14 @@ export class AssociationCCReport extends AssociationCC { .reduce((prev, cur) => prev.concat(...cur), []); } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.groupId, this.maxNodes, this.reportsToFollow, ...this.nodeIds, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -731,9 +732,9 @@ export class AssociationCCGet extends AssociationCC { public groupId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -772,9 +773,9 @@ export class AssociationCCSupportedGroupingsReport extends AssociationCC { @ccValue(AssociationCCValues.groupCount) public groupCount: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupCount]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -814,9 +815,9 @@ export class AssociationCCSpecificGroupReport extends AssociationCC { public group: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.group]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index f4d23b575e84..bf51e322b7b0 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -513,12 +514,12 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.groupId, this.name.length]), Buffer.from(this.name, "utf8"), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -557,9 +558,9 @@ export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC { public groupId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -649,7 +650,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.alloc(1 + this.groups.length * 7, 0); this.payload[0] = (this.isListMode ? 0b1000_0000 : 0) @@ -663,7 +664,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { // The remaining bytes are zero } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -732,7 +733,7 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC { public listMode?: boolean; public groupId?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const isListMode = this.listMode === true; const optionByte = (this.refreshCache ? 0b1000_0000 : 0) | (isListMode ? 0b0100_0000 : 0); @@ -740,7 +741,7 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC { optionByte, isListMode ? 0 : this.groupId!, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -812,7 +813,7 @@ export class AssociationGroupInfoCCCommandListReport ) public readonly commands: ReadonlyMap; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // To make it easier to encode possible extended CCs, we first // allocate as much space as we may need, then trim it again this.payload = Buffer.allocUnsafe(2 + this.commands.size * 3); @@ -827,7 +828,7 @@ export class AssociationGroupInfoCCCommandListReport } this.payload[1] = offset - 2; // list length - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -884,12 +885,12 @@ export class AssociationGroupInfoCCCommandListGet public allowCache: boolean; public groupId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.allowCache ? 0b1000_0000 : 0, this.groupId, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 5ceb87941903..7460357c2ab4 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MaybeUnknown, @@ -569,9 +570,9 @@ export class BarrierOperatorCCSet extends BarrierOperatorCC { public targetState: BarrierState.Open | BarrierState.Closed; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.targetState]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -712,9 +713,9 @@ export class BarrierOperatorCCEventSignalingSet extends BarrierOperatorCC { public subsystemType: SubsystemType; public subsystemState: SubsystemState; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.subsystemType, this.subsystemState]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -810,9 +811,9 @@ export class BarrierOperatorCCEventSignalingGet extends BarrierOperatorCC { public subsystemType: SubsystemType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.subsystemType]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 5e870e330fb4..ab22966d166f 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -376,9 +377,9 @@ export class BasicCCSet extends BasicCC { public targetValue: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.targetValue]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -485,7 +486,7 @@ export class BasicCCReport extends BasicCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.currentValue ?? 0xfe, this.targetValue ?? 0xfe, @@ -501,7 +502,7 @@ export class BasicCCReport extends BasicCC { this.payload = this.payload.subarray(0, 1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 1e3591111e3f..f6e9eea873f0 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -1,5 +1,6 @@ import { timespan } from "@zwave-js/core"; import type { + CCEncodingContext, MessageOrCCLogEntry, MessageRecord, SinglecastCC, @@ -527,7 +528,7 @@ export class BatteryCCReport extends BatteryCC { @ccValue(BatteryCCValues.lowTemperatureStatus) public readonly lowTemperatureStatus: boolean | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.isLow ? 0xff : this.level]); if (this.chargingStatus != undefined) { this.payload = Buffer.concat([ @@ -549,7 +550,7 @@ export class BatteryCCReport extends BatteryCC { ]), ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 5cf8c3d33e93..a41f35dcd442 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -391,9 +392,9 @@ export class BinarySensorCCReport extends BinarySensorCC { public type: BinarySensorType; public value: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.value ? 0xff : 0x00, this.type]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -445,9 +446,9 @@ export class BinarySensorCCGet extends BinarySensorCC { public sensorType: BinarySensorType | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sensorType ?? BinarySensorType.Any]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -493,13 +494,13 @@ export class BinarySensorCCSupportedReport extends BinarySensorCC { @ccValue(BinarySensorCCValues.supportedSensorTypes) public supportedSensorTypes: BinarySensorType[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeBitMask( this.supportedSensorTypes.filter((t) => t !== BinarySensorType.Any), undefined, 0, ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index fd6bb109e293..82ebc60ea16e 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -332,7 +333,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC { public targetValue: boolean; public duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.targetValue ? 0xff : 0x00, (this.duration ?? Duration.default()).serializeSet(), @@ -347,7 +348,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC { this.payload = this.payload.subarray(0, 1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -409,7 +410,7 @@ export class BinarySwitchCCReport extends BinarySwitchCC { @ccValue(BinarySwitchCCValues.duration) public readonly duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ encodeMaybeBoolean(this.currentValue ?? UNKNOWN_STATE), ]); @@ -422,7 +423,7 @@ export class BinarySwitchCCReport extends BinarySwitchCC { ]), ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index 189ab3e13d2f..fd9de6776bb0 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CRC16_CCITT, CommandClasses, EncapsulationFlags, @@ -10,7 +11,6 @@ import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -132,7 +132,7 @@ export class CRC16CCCommandEncapsulation extends CRC16CC { fromEncapsulation: true, encapCC: this, origin: options.origin, - frameType: options.frameType, + context: options.context, }); } else { this.encapsulated = options.encapsulated; @@ -143,8 +143,8 @@ export class CRC16CCCommandEncapsulation extends CRC16CC { public encapsulated: CommandClass; private readonly headerBuffer = Buffer.from([this.ccId, this.ccCommand]); - public serialize(): Buffer { - const commandBuffer = this.encapsulated.serialize(); + public serialize(ctx: CCEncodingContext): Buffer { + const commandBuffer = this.encapsulated.serialize(ctx); // Reserve 2 bytes for the CRC this.payload = Buffer.concat([commandBuffer, Buffer.allocUnsafe(2)]); @@ -154,7 +154,7 @@ export class CRC16CCCommandEncapsulation extends CRC16CC { crc = CRC16_CCITT(commandBuffer, crc); this.payload.writeUInt16BE(crc, this.payload.length - 2); - return super.serialize(); + return super.serialize(ctx); } protected computeEncapsulationOverhead(): number { diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 04a55bd64ed7..9c90374d3952 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -515,9 +516,9 @@ export class CentralSceneCCConfigurationSet extends CentralSceneCC { public slowRefresh: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.slowRefresh ? 0b1000_0000 : 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index c2d922b88192..b510dbd69185 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -16,7 +17,6 @@ import { padStart } from "alcalzone-shared/strings"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -244,7 +244,7 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { public switchPoints: Switchpoint[]; public weekday: Weekday; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Make sure we have exactly 9 entries const allSwitchPoints = this.switchPoints.slice(0, 9); // maximum 9 while (allSwitchPoints.length < 9) { @@ -258,7 +258,7 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { Buffer.from([this.weekday & 0b111]), ...allSwitchPoints.map((sp) => encodeSwitchpoint(sp)), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -363,9 +363,9 @@ export class ClimateControlScheduleCCGet extends ClimateControlScheduleCC { public weekday: Weekday; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.weekday & 0b111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -482,12 +482,12 @@ export class ClimateControlScheduleCCOverrideSet public overrideType: ScheduleOverrideType; public overrideState: SetbackState; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.overrideType & 0b11, encodeSetbackState(this.overrideState), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 6c3f679effa9..e7162708c393 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -1,4 +1,5 @@ import type { + CCEncodingContext, MessageOrCCLogEntry, SupervisionResult, } from "@zwave-js/core/safe"; @@ -174,12 +175,12 @@ export class ClockCCSet extends ClockCC { public hour: number; public minute: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ ((this.weekday & 0b111) << 5) | (this.hour & 0b11111), this.minute, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 7a1160ef3e15..bf9f30d21290 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -15,7 +15,11 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown, encodeBitMask } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type MaybeNotKnown, + encodeBitMask, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -708,13 +712,13 @@ export class ColorSwitchCCSupportedReport extends ColorSwitchCC { @ccValue(ColorSwitchCCValues.supportedColorComponents) public readonly supportedColorComponents: readonly ColorComponent[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeBitMask( this.supportedColorComponents, 15, // fixed 2 bytes ColorComponent["Warm White"], ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -849,7 +853,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { @ccValue(ColorSwitchCCValues.duration) public readonly duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.colorComponent, this.currentValue, @@ -863,7 +867,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { ]), ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -929,9 +933,9 @@ export class ColorSwitchCCGet extends ColorSwitchCC { this._colorComponent = value; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this._colorComponent]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1005,7 +1009,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC { public colorTable: ColorTable; public duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const populatedColorCount = Object.keys(this.colorTable).length; this.payload = Buffer.allocUnsafe( 1 + populatedColorCount * 2 + 1, @@ -1031,7 +1035,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC { this.payload = this.payload.subarray(0, -1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1111,7 +1115,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { public direction: keyof typeof LevelChangeDirection; public colorComponent: ColorComponent; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const controlByte = (LevelChangeDirection[this.direction] << 6) | (this.ignoreStartLevel ? 0b0010_0000 : 0); this.payload = Buffer.from([ @@ -1130,7 +1134,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { this.payload = this.payload.subarray(0, -1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1179,9 +1183,9 @@ export class ColorSwitchCCStopLevelChange extends ColorSwitchCC { public readonly colorComponent: ColorComponent; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.colorComponent]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index c455f9100e22..5bbf9fc9a114 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -1,5 +1,6 @@ import type { ParamInfoMap } from "@zwave-js/config"; import { + type CCEncodingContext, CommandClasses, ConfigValueFormat, type ConfigurationMetadata, @@ -1731,7 +1732,7 @@ export class ConfigurationCCReport extends ConfigurationCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.parameter, this.valueSize & 0b111]), Buffer.allocUnsafe(this.valueSize), @@ -1744,7 +1745,7 @@ export class ConfigurationCCReport extends ConfigurationCC { this.value, ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1801,9 +1802,9 @@ export class ConfigurationCCGet extends ConfigurationCC { public parameter: number; public allowUnexpectedResponse: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.parameter]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1887,7 +1888,7 @@ export class ConfigurationCCSet extends ConfigurationCC { public valueFormat: ConfigValueFormat | undefined; public value: ConfigValue | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const valueSize = this.resetToDefault ? 1 : this.valueSize!; const payloadLength = 2 + valueSize; this.payload = Buffer.alloc(payloadLength, 0); @@ -1927,7 +1928,7 @@ export class ConfigurationCCSet extends ConfigurationCC { ); } } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2047,7 +2048,7 @@ export class ConfigurationCCBulkSet extends ConfigurationCC { return this._handshake; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const valueSize = this._resetToDefault ? 1 : this.valueSize; const payloadLength = 4 + valueSize * this.parameters.length; this.payload = Buffer.alloc(payloadLength, 0); @@ -2091,7 +2092,7 @@ export class ConfigurationCCBulkSet extends ConfigurationCC { } } } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2281,11 +2282,11 @@ export class ConfigurationCCBulkGet extends ConfigurationCC { return this._parameters; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(3); this.payload.writeUInt16BE(this.parameters[0], 0); this.payload[2] = this.parameters.length; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2370,14 +2371,14 @@ export class ConfigurationCCNameReport extends ConfigurationCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const nameBuffer = Buffer.from(this.name, "utf8"); this.payload = Buffer.allocUnsafe(3 + nameBuffer.length); this.payload.writeUInt16BE(this.parameter, 0); this.payload[2] = this.reportsToFollow; nameBuffer.copy(this.payload, 3); - return super.serialize(); + return super.serialize(ctx); } public getPartialCCSessionId(): Record | undefined { @@ -2429,10 +2430,10 @@ export class ConfigurationCCNameGet extends ConfigurationCC { public parameter: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(2); this.payload.writeUInt16BE(this.parameter, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2530,14 +2531,14 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const infoBuffer = Buffer.from(this.info, "utf8"); this.payload = Buffer.allocUnsafe(3 + infoBuffer.length); this.payload.writeUInt16BE(this.parameter, 0); this.payload[2] = this.reportsToFollow; infoBuffer.copy(this.payload, 3); - return super.serialize(); + return super.serialize(ctx); } public getPartialCCSessionId(): Record | undefined { @@ -2589,10 +2590,10 @@ export class ConfigurationCCInfoGet extends ConfigurationCC { public parameter: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(2); this.payload.writeUInt16BE(this.parameter, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2811,7 +2812,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { public isAdvanced: MaybeNotKnown; public noBulkSupport: MaybeNotKnown; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe( 3 // preamble + 3 * this.valueSize // min, max, default value @@ -2859,7 +2860,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { | (this.noBulkSupport ? 0b10 : 0); this.payload[offset] = options2; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2918,10 +2919,10 @@ export class ConfigurationCCPropertiesGet extends ConfigurationCC { public parameter: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(2); this.payload.writeUInt16BE(this.parameter, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index e11c652631ce..987c1074907d 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, type EndpointId, @@ -853,9 +854,9 @@ export class DoorLockCCOperationSet extends DoorLockCC { public mode: DoorLockMode; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.mode]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1224,7 +1225,7 @@ export class DoorLockCCConfigurationSet extends DoorLockCC { public twistAssist?: boolean; public blockToBlock?: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const insideHandles = isArray( this.insideHandlesCanOpenDoorConfiguration, ) @@ -1274,7 +1275,7 @@ export class DoorLockCCConfigurationSet extends DoorLockCC { 6, ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index b9b284f66955..ebb14e2d5bd8 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -389,9 +390,9 @@ export class DoorLockLoggingCCRecordGet extends DoorLockLoggingCC { public recordNumber: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.recordNumber]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index d43934b4a0a7..dec599ee0662 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -7,7 +7,10 @@ import { parseFloatWithScale, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type MaybeNotKnown, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -240,12 +243,12 @@ export class EnergyProductionCCReport extends EnergyProductionCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.parameter]), encodeFloatWithScale(this.value, this.scale.key), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -298,9 +301,9 @@ export class EnergyProductionCCGet extends EnergyProductionCC { public parameter: EnergyProductionParameter; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.parameter]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index eca66d6e4c38..17248fb74086 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -695,9 +696,9 @@ export class EntryControlCCConfigurationSet extends EntryControlCC { public readonly keyCacheSize: number; public readonly keyCacheTimeout: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.keyCacheSize, this.keyCacheTimeout]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index 908bc9bcca74..3e35daefec92 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CRC16_CCITT, CommandClasses, type MaybeNotKnown, @@ -436,7 +437,7 @@ export class FirmwareUpdateMetaDataCCMetaDataReport @ccValue(FirmwareUpdateMetaDataCCValues.supportsNonSecureTransfer) public readonly supportsNonSecureTransfer?: MaybeNotKnown; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.alloc( 12 + 2 * this.additionalFirmwareIDs.length, ); @@ -457,7 +458,7 @@ export class FirmwareUpdateMetaDataCCMetaDataReport | (this.supportsNonSecureTransfer ? 0b100 : 0) | (this.supportsResuming ? 0b1000 : 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -610,7 +611,7 @@ export class FirmwareUpdateMetaDataCCRequestGet public resume?: boolean; public nonSecureTransfer?: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const isV3 = this.version >= 3 && this.firmwareTarget != undefined && this.fragmentSize != undefined; @@ -636,7 +637,7 @@ export class FirmwareUpdateMetaDataCCRequestGet if (isV5) { this.payload[10] = this.hardwareVersion!; } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -733,7 +734,7 @@ export class FirmwareUpdateMetaDataCCReport extends FirmwareUpdateMetaDataCC { public reportNumber: number; public firmwareData: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const commandBuffer = Buffer.concat([ Buffer.allocUnsafe(2), // placeholder for report number this.firmwareData, @@ -757,7 +758,7 @@ export class FirmwareUpdateMetaDataCCReport extends FirmwareUpdateMetaDataCC { this.payload = commandBuffer; } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -896,7 +897,7 @@ export class FirmwareUpdateMetaDataCCActivationSet public firmwareTarget: number; public hardwareVersion?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const isV5 = this.version >= 5 && this.hardwareVersion != undefined; this.payload = Buffer.allocUnsafe(7 + (isV5 ? 1 : 0)); this.payload.writeUInt16BE(this.manufacturerId, 0); @@ -906,7 +907,7 @@ export class FirmwareUpdateMetaDataCCActivationSet if (isV5) { this.payload[7] = this.hardwareVersion!; } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -998,14 +999,14 @@ export class FirmwareUpdateMetaDataCCPrepareGet public fragmentSize: number; public hardwareVersion: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(8); this.payload.writeUInt16BE(this.manufacturerId, 0); this.payload.writeUInt16BE(this.firmwareId, 2); this.payload[4] = this.firmwareTarget; this.payload.writeUInt16BE(this.fragmentSize, 5); this.payload[7] = this.hardwareVersion; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index ad166fa122f5..479f0b42c89d 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -304,9 +305,9 @@ export class HumidityControlModeCCSet extends HumidityControlModeCC { public mode: HumidityControlMode; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.mode & 0b1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 76ba80ee0e05..07d822b94029 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -549,12 +550,12 @@ export class HumidityControlSetpointCCSet extends HumidityControlSetpointCC { public value: number; public scale: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.setpointType & 0b1111]), encodeFloatWithScale(this.value, this.scale), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -693,9 +694,9 @@ export class HumidityControlSetpointCCGet extends HumidityControlSetpointCC { public setpointType: HumidityControlSetpointType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.setpointType & 0b1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -825,9 +826,9 @@ export class HumidityControlSetpointCCScaleSupportedGet public setpointType: HumidityControlSetpointType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.setpointType & 0b1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -958,9 +959,9 @@ export class HumidityControlSetpointCCCapabilitiesGet public setpointType: HumidityControlSetpointType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.setpointType & 0b1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index 1e4ddb87301f..0ac2f402fa2a 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -3,13 +3,15 @@ import { type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type MaybeNotKnown, +} from "@zwave-js/core/safe"; import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host"; import { getEnumMemberName } from "@zwave-js/shared"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -118,9 +120,9 @@ export class InclusionControllerCCComplete extends InclusionControllerCC { public step: InclusionControllerStep; public status: InclusionControllerStatus; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.step, this.status]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -168,9 +170,9 @@ export class InclusionControllerCCInitiate extends InclusionControllerCC { public includedNodeId: number; public step: InclusionControllerStep; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.includedNodeId, this.step]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 225bb888f621..79c28a2e5942 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -1,5 +1,6 @@ import type { ConfigManager } from "@zwave-js/config"; import { + type CCEncodingContext, CommandClasses, type EndpointId, Indicator, @@ -943,7 +944,7 @@ export class IndicatorCCSet extends IndicatorCC { public indicator0Value: number | undefined; public values: IndicatorObject[] | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if (this.values != undefined) { // V2+ this.payload = Buffer.alloc(2 + 3 * this.values.length, 0); @@ -965,7 +966,7 @@ export class IndicatorCCSet extends IndicatorCC { // V1 this.payload = Buffer.from([this.indicator0Value ?? 0]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1157,7 +1158,7 @@ export class IndicatorCCReport extends IndicatorCC { this.setValue(applHost, valueV2, value.value); } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if (this.values != undefined) { // V2+ this.payload = Buffer.alloc(2 + 3 * this.values.length, 0); @@ -1179,7 +1180,7 @@ export class IndicatorCCReport extends IndicatorCC { // V1 this.payload = Buffer.from([this.indicator0Value ?? 0]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1230,11 +1231,11 @@ export class IndicatorCCGet extends IndicatorCC { public indicatorId: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if (this.indicatorId != undefined) { this.payload = Buffer.from([this.indicatorId]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1304,7 +1305,7 @@ export class IndicatorCCSupportedReport extends IndicatorCC { public readonly nextIndicatorId: number; public readonly supportedProperties: readonly number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const bitmask = this.supportedProperties.length > 0 ? encodeBitMask(this.supportedProperties, undefined, 0) : Buffer.from([]); @@ -1317,7 +1318,7 @@ export class IndicatorCCSupportedReport extends IndicatorCC { bitmask, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1375,9 +1376,9 @@ export class IndicatorCCSupportedGet extends IndicatorCC { public indicatorId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.indicatorId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1437,13 +1438,13 @@ export class IndicatorCCDescriptionReport extends IndicatorCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const description = Buffer.from(this.description, "utf8"); this.payload = Buffer.concat([ Buffer.from([this.indicatorId, description.length]), description, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1498,9 +1499,9 @@ export class IndicatorCCDescriptionGet extends IndicatorCC { public indicatorId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.indicatorId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 3dd8423f3cc2..12872db26eca 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -1570,7 +1571,7 @@ export class IrrigationCCSystemConfigSet extends IrrigationCC { public rainSensorPolarity?: IrrigationSensorPolarity; public moistureSensorPolarity?: IrrigationSensorPolarity; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { let polarity = 0; if (this.rainSensorPolarity != undefined) polarity |= 0b1; if (this.moistureSensorPolarity != undefined) polarity |= 0b10; @@ -1587,7 +1588,7 @@ export class IrrigationCCSystemConfigSet extends IrrigationCC { encodeFloatWithScale(this.lowPressureThreshold, 0 /* kPa */), Buffer.from([polarity]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1866,12 +1867,12 @@ export class IrrigationCCValveInfoGet extends IrrigationCC { public valveId: ValveId; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.valveId === "master" ? 1 : 0, this.valveId === "master" ? 1 : this.valveId || 1, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1935,7 +1936,7 @@ export class IrrigationCCValveConfigSet extends IrrigationCC { public useRainSensor: boolean; public useMoistureSensor: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([ this.valveId === "master" ? 1 : 0, @@ -1951,7 +1952,7 @@ export class IrrigationCCValveConfigSet extends IrrigationCC { | (this.useMoistureSensor ? 0b10 : 0), ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2137,12 +2138,12 @@ export class IrrigationCCValveConfigGet extends IrrigationCC { public valveId: ValveId; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.valveId === "master" ? 1 : 0, this.valveId === "master" ? 1 : this.valveId || 1, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2186,7 +2187,7 @@ export class IrrigationCCValveRun extends IrrigationCC { public valveId: ValveId; public duration: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.valveId === "master" ? 1 : 0, this.valveId === "master" ? 1 : this.valveId || 1, @@ -2194,7 +2195,7 @@ export class IrrigationCCValveRun extends IrrigationCC { 0, ]); this.payload.writeUInt16BE(this.duration, 2); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2244,7 +2245,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC { public tableId: number; public entries: ValveTableEntry[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(1 + this.entries.length * 3); this.payload[0] = this.tableId; for (let i = 0; i < this.entries.length; i++) { @@ -2253,7 +2254,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC { this.payload[offset] = entry.valveId; this.payload.writeUInt16BE(entry.duration, offset + 1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2355,9 +2356,9 @@ export class IrrigationCCValveTableGet extends IrrigationCC { public tableId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.tableId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2404,9 +2405,9 @@ export class IrrigationCCValveTableRun extends IrrigationCC { public tableIDs: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from(this.tableIDs); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2453,9 +2454,9 @@ export class IrrigationCCSystemShutoff extends IrrigationCC { public duration?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.duration ?? 255]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 77befb25bd14..feb07f8aeae7 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -1,4 +1,5 @@ import type { + CCEncodingContext, MessageOrCCLogEntry, MessageRecord, SupervisionResult, @@ -220,11 +221,11 @@ export class LanguageCCSet extends LanguageCC { this._country = value; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(!!this._country ? 5 : 3); this.payload.write(this._language, 0, "ascii"); if (!!this._country) this.payload.write(this._country, 3, "ascii"); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 80952dbcb3b5..3ec0aba6c3b3 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -207,9 +208,9 @@ export class LockCCSet extends LockCC { public locked: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.locked ? 1 : 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index 2d93ef32dc29..04b21a234a8c 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, ZWaveError, ZWaveErrorCodes, @@ -191,7 +192,7 @@ export class ManufacturerProprietaryCC extends CommandClass { return this.manufacturerId; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const manufacturerId = this.getManufacturerIdOrThrow(); // ManufacturerProprietaryCC has no CC command, so the first byte // is stored in ccCommand @@ -204,7 +205,7 @@ export class ManufacturerProprietaryCC extends CommandClass { ]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } public createSpecificInstance(): ManufacturerProprietaryCC | undefined { diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 6dec47054712..9fe8115c790f 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -1,4 +1,7 @@ -import type { MessageOrCCLogEntry } from "@zwave-js/core/safe"; +import type { + CCEncodingContext, + MessageOrCCLogEntry, +} from "@zwave-js/core/safe"; import { CommandClasses, type MaybeNotKnown, @@ -265,12 +268,12 @@ export class ManufacturerSpecificCCReport extends ManufacturerSpecificCC { @ccValue(ManufacturerSpecificCCValues.productId) public readonly productId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(6); this.payload.writeUInt16BE(this.manufacturerId, 0); this.payload.writeUInt16BE(this.productType, 2); this.payload.writeUInt16BE(this.productId, 4); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -362,9 +365,9 @@ export class ManufacturerSpecificCCDeviceSpecificGet public deviceIdType: DeviceIdType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([(this.deviceIdType || 0) & 0b111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 420d53b7cd23..f2984b4818b3 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -11,6 +11,7 @@ import { timespan, } from "@zwave-js/core"; import { + type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -1016,7 +1017,7 @@ export class MeterCCReport extends MeterCC { public rateType: RateType; public deltaTime: MaybeUnknown; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const { data: typeAndValue, floatParams, scale2 } = encodeMeterValueAndInfo( this.type, @@ -1055,7 +1056,7 @@ export class MeterCCReport extends MeterCC { ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1124,7 +1125,7 @@ export class MeterCCGet extends MeterCC { public rateType: RateType | undefined; public scale: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { let scale1: number; let scale2: number | undefined; let bufferLength = 0; @@ -1155,7 +1156,7 @@ export class MeterCCGet extends MeterCC { this.payload[0] = (rateTypeFlags << 6) | (scale1 << 3); if (scale2) this.payload[1] = scale2; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1285,7 +1286,7 @@ export class MeterCCSupportedReport extends MeterCC { return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const typeByte = (this.type & 0b0_00_11111) | (this.supportedRateTypes.includes(RateType.Consumed) ? 0b0_01_00000 @@ -1317,7 +1318,7 @@ export class MeterCCSupportedReport extends MeterCC { ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1392,7 +1393,7 @@ export class MeterCCReset extends MeterCC { public rateType: RateType | undefined; public targetValue: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if ( this.type != undefined && this.scale != undefined @@ -1415,7 +1416,7 @@ export class MeterCCReset extends MeterCC { ]); } } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index e47530799326..dbf4afab230e 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -1,4 +1,5 @@ import type { + CCEncodingContext, EndpointId, MessageRecord, SupervisionResult, @@ -664,7 +665,7 @@ export class MultiChannelAssociationCCSet extends MultiChannelAssociationCC { public nodeIds: number[]; public endpoints: EndpointAddress[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.groupId]), serializeMultiChannelAssociationDestination( @@ -672,7 +673,7 @@ export class MultiChannelAssociationCCSet extends MultiChannelAssociationCC { this.endpoints, ), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -743,7 +744,7 @@ export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { public nodeIds?: number[]; public endpoints?: EndpointAddress[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.groupId || 0]), serializeMultiChannelAssociationDestination( @@ -751,7 +752,7 @@ export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { this.endpoints || [], ), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -853,7 +854,7 @@ export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { .reduce((prev, cur) => prev.concat(...cur), []); } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const destinations = serializeMultiChannelAssociationDestination( this.nodeIds, this.endpoints, @@ -866,7 +867,7 @@ export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { ]), destinations, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -913,9 +914,9 @@ export class MultiChannelAssociationCCGet extends MultiChannelAssociationCC { public groupId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -956,9 +957,9 @@ export class MultiChannelAssociationCCSupportedGroupingsReport @ccValue(MultiChannelAssociationCCValues.groupCount) public readonly groupCount: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupCount]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index fe00f5b30418..2cea58c8d0f3 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -1,5 +1,6 @@ import { type ApplicationNodeInformation, + type CCEncodingContext, CommandClasses, type GenericDeviceClass, type MaybeNotKnown, @@ -856,14 +857,14 @@ export class MultiChannelCCEndPointReport extends MultiChannelCC { @ccValue(MultiChannelCCValues.aggregatedEndpointCount) public aggregatedCount: MaybeNotKnown; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ (this.countIsDynamic ? 0b10000000 : 0) | (this.identicalCapabilities ? 0b01000000 : 0), this.individualCount & 0b01111111, this.aggregatedCount ?? 0, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -965,7 +966,7 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC public readonly isDynamic: boolean; public readonly wasRemoved: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([ (this.endpointIndex & 0b01111111) @@ -973,7 +974,7 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC ]), encodeApplicationNodeInformation(this), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1032,9 +1033,9 @@ export class MultiChannelCCCapabilityGet extends MultiChannelCC { public requestedEndpoint: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.requestedEndpoint & 0b01111111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1089,7 +1090,7 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC { public foundEndpoints: number[]; public reportsToFollow: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([ this.reportsToFollow, @@ -1098,7 +1099,7 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC { ]), Buffer.from(this.foundEndpoints.map((e) => e & 0b01111111)), ]); - return super.serialize(); + return super.serialize(ctx); } public getPartialCCSessionId(): Record | undefined { @@ -1170,9 +1171,9 @@ export class MultiChannelCCEndPointFind extends MultiChannelCC { public genericClass: number; public specificClass: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.genericClass, this.specificClass]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1256,9 +1257,9 @@ export class MultiChannelCCAggregatedMembersGet extends MultiChannelCC { public requestedEndpoint: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.requestedEndpoint & 0b0111_1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1357,7 +1358,7 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { fromEncapsulation: true, encapCC: this, origin: options.origin, - frameType: options.frameType, + context: options.context, }); } else { this.encapsulated = options.encapsulated; @@ -1380,7 +1381,7 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { /** The destination end point (0-127) or an array of destination end points (1-7) */ public destination: MultiChannelCCDestination; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const destination = typeof this.destination === "number" // The destination is a single number ? this.destination & 0b0111_1111 @@ -1388,9 +1389,9 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { : encodeBitMask(this.destination, 7)[0] | 0b1000_0000; this.payload = Buffer.concat([ Buffer.from([this.endpointIndex & 0b0111_1111, destination]), - this.encapsulated.serialize(), + this.encapsulated.serialize(ctx), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1473,9 +1474,9 @@ export class MultiChannelCCV1Get extends MultiChannelCC { public requestedCC: CommandClasses; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.requestedCC]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1539,7 +1540,7 @@ export class MultiChannelCCV1CommandEncapsulation extends MultiChannelCC { fromEncapsulation: true, encapCC: this, origin: options.origin, - frameType: options.frameType, + context: options.context, }); } else { this.encapsulated = options.encapsulated; @@ -1550,12 +1551,12 @@ export class MultiChannelCCV1CommandEncapsulation extends MultiChannelCC { public encapsulated!: CommandClass; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.endpointIndex]), - this.encapsulated.serialize(), + this.encapsulated.serialize(ctx), ]); - return super.serialize(); + return super.serialize(ctx); } protected computeEncapsulationOverhead(): number { diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index 4bb1678dd63a..00a3e2322ac0 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -1,8 +1,9 @@ -import type { MessageOrCCLogEntry } from "@zwave-js/core/safe"; import { + type CCEncodingContext, CommandClasses, EncapsulationFlags, type MaybeNotKnown, + type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core/safe"; import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; @@ -10,7 +11,6 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -130,7 +130,7 @@ export class MultiCommandCCCommandEncapsulation extends MultiCommandCC { fromEncapsulation: true, encapCC: this, origin: options.origin, - frameType: options.frameType, + context: options.context, }), ); offset += 1 + cmdLength; @@ -145,16 +145,16 @@ export class MultiCommandCCCommandEncapsulation extends MultiCommandCC { public encapsulated: CommandClass[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const buffers: Buffer[] = []; buffers.push(Buffer.from([this.encapsulated.length])); for (const cmd of this.encapsulated) { - const cmdBuffer = cmd.serialize(); + const cmdBuffer = cmd.serialize(ctx); buffers.push(Buffer.from([cmdBuffer.length])); buffers.push(cmdBuffer); } this.payload = Buffer.concat(buffers); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index c2586fa999d3..20af5b949c96 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -7,6 +7,7 @@ import { timespan, } from "@zwave-js/core"; import type { + CCEncodingContext, EndpointId, MessageOrCCLogEntry, MessageRecord, @@ -726,12 +727,12 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { public scale: number; public value: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.type]), encodeFloatWithScale(this.value, this.scale), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -794,7 +795,7 @@ export class MultilevelSensorCCGet extends MultilevelSensorCC { public sensorType: number | undefined; public scale: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if ( this.sensorType != undefined && this.scale != undefined @@ -804,7 +805,7 @@ export class MultilevelSensorCCGet extends MultilevelSensorCC { (this.scale & 0b11) << 3, ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -861,9 +862,9 @@ export class MultilevelSensorCCSupportedSensorReport @ccValue(MultilevelSensorCCValues.supportedSensorTypes) public supportedSensorTypes: readonly number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeBitMask(this.supportedSensorTypes); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -922,12 +923,12 @@ export class MultilevelSensorCCSupportedScaleReport extends MultilevelSensorCC { ) public readonly supportedScales: readonly number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.sensorType]), encodeBitMask(this.supportedScales, 4, 0), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -976,9 +977,9 @@ export class MultilevelSensorCCGetSupportedScale extends MultilevelSensorCC { public sensorType: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sensorType]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 6991cc84ee79..5ef903e049e7 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -648,7 +649,7 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { public targetValue: number; public duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.targetValue, (this.duration ?? Duration.default()).serializeSet(), @@ -663,7 +664,7 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { this.payload = this.payload.subarray(0, 1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -724,13 +725,13 @@ export class MultilevelSwitchCCReport extends MultilevelSwitchCC { @ccValue(MultilevelSwitchCCValues.currentValue) public currentValue: MaybeUnknown | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.currentValue ?? 0xfe, this.targetValue ?? 0xfe, (this.duration ?? Duration.default()).serializeReport(), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -807,7 +808,7 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { public ignoreStartLevel: boolean; public direction: keyof typeof LevelChangeDirection; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const controlByte = (LevelChangeDirection[this.direction] << 6) | (this.ignoreStartLevel ? 0b0010_0000 : 0); this.payload = Buffer.from([ @@ -825,7 +826,7 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { this.payload = this.payload.subarray(0, -1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index e0de1b25eee7..c946e9fc5c3a 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -296,7 +297,7 @@ export class NodeNamingAndLocationCCNameSet extends NodeNamingAndLocationCC { public name: string; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const encoding = isASCII(this.name) ? "ascii" : "utf16le"; this.payload = Buffer.allocUnsafe( 1 + this.name.length * (encoding === "ascii" ? 1 : 2), @@ -314,7 +315,7 @@ export class NodeNamingAndLocationCCNameSet extends NodeNamingAndLocationCC { 0, Math.min(16, nameAsBuffer.length), ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -389,7 +390,7 @@ export class NodeNamingAndLocationCCLocationSet public location: string; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const encoding = isASCII(this.location) ? "ascii" : "utf16le"; this.payload = Buffer.allocUnsafe( 1 + this.location.length * (encoding === "ascii" ? 1 : 2), @@ -407,7 +408,7 @@ export class NodeNamingAndLocationCCLocationSet 0, Math.min(16, locationAsBuffer.length), ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index cb9e65fa2413..d6bcea0000b0 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -10,6 +10,7 @@ import { timespan, } from "@zwave-js/core"; import { + type CCEncodingContext, CommandClasses, Duration, type EndpointId, @@ -932,12 +933,12 @@ export class NotificationCCSet extends NotificationCC { public notificationType: number; public notificationStatus: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.notificationType, this.notificationStatus ? 0xff : 0x00, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1290,6 +1291,8 @@ export class NotificationCCReport extends NotificationCC { data: this.eventParameters, fromEncapsulation: true, encapCC: this, + // FIXME: persistValues needs access to the CCParsingContext + context: {} as any, }); validatePayload(!(cc instanceof InvalidCC)); @@ -1376,7 +1379,7 @@ export class NotificationCCReport extends NotificationCC { } } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if (this.version === 1) { if (this.alarmLevel == undefined || this.alarmType == undefined) { throw new ZWaveError( @@ -1428,7 +1431,7 @@ export class NotificationCCReport extends NotificationCC { ]); } } - return super.serialize(); + return super.serialize(ctx); } } @@ -1478,7 +1481,7 @@ export class NotificationCCGet extends NotificationCC { public notificationType: number | undefined; public notificationEvent: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const payload: number[] = [this.alarmType || 0]; if (this.version >= 2 && this.notificationType != undefined) { payload.push(this.notificationType); @@ -1491,7 +1494,7 @@ export class NotificationCCGet extends NotificationCC { } } this.payload = Buffer.from(payload); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1563,7 +1566,7 @@ export class NotificationCCSupportedReport extends NotificationCC { @ccValue(NotificationCCValues.supportedNotificationTypes) public supportedNotificationTypes: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const bitMask = encodeBitMask( this.supportedNotificationTypes, Math.max(...this.supportedNotificationTypes), @@ -1575,7 +1578,7 @@ export class NotificationCCSupportedReport extends NotificationCC { ]), bitMask, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1696,7 +1699,7 @@ export class NotificationCCEventSupportedReport extends NotificationCC { public notificationType: number; public supportedEvents: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.notificationType, 0]); if (this.supportedEvents.length > 0) { const bitMask = encodeBitMask( @@ -1708,7 +1711,7 @@ export class NotificationCCEventSupportedReport extends NotificationCC { this.payload = Buffer.concat([this.payload, bitMask]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1759,9 +1762,9 @@ export class NotificationCCEventSupportedGet extends NotificationCC { public notificationType: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.notificationType]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index 9a359f759b59..4775ff2cb9af 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -251,9 +252,9 @@ export class PowerlevelCCSet extends PowerlevelCC { public powerlevel: Powerlevel; public timeout?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.powerlevel, this.timeout ?? 0x00]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -303,9 +304,9 @@ export class PowerlevelCCReport extends PowerlevelCC { public readonly powerlevel: Powerlevel; public readonly timeout?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.powerlevel, this.timeout ?? 0x00]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -359,10 +360,10 @@ export class PowerlevelCCTestNodeSet extends PowerlevelCC { public powerlevel: Powerlevel; public testFrameCount: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.testNodeId, this.powerlevel, 0, 0]); this.payload.writeUInt16BE(this.testFrameCount, 2); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -410,7 +411,7 @@ export class PowerlevelCCTestNodeReport extends PowerlevelCC { public status: PowerlevelTestStatus; public acknowledgedFrames: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.testNodeId, this.status, @@ -419,7 +420,7 @@ export class PowerlevelCCTestNodeReport extends PowerlevelCC { 0, ]); this.payload.writeUInt16BE(this.acknowledgedFrames, 2); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 235c8d8722c3..2477a6e2c38e 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, MAX_NODES, type MaybeNotKnown, @@ -525,7 +526,7 @@ export class ProtectionCCSet extends ProtectionCC { public local: LocalProtectionState; public rf?: RFProtectionState; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.local & 0b1111, (this.rf ?? RFProtectionState.Unprotected) & 0b1111, @@ -540,7 +541,7 @@ export class ProtectionCCSet extends ProtectionCC { this.payload = this.payload.subarray(0, 1); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -736,9 +737,9 @@ export class ProtectionCCExclusiveControlSet extends ProtectionCC { public exclusiveControlNodeId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.exclusiveControlNodeId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -806,9 +807,9 @@ export class ProtectionCCTimeoutSet extends ProtectionCC { public timeout: Timeout; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.timeout.serialize()]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index 9c26a98e432b..bbc72147dba8 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -1,4 +1,5 @@ import type { + CCEncodingContext, MessageOrCCLogEntry, MessageRecord, SupervisionResult, @@ -21,7 +22,6 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -163,12 +163,12 @@ export class SceneActivationCCSet extends SceneActivationCC { @ccValue(SceneActivationCCValues.dimmingDuration) public dimmingDuration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.sceneId, this.dimmingDuration?.serializeSet() ?? 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 11dcfe854742..95d71893b148 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -388,14 +389,14 @@ export class SceneActuatorConfigurationCCSet public dimmingDuration: Duration; public level?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.sceneId, this.dimmingDuration.serializeSet(), this.level != undefined ? 0b1000_0000 : 0, this.level ?? 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -526,9 +527,9 @@ export class SceneActuatorConfigurationCCGet public sceneId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sceneId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 5c129dc87c62..cce384d115a9 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, type EndpointId, @@ -521,13 +522,13 @@ export class SceneControllerConfigurationCCSet public sceneId: number; public dimmingDuration: Duration; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.groupId, this.sceneId, this.dimmingDuration.serializeSet(), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -638,9 +639,9 @@ export class SceneControllerConfigurationCCGet public groupId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.groupId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 0cf071c4291f..522adf425eaf 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -12,7 +12,11 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import { type EndpointId, type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type EndpointId, + type MaybeNotKnown, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -962,9 +966,9 @@ export class ScheduleEntryLockCCEnableSet extends ScheduleEntryLockCC { public userId: number; public enabled: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.userId, this.enabled ? 0x01 : 0x00]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1005,9 +1009,9 @@ export class ScheduleEntryLockCCEnableAllSet extends ScheduleEntryLockCC { public enabled: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.enabled ? 0x01 : 0x00]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1059,13 +1063,13 @@ export class ScheduleEntryLockCCSupportedReport extends ScheduleEntryLockCC { @ccValue(ScheduleEntryLockCCValues.numDailyRepeatingSlots) public numDailyRepeatingSlots: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.numWeekDaySlots, this.numYearDaySlots, this.numDailyRepeatingSlots ?? 0, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1153,7 +1157,7 @@ export class ScheduleEntryLockCCWeekDayScheduleSet extends ScheduleEntryLockCC { public stopHour?: number; public stopMinute?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.action, this.userId, @@ -1167,7 +1171,7 @@ export class ScheduleEntryLockCCWeekDayScheduleSet extends ScheduleEntryLockCC { this.stopHour ?? 0xff, this.stopMinute ?? 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1284,7 +1288,7 @@ export class ScheduleEntryLockCCWeekDayScheduleReport return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.userId, this.slotId, @@ -1294,7 +1298,7 @@ export class ScheduleEntryLockCCWeekDayScheduleReport this.stopHour ?? 0xff, this.stopMinute ?? 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1358,9 +1362,9 @@ export class ScheduleEntryLockCCWeekDayScheduleGet extends ScheduleEntryLockCC { public userId: number; public slotId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.userId, this.slotId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1454,7 +1458,7 @@ export class ScheduleEntryLockCCYearDayScheduleSet extends ScheduleEntryLockCC { public stopHour?: number; public stopMinute?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.action, this.userId, @@ -1473,7 +1477,7 @@ export class ScheduleEntryLockCCYearDayScheduleSet extends ScheduleEntryLockCC { this.stopHour ?? 0xff, this.stopMinute ?? 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1622,7 +1626,7 @@ export class ScheduleEntryLockCCYearDayScheduleReport return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.userId, this.slotId, @@ -1637,7 +1641,7 @@ export class ScheduleEntryLockCCYearDayScheduleReport this.stopHour ?? 0xff, this.stopMinute ?? 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1704,9 +1708,9 @@ export class ScheduleEntryLockCCYearDayScheduleGet extends ScheduleEntryLockCC { public userId: number; public slotId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.userId, this.slotId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1751,12 +1755,12 @@ export class ScheduleEntryLockCCTimeOffsetSet extends ScheduleEntryLockCC { public standardOffset: number; public dstOffset: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeTimezone({ standardOffset: this.standardOffset, dstOffset: this.dstOffset, }); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1800,12 +1804,12 @@ export class ScheduleEntryLockCCTimeOffsetReport extends ScheduleEntryLockCC { public standardOffset: number; public dstOffset: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeTimezone({ standardOffset: this.standardOffset, dstOffset: this.dstOffset, }); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1893,7 +1897,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleSet public durationHour?: number; public durationMinute?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.action, this.userId, this.slotId]); if (this.action === ScheduleEntryLockSetAction.Set) { this.payload = Buffer.concat([ @@ -1915,7 +1919,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleSet this.payload = Buffer.concat([this.payload, Buffer.alloc(5, 0xff)]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2028,7 +2032,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.userId, this.slotId]); if (this.weekdays) { this.payload = Buffer.concat([ @@ -2050,7 +2054,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport this.payload = Buffer.concat([this.payload, Buffer.alloc(5, 0)]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2116,9 +2120,9 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleGet public userId: number; public slotId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.userId, this.slotId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index d8748a8e0636..7f18f63882cf 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -29,6 +29,8 @@ import { validatePayload, } from "@zwave-js/core"; import { + type CCEncodingContext, + type CCParsingContext, EncapsulationFlags, type MaybeNotKnown, NODE_ID_BROADCAST, @@ -1048,7 +1050,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { const sendingNodeId = this.nodeId as number; // Ensure the node has a security class - const securityClass = this.host.getHighestSecurityClass( + const securityClass = options.context.getHighestSecurityClass( sendingNodeId, ); validatePayload.withReason("No security class granted")( @@ -1133,8 +1135,8 @@ export class Security2CCMessageEncapsulation extends Security2CC { const ctx = ((): MulticastContext => { const multicastGroupId = this.getMulticastGroupId(); if ( - options.frameType === "multicast" - || options.frameType === "broadcast" + options.context.frameType === "multicast" + || options.context.frameType === "broadcast" ) { if (multicastGroupId == undefined) { validatePayload.fail( @@ -1248,6 +1250,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { decrypt = () => this.decryptSinglecast( + options.context, sendingNodeId, prevSequenceNumber!, ciphertext, @@ -1351,7 +1354,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { data: decryptedCCBytes, fromEncapsulation: true, encapCC: this, - frameType: options.frameType, + context: options.context, }); } this.plaintext = decryptedCCBytes; @@ -1484,7 +1487,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { return spanExtension?.senderEI; } - private maybeAddSPANExtension(): void { + private maybeAddSPANExtension(ctx: CCEncodingContext): void { if (!this.isSinglecast()) return; const receiverNodeId: number = this.nodeId; @@ -1521,7 +1524,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { ); } else { const securityClass = this.securityClass - ?? this.host.getHighestSecurityClass(receiverNodeId); + ?? ctx.getHighestSecurityClass(receiverNodeId); if (securityClass == undefined) { throw new ZWaveError( @@ -1550,9 +1553,9 @@ export class Security2CCMessageEncapsulation extends Security2CC { } } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Include Sender EI in the command if we only have the receiver's EI - this.maybeAddSPANExtension(); + this.maybeAddSPANExtension(ctx); const unencryptedExtensions = this.extensions.filter( (e) => !e.isEncrypted(), @@ -1571,7 +1574,8 @@ export class Security2CCMessageEncapsulation extends Security2CC { e.serialize(index < unencryptedExtensions.length - 1) ), ]); - const serializedCC = this.encapsulated?.serialize() ?? Buffer.from([]); + const serializedCC = this.encapsulated?.serialize(ctx) + ?? Buffer.from([]); const plaintextPayload = Buffer.concat([ ...encryptedExtensions.map((e, index) => e.serialize(index < encryptedExtensions.length - 1) @@ -1636,7 +1640,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { ciphertextPayload, authTag, ]); - return super.serialize(); + return super.serialize(ctx); } protected computeEncapsulationOverhead(): number { @@ -1717,6 +1721,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { } private decryptSinglecast( + ctx: CCParsingContext, sendingNodeId: number, prevSequenceNumber: number, ciphertext: Buffer, @@ -1827,10 +1832,10 @@ export class Security2CCMessageEncapsulation extends Security2CC { // Try all security classes where we do not definitely know that it was not granted // While bootstrapping a node, we consider the key that is being exchanged (including S0) to be the highest. No need to look at others const possibleSecurityClasses = isBootstrappingNode - ? [this.host.getHighestSecurityClass(sendingNodeId)!] + ? [ctx.getHighestSecurityClass(sendingNodeId)!] : securityClassOrder.filter( (s) => - this.host.hasSecurityClass(sendingNodeId, s) + ctx.hasSecurityClass(sendingNodeId, s) !== false, ); @@ -1857,14 +1862,10 @@ export class Security2CCMessageEncapsulation extends Security2CC { if (ret.authOK) { // Also if we weren't sure before, we now know that the security class is granted if ( - this.host.hasSecurityClass(sendingNodeId, secClass) + ctx.hasSecurityClass(sendingNodeId, secClass) === undefined ) { - this.host.setSecurityClass( - sendingNodeId, - secClass, - true, - ); + ctx.setSecurityClass(sendingNodeId, secClass, true); } return { ...ret, @@ -1990,7 +1991,7 @@ export class Security2CCNonceReport extends Security2CC { public readonly MOS: boolean; public readonly receiverEI?: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.sequenceNumber, (this.MOS ? 0b10 : 0) + (this.SOS ? 0b1 : 0), @@ -1998,7 +1999,7 @@ export class Security2CCNonceReport extends Security2CC { if (this.SOS) { this.payload = Buffer.concat([this.payload, this.receiverEI!]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2058,9 +2059,9 @@ export class Security2CCNonceGet extends Security2CC { return this._sequenceNumber; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sequenceNumber]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2126,7 +2127,7 @@ export class Security2CCKEXReport extends Security2CC { public readonly supportedECDHProfiles: readonly ECDHProfiles[]; public readonly requestedKeys: readonly SecurityClass[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([ this._reserved @@ -2146,7 +2147,7 @@ export class Security2CCKEXReport extends Security2CC { SecurityClass.S2_Unauthenticated, ), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2256,7 +2257,7 @@ export class Security2CCKEXSet extends Security2CC { public selectedECDHProfile: ECDHProfiles; public grantedKeys: SecurityClass[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([ this._reserved @@ -2276,7 +2277,7 @@ export class Security2CCKEXSet extends Security2CC { SecurityClass.S2_Unauthenticated, ), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2323,9 +2324,9 @@ export class Security2CCKEXFail extends Security2CC { public failType: KEXFailType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.failType]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2364,12 +2365,12 @@ export class Security2CCPublicKeyReport extends Security2CC { public includingNode: boolean; public publicKey: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.includingNode ? 1 : 0]), this.publicKey, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2411,12 +2412,12 @@ export class Security2CCNetworkKeyReport extends Security2CC { public grantedKey: SecurityClass; public networkKey: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ securityClassToBitMask(this.grantedKey), this.networkKey, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2460,9 +2461,9 @@ export class Security2CCNetworkKeyGet extends Security2CC { public requestedKey: SecurityClass; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = securityClassToBitMask(this.requestedKey); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2509,11 +2510,11 @@ export class Security2CCTransferEnd extends Security2CC { public keyVerified: boolean; public keyRequestComplete: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ (this.keyVerified ? 0b10 : 0) + (this.keyRequestComplete ? 0b1 : 0), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2557,9 +2558,9 @@ export class Security2CCCommandsSupportedReport extends Security2CC { public readonly supportedCCs: CommandClasses[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeCCList(this.supportedCCs, []); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index b59babd5205e..48738e6b3bfa 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -20,7 +20,11 @@ import { parseCCList, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type CCParsingContext, + type MaybeNotKnown, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -546,9 +550,9 @@ export class SecurityCCNonceReport extends SecurityCC { public nonce: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = this.nonce; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -723,6 +727,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { public mergePartialCCs( applHost: ZWaveApplicationHost, partials: SecurityCCCommandEncapsulation[], + ctx: CCParsingContext, ): void { // Concat the CC buffers this.decryptedCCBytes = Buffer.concat( @@ -735,16 +740,17 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { data: this.decryptedCCBytes, fromEncapsulation: true, encapCC: this, + context: ctx, }); } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if (!this.nonce) throwNoNonce(); if (this.nonce.length !== HALF_NONCE_SIZE) { throwNoNonce("Invalid nonce size"); } - const serializedCC = this.encapsulated.serialize(); + const serializedCC = this.encapsulated.serialize(ctx); const plaintext = Buffer.concat([ Buffer.from([0]), // TODO: frame control serializedCC, @@ -776,7 +782,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { Buffer.from([this.nonceId!]), authCode, ]); - return super.serialize(); + return super.serialize(ctx); } protected computeEncapsulationOverhead(): number { @@ -846,10 +852,10 @@ export class SecurityCCSchemeReport extends SecurityCC { } } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Since it is unlikely that any more schemes will be added to S0, we hardcode the default scheme here (bit 0 = 0) this.payload = Buffer.from([0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -872,10 +878,10 @@ export class SecurityCCSchemeGet extends SecurityCC { // Don't care, we won't get sent this and we have no options } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Since it is unlikely that any more schemes will be added to S0, we hardcode the default scheme here (bit 0 = 0) this.payload = Buffer.from([0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -898,10 +904,10 @@ export class SecurityCCSchemeInherit extends SecurityCC { // Don't care, we won't get sent this and we have no options } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Since it is unlikely that any more schemes will be added to S0, we hardcode the default scheme here (bit 0 = 0) this.payload = Buffer.from([0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -947,9 +953,9 @@ export class SecurityCCNetworkKeySet extends SecurityCC { public networkKey: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = this.networkKey; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(applHost: ZWaveApplicationHost): MessageOrCCLogEntry { @@ -993,12 +999,12 @@ export class SecurityCCCommandsSupportedReport extends SecurityCC { public readonly reportsToFollow: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.reportsToFollow]), encodeCCList(this.supportedCCs, this.controlledCCs), ]); - return super.serialize(); + return super.serialize(ctx); } public getPartialCCSessionId(): Record | undefined { diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index 2b4874c526b2..0f8bd9bdb5fd 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -496,9 +497,9 @@ export class SoundSwitchCCTonesNumberReport extends SoundSwitchCC { public toneCount: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.toneCount]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -549,13 +550,13 @@ export class SoundSwitchCCToneInfoReport extends SoundSwitchCC { public readonly duration: number; public readonly name: string; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.toneId, 0, 0, this.name.length]), Buffer.from(this.name, "utf8"), ]); this.payload.writeUInt16BE(this.duration, 1); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -605,9 +606,9 @@ export class SoundSwitchCCToneInfoGet extends SoundSwitchCC { public toneId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.toneId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -649,9 +650,9 @@ export class SoundSwitchCCConfigurationSet extends SoundSwitchCC { public defaultVolume: number; public defaultToneId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.defaultVolume, this.defaultToneId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -698,9 +699,9 @@ export class SoundSwitchCCConfigurationReport extends SoundSwitchCC { @ccValue(SoundSwitchCCValues.defaultToneId) public defaultToneId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.defaultVolume, this.defaultToneId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -750,9 +751,9 @@ export class SoundSwitchCCTonePlaySet extends SoundSwitchCC { public toneId: ToneId | number; public volume?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.toneId, this.volume ?? 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index a20721ae44f3..fd8adc44d865 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, Duration, EncapsulationFlags, @@ -145,6 +146,7 @@ export class SupervisionCC extends CommandClass { public static encapsulate( host: ZWaveHost, cc: CommandClass, + sessionId: number, requestStatusUpdates: boolean = true, ): SupervisionCCGet { if (!cc.isSinglecast()) { @@ -159,6 +161,7 @@ export class SupervisionCC extends CommandClass { // Supervision CC is wrapped inside MultiChannel CCs, so the endpoint must be copied endpoint: cc.endpointIndex, encapsulated: cc, + sessionId, requestStatusUpdates, }); @@ -321,7 +324,7 @@ export class SupervisionCCReport extends SupervisionCC { public readonly status: SupervisionStatus; public readonly duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([ (this.moreUpdatesFollow ? 0b1_0_000000 : 0) @@ -337,7 +340,7 @@ export class SupervisionCCReport extends SupervisionCC { Buffer.from([this.duration.serializeReport()]), ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -373,6 +376,7 @@ export class SupervisionCCReport extends SupervisionCC { export interface SupervisionCCGetOptions extends CCCommandOptions { requestStatusUpdates: boolean; encapsulated: CommandClass; + sessionId: number; } function testResponseForSupervisionCCGet( @@ -400,9 +404,10 @@ export class SupervisionCCGet extends SupervisionCC { fromEncapsulation: true, encapCC: this, origin: options.origin, + context: options.context, }); } else { - this.sessionId = host.getNextSupervisionSessionId(this.nodeId); + this.sessionId = options.sessionId; this.requestStatusUpdates = options.requestStatusUpdates; this.encapsulated = options.encapsulated; options.encapsulated.encapsulatingCC = this as any; @@ -413,8 +418,8 @@ export class SupervisionCCGet extends SupervisionCC { public sessionId: number; public encapsulated: CommandClass; - public serialize(): Buffer { - const encapCC = this.encapsulated.serialize(); + public serialize(ctx: CCEncodingContext): Buffer { + const encapCC = this.encapsulated.serialize(ctx); this.payload = Buffer.concat([ Buffer.from([ (this.requestStatusUpdates ? 0b10_000000 : 0) @@ -423,7 +428,7 @@ export class SupervisionCCGet extends SupervisionCC { ]), encapCC, ]); - return super.serialize(); + return super.serialize(ctx); } protected computeEncapsulationOverhead(): number { diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index 58f1366f8fe2..a9ac85577a04 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -364,12 +365,12 @@ export class ThermostatFanModeCCSet extends ThermostatFanModeCC { public mode: ThermostatFanMode; public off: boolean | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ (this.off ? 0b1000_0000 : 0) | (this.mode & 0b1111), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index 889785adb564..de1caf2c039c 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -356,7 +357,7 @@ export class ThermostatModeCCSet extends ThermostatModeCC { public mode: ThermostatMode; public manufacturerData?: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const manufacturerData = this.mode === ThermostatMode["Manufacturer specific"] && this.manufacturerData @@ -369,7 +370,7 @@ export class ThermostatModeCCSet extends ThermostatModeCC { ]), manufacturerData, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -475,7 +476,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { @ccValue(ThermostatModeCCValues.manufacturerData) public readonly manufacturerData: Buffer | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const manufacturerDataLength = this.mode === ThermostatMode["Manufacturer specific"] && this.manufacturerData @@ -491,7 +492,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { manufacturerDataLength, ); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -557,13 +558,13 @@ export class ThermostatModeCCSupportedReport extends ThermostatModeCC { @ccValue(ThermostatModeCCValues.supportedModes) public readonly supportedModes: ThermostatMode[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeBitMask( this.supportedModes, ThermostatMode["Manufacturer specific"], ThermostatMode.Off, ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 6aee139733fc..be0bf10c97b7 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -1,11 +1,10 @@ -import type { - MessageOrCCLogEntry, - SupervisionResult, -} from "@zwave-js/core/safe"; import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, + type MessageOrCCLogEntry, MessagePriority, + type SupervisionResult, ValueMetadata, ZWaveError, ZWaveErrorCodes, @@ -232,12 +231,12 @@ export class ThermostatSetbackCCSet extends ThermostatSetbackCC { /** The offset from the setpoint in 0.1 Kelvin or a special mode */ public setbackState: SetbackState; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.setbackType & 0b11, encodeSetbackState(this.setbackState), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 1ea7f07f79b9..a1c5a234a6bc 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -649,7 +650,7 @@ export class ThermostatSetpointCCSet extends ThermostatSetpointCC { public value: number; public scale: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // If a config file overwrites how the float should be encoded, use that information const override = this.host.getDeviceConfig?.(this.nodeId as number) ?.compat?.overrideFloatEncoding; @@ -657,7 +658,7 @@ export class ThermostatSetpointCCSet extends ThermostatSetpointCC { Buffer.from([this.setpointType & 0b1111]), encodeFloatWithScale(this.value, this.scale, override), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -748,12 +749,12 @@ export class ThermostatSetpointCCReport extends ThermostatSetpointCC { public scale: number; public value: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.type & 0b1111]), encodeFloatWithScale(this.value, this.scale), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -807,9 +808,9 @@ export class ThermostatSetpointCCGet extends ThermostatSetpointCC { public setpointType: ThermostatSetpointType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.setpointType & 0b1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -891,11 +892,11 @@ export class ThermostatSetpointCCCapabilitiesReport public minValueScale: number; public maxValueScale: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const min = encodeFloatWithScale(this.minValue, this.minValueScale); const max = encodeFloatWithScale(this.maxValue, this.maxValueScale); this.payload = Buffer.concat([Buffer.from([this.type]), min, max]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -942,9 +943,9 @@ export class ThermostatSetpointCCCapabilitiesGet extends ThermostatSetpointCC { public setpointType: ThermostatSetpointType; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.setpointType & 0b1111]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1018,7 +1019,7 @@ export class ThermostatSetpointCCSupportedReport extends ThermostatSetpointCC { @ccValue(ThermostatSetpointCCValues.supportedSetpointTypes) public readonly supportedSetpointTypes: readonly ThermostatSetpointType[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeBitMask( // Encode as interpretation A this.supportedSetpointTypes @@ -1027,7 +1028,7 @@ export class ThermostatSetpointCCSupportedReport extends ThermostatSetpointCC { undefined, ThermostatSetpointType["N/A"], ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 313f515b9a19..26891e3d7766 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -10,7 +10,10 @@ import { getDSTInfo, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type MaybeNotKnown, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -261,13 +264,13 @@ export class TimeCCTimeReport extends TimeCC { public minute: number; public second: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.hour & 0b11111, this.minute, this.second, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -320,7 +323,7 @@ export class TimeCCDateReport extends TimeCC { public month: number; public day: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ // 2 bytes placeholder for year 0, @@ -329,7 +332,7 @@ export class TimeCCDateReport extends TimeCC { this.day, ]); this.payload.writeUInt16BE(this.year, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -389,7 +392,7 @@ export class TimeCCTimeOffsetSet extends TimeCC { public dstStartDate: Date; public dstEndDate: Date; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ encodeTimezone({ standardOffset: this.standardOffset, @@ -404,7 +407,7 @@ export class TimeCCTimeOffsetSet extends TimeCC { this.dstEndDate.getUTCHours(), ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -473,7 +476,7 @@ export class TimeCCTimeOffsetReport extends TimeCC { public dstStartDate: Date; public dstEndDate: Date; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ encodeTimezone({ standardOffset: this.standardOffset, @@ -488,7 +491,7 @@ export class TimeCCTimeOffsetReport extends TimeCC { this.dstEndDate.getUTCHours(), ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 4dde6937e4d5..220db50f94ab 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -8,6 +8,7 @@ import { validatePayload, } from "@zwave-js/core"; import { + type CCEncodingContext, type ControlsCC, type EndpointId, type MaybeNotKnown, @@ -373,7 +374,7 @@ export class TimeParametersCCSet extends TimeParametersCC { public dateAndTime: Date; private useLocalTime?: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const dateSegments = dateToSegments( this.dateAndTime, !!this.useLocalTime, @@ -389,7 +390,7 @@ export class TimeParametersCCSet extends TimeParametersCC { dateSegments.second, ]); this.payload.writeUInt16BE(dateSegments.year, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/TransportServiceCC.ts b/packages/cc/src/cc/TransportServiceCC.ts index 15f7c766b1cc..35ee6ac9ae3b 100644 --- a/packages/cc/src/cc/TransportServiceCC.ts +++ b/packages/cc/src/cc/TransportServiceCC.ts @@ -1,4 +1,6 @@ import { + type CCEncodingContext, + type CCParsingContext, CRC16_CCITT, CommandClasses, type MessageOrCCLogEntry, @@ -171,7 +173,7 @@ export class TransportServiceCCFirstSegment extends TransportServiceCC { public partialDatagram: Buffer; public encapsulated!: CommandClass; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Transport Service re-uses the lower 3 bits of the ccCommand as payload this.ccCommand = (this.ccCommand & 0b11111_000) | ((this.datagramSize >>> 8) & 0b111); @@ -202,7 +204,7 @@ export class TransportServiceCCFirstSegment extends TransportServiceCC { // Write the checksum into the last two bytes of the payload this.payload.writeUInt16BE(crc, this.payload.length - 2); - return super.serialize(); + return super.serialize(ctx); } public expectMoreMessages(): boolean { @@ -352,6 +354,7 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { TransportServiceCCFirstSegment, ...TransportServiceCCSubsequentSegment[], ], + ctx: CCParsingContext, ): void { // Concat the CC buffers const datagram = Buffer.allocUnsafe(this.datagramSize); @@ -374,10 +377,11 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { data: datagram, fromEncapsulation: true, encapCC: this, + context: ctx, }); } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { // Transport Service re-uses the lower 3 bits of the ccCommand as payload this.ccCommand = (this.ccCommand & 0b11111_000) | ((this.datagramSize >>> 8) & 0b111); @@ -411,7 +415,7 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { // Write the checksum into the last two bytes of the payload this.payload.writeUInt16BE(crc, this.payload.length - 2); - return super.serialize(); + return super.serialize(ctx); } protected computeEncapsulationOverhead(): number { @@ -487,13 +491,13 @@ export class TransportServiceCCSegmentRequest extends TransportServiceCC { public sessionId: number; public datagramOffset: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ ((this.sessionId & 0b1111) << 4) | ((this.datagramOffset >>> 8) & 0b111), this.datagramOffset & 0xff, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -533,9 +537,9 @@ export class TransportServiceCCSegmentComplete extends TransportServiceCC { public sessionId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([(this.sessionId & 0b1111) << 4]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -570,9 +574,9 @@ export class TransportServiceCCSegmentWait extends TransportServiceCC { public pendingSegments: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.pendingSegments]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 0a695c9aafc2..574cd7f93dd4 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -1288,14 +1289,14 @@ export class UserCodeCCSet extends UserCodeCC { public userIdStatus: UserIDStatus; public userCode: string | Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.userId, this.userIdStatus]), typeof this.userCode === "string" ? Buffer.from(this.userCode, "ascii") : this.userCode, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1387,7 +1388,7 @@ export class UserCodeCCReport extends UserCodeCC return true; } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { let userCodeBuffer: Buffer; if (typeof this.userCode === "string") { userCodeBuffer = Buffer.from(this.userCode, "ascii"); @@ -1399,7 +1400,7 @@ export class UserCodeCCReport extends UserCodeCC Buffer.from([this.userId, this.userIdStatus]), userCodeBuffer, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1442,9 +1443,9 @@ export class UserCodeCCGet extends UserCodeCC { public userId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.userId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1487,12 +1488,12 @@ export class UserCodeCCUsersNumberReport extends UserCodeCC { @ccValue(UserCodeCCValues.supportedUsers) public readonly supportedUsers: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(3); // If the node implements more than 255 users, this field MUST be set to 255 this.payload[0] = Math.min(255, this.supportedUsers); this.payload.writeUInt16BE(this.supportedUsers, 1); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1622,7 +1623,7 @@ export class UserCodeCCCapabilitiesReport extends UserCodeCC { @ccValue(UserCodeCCValues.supportedASCIIChars) public readonly supportedASCIIChars: string; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const supportedStatusesBitmask = encodeBitMask( this.supportedUserIDStatuses, undefined, @@ -1656,7 +1657,7 @@ export class UserCodeCCCapabilitiesReport extends UserCodeCC { Buffer.from([controlByte3]), supportedKeysBitmask, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1715,9 +1716,9 @@ export class UserCodeCCKeypadModeSet extends UserCodeCC { public keypadMode: KeypadMode; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.keypadMode]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1774,9 +1775,9 @@ export class UserCodeCCKeypadModeReport extends UserCodeCC { @ccValue(UserCodeCCValues.keypadMode) public readonly keypadMode: KeypadMode; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.keypadMode]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1822,12 +1823,12 @@ export class UserCodeCCAdminCodeSet extends UserCodeCC { public adminCode: string; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.adminCode.length & 0b1111]), Buffer.from(this.adminCode, "ascii"), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1867,12 +1868,12 @@ export class UserCodeCCAdminCodeReport extends UserCodeCC { @ccValue(UserCodeCCValues.adminCode) public readonly adminCode: string; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.adminCode.length & 0b1111]), Buffer.from(this.adminCode, "ascii"), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1914,10 +1915,10 @@ export class UserCodeCCUserCodeChecksumReport extends UserCodeCC { @ccValue(UserCodeCCValues.userCodeChecksum) public readonly userCodeChecksum: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(2); this.payload.writeUInt16BE(this.userCodeChecksum, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1966,7 +1967,7 @@ export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { public userCodes: UserCodeCCSetOptions[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const userCodeBuffers = this.userCodes.map((code) => { const ret = Buffer.concat([ Buffer.from([ @@ -1986,7 +1987,7 @@ export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { Buffer.from([this.userCodes.length]), ...userCodeBuffers, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -2096,10 +2097,10 @@ export class UserCodeCCExtendedUserCodeGet extends UserCodeCC { public userId: number; public reportMore: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([0, 0, this.reportMore ? 1 : 0]); this.payload.writeUInt16BE(this.userId, 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index e2507f3b6f28..bb0c700db0c3 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -730,7 +731,7 @@ export class VersionCCReport extends VersionCC { @ccValue(VersionCCValues.hardwareVersion) public readonly hardwareVersion: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.libraryType, ...this.protocolVersion @@ -759,7 +760,7 @@ export class VersionCCReport extends VersionCC { this.payload = Buffer.concat([this.payload, firmwaresBuffer]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -813,9 +814,9 @@ export class VersionCCCommandClassReport extends VersionCC { public ccVersion: number; public requestedCC: CommandClasses; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.requestedCC, this.ccVersion]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -865,9 +866,9 @@ export class VersionCCCommandClassGet extends VersionCC { public requestedCC: CommandClasses; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.requestedCC]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -905,11 +906,11 @@ export class VersionCCCapabilitiesReport extends VersionCC { @ccValue(VersionCCValues.supportsZWaveSoftwareGet) public supportsZWaveSoftwareGet: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ (this.supportsZWaveSoftwareGet ? 0b100 : 0) | 0b11, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index de909727c4c5..5b01c972a56e 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -382,7 +383,7 @@ export class WakeUpCCIntervalSet extends WakeUpCC { public wakeUpInterval: number; public controllerNodeId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ 0, 0, @@ -390,7 +391,7 @@ export class WakeUpCCIntervalSet extends WakeUpCC { this.controllerNodeId, ]); this.payload.writeUIntBE(this.wakeUpInterval, 0, 3); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 89bc21460af0..a7a39a5e90e0 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -10,7 +10,10 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import { + type CCEncodingContext, + type MaybeNotKnown, +} from "@zwave-js/core/safe"; import type { ZWaveApplicationHost, ZWaveHost, @@ -715,7 +718,7 @@ export class WindowCoveringCCSupportedReport extends WindowCoveringCC { @ccValue(WindowCoveringCCValues.supportedParameters) public readonly supportedParameters: readonly WindowCoveringParameter[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const bitmask = encodeBitMask( this.supportedParameters, undefined, @@ -728,7 +731,7 @@ export class WindowCoveringCCSupportedReport extends WindowCoveringCC { bitmask.subarray(0, numBitmaskBytes), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -836,9 +839,9 @@ export class WindowCoveringCCGet extends WindowCoveringCC { public parameter: WindowCoveringParameter; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.parameter]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -903,7 +906,7 @@ export class WindowCoveringCCSet extends WindowCoveringCC { }[]; public duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const numEntries = this.targetValues.length & 0b11111; this.payload = Buffer.allocUnsafe(2 + numEntries * 2); @@ -918,7 +921,7 @@ export class WindowCoveringCCSet extends WindowCoveringCC { this.duration ?? Duration.default() ).serializeSet(); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -975,13 +978,13 @@ export class WindowCoveringCCStartLevelChange extends WindowCoveringCC { public direction: keyof typeof LevelChangeDirection; public duration: Duration | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.direction === "up" ? 0b0100_0000 : 0b0000_0000, this.parameter, (this.duration ?? Duration.default()).serializeSet(), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { @@ -1029,9 +1032,9 @@ export class WindowCoveringCCStopLevelChange extends WindowCoveringCC { public parameter: WindowCoveringParameter; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.parameter]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index 2d69fea59d7a..444bb813a869 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -216,7 +217,7 @@ export class ZWavePlusCCReport extends ZWavePlusCC { @ccValue(ZWavePlusCCValues.userIcon) public userIcon: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.zwavePlusVersion, this.roleType, @@ -229,7 +230,7 @@ export class ZWavePlusCCReport extends ZWavePlusCC { ]); this.payload.writeUInt16BE(this.installerIcon, 3); this.payload.writeUInt16BE(this.userIcon, 5); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/cc/ZWaveProtocolCC.ts b/packages/cc/src/cc/ZWaveProtocolCC.ts index 35517512bb2d..de7b0cc5f4a2 100644 --- a/packages/cc/src/cc/ZWaveProtocolCC.ts +++ b/packages/cc/src/cc/ZWaveProtocolCC.ts @@ -1,5 +1,6 @@ import { type BasicDeviceClass, + type CCEncodingContext, CommandClasses, type DataRate, type FLiRS, @@ -23,7 +24,6 @@ import { import type { ZWaveHost } from "@zwave-js/host"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, gotDeserializationOptions, @@ -122,9 +122,9 @@ export class ZWaveProtocolCCNodeInformationFrame extends ZWaveProtocolCC public supportsBeaming: boolean; public supportedCCs: CommandClasses[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = encodeNodeInformationFrame(this); - return super.serialize(); + return super.serialize(ctx); } } @@ -162,11 +162,11 @@ export class ZWaveProtocolCCAssignIDs extends ZWaveProtocolCC { public assignedNodeId: number; public homeId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(5); this.payload[0] = this.assignedNodeId; this.payload.writeUInt32BE(this.homeId, 1); - return super.serialize(); + return super.serialize(ctx); } } @@ -228,7 +228,7 @@ export class ZWaveProtocolCCFindNodesInRange extends ZWaveProtocolCC { public wakeUpTime: WakeUpTime; public dataRate: ZWaveDataRate; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const nodesBitmask = encodeBitMask(this.candidateNodeIds, MAX_NODES); const speedAndLength = 0b1000_0000 | nodesBitmask.length; this.payload = Buffer.concat([ @@ -236,7 +236,7 @@ export class ZWaveProtocolCCFindNodesInRange extends ZWaveProtocolCC { nodesBitmask, Buffer.from([this.wakeUpTime, this.dataRate]), ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -277,7 +277,7 @@ export class ZWaveProtocolCCRangeInfo extends ZWaveProtocolCC { public neighborNodeIds: number[]; public wakeUpTime?: WakeUpTime; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const nodesBitmask = encodeBitMask(this.neighborNodeIds, MAX_NODES); this.payload = Buffer.concat([ Buffer.from([nodesBitmask.length]), @@ -286,7 +286,7 @@ export class ZWaveProtocolCCRangeInfo extends ZWaveProtocolCC { ? Buffer.from([this.wakeUpTime]) : Buffer.alloc(0), ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -320,9 +320,9 @@ export class ZWaveProtocolCCCommandComplete extends ZWaveProtocolCC { public sequenceNumber: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sequenceNumber]); - return super.serialize(); + return super.serialize(ctx); } } @@ -367,13 +367,13 @@ export class ZWaveProtocolCCTransferPresentation extends ZWaveProtocolCC { public includeNode: boolean; public excludeNode: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ (this.supportsNWI ? 0b0001 : 0) | (this.excludeNode ? 0b0010 : 0) | (this.includeNode ? 0b0100 : 0), ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -440,12 +440,12 @@ export class ZWaveProtocolCCTransferNodeInformation extends ZWaveProtocolCC public supportsSecurity: boolean; public supportsBeaming: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.sequenceNumber, this.sourceNodeId]), encodeNodeProtocolInfoAndDeviceClass(this), ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -487,7 +487,7 @@ export class ZWaveProtocolCCTransferRangeInformation extends ZWaveProtocolCC { public testedNodeId: number; public neighborNodeIds: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const nodesBitmask = encodeBitMask(this.neighborNodeIds, MAX_NODES); this.payload = Buffer.concat([ Buffer.from([ @@ -497,7 +497,7 @@ export class ZWaveProtocolCCTransferRangeInformation extends ZWaveProtocolCC { ]), nodesBitmask, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -525,9 +525,9 @@ export class ZWaveProtocolCCTransferEnd extends ZWaveProtocolCC { public status: NetworkTransferStatus; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.status]); - return super.serialize(); + return super.serialize(ctx); } } @@ -584,7 +584,7 @@ export class ZWaveProtocolCCAssignReturnRoute extends ZWaveProtocolCC { public destinationWakeUp: WakeUpTime; public destinationSpeed: ZWaveDataRate; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const routeByte = (this.routeIndex << 4) | this.repeaters.length; const speedMask = dataRate2Bitmask(this.destinationSpeed); const speedByte = (speedMask << 3) | (this.destinationWakeUp << 1); @@ -594,7 +594,7 @@ export class ZWaveProtocolCCAssignReturnRoute extends ZWaveProtocolCC { ...this.repeaters, speedByte, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -657,12 +657,12 @@ export class ZWaveProtocolCCNewNodeRegistered extends ZWaveProtocolCC public supportsBeaming: boolean; public supportedCCs: CommandClasses[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.newNodeId]), encodeNodeInformationFrame(this), ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -699,13 +699,13 @@ export class ZWaveProtocolCCNewRangeRegistered extends ZWaveProtocolCC { public testedNodeId: number; public neighborNodeIds: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const nodesBitmask = encodeBitMask(this.neighborNodeIds, MAX_NODES); this.payload = Buffer.concat([ Buffer.from([this.testedNodeId, nodesBitmask.length]), nodesBitmask, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -737,9 +737,9 @@ export class ZWaveProtocolCCTransferNewPrimaryControllerComplete public genericDeviceClass: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.genericDeviceClass]); - return super.serialize(); + return super.serialize(ctx); } } @@ -777,9 +777,9 @@ export class ZWaveProtocolCCSUCNodeID extends ZWaveProtocolCC { public sucNodeId: number; public isSIS: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.sucNodeId, this.isSIS ? 0b1 : 0]); - return super.serialize(); + return super.serialize(ctx); } } @@ -809,9 +809,9 @@ export class ZWaveProtocolCCSetSUC extends ZWaveProtocolCC { public enableSIS: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([0x01, this.enableSIS ? 0b1 : 0]); - return super.serialize(); + return super.serialize(ctx); } } @@ -844,12 +844,12 @@ export class ZWaveProtocolCCSetSUCAck extends ZWaveProtocolCC { public accepted: boolean; public isSIS: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.accepted ? 0x01 : 0x00, this.isSIS ? 0b1 : 0, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -892,12 +892,12 @@ export class ZWaveProtocolCCStaticRouteRequest extends ZWaveProtocolCC { public nodeIds: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.alloc(5, 0); for (let i = 0; i < this.nodeIds.length && i < 5; i++) { this.payload[i] = this.nodeIds[i]; } - return super.serialize(); + return super.serialize(ctx); } } @@ -925,9 +925,9 @@ export class ZWaveProtocolCCLost extends ZWaveProtocolCC { public lostNodeId: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.lostNodeId]); - return super.serialize(); + return super.serialize(ctx); } } @@ -958,9 +958,9 @@ export class ZWaveProtocolCCAcceptLost extends ZWaveProtocolCC { public accepted: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.accepted ? 0x05 : 0x04]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1018,9 +1018,9 @@ export class ZWaveProtocolCCNOPPower extends ZWaveProtocolCC { // Power dampening in (negative) dBm. A value of 2 means -2 dBm. public powerDampening: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([0, this.powerDampening]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1052,12 +1052,12 @@ export class ZWaveProtocolCCReservedIDs extends ZWaveProtocolCC { public reservedNodeIDs: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.reservedNodeIDs.length, ...this.reservedNodeIDs, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1086,9 +1086,9 @@ export class ZWaveProtocolCCReserveNodeIDs extends ZWaveProtocolCC { public numNodeIDs: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.numNodeIDs]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1122,12 +1122,12 @@ export class ZWaveProtocolCCNodesExistReply extends ZWaveProtocolCC { public nodeMaskType: number; public nodeListUpdated: boolean; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.nodeMaskType, this.nodeListUpdated ? 0x01 : 0x00, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1172,13 +1172,13 @@ export class ZWaveProtocolCCNodesExist extends ZWaveProtocolCC { public nodeMaskType: number; public nodeIDs: number[]; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.nodeMaskType, this.nodeIDs.length, ...this.nodeIDs, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1210,12 +1210,12 @@ export class ZWaveProtocolCCSetNWIMode extends ZWaveProtocolCC { public enabled: boolean; public timeoutMinutes?: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([ this.enabled ? 0x01 : 0x00, this.timeoutMinutes ?? 0x00, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1254,9 +1254,9 @@ export class ZWaveProtocolCCAssignReturnRoutePriority extends ZWaveProtocolCC { public targetNodeId: number; public routeNumber: number; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from([this.targetNodeId, this.routeNumber]); - return super.serialize(); + return super.serialize(ctx); } } @@ -1299,9 +1299,9 @@ export class ZWaveProtocolCCSmartStartIncludedNodeInformation public nwiHomeId: Buffer; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { this.payload = Buffer.from(this.nwiHomeId); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 1fdb364fbd63..9c5ceda98dc7 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -1,4 +1,5 @@ import { + type CCEncodingContext, CommandClasses, type MaybeUnknown, type MessageOrCCLogEntry, @@ -282,7 +283,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { } } - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { if (this.fibaroCCId == undefined) { throw new ZWaveError( "Cannot serialize a Fibaro CC without a Fibaro CC ID", @@ -298,7 +299,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { Buffer.from([this.fibaroCCId, this.fibaroCCCommand]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -414,7 +415,7 @@ export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { public position: number | undefined; public tilt: number | undefined; - public serialize(): Buffer { + public serialize(ctx: CCEncodingContext): Buffer { const controlByte = (this.position != undefined ? 0b10 : 0) | (this.tilt != undefined ? 0b01 : 0); this.payload = Buffer.from([ @@ -422,7 +423,7 @@ export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { this.position ?? 0, this.tilt ?? 0, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 3404458f0616..691df0c94bed 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -1,5 +1,7 @@ import { type BroadcastCC, + type CCEncodingContext, + type CCParsingContext, CommandClasses, type ControlsCC, EncapsulationFlags, @@ -79,8 +81,7 @@ export type CommandClassDeserializationOptions = & { data: Buffer; origin?: MessageOrigin; - /** If known, the frame type of the containing message */ - frameType?: FrameType; + context: CCParsingContext; } & ( | { @@ -185,7 +186,7 @@ export class CommandClass implements ICommandClass { this.nodeId = options.nodeId; } - this.frameType = options.frameType; + this.frameType = options.context.frameType; ({ ccId: this.ccId, @@ -358,7 +359,8 @@ export class CommandClass implements ICommandClass { /** * Serializes this CommandClass to be embedded in a message payload or another CC */ - public serialize(): Buffer { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public serialize(ctx: CCEncodingContext): Buffer { // NoOp CCs have no command and no payload if (this.ccId === CommandClasses["No Operation"]) { return Buffer.from([this.ccId]); @@ -1011,10 +1013,10 @@ export class CommandClass implements ICommandClass { } /** Include previously received partial responses into a final CC */ - /* istanbul ignore next */ public mergePartialCCs( _applHost: ZWaveApplicationHost, _partials: CommandClass[], + _ctx: CCParsingContext, ): void { // This is highly CC dependent // Overwrite this in derived classes, by default do nothing diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts index 392c485d6d1e..d6e1255dfc49 100644 --- a/packages/core/src/abstractions/ICommandClass.ts +++ b/packages/core/src/abstractions/ICommandClass.ts @@ -1,16 +1,58 @@ import type { CommandClasses } from "../capabilities/CommandClasses"; import type { + FrameType, MulticastDestination, NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, } from "../consts"; +import { type SecurityClass } from "../security/SecurityClass"; +import { type MaybeNotKnown } from "../values/Primitive"; + +/** Additional context needed for deserializing CCs */ +export interface CCParsingContext { + sourceNodeId: number; + ownNodeId: number; + + /** If known, the frame type of the containing message */ + frameType?: FrameType; + + getHighestSecurityClass(nodeId: number): MaybeNotKnown; + + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown; + + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void; +} + +/** Additional context needed for serializing CCs */ +// FIXME: Lot of duplication between the CC and message contexts +export interface CCEncodingContext { + getHighestSecurityClass(nodeId: number): MaybeNotKnown; + + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown; + + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void; +} /** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ export interface ICommandClass { ccId: CommandClasses; ccCommand?: number; - serialize(): Buffer; + serialize(ctx: CCEncodingContext): Buffer; nodeId: number | MulticastDestination; expectsCCResponse(): boolean; isExpectedCCResponse(received: ICommandClass): boolean; diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 2b7687ef4cdd..4535b01300d6 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -3,10 +3,8 @@ import type { CommandClasses, ControllerLogger, ICommandClass, - MaybeNotKnown, NodeIDType, NodeId, - SecurityClass, SecurityManager, SecurityManager2, SendCommandOptions, @@ -16,22 +14,40 @@ import type { } from "@zwave-js/core"; import type { ZWaveHostOptions } from "./ZWaveHostOptions"; -/** Host application abstractions to be used in Serial API and CC implementations */ -export interface ZWaveHost { +/** Allows querying the home ID and node ID of the host */ +export interface HostIDs { /** The ID of this node in the current network */ ownNodeId: number; /** The Home ID of the current network */ homeId: number; +} - /** How many bytes a node ID occupies in serial API commands */ - readonly nodeIdType?: NodeIDType; - +/** Allows accessing the security manager instances */ +export interface SecurityManagers { /** Management of Security S0 keys and nonces */ - securityManager: SecurityManager | undefined; + readonly securityManager: SecurityManager | undefined; /** Management of Security S2 keys and nonces (Z-Wave Classic) */ - securityManager2: SecurityManager2 | undefined; + readonly securityManager2: SecurityManager2 | undefined; /** Management of Security S2 keys and nonces (Z-Wave Long Range) */ - securityManagerLR: SecurityManager2 | undefined; + readonly securityManagerLR: SecurityManager2 | undefined; +} + +// FIXME: This should not be needed. Instead have the driver set callback IDs during sendMessage +/** Allows generating a new callback ID */ +export interface GetNextCallbackId { + /** + * Returns the next callback ID. Callback IDs are used to correlate requests + * to the controller/nodes with its response + */ + getNextCallbackId(): number; +} + +/** Host application abstractions to be used in Serial API and CC implementations */ +export interface ZWaveHost + extends HostIDs, SecurityManagers, GetNextCallbackId +{ + /** How many bytes a node ID occupies in serial API commands */ + readonly nodeIdType?: NodeIDType; /** * Retrieves the maximum version of a command class that can be used to communicate with a node. @@ -63,30 +79,6 @@ export interface ZWaveHost { endpointIndex?: number, ): boolean; - getHighestSecurityClass(nodeId: number): MaybeNotKnown; - - hasSecurityClass( - nodeId: number, - securityClass: SecurityClass, - ): MaybeNotKnown; - - setSecurityClass( - nodeId: number, - securityClass: SecurityClass, - granted: boolean, - ): void; - - /** - * Returns the next callback ID. Callback IDs are used to correlate requests - * to the controller/nodes with its response - */ - getNextCallbackId(): number; - - /** - * Returns the next session ID for supervised communication - */ - getNextSupervisionSessionId(nodeId: number): number; - getDeviceConfig?: (nodeId: number) => DeviceConfig | undefined; __internalIsMockNode?: boolean; diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index bb618b237c6a..ca4fde2e9296 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -1,9 +1,13 @@ /* eslint-disable @typescript-eslint/require-await */ import { ConfigManager } from "@zwave-js/config"; import { - type IZWaveNode, - MAX_SUPERVISION_SESSION_ID, + type EndpointId, + type GetEndpoint, + type IsCCSecure, NodeIDType, + type NodeId, + type QuerySecurityClasses, + type SetSecurityClass, ValueDB, ZWaveError, ZWaveErrorCodes, @@ -18,27 +22,41 @@ export interface CreateTestingHostOptions { getSupportedCCVersion?: ZWaveHost["getSupportedCCVersion"]; } -export type TestingHost = Omit< - ZWaveApplicationHost, - "__internalIsMockNode" ->; +export type BaseTestNode = + & NodeId + & QuerySecurityClasses + & SetSecurityClass + & IsCCSecure + & GetEndpoint; + +export type TestingHost< + TNode extends BaseTestNode, +> = + & Omit< + ZWaveApplicationHost, + "__internalIsMockNode" + > + & { + setNode(nodeId: number, node: TNode): void; + }; /** Creates a {@link ZWaveApplicationHost} that can be used for testing */ -export function createTestingHost( +export function createTestingHost< + TNode extends BaseTestNode, +>( options: Partial = {}, -): TestingHost { +): TestingHost { const valuesStorage = new Map(); const metadataStorage = new Map(); const valueDBCache = new Map(); - const supervisionSessionIDs = new Map number>(); - const nodes = createThrowingMap((nodeId) => { + const nodes = createThrowingMap((nodeId) => { throw new ZWaveError( `Node ${nodeId} was not found!`, ZWaveErrorCodes.Controller_NodeNotFound, ); }); - const ret: TestingHost = { + const ret: TestingHost = { homeId: options.homeId ?? 0x7e570001, ownNodeId: options.ownNodeId ?? 1, nodeIdType: NodeIDType.Short, @@ -67,29 +85,23 @@ export function createTestingHost( refreshValueAfterTransition: 1000, }, }, - getNode(nodeId: number) { + getNode(nodeId) { return nodes.get(nodeId); }, - getNodeOrThrow(nodeId: number) { + getNodeOrThrow(nodeId) { return nodes.getOrThrow(nodeId); }, getAllNodes() { return [...nodes.values()]; }, + setNode(nodeId, node) { + nodes.set(nodeId, node); + }, getSafeCCVersion: options.getSafeCCVersion ?? (() => 100), getSupportedCCVersion: options.getSupportedCCVersion ?? options.getSafeCCVersion ?? (() => 100), getNextCallbackId: createWrappingCounter(0xff), - 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( @@ -115,18 +127,18 @@ export function createTestingHost( && !!(ret.securityManager || ret.securityManager2) ); }, - 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); - }, + // 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; }, diff --git a/packages/serial/src/message/Message.test.ts b/packages/serial/src/message/Message.test.ts index 72be3ca3b0af..181e91f86d3a 100644 --- a/packages/serial/src/message/Message.test.ts +++ b/packages/serial/src/message/Message.test.ts @@ -51,7 +51,7 @@ test("should serialize correctly when the payload is null", (t) => { const expected = Buffer.from([0x01, 0x03, 0x00, 0xff, 0x03]); const message = new Message(host, { type: MessageType.Request, - functionType: 0xff, + functionType: 0xff as any, }); t.deepEqual(message.serialize(), expected); }); @@ -309,12 +309,16 @@ test("getConstructor() should return `Message` for an unknown packet type", (t) test(`the constructor should throw when no message type is specified`, (t) => { const host = createTestingHost(); - assertZWaveError(t, () => new Message(host, { functionType: 0xff }), { - errorCode: ZWaveErrorCodes.Argument_Invalid, - messageMatches: /message type/i, - }); + assertZWaveError( + t, + () => new Message(host, { functionType: 0xff as any }), + { + errorCode: ZWaveErrorCodes.Argument_Invalid, + messageMatches: /message type/i, + }, + ); - @messageTypes(undefined as any, 0xff) + @messageTypes(undefined as any, 0xff as any) class FakeMessageWithoutMessageType extends Message {} assertZWaveError(t, () => new FakeMessageWithoutMessageType(host), { @@ -347,7 +351,7 @@ test("getNodeUnsafe() returns undefined when the controller is not initialized y const host = createTestingHost(); const msg = new Message(host, { type: MessageType.Request, - functionType: 0xff, + functionType: 0xff as any, }); t.is(msg.getNodeUnsafe(host), undefined); }); @@ -356,23 +360,23 @@ test("getNodeUnsafe() returns undefined when the message is no node query", (t) const host = createTestingHost(); const msg = new Message(host, { type: MessageType.Request, - functionType: 0xff, + functionType: 0xff as any, }); t.is(msg.getNodeUnsafe(host), undefined); }); test("getNodeUnsafe() returns the associated node otherwise", (t) => { const host = createTestingHost(); - host.nodes.set(1, {} as any); + host.setNode(1, {} as any); const msg = new Message(host, { type: MessageType.Request, - functionType: 0xff, + functionType: 0xff as any, }); // This node exists (msg as any as INodeQuery).nodeId = 1; - t.is(msg.getNodeUnsafe(host), host.nodes.get(1)); + t.is(msg.getNodeUnsafe(host), host.getNode(1)); // This one does (msg as any as INodeQuery).nodeId = 2; diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index f5e76b4ea85b..02ac86cee630 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -1,7 +1,9 @@ import { + type MaybeNotKnown, type MessageOrCCLogEntry, type MessagePriority, type NodeId, + type SecurityClass, ZWaveError, ZWaveErrorCodes, createReflectionDecorator, @@ -31,6 +33,21 @@ export enum MessageOrigin { Host, } +export interface MessageParsingContext { + getHighestSecurityClass(nodeId: number): MaybeNotKnown; + + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown; + + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void; +} + export interface MessageDeserializationOptions { data: Buffer; origin?: MessageOrigin; @@ -40,6 +57,8 @@ export interface MessageDeserializationOptions { sdkVersion?: string; /** Optional context used during deserialization */ context?: unknown; + // FIXME: This is a terrible property name when context already exists + ctx: MessageParsingContext; } /** @@ -67,6 +86,21 @@ export type MessageOptions = | MessageCreationOptions | MessageDeserializationOptions; +export interface MessageEncodingContext { + getHighestSecurityClass(nodeId: number): MaybeNotKnown; + + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown; + + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void; +} + /** * Represents a Z-Wave message for communication with the serial interface */ @@ -209,7 +243,8 @@ export class Message { } /** Serializes this message into a Buffer */ - public serialize(): Buffer { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public serialize(ctx: MessageEncodingContext): Buffer { const ret = Buffer.allocUnsafe(this.payload.length + 5); ret[0] = MessageHeaders.SOF; // length of the following data, including the checksum diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 2b26e3d4193b..18f17a09e7d8 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -1,14 +1,16 @@ -import { type ICommandClass, MAX_SUPERVISION_SESSION_ID } from "@zwave-js/core"; +import { type ICommandClass } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; import { Message, + type MessageEncodingContext, MessageHeaders, MessageOrigin, + type MessageParsingContext, SerialAPIParser, } from "@zwave-js/serial"; import type { MockPortBinding } from "@zwave-js/serial/mock"; import { AsyncQueue } from "@zwave-js/shared"; -import { TimedExpectation, createWrappingCounter } from "@zwave-js/shared/safe"; +import { TimedExpectation } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; import { randomInt } from "node:crypto"; import { @@ -49,7 +51,7 @@ export class MockController { // const valuesStorage = new Map(); // const metadataStorage = new Map(); // const valueDBCache = new Map(); - const supervisionSessionIDs = new Map number>(); + // const supervisionSessionIDs = new Map number>(); this.host = { ownNodeId: options.ownNodeId ?? 1, @@ -59,15 +61,15 @@ export class MockController { securityManagerLR: undefined, // nodes: this.nodes as any, getNextCallbackId: () => 1, - getNextSupervisionSessionId: (nodeId) => { - if (!supervisionSessionIDs.has(nodeId)) { - supervisionSessionIDs.set( - nodeId, - createWrappingCounter(MAX_SUPERVISION_SESSION_ID, true), - ); - } - return supervisionSessionIDs.get(nodeId)!(); - }, + // 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)) { @@ -78,11 +80,6 @@ export class MockController { return (endpoint ?? node).implementedCCs.get(cc)?.version ?? 0; }, isCCSecure: () => false, - // TODO: We don't care about security classes on the controller - // This is handled by the nodes hosts - getHighestSecurityClass: () => undefined, - hasSecurityClass: () => false, - setSecurityClass: () => {}, // getValueDB: (nodeId) => { // if (!valueDBCache.has(nodeId)) { // valueDBCache.set( @@ -103,9 +100,25 @@ export class MockController { ...options.capabilities, }; + this.parsingContext = { + // We don't care about security classes on the mock controller + getHighestSecurityClass: () => undefined, + hasSecurityClass: () => false, + setSecurityClass: () => {}, + }; + this.encodingContext = { + // We don't care about security classes on the mock controller + getHighestSecurityClass: () => undefined, + hasSecurityClass: () => false, + setSecurityClass: () => {}, + }; + void this.execute(); } + private parsingContext: MessageParsingContext; + private encodingContext: MessageEncodingContext; + public readonly serial: MockPortBinding; private readonly serialParser: SerialAPIParser; @@ -193,6 +206,7 @@ export class MockController { data, origin: MessageOrigin.Host, parseCCs: false, + ctx: this.parsingContext, }); this._receivedHostMessages.push(msg); if (this.autoAckHostMessages) { @@ -338,6 +352,18 @@ export class MockController { this.serial.emitData(Buffer.from([data])); } + /** Sends a raw buffer to the host/driver and expect an ACK */ + public async sendMessageToHost( + msg: Message, + delayMs?: number, + ): Promise { + const data = msg.serialize(this.encodingContext); + if (delayMs) await wait(delayMs); + this.serial.emitData(data); + // TODO: make the timeout match the configured ACK timeout + await this.expectHostACK(1000); + } + /** Sends a raw buffer to the host/driver and expect an ACK */ public async sendToHost(data: Buffer): Promise { this.serial.emitData(data); @@ -459,7 +485,10 @@ export class MockController { await wait(node.capabilities.txDelay); - const unlazy = unlazyMockZWaveFrame(frame); + const unlazy = unlazyMockZWaveFrame( + frame, + this.encodingContext, + ); onTransmit?.(unlazy); node.onControllerFrame(unlazy).catch((e) => { console.error(e); @@ -471,7 +500,10 @@ export class MockController { await wait(node.capabilities.txDelay); - const unlazy = unlazyMockZWaveFrame(frame); + const unlazy = unlazyMockZWaveFrame( + frame, + this.encodingContext, + ); onTransmit?.(unlazy); this.onNodeFrame(node, unlazy).catch((e) => { console.error(e); diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 7d869e7c5cb4..7b944cc79c5f 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -1,12 +1,5 @@ import type { CommandClass } from "@zwave-js/cc"; -import { - type CommandClassInfo, - type CommandClasses, - type MaybeNotKnown, - NOT_KNOWN, - SecurityClass, - securityClassOrder, -} from "@zwave-js/core"; +import { type CommandClassInfo, type CommandClasses } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; import { TimedExpectation } from "@zwave-js/shared"; import { isDeepStrictEqual } from "node:util"; @@ -112,46 +105,45 @@ export class MockNode { this.controller = options.controller; // A node's host is a bit more specialized than the controller's host. - const securityClasses = new Map>(); + // const securityClasses = new Map>(); this.host = { ...this.controller.host, ownNodeId: this.id, __internalIsMockNode: true, - - // Mimic the behavior of ZWaveNode, but for arbitrary node IDs - hasSecurityClass( - nodeId: number, - securityClass: SecurityClass, - ): MaybeNotKnown { - return ( - securityClasses.get(nodeId)?.get(securityClass) ?? NOT_KNOWN - ); - }, - setSecurityClass( - nodeId: number, - securityClass: SecurityClass, - granted: boolean, - ): void { - if (!securityClasses.has(nodeId)) { - securityClasses.set(nodeId, new Map()); - } - securityClasses.get(nodeId)!.set(securityClass, granted); - }, - getHighestSecurityClass( - nodeId: number, - ): MaybeNotKnown { - const map = securityClasses.get(nodeId); - if (!map?.size) return undefined; - let missingSome = false; - for (const secClass of securityClassOrder) { - if (map.get(secClass) === true) return secClass; - if (!map.has(secClass)) { - missingSome = true; - } - } - // If we don't have the info for every security class, we don't know the highest one yet - return missingSome ? undefined : SecurityClass.None; - }, + // // Mimic the behavior of ZWaveNode, but for arbitrary node IDs + // hasSecurityClass( + // nodeId: number, + // securityClass: SecurityClass, + // ): MaybeNotKnown { + // return ( + // securityClasses.get(nodeId)?.get(securityClass) ?? NOT_KNOWN + // ); + // }, + // setSecurityClass( + // nodeId: number, + // securityClass: SecurityClass, + // granted: boolean, + // ): void { + // if (!securityClasses.has(nodeId)) { + // securityClasses.set(nodeId, new Map()); + // } + // securityClasses.get(nodeId)!.set(securityClass, granted); + // }, + // getHighestSecurityClass( + // nodeId: number, + // ): MaybeNotKnown { + // const map = securityClasses.get(nodeId); + // if (!map?.size) return undefined; + // let missingSome = false; + // for (const secClass of securityClassOrder) { + // if (map.get(secClass) === true) return secClass; + // if (!map.has(secClass)) { + // missingSome = true; + // } + // } + // // If we don't have the info for every security class, we don't know the highest one yet + // return missingSome ? undefined : SecurityClass.None; + // }, }; const { diff --git a/packages/testing/src/MockZWaveFrame.ts b/packages/testing/src/MockZWaveFrame.ts index 37221f783560..1e2015300ee4 100644 --- a/packages/testing/src/MockZWaveFrame.ts +++ b/packages/testing/src/MockZWaveFrame.ts @@ -1,4 +1,5 @@ import { type CommandClass } from "@zwave-js/cc"; +import { type MessageEncodingContext } from "@zwave-js/serial"; /** * Is used to simulate communication between a {@link MockController} and a {@link MockNode}. @@ -25,7 +26,7 @@ export interface LazyMockZWaveRequestFrame { /** Whether an ACK is requested from the destination */ ackRequested: boolean; /** The Command Class contained in the frame */ - payload: CommandClass | (() => CommandClass); + payload: CommandClass | ((ctx: MessageEncodingContext) => CommandClass); } export interface MockZWaveAckFrame { @@ -44,7 +45,7 @@ export enum MockZWaveFrameType { } export function createMockZWaveRequestFrame( - payload: CommandClass | (() => CommandClass), + payload: CommandClass | ((ctx: MessageEncodingContext) => CommandClass), options: Partial> = {}, ): LazyMockZWaveRequestFrame { const { repeaters = [], ackRequested = true } = options; @@ -70,11 +71,12 @@ export function createMockZWaveAckFrame( export function unlazyMockZWaveFrame( frame: LazyMockZWaveFrame, + ctx: MessageEncodingContext, ): MockZWaveFrame { if (frame.type === MockZWaveFrameType.ACK) return frame; let payload = frame.payload; if (typeof payload === "function") { - payload = payload(); + payload = payload(ctx); } return { ...frame, diff --git a/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts b/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts index f4c18c07ed7b..9d43f4bdb535 100644 --- a/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts +++ b/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts @@ -43,7 +43,7 @@ test("associations between insecure nodes are allowed", (t) => { return false; }, }); - host.nodes.set(node2.id, node2); + host.setNode(node2.id, node2); node2.setSecurityClass(SecurityClass.S0_Legacy, false); node2.setSecurityClass(SecurityClass.S2_AccessControl, false); @@ -64,7 +64,7 @@ test("associations between insecure nodes are allowed", (t) => { return false; }, }); - host.nodes.set(node3.id, node3); + host.setNode(node3.id, node3); node3.setSecurityClass(SecurityClass.S0_Legacy, false); node3.setSecurityClass(SecurityClass.S2_AccessControl, false); diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index 3c5eb2a7f90a..08de3dbeb329 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -14,7 +14,7 @@ import { isZWaveError, } from "@zwave-js/core"; import { type ZWaveHost } from "@zwave-js/host"; -import { MessageOrigin } from "@zwave-js/serial"; +import { type MessageEncodingContext, MessageOrigin } from "@zwave-js/serial"; import { MOCK_FRAME_ACK_TIMEOUT, type MockController, @@ -23,7 +23,6 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async"; import { ApplicationCommandRequest } from "../serialapi/application/ApplicationCommandRequest"; import { type ApplicationUpdateRequest, @@ -91,13 +90,18 @@ function createLazySendDataPayload( controller: MockController, node: MockNode, msg: SendDataRequest | SendDataMulticastRequest, -): () => CommandClass { - return () => { +): (ctx: MessageEncodingContext) => CommandClass { + return (ctx: MessageEncodingContext) => { try { const cmd = CommandClass.from(node.host, { nodeId: controller.host.ownNodeId, data: msg.payload, origin: MessageOrigin.Host, + context: { + ownNodeId: controller.host.ownNodeId, + sourceNodeId: node.id, + ...ctx, + }, }); // Store the command because assertReceivedHostMessage needs it // @ts-expect-error @@ -144,7 +148,7 @@ const respondToGetControllerId: MockControllerBehavior = { homeId: host.homeId, ownNodeId: host.ownNodeId, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } }, @@ -156,7 +160,7 @@ const respondToGetSerialApiCapabilities: MockControllerBehavior = { const ret = new GetSerialApiCapabilitiesResponse(host, { ...controller.capabilities, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } }, @@ -168,7 +172,7 @@ const respondToGetControllerVersion: MockControllerBehavior = { const ret = new GetControllerVersionResponse(host, { ...controller.capabilities, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } }, @@ -180,7 +184,7 @@ const respondToGetControllerCapabilities: MockControllerBehavior = { const ret = new GetControllerCapabilitiesResponse(host, { ...controller.capabilities, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } }, @@ -195,7 +199,7 @@ const respondToGetSUCNodeId: MockControllerBehavior = { const ret = new GetSUCNodeIdResponse(host, { sucNodeId, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } }, @@ -217,7 +221,7 @@ const respondToGetSerialApiInitData: MockControllerBehavior = { nodeIds: [...nodeIds], zwaveChipType: controller.capabilities.zwaveChipType, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } }, @@ -234,7 +238,7 @@ const respondToSoftReset: MockControllerBehavior = { supportsLongRange: controller.capabilities.supportsLongRange, }); setImmediate(async () => { - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); }); return true; } @@ -257,7 +261,7 @@ const respondToGetNodeProtocolInfo: MockControllerBehavior = { optionalFunctionality: true, protocolVersion: 3, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } else if (controller.nodes.has(msg.requestedNodeId)) { const nodeCaps = controller.nodes.get( @@ -266,7 +270,7 @@ const respondToGetNodeProtocolInfo: MockControllerBehavior = { const ret = new GetNodeProtocolInfoResponse(host, { ...nodeCaps, }); - await controller.sendToHost(ret.serialize()); + await controller.sendMessageToHost(ret); return true; } } @@ -297,7 +301,7 @@ const handleSendData: MockControllerBehavior = { const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); // We deferred parsing of the CC because it requires the node's host to do so. // Now we can do that. Also set the CC node ID to the controller's own node ID, @@ -352,7 +356,7 @@ const handleSendData: MockControllerBehavior = { : TransmitStatus.NoAck, }); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); } else { // No callback was requested, we're done controller.state.set( @@ -391,7 +395,7 @@ const handleSendDataMulticast: MockControllerBehavior = { const res = new SendDataMulticastResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); // We deferred parsing of the CC because it requires the node's host to do so. // Now we can do that. Also set the CC node ID to the controller's own node ID, @@ -451,7 +455,7 @@ const handleSendDataMulticast: MockControllerBehavior = { : TransmitStatus.NoAck, }); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); } else { // No callback was requested, we're done controller.state.set( @@ -506,7 +510,7 @@ const handleRequestNodeInfo: MockControllerBehavior = { const res = new RequestNodeInfoResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); // Put the controller into waiting state controller.state.set( @@ -532,7 +536,7 @@ const handleRequestNodeInfo: MockControllerBehavior = { MockControllerCommunicationState.Idle, ); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); return true; } }, @@ -581,7 +585,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { const res = new AssignSUCReturnRouteResponse(host, { wasExecuted: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); let ack = false; if (expectCallback) { @@ -612,7 +616,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { : TransmitStatus.NoAck, }); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); } return true; } @@ -632,11 +636,8 @@ const forwardCommandClassesToHost: MockControllerBehavior = { }); // Nodes send commands TO the controller, so we need to fix the node ID before forwarding msg.getNodeId = () => node.id; - // Simulate a serialized frame being transmitted via radio - const data = msg.serialize(); - await wait(node.capabilities.txDelay); - // Then receive it - await controller.sendToHost(data); + // Simulate a serialized frame being transmitted via radio before receiving it + await controller.sendMessageToHost(msg, node.capabilities.txDelay); return true; } }, @@ -657,11 +658,11 @@ const forwardUnsolicitedNIF: MockControllerBehavior = { }, }, ); - // Simulate a serialized frame being transmitted via radio - const data = updateRequest.serialize(); - await wait(node.capabilities.txDelay); - // Then receive it - await controller.sendToHost(data); + // Simulate a serialized frame being transmitted via radio before receiving it + await controller.sendMessageToHost( + updateRequest, + node.capabilities.txDelay, + ); return true; } }, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 68a6af4a1502..2a8a2649c455 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -118,7 +118,9 @@ import { FunctionType, type INodeQuery, Message, + type MessageEncodingContext, MessageHeaders, + type MessageParsingContext, MessageType, type SuccessIndicator, XModemMessageHeaders, @@ -653,6 +655,23 @@ export class Driver extends TypedEventEmitter this._options.storage.deviceConfigPriorityDir, }); + this.messageParsingContext = { + getHighestSecurityClass: (nodeId) => + this.getHighestSecurityClass(nodeId), + hasSecurityClass: (nodeId, securityClass) => + this.hasSecurityClass(nodeId, securityClass), + setSecurityClass: (nodeId, securityClass, granted) => + this.setSecurityClass(nodeId, securityClass, granted), + }; + this.messageEncodingContext = { + getHighestSecurityClass: (nodeId) => + this.getHighestSecurityClass(nodeId), + hasSecurityClass: (nodeId, securityClass) => + this.hasSecurityClass(nodeId, securityClass), + setSecurityClass: (nodeId, securityClass, granted) => + this.setSecurityClass(nodeId, securityClass, granted), + }; + this.immediateQueue = new TransactionQueue({ name: "immediate", mayStartNextTransaction: (t) => { @@ -687,6 +706,9 @@ export class Driver extends TypedEventEmitter /** The serial port instance */ private serial: ZWaveSerialPortBase | undefined; + private messageParsingContext: MessageParsingContext; + private messageEncodingContext: MessageEncodingContext; + // We have multiple queues to achieve multiple "layers" of communication priority: // The default queue for most messages private queue: TransactionQueue; @@ -3422,6 +3444,7 @@ export class Driver extends TypedEventEmitter msg = Message.from(this, { data, sdkVersion: this._controller?.sdkVersion, + ctx: this.messageParsingContext, }, this._requestContext); if (isCommandClassContainer(msg)) { // Whether successful or not, a message from a node should update last seen @@ -4384,7 +4407,11 @@ export class Driver extends TypedEventEmitter // this is the final one, merge the previous responses this.partialCCSessions.delete(partialSessionKey!); try { - command.mergePartialCCs(this, session); + command.mergePartialCCs(this, session, { + ownNodeId: this.ownNodeId, + sourceNodeId: msg.command.nodeId as number, + ...this.messageParsingContext, + }); // Ensure there are no errors assertValidCCs(msg); } catch (e) { @@ -5186,7 +5213,11 @@ ${handlers.length} left`, // 3. if (SupervisionCC.requiresEncapsulation(cmd)) { - cmd = SupervisionCC.encapsulate(this, cmd); + cmd = SupervisionCC.encapsulate( + this, + cmd, + this.getNextSupervisionSessionId(cmd.nodeId as number), + ); } // 4. @@ -5707,6 +5738,7 @@ ${handlers.length} left`, ): Promise { const machine = createSerialAPICommandMachine( msg, + msg.serialize(this.messageEncodingContext), { sendData: (data) => this.writeSerial(data), sendDataAbort: () => this.abortSendData(), @@ -5905,6 +5937,7 @@ ${handlers.length} left`, // Create the transaction const { generator, resultPromise } = createMessageGenerator( this, + this.messageEncodingContext, msg, (msg, _result) => { this.handleSerialAPICommandResult(msg, options, _result); @@ -6147,9 +6180,11 @@ ${handlers.length} left`, }, ): Promise { // Create the encapsulating CC so we have a session ID + const sessionId = this.getNextSupervisionSessionId(command.nodeId); command = SupervisionCC.encapsulate( this, command, + sessionId, options.requestStatusUpdates, ); @@ -6259,7 +6294,9 @@ ${handlers.length} left`, private async abortSendData(): Promise { try { const abort = new SendDataAbort(this); - await this.writeSerial(abort.serialize()); + await this.writeSerial( + abort.serialize(this.messageEncodingContext), + ); this.driverLog.logMessage(abort, { direction: "outbound", }); @@ -6947,7 +6984,8 @@ ${handlers.length} left`, } public exceedsMaxPayloadLength(msg: SendDataMessage): boolean { - return msg.serializeCC().length > this.getMaxPayloadLength(msg); + return msg.serializeCC(this.messageEncodingContext).length + > this.getMaxPayloadLength(msg); } /** Determines time in milliseconds to wait for a report from a node */ diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index cff635c21168..72b6b9c0664c 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -28,6 +28,7 @@ import { TransportServiceTimeouts, } from "@zwave-js/cc/TransportServiceCC"; import { + type CCEncodingContext, CommandClasses, EncapsulationFlags, MessagePriority, @@ -59,6 +60,7 @@ import type { MessageGenerator } from "./Transaction"; export type MessageGeneratorImplementation = ( /** A reference to the driver */ driver: Driver, + ctx: CCEncodingContext, /** The "primary" message */ message: Message, /** @@ -128,6 +130,7 @@ function getNodeUpdateTimeout( export const simpleMessageGenerator: MessageGeneratorImplementation = async function*( driver, + ctx, msg, onMessageSent, additionalCommandTimeoutMs = 0, @@ -207,7 +210,13 @@ export const simpleMessageGenerator: MessageGeneratorImplementation = /** A generator for singlecast SendData messages that automatically uses Transport Service when necessary */ export const maybeTransportServiceGenerator: MessageGeneratorImplementation = - async function*(driver, msg, onMessageSent, additionalCommandTimeoutMs) { + async function*( + driver, + ctx, + msg, + onMessageSent, + additionalCommandTimeoutMs, + ) { // Make sure we can send this message if (!isSendData(msg)) { throw new ZWaveError( @@ -230,6 +239,7 @@ export const maybeTransportServiceGenerator: MessageGeneratorImplementation = // Transport Service isn't needed for this message return yield* simpleMessageGenerator( driver, + ctx, msg, onMessageSent, additionalCommandTimeoutMs, @@ -237,7 +247,7 @@ export const maybeTransportServiceGenerator: MessageGeneratorImplementation = } // Send the command split into multiple segments - const payload = msg.serializeCC(); + const payload = msg.serializeCC(ctx); const numSegments = Math.ceil(payload.length / MAX_SEGMENT_SIZE); const segmentDelay = numSegments > RELAXED_TIMING_THRESHOLD ? TransportServiceTimeouts.relaxedTimingDelayR2 @@ -353,6 +363,7 @@ export const maybeTransportServiceGenerator: MessageGeneratorImplementation = }); result = yield* simpleMessageGenerator( driver, + ctx, tmsg, onMessageSent, ); @@ -465,6 +476,7 @@ async function* sendCommandGenerator< TResponse extends CommandClass = CommandClass, >( driver: Driver, + ctx: CCEncodingContext, command: CommandClass, onMessageSent: (msg: Message, result: Message | undefined) => void, options?: SendCommandOptions, @@ -473,6 +485,7 @@ async function* sendCommandGenerator< const resp = yield* maybeTransportServiceGenerator( driver, + ctx, msg, onMessageSent, ); @@ -484,7 +497,7 @@ async function* sendCommandGenerator< /** A message generator for security encapsulated messages (S0) */ export const secureMessageGeneratorS0: MessageGeneratorImplementation = - async function*(driver, msg, onMessageSent) { + async function*(driver, ctx, msg, onMessageSent) { if (!isSendData(msg)) { throw new ZWaveError( "Cannot use the S0 message generator for a command that's not a SendData message!", @@ -519,6 +532,7 @@ export const secureMessageGeneratorS0: MessageGeneratorImplementation = SecurityCCNonceReport >( driver, + ctx, cc, (msg, result) => { additionalTimeoutMs = Math.ceil(msg.rtt! / 1e6); @@ -542,6 +556,7 @@ export const secureMessageGeneratorS0: MessageGeneratorImplementation = // Now send the actual secure command return yield* simpleMessageGenerator( driver, + ctx, msg, onMessageSent, additionalTimeoutMs, @@ -550,7 +565,7 @@ export const secureMessageGeneratorS0: MessageGeneratorImplementation = /** A message generator for security encapsulated messages (S2) */ export const secureMessageGeneratorS2: MessageGeneratorImplementation = - async function*(driver, msg, onMessageSent) { + async function*(driver, ctx, msg, onMessageSent) { if (!isSendData(msg)) { throw new ZWaveError( "Cannot use the S2 message generator for a command that's not a SendData message!", @@ -596,6 +611,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = Security2CCNonceReport >( driver, + ctx, cc, (msg, result) => { additionalTimeoutMs = Math.ceil(msg.rtt! / 1e6); @@ -619,6 +635,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = // Now send the actual secure command let response = yield* maybeTransportServiceGenerator( driver, + ctx, msg, onMessageSent, additionalTimeoutMs, @@ -688,6 +705,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = msg.prepareRetransmission(); response = yield* maybeTransportServiceGenerator( driver, + ctx, msg, onMessageSent, additionalTimeoutMs, @@ -716,7 +734,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = /** A message generator for security encapsulated messages (S2 Multicast) */ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = - async function*(driver, msg, onMessageSent) { + async function*(driver, ctx, msg, onMessageSent) { if (!isSendData(msg)) { throw new ZWaveError( "Cannot use the S2 multicast message generator for a command that's not a SendData message!", @@ -754,6 +772,7 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = // Send the multicast command. We remember the transmit report and treat it as the result of the multicast command const response = yield* simpleMessageGenerator( driver, + ctx, msg, onMessageSent, ); @@ -798,6 +817,7 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = try { const scResponse = yield* secureMessageGeneratorS2( driver, + ctx, scMsg, onMessageSent, ); @@ -823,17 +843,23 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = }); // Send it the MPAN - yield* sendCommandGenerator(driver, cc, onMessageSent, { - // Seems we need these options or some nodes won't accept the nonce - transmitOptions: TransmitOptions.ACK - | TransmitOptions.AutoRoute, - // Only try sending a nonce once - maxSendAttempts: 1, - // Nonce requests must be handled immediately - priority: MessagePriority.Immediate, - // We don't want failures causing us to treat the node as asleep or dead - changeNodeStatusOnMissingACK: false, - }); + yield* sendCommandGenerator( + driver, + ctx, + cc, + onMessageSent, + { + // Seems we need these options or some nodes won't accept the nonce + transmitOptions: TransmitOptions.ACK + | TransmitOptions.AutoRoute, + // Only try sending a nonce once + maxSendAttempts: 1, + // Nonce requests must be handled immediately + priority: MessagePriority.Immediate, + // We don't want failures causing us to treat the node as asleep or dead + changeNodeStatusOnMissingACK: false, + }, + ); } } @@ -884,6 +910,7 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = export function createMessageGenerator( driver: Driver, + ctx: CCEncodingContext, msg: Message, onMessageSent: (msg: Message, result: Message | undefined) => void, ): { @@ -923,7 +950,7 @@ export function createMessageGenerator( // Step through the generator so we can easily cancel it and don't // accidentally forget to unset this.current at the end - const gen = implementation(driver, msg, onMessageSent); + const gen = implementation(driver, ctx, msg, onMessageSent); let sendResult: Message | undefined; let result: Message | undefined; while (true) { diff --git a/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.ts b/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.ts index 04ea7db84021..65f788e955ed 100644 --- a/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.ts +++ b/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.ts @@ -141,6 +141,7 @@ export type SerialAPICommandMachineParams = { export function getSerialAPICommandMachineConfig( message: Message, + messageData: Buffer, { timestamp, logOutgoingMessage, @@ -161,7 +162,7 @@ export function getSerialAPICommandMachineConfig( initial: "sending", context: { msg: message, - data: message.serialize(), + data: messageData, attempts: 0, maxAttempts: attemptsConfig.controller, }, @@ -449,12 +450,14 @@ export function getSerialAPICommandMachineOptions( export function createSerialAPICommandMachine( message: Message, + messageData: Buffer, implementations: SerialAPICommandServiceImplementations, params: SerialAPICommandMachineParams, ): SerialAPICommandMachine { return createMachine( getSerialAPICommandMachineConfig( message, + messageData, implementations, params.attempts, ), diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts index fb2517781f87..69c834f00e0e 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts @@ -16,6 +16,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, gotDeserializationOptions, messageTypes, @@ -95,7 +96,11 @@ export class ApplicationCommandRequest extends Message data: this.payload.subarray(offset, offset + commandLength), nodeId, origin: options.origin, - frameType: this.frameType, + context: { + ownNodeId: this.host.ownNodeId, + sourceNodeId: nodeId, + ...options.ctx, + }, }) as SinglecastCC; } else { // TODO: This logic is unsound @@ -131,7 +136,7 @@ export class ApplicationCommandRequest extends Message return super.getNodeId(); } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const statusByte = (this.frameType === "broadcast" ? ApplicationCommandStatusFlags.TypeBroad : this.frameType === "multicast" @@ -139,7 +144,7 @@ export class ApplicationCommandRequest extends Message : 0) | (this.routedBusy ? ApplicationCommandStatusFlags.RoutedBusy : 0); - const serializedCC = this.command.serialize(); + const serializedCC = this.command.serialize(ctx); const nodeId = encodeNodeID( this.getNodeId() ?? this.host.ownNodeId, this.host.nodeIdType, @@ -151,7 +156,7 @@ export class ApplicationCommandRequest extends Message serializedCC, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts index c528d7408735..e8c71dcfdccb 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts @@ -18,6 +18,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageType, type SuccessIndicator, @@ -78,12 +79,12 @@ export class ApplicationUpdateRequest extends Message { public readonly updateType: ApplicationUpdateTypes; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.updateType]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } } @@ -119,12 +120,12 @@ export class ApplicationUpdateRequestWithNodeInfo public nodeId: number; public nodeInformation: NodeUpdatePayload; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeUpdatePayload( this.nodeInformation, this.host.nodeIdType, ); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts index 859512358209..af6a095402db 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts @@ -15,6 +15,7 @@ test("BridgeApplicationCommandRequest can be parsed without RSSI", async (t) => "011200a80001020a320221340000000000000069", "hex", ), + ctx: {} as any, }) ); }); diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index 98ef572cc3b7..26907ad3d95e 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -76,7 +76,11 @@ export class BridgeApplicationCommandRequest extends Message data: this.payload.subarray(offset, offset + commandLength), nodeId: sourceNodeId, origin: options.origin, - frameType: this.frameType, + context: { + ownNodeId: this.host.ownNodeId, + sourceNodeId, + ...options.ctx, + }, }) as SinglecastCC; offset += commandLength; diff --git a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts index 3fffcdbd9b5b..028f0782a53a 100644 --- a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, gotDeserializationOptions, messageTypes, @@ -108,7 +109,7 @@ export class SerialAPIStartedRequest extends Message { public controlledCCs: CommandClasses[]; public supportsLongRange: boolean = false; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const ccList = encodeCCList(this.supportedCCs, this.controlledCCs); const numCCBytes = ccList.length; @@ -122,7 +123,7 @@ export class SerialAPIStartedRequest extends Message { ccList.copy(this.payload, 6); this.payload[6 + numCCBytes] = this.supportsLongRange ? 0b1 : 0; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts index 3cf9a6370e8a..15b08a5a3be3 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -76,7 +77,7 @@ export class GetControllerCapabilitiesResponse extends Message { public isStaticUpdateController: boolean; public noNodesIncluded: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([ (this.isSecondary ? ControllerCapabilityFlags.Secondary : 0) | (this.isUsingHomeIdFromOtherNetwork @@ -93,6 +94,6 @@ export class GetControllerCapabilitiesResponse extends Message { ? ControllerCapabilityFlags.NoNodesIncluded : 0), ]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts index bea2a275ec75..d642a83493e2 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -49,12 +50,12 @@ export class GetControllerVersionResponse extends Message { public controllerType: ZWaveLibraryTypes; public libraryVersion: string; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from(`${this.libraryVersion}\0`, "ascii"), Buffer.from([this.controllerType]), ]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts index dbbe9b26d0c1..f92b098ffc3e 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -43,9 +44,9 @@ export class GetLongRangeNodesRequest extends Message { public segmentNumber: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.segmentNumber]); - return super.serialize(); + return super.serialize(ctx); } } @@ -95,7 +96,7 @@ export class GetLongRangeNodesResponse extends Message { public segmentNumber: number; public nodeIds: readonly number[]; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe( 3 + NUM_LR_NODEMASK_SEGMENT_BYTES, ); @@ -110,7 +111,7 @@ export class GetLongRangeNodesResponse extends Message { ); nodeBitMask.copy(this.payload, 3); - return super.serialize(); + return super.serialize(ctx); } private listStartNode(): number { diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts index dbf295ca63d6..032a2b2ec4dc 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -67,7 +68,7 @@ export class GetSerialApiCapabilitiesResponse extends Message { public productId: number; public supportedFunctionTypes: FunctionType[]; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(8 + NUM_FUNCTION_BYTES); const firmwareBytes = this.firmwareVersion @@ -86,6 +87,6 @@ export class GetSerialApiCapabilitiesResponse extends Message { ); functionBitMask.copy(this.payload, 8); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts index c6982f85dedc..9059e4cdaca2 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts @@ -18,6 +18,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -117,7 +118,7 @@ export class GetSerialApiInitDataResponse extends Message { public zwaveChipType?: string | UnknownZWaveChipType; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { let chipType: UnknownZWaveChipType | undefined; if (typeof this.zwaveChipType === "string") { chipType = getChipTypeAndVersion(this.zwaveChipType); @@ -152,7 +153,7 @@ export class GetSerialApiInitDataResponse extends Message { this.payload[3 + NUM_NODEMASK_BYTES + 1] = chipType.version; } - return super.serialize(); + return super.serialize(ctx); } // public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts index 48c74811cb3a..d3239e31cc51 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts @@ -5,6 +5,7 @@ import { FunctionType, Message, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageOrigin, MessageType, @@ -37,9 +38,9 @@ export class HardResetRequestBase extends Message { @expectedCallback(FunctionType.HardReset) export class HardResetRequest extends HardResetRequestBase { - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.callbackId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts index d8f5b9c1aea1..d21ba28d63cb 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, type SuccessIndicator, expectedResponse, @@ -80,9 +81,9 @@ export class SetLongRangeChannelRequest extends Message { public channel: LongRangeChannel; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.channel]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts index 71ebbe27a170..2a20792032fc 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts @@ -11,7 +11,11 @@ test("GetSupportedCommandsResponse with extended bitmask parses correctly (pre-7 "hex", ); - const msg = Message.from(host, { data, sdkVersion: "7.19.0" }); + const msg = Message.from(host, { + data, + sdkVersion: "7.19.0", + ctx: {} as any, + }); t.true(msg instanceof SerialAPISetup_GetSupportedCommandsResponse); const supported = (msg as SerialAPISetup_GetSupportedCommandsResponse) .supportedCommands; @@ -28,7 +32,11 @@ test("GetSupportedCommandsResponse with extended bitmask parses correctly (post- "hex", ); - const msg = Message.from(host, { data, sdkVersion: "7.19.1" }); + const msg = Message.from(host, { + data, + sdkVersion: "7.19.1", + ctx: {} as any, + }); t.true(msg instanceof SerialAPISetup_GetSupportedCommandsResponse); const supported = (msg as SerialAPISetup_GetSupportedCommandsResponse) .supportedCommands; diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts index a783fb392a31..45cc16b23240 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts @@ -13,6 +13,7 @@ import { import type { ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, + MessageEncodingContext, SuccessIndicator, } from "@zwave-js/serial"; import { @@ -100,13 +101,13 @@ export class SerialAPISetupRequest extends Message { public command: SerialAPISetupCommand; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.command]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -286,10 +287,10 @@ export class SerialAPISetup_SetTXStatusReportRequest public enabled: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.enabled ? 0xff : 0x00]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -360,10 +361,10 @@ export class SerialAPISetup_SetNodeIDTypeRequest extends SerialAPISetupRequest { public nodeIdType: NodeIDType; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.nodeIdType]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -464,9 +465,9 @@ export class SerialAPISetup_SetRFRegionRequest extends SerialAPISetupRequest { public region: RFRegion; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.region]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -594,13 +595,13 @@ export class SerialAPISetup_SetPowerlevelRequest extends SerialAPISetupRequest { public powerlevel: number; public measured0dBm: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(2); // The values are in 0.1 dBm this.payload.writeInt8(Math.round(this.powerlevel * 10), 0); this.payload.writeInt8(Math.round(this.measured0dBm * 10), 1); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -736,13 +737,13 @@ export class SerialAPISetup_SetPowerlevel16BitRequest public powerlevel: number; public measured0dBm: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(4); // The values are in 0.1 dBm this.payload.writeInt16BE(Math.round(this.powerlevel * 10), 0); this.payload.writeInt16BE(Math.round(this.measured0dBm * 10), 2); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -868,12 +869,12 @@ export class SerialAPISetup_SetLongRangeMaximumTxPowerRequest /** The maximum LR TX power in dBm */ public limit: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(2); // The values are in 0.1 dBm, signed this.payload.writeInt16BE(Math.round(this.limit * 10), 0); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -1049,9 +1050,9 @@ export class SerialAPISetup_GetRegionInfoRequest extends SerialAPISetupRequest { public region: RFRegion; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.region]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts index 1168ea195f7c..5ea1fed5107b 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts @@ -10,6 +10,7 @@ import { FunctionType, Message, type MessageBaseOptions, + type MessageEncodingContext, MessageType, messageTypes, priority, @@ -47,7 +48,7 @@ export class SetApplicationNodeInformationRequest extends Message { public supportedCCs: CommandClasses[]; public controlledCCs: CommandClasses[]; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const ccList = encodeCCList(this.supportedCCs, this.controlledCCs); const ccListLength = Math.min(ccList.length, 35); this.payload = Buffer.from([ @@ -58,7 +59,7 @@ export class SetApplicationNodeInformationRequest extends Message { ...ccList.subarray(0, ccListLength), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts index a0033d3e0faf..c20cdc92cfb0 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, gotDeserializationOptions, messageTypes, @@ -44,7 +45,7 @@ export class SetLongRangeShadowNodeIDsRequest extends Message { public shadowNodeIds: number[]; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(1); this.payload = encodeBitMask( this.shadowNodeIds, @@ -54,6 +55,6 @@ export class SetLongRangeShadowNodeIDsRequest extends Message { LONG_RANGE_SHADOW_NODE_IDS_START, ); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts index ea89fddfb3ce..69274cfe548b 100644 --- a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts @@ -6,6 +6,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -45,14 +46,14 @@ export class GetControllerIdResponse extends Message { public homeId: number; public ownNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.ownNodeId, this.host.nodeIdType); const homeId = Buffer.allocUnsafe(4); homeId.writeUInt32BE(this.homeId, 0); this.payload = Buffer.concat([homeId, nodeId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts index 12451975aa25..fa739bca700e 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts @@ -5,7 +5,10 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -44,10 +47,10 @@ export class SetRFReceiveModeRequest extends Message { public enabled: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.enabled ? 0x01 : 0x00]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts index a84da19a4f33..d404f2c4df34 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, messageTypes, @@ -32,12 +33,12 @@ export class SetSerialApiTimeoutsRequest extends Message { public ackTimeout: number; public byteTimeout: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([ Math.round(this.ackTimeout / 10), Math.round(this.byteTimeout / 10), ]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts index f6f819e360cf..cd91b3056995 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts @@ -12,7 +12,10 @@ import { parseNodeUpdatePayload, } from "@zwave-js/core"; import type { GetAllNodes, ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -149,14 +152,14 @@ export class AddNodeToNetworkRequest extends AddNodeToNetworkRequestBase { /** Whether to include network wide */ public networkWide: boolean = false; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { let data: number = this.addNodeType || AddNodeType.Any; if (this.highPower) data |= AddNodeFlags.HighPower; if (this.networkWide) data |= AddNodeFlags.NetworkWide; this.payload = Buffer.from([data, this.callbackId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -185,14 +188,14 @@ export class AddNodeToNetworkRequest extends AddNodeToNetworkRequestBase { } export class EnableSmartStartListenRequest extends AddNodeToNetworkRequestBase { - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const control: number = AddNodeType.SmartStartListen | AddNodeFlags.NetworkWide; // The Serial API does not send a callback, so disable waiting for one this.callbackId = 0; this.payload = Buffer.from([control, this.callbackId]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -229,7 +232,7 @@ export class AddNodeDSKToNetworkRequest extends AddNodeToNetworkRequestBase { /** Whether to include as long-range or not */ public protocol: Protocols; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { let control: number = AddNodeType.SmartStartDSK; if (this.highPower) control |= AddNodeFlags.HighPower; if (this.networkWide) control |= AddNodeFlags.NetworkWide; @@ -243,7 +246,7 @@ export class AddNodeDSKToNetworkRequest extends AddNodeToNetworkRequestBase { this.authHomeId, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts index de5076baed1c..b13bb529c9ed 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts @@ -15,6 +15,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageType, type SuccessIndicator, @@ -99,7 +100,7 @@ export class AssignPriorityReturnRouteRequest public repeaters: number[]; public routeSpeed: ZWaveDataRate; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); const destinationNodeId = encodeNodeID( this.destinationNodeId, @@ -118,7 +119,7 @@ export class AssignPriorityReturnRouteRequest ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts index 8d3c8a3eb367..9419a8bad89a 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts @@ -15,6 +15,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageType, type SuccessIndicator, @@ -90,7 +91,7 @@ export class AssignPrioritySUCReturnRouteRequest public repeaters: number[]; public routeSpeed: ZWaveDataRate; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); this.payload = Buffer.concat([ nodeId, @@ -104,7 +105,7 @@ export class AssignPrioritySUCReturnRouteRequest ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts index 7deec2f1ca05..1b5f49f8e216 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts @@ -7,7 +7,11 @@ import { encodeNodeID, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { INodeQuery, SuccessIndicator } from "@zwave-js/serial"; +import type { + INodeQuery, + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -74,7 +78,7 @@ export class AssignReturnRouteRequest extends AssignReturnRouteRequestBase public nodeId: number; public destinationNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); const destinationNodeId = encodeNodeID( this.destinationNodeId, @@ -87,7 +91,7 @@ export class AssignReturnRouteRequest extends AssignReturnRouteRequestBase Buffer.from([this.callbackId]), ]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts index 1eb2f7fc64e5..87f5f8eed0d1 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageOrigin, MessageType, @@ -92,11 +93,11 @@ export class AssignSUCReturnRouteRequest extends AssignSUCReturnRouteRequestBase public nodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); - return super.serialize(); + return super.serialize(ctx); } } @@ -128,9 +129,9 @@ export class AssignSUCReturnRouteResponse extends Message public wasExecuted: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.wasExecuted ? 0x01 : 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -178,9 +179,9 @@ export class AssignSUCReturnRouteRequestTransmitReport public transmitStatus: TransmitStatus; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.callbackId, this.transmitStatus]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts index 55d3e1dcd114..ac4f162d59d3 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts @@ -7,7 +7,11 @@ import { encodeNodeID, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { INodeQuery, SuccessIndicator } from "@zwave-js/serial"; +import type { + INodeQuery, + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -65,11 +69,11 @@ export class DeleteReturnRouteRequest extends DeleteReturnRouteRequestBase public nodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts index 40960535f621..3ae23032c893 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts @@ -5,7 +5,11 @@ import { encodeNodeID, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { INodeQuery, SuccessIndicator } from "@zwave-js/serial"; +import type { + INodeQuery, + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -91,11 +95,11 @@ export class DeleteSUCReturnRouteRequest extends DeleteSUCReturnRouteRequestBase public nodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); - return super.serialize(); + return super.serialize(ctx); } } @@ -127,9 +131,9 @@ export class DeleteSUCReturnRouteResponse extends Message public readonly wasExecuted: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.wasExecuted ? 0x01 : 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -177,9 +181,9 @@ export class DeleteSUCReturnRouteRequestTransmitReport public readonly transmitStatus: TransmitStatus; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.callbackId, this.transmitStatus]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts index a13ae9071fef..e0a626774bfd 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts @@ -18,6 +18,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -53,9 +54,9 @@ export class GetNodeProtocolInfoRequest extends Message { // but this is a message to the controller public requestedNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeID(this.requestedNodeId, this.host.nodeIdType); - return super.serialize(); + return super.serialize(ctx); } } @@ -143,7 +144,7 @@ export class GetNodeProtocolInfoResponse extends Message { public genericDeviceClass: number; public specificDeviceClass: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const protocolInfo = encodeNodeProtocolInfo({ isListening: this.isListening, isFrequentListening: this.isFrequentListening, @@ -165,6 +166,6 @@ export class GetNodeProtocolInfoResponse extends Message { ]), ]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts index ab2705c82e39..14d83002fe59 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts @@ -16,6 +16,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -49,13 +50,13 @@ export class GetPriorityRouteRequest extends Message { public destinationNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeID( this.destinationNodeId, this.host.nodeIdType, ); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts index 26431a51ee79..2b65ddc1f5e0 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, messageTypes, @@ -38,7 +39,7 @@ export class GetRoutingInfoRequest extends Message { public removeNonRepeaters: boolean; public removeBadLinks: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.sourceNodeId, this.host.nodeIdType); const optionsByte = (this.removeBadLinks ? 0b1000_0000 : 0) | (this.removeNonRepeaters ? 0b0100_0000 : 0); @@ -49,7 +50,7 @@ export class GetRoutingInfoRequest extends Message { 0, // callbackId - this must be 0 as per the docs ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts index 31402458a911..28333e29ce96 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -43,8 +44,8 @@ export class GetSUCNodeIdResponse extends Message { /** The node id of the SUC or 0 if none is present */ public sucNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeID(this.sucNodeId, this.host.nodeIdType); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts index 6960e2db01da..e59a0d815b04 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts @@ -5,6 +5,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, messageTypes, @@ -28,9 +29,9 @@ export class IsFailedNodeRequest extends Message { // This must not be called nodeId or rejectAllTransactions may reject the request public failedNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeID(this.failedNodeId, this.host.nodeIdType); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts index 8b8e96e39d82..84417476f442 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts @@ -1,6 +1,9 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -75,10 +78,10 @@ export class RemoveFailedNodeRequest extends RemoveFailedNodeRequestBase { /** The node that should be removed */ public failedNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.failedNodeId, this.host.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts index d5b06589f785..108620c64bef 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts @@ -4,7 +4,10 @@ import { parseNodeID, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -111,14 +114,14 @@ export class RemoveNodeFromNetworkRequest /** Whether to exclude network wide */ public networkWide: boolean = false; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { let data: number = this.removeNodeType || RemoveNodeType.Any; if (this.highPower) data |= RemoveNodeFlags.HighPower; if (this.networkWide) data |= RemoveNodeFlags.NetworkWide; this.payload = Buffer.from([data, this.callbackId]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts index 1e3f979b02f8..746de9e2d7e9 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts @@ -1,6 +1,9 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -74,10 +77,10 @@ export class ReplaceFailedNodeRequest extends ReplaceFailedNodeRequestBase { /** The node that should be removed */ public failedNodeId: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.failedNodeId, this.host.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); - return super.serialize(); + return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts index 088ad6e69aab..2c3ba3ab2ee0 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, type SuccessIndicator, expectedCallback, @@ -50,9 +51,9 @@ export class RequestNodeInfoResponse extends Message return this.wasSent; } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.wasSent ? 0x01 : 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -106,9 +107,9 @@ export class RequestNodeInfoRequest extends Message implements INodeQuery { return false; } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeID(this.nodeId, this.host.nodeIdType); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts index 8008444c9e1a..e61290136e0f 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts @@ -1,7 +1,11 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { MultiStageCallback, SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + MultiStageCallback, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -60,10 +64,10 @@ export class RequestNodeNeighborUpdateRequest public nodeId: number; public discoveryTimeout: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); - return super.serialize(); + return super.serialize(ctx); } public getCallbackTimeout(): number | undefined { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts index 4d38e0d3b6cd..e306028923db 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts @@ -11,6 +11,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageType, type SuccessIndicator, @@ -82,13 +83,13 @@ export class SetLearnModeRequest extends SetLearnModeRequestBase { public intent: LearnModeIntent; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([ this.intent, this.callbackId, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts index 2af0f8077e9e..1124d8808d9b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts @@ -16,6 +16,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, type SuccessIndicator, expectedResponse, @@ -79,7 +80,7 @@ export class SetPriorityRouteRequest extends Message { public repeaters: number[] | undefined; public routeSpeed: ZWaveDataRate | undefined; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID( this.destinationNodeId, this.host.nodeIdType, @@ -101,7 +102,7 @@ export class SetPriorityRouteRequest extends Message { ]); } - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index 4b07cbd34061..1952297c54ec 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -7,7 +7,10 @@ import { encodeNodeID, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -75,7 +78,7 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { public enableSIS: boolean; public transmitOptions: TransmitOptions; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.sucNodeId, this.host.nodeIdType); this.payload = Buffer.concat([ nodeId, @@ -87,7 +90,7 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { ]), ]); - return super.serialize(); + return super.serialize(ctx); } public expectsCallback(): boolean { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts index f9b43b6e82f6..c4c84b3d0721 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts @@ -10,6 +10,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -61,11 +62,11 @@ export class ExtNVMReadLongBufferRequest extends Message { public offset: number; public length: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(5); this.payload.writeUIntBE(this.offset, 0, 3); this.payload.writeUInt16BE(this.length, 3); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts index 245a6b0b0782..cd748277f557 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts @@ -10,6 +10,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -51,10 +52,10 @@ export class ExtNVMReadLongByteRequest extends Message { public offset: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(3); this.payload.writeUIntBE(this.offset, 0, 3); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts index ba4f9e47433b..280acbee33d6 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts @@ -10,6 +10,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -62,12 +63,12 @@ export class ExtNVMWriteLongBufferRequest extends Message { public offset: number; public buffer: Buffer; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(5 + this.buffer.length); this.payload.writeUIntBE(this.offset, 0, 3); this.payload.writeUInt16BE(this.buffer.length, 3); this.buffer.copy(this.payload, 5); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts index c47e36afd05d..a8919c8aaa48 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts @@ -10,6 +10,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, MessageType, expectedResponse, gotDeserializationOptions, @@ -60,11 +61,11 @@ export class ExtNVMWriteLongByteRequest extends Message { public offset: number; public byte: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(4); this.payload.writeUIntBE(this.offset, 0, 3); this.payload[3] = this.byte; - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts index e8fac7aa425c..9f51e2e18408 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts @@ -7,7 +7,10 @@ import { validatePayload, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -45,13 +48,13 @@ export class ExtendedNVMOperationsRequest extends Message { // This must be set in subclasses public command!: ExtendedNVMOperationsCommand; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.command]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -138,12 +141,12 @@ export class ExtendedNVMOperationsReadRequest public length: number; public offset: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(5); this.payload[0] = this.length; this.payload.writeUInt32BE(this.offset, 1); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -207,12 +210,12 @@ export class ExtendedNVMOperationsWriteRequest public offset: number; public buffer: Buffer; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(1 + 4 + this.buffer.length); this.payload[0] = this.buffer.length; this.payload.writeUInt32BE(this.offset, 1); this.buffer.copy(this.payload, 5); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts index 0c1d229373bd..53b257187d2d 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts @@ -11,6 +11,7 @@ import type { ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageBaseOptions, + MessageEncodingContext, } from "@zwave-js/serial"; import { FunctionType, @@ -84,13 +85,13 @@ export class FirmwareUpdateNVMRequest extends Message { public command: FirmwareUpdateNVMCommand; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.command]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -201,10 +202,10 @@ export class FirmwareUpdateNVM_SetNewImageRequest public newImage: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.newImage ? 1 : 0]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -313,13 +314,13 @@ export class FirmwareUpdateNVM_UpdateCRC16Request return 30000; } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(7); this.payload.writeUIntBE(this.offset, 0, 3); this.payload.writeUInt16BE(this.blockLength, 3); this.payload.writeUInt16BE(this.crcSeed, 5); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -427,12 +428,12 @@ export class FirmwareUpdateNVM_WriteRequest extends FirmwareUpdateNVMRequest { public offset: number; public buffer: Buffer; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([Buffer.allocUnsafe(5), this.buffer]); this.payload.writeUintBE(this.offset, 0, 3); this.payload.writeUInt16BE(this.buffer.length, 3); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts index 5adc036411f9..08d3f3a95f11 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts @@ -7,14 +7,15 @@ import { validatePayload, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; import { FunctionType, Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageType, + type SuccessIndicator, expectedResponse, gotDeserializationOptions, messageTypes, @@ -44,13 +45,13 @@ export class NVMOperationsRequest extends Message { // This must be set in subclasses public command!: NVMOperationsCommand; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.concat([ Buffer.from([this.command]), this.payload, ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -126,12 +127,12 @@ export class NVMOperationsReadRequest extends NVMOperationsRequest { public length: number; public offset: number; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(3); this.payload[0] = this.length; this.payload.writeUInt16BE(this.offset, 1); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -191,12 +192,12 @@ export class NVMOperationsWriteRequest extends NVMOperationsRequest { public offset: number; public buffer: Buffer; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.allocUnsafe(3 + this.buffer.length); this.payload[0] = this.buffer.length; this.payload.writeUInt16BE(this.offset, 1); this.buffer.copy(this.payload, 3); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts index 94277d88cae2..bf1f38d62029 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts @@ -1,5 +1,6 @@ import type { CommandClass, ICommandClassContainer } from "@zwave-js/cc"; import { + type CCEncodingContext, MAX_NODES, type MessageOrCCLogEntry, MessagePriority, @@ -13,7 +14,10 @@ import { encodeNodeID, } from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; -import type { SuccessIndicator } from "@zwave-js/serial"; +import type { + MessageEncodingContext, + SuccessIndicator, +} from "@zwave-js/serial"; import { FunctionType, Message, @@ -110,9 +114,9 @@ export class SendDataBridgeRequest // Cache the serialized CC, so we can check if it needs to be fragmented private _serializedCC: Buffer | undefined; /** @internal */ - public serializeCC(): Buffer { + public serializeCC(ctx: CCEncodingContext): Buffer { if (!this._serializedCC) { - this._serializedCC = this.command.serialize(); + this._serializedCC = this.command.serialize(ctx); } return this._serializedCC; } @@ -123,7 +127,7 @@ export class SendDataBridgeRequest this.callbackId = undefined; } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const sourceNodeId = encodeNodeID( this.sourceNodeId, this.host.nodeIdType, @@ -132,7 +136,7 @@ export class SendDataBridgeRequest this.command.nodeId, this.host.nodeIdType, ); - const serializedCC = this.serializeCC(); + const serializedCC = this.serializeCC(ctx); this.payload = Buffer.concat([ sourceNodeId, @@ -142,7 +146,7 @@ export class SendDataBridgeRequest Buffer.from([this.transmitOptions, 0, 0, 0, 0, this.callbackId]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -350,9 +354,9 @@ export class SendDataMulticastBridgeRequest< // Cache the serialized CC, so we can check if it needs to be fragmented private _serializedCC: Buffer | undefined; /** @internal */ - public serializeCC(): Buffer { + public serializeCC(ctx: CCEncodingContext): Buffer { if (!this._serializedCC) { - this._serializedCC = this.command.serialize(); + this._serializedCC = this.command.serialize(ctx); } return this._serializedCC; } @@ -363,8 +367,8 @@ export class SendDataMulticastBridgeRequest< this.callbackId = undefined; } - public serialize(): Buffer { - const serializedCC = this.serializeCC(); + public serialize(ctx: MessageEncodingContext): Buffer { + const serializedCC = this.serializeCC(ctx); const sourceNodeId = encodeNodeID( this.sourceNodeId, this.host.nodeIdType, @@ -384,7 +388,7 @@ export class SendDataMulticastBridgeRequest< Buffer.from([this.transmitOptions, this.callbackId]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts index f2f7f169a4ec..1dc8c44b766b 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts @@ -5,6 +5,7 @@ import { MessagePriority, type MulticastCC, type MulticastDestination, + NODE_ID_BROADCAST, type SerializableTXReport, type SinglecastCC, type TXReport, @@ -21,6 +22,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageOrigin, MessageType, @@ -107,6 +109,11 @@ export class SendDataRequest nodeId, data: this.payload, origin: options.origin, + context: { + ownNodeId: host.ownNodeId, + sourceNodeId: nodeId, + ...options.ctx, + }, }) as SinglecastCC; } else { // Little hack for testing with a network mock. This will be parsed in the next step. @@ -155,9 +162,9 @@ export class SendDataRequest // Cache the serialized CC, so we can check if it needs to be fragmented private _serializedCC: Buffer | undefined; /** @internal */ - public serializeCC(): Buffer { + public serializeCC(ctx: MessageEncodingContext): Buffer { if (!this._serializedCC) { - this._serializedCC = this.command.serialize(); + this._serializedCC = this.command.serialize(ctx); } return this._serializedCC; } @@ -168,9 +175,9 @@ export class SendDataRequest this.callbackId = undefined; } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.command.nodeId, this.host.nodeIdType); - const serializedCC = this.serializeCC(); + const serializedCC = this.serializeCC(ctx); this.payload = Buffer.concat([ nodeId, Buffer.from([serializedCC.length]), @@ -178,7 +185,7 @@ export class SendDataRequest Buffer.from([this.transmitOptions, this.callbackId]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -245,7 +252,7 @@ export class SendDataRequestTransmitReport extends SendDataRequestBase private _txReport: SerializableTXReport | undefined; public txReport: TXReport | undefined; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([ this.callbackId, this.transmitStatus, @@ -257,7 +264,7 @@ export class SendDataRequestTransmitReport extends SendDataRequestBase ]); } - return super.serialize(); + return super.serialize(ctx); } public isOK(): boolean { @@ -302,9 +309,9 @@ export class SendDataResponse extends Message implements SuccessIndicator { public wasSent: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.wasSent ? 1 : 0]); - return super.serialize(); + return super.serialize(ctx); } isOK(): boolean { @@ -399,6 +406,11 @@ export class SendDataMulticastRequest< nodeId: this._nodeIds[0], data: this.payload, origin: options.origin, + context: { + ownNodeId: host.ownNodeId, + sourceNodeId: NODE_ID_BROADCAST, // FIXME: Unknown? + ...options.ctx, + }, }) as MulticastCC; this.command.nodeId = this._nodeIds; } else { @@ -457,9 +469,9 @@ export class SendDataMulticastRequest< // Cache the serialized CC, so we can check if it needs to be fragmented private _serializedCC: Buffer | undefined; /** @internal */ - public serializeCC(): Buffer { + public serializeCC(ctx: MessageEncodingContext): Buffer { if (!this._serializedCC) { - this._serializedCC = this.command.serialize(); + this._serializedCC = this.command.serialize(ctx); } return this._serializedCC; } @@ -470,8 +482,8 @@ export class SendDataMulticastRequest< this.callbackId = undefined; } - public serialize(): Buffer { - const serializedCC = this.serializeCC(); + public serialize(ctx: MessageEncodingContext): Buffer { + const serializedCC = this.serializeCC(ctx); const destinationNodeIDs = this.command.nodeId.map((id) => encodeNodeID(id, this.host.nodeIdType) ); @@ -485,7 +497,7 @@ export class SendDataMulticastRequest< Buffer.from([this.transmitOptions, this.callbackId]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { @@ -534,9 +546,9 @@ export class SendDataMulticastRequestTransmitReport return this._transmitStatus; } - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.callbackId, this._transmitStatus]); - return super.serialize(); + return super.serialize(ctx); } public isOK(): boolean { @@ -581,9 +593,9 @@ export class SendDataMulticastResponse extends Message public wasSent: boolean; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { this.payload = Buffer.from([this.wasSent ? 1 : 0]); - return super.serialize(); + return super.serialize(ctx); } public isOK(): boolean { diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts index feea59a1c3e1..9e067aab6f8e 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts @@ -12,6 +12,7 @@ import { Message, type MessageBaseOptions, type MessageDeserializationOptions, + type MessageEncodingContext, type MessageOptions, MessageType, type SuccessIndicator, @@ -71,7 +72,7 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { public testNodeId: number; public powerlevel: Powerlevel; - public serialize(): Buffer { + public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.testNodeId, this.host.nodeIdType); this.payload = Buffer.concat([ nodeId, @@ -81,7 +82,7 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { ]), ]); - return super.serialize(); + return super.serialize(ctx); } public toLogEntry(): MessageOrCCLogEntry { diff --git a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts index a047a46ff7f4..4f81fc6a1134 100644 --- a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts @@ -120,7 +120,7 @@ test("getDefinedValueIDs() should include the target value for all endpoints exc return 0; }, }); - host.nodes.set(node2.id, node2); + host.setNode(node2.id, node2); const valueIDs = nodeUtils .getDefinedValueIDs(host as any, node2) diff --git a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts index d28b30f26ce2..be0075a97f40 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts @@ -26,7 +26,7 @@ const groupCountValueId = AssociationCCValues.groupCount.id; function prepareTest(): { host: TestingHost; node2: IZWaveNode } { const host = createTestingHost(); const node2 = createTestNode(host, { id: 2 }); - host.nodes.set(2, node2); + host.setNode(2, node2); host.getValueDB(2).setValue(groupCountValueId, fakeGroupCount); return { host, node2 }; diff --git a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts index 5e5d05951f9e..a2a89584641d 100644 --- a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts +++ b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts @@ -89,7 +89,7 @@ integrationTest( const res = new AssignSUCReturnRouteResponse(host, { wasExecuted: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); let ack = false; if (expectCallback) { @@ -124,7 +124,7 @@ integrationTest( }, ); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); } return true; } @@ -179,7 +179,7 @@ integrationTest( const res = new DeleteSUCReturnRouteResponse(host, { wasExecuted: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); let ack = false; if (expectCallback) { @@ -216,7 +216,7 @@ integrationTest( // @ts-expect-error 0 is not a valid function type cb.functionType = 0; - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); } return true; } diff --git a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts index dc89fb2d47d9..928962da7bbc 100644 --- a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts +++ b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts @@ -72,7 +72,7 @@ integrationTest("update the controller status and wait if TX status is Fail", { const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); await wait(100); @@ -91,7 +91,7 @@ integrationTest("update the controller status and wait if TX status is Fail", { ackRSSI: 0, }, }); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); return true; } else if (msg instanceof SendDataAbort) { @@ -195,7 +195,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); await wait(100); @@ -214,7 +214,7 @@ integrationTest( ackRSSI: 0, }, }); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); return true; } else if (msg instanceof SendDataAbort) { @@ -336,7 +336,7 @@ integrationTestMulti( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); await wait(100); @@ -355,7 +355,7 @@ integrationTestMulti( ackRSSI: 0, }, }); - await controller.sendToHost(cb.serialize()); + await controller.sendMessageToHost(cb); return true; } else if (msg instanceof SendDataAbort) { diff --git a/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts index 163f4114d347..77a0802f2ac4 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts @@ -68,7 +68,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -185,7 +185,7 @@ integrationTest( // const res = new SendDataResponse(host, { // wasSent: true, // }); -// await controller.sendToHost(res.serialize()); +// await controller.sendMessageToHost(res); // return true; // } else if (msg instanceof SendDataAbort) { @@ -283,7 +283,7 @@ integrationTest( // const res = new SendDataResponse(host, { // wasSent: true, // }); -// await controller.sendToHost(res.serialize()); +// await controller.sendMessageToHost(res); // return true; // } else if (msg instanceof SendDataAbort) { @@ -362,7 +362,7 @@ integrationTest( // const res = new RequestNodeInfoResponse(host, { // wasSent: true, // }); -// await controller.sendToHost(res.serialize()); +// await controller.sendMessageToHost(res); // // And never send a callback // return true; diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts index 99407c84c517..400cae68b707 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts @@ -82,7 +82,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -183,7 +183,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -281,7 +281,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -360,7 +360,7 @@ integrationTest( const res = new RequestNodeInfoResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); // And never send a callback return true; @@ -437,7 +437,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -548,7 +548,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -656,7 +656,7 @@ integrationTestMulti( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { @@ -768,7 +768,7 @@ integrationTest( const res = new SendDataResponse(host, { wasSent: true, }); - await controller.sendToHost(res.serialize()); + await controller.sendMessageToHost(res); return true; } else if (msg instanceof SendDataAbort) { diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts index f4d5b2f25cd3..5391538971ea 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts @@ -238,7 +238,7 @@ integrationTest( // const res = new SendDataResponse(host, { // wasSent: true, // }); -// await controller.sendToHost(res.serialize()); +// await controller.sendMessageToHost(res); // return true; // } else if (msg instanceof SendDataAbort) { @@ -336,7 +336,7 @@ integrationTest( // const res = new SendDataResponse(host, { // wasSent: true, // }); -// await controller.sendToHost(res.serialize()); +// await controller.sendMessageToHost(res); // return true; // } else if (msg instanceof SendDataAbort) { @@ -415,7 +415,7 @@ integrationTest( // const res = new RequestNodeInfoResponse(host, { // wasSent: true, // }); -// await controller.sendToHost(res.serialize()); +// await controller.sendMessageToHost(res); // // And never send a callback // return true; diff --git a/packages/zwave-js/src/lib/test/mocks.ts b/packages/zwave-js/src/lib/test/mocks.ts index a1ee4c838aa6..b407a372d5d1 100644 --- a/packages/zwave-js/src/lib/test/mocks.ts +++ b/packages/zwave-js/src/lib/test/mocks.ts @@ -17,7 +17,7 @@ import { ZWaveErrorCodes, securityClassOrder, } from "@zwave-js/core"; -import type { TestingHost } from "@zwave-js/host"; +import type { BaseTestNode, TestingHost } from "@zwave-js/host"; import { type FunctionType, Message, @@ -219,18 +219,18 @@ export interface CreateTestNodeOptions { getCCVersion?: (cc: CommandClasses) => number; } -export interface TestNode extends IZWaveNode { +export type TestNode = T & { setEndpoint(endpoint: CreateTestEndpointOptions): void; -} +}; -export function createTestNode( - host: TestingHost, +export function createTestNode( + host: TestingHost, options: CreateTestNodeOptions, -): TestNode { +): TestNode { const endpointCache = new Map(); const securityClasses = new Map(); - const ret: TestNode = { + const ret: TestNode = { id: options.id, ...createTestEndpoint(host, { nodeId: options.id, diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 1bc815f01413..3a0c4425dd44 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -9,6 +9,7 @@ import { CommandClasses, type LogConfig, MPDUHeaderType, + type MaybeNotKnown, type RSSI, SPANState, SecurityClass, @@ -25,6 +26,7 @@ import { securityClassIsS2, } from "@zwave-js/core"; import { + type MessageParsingContext, type ZWaveSerialPortImplementation, type ZnifferDataMessage, ZnifferFrameType, @@ -202,12 +204,37 @@ export class Zniffer extends TypedEventEmitter { this._options = options; this._active = false; + + this.parsingContext = { + getHighestSecurityClass( + _nodeId: number, + ): MaybeNotKnown { + return SecurityClass.S2_AccessControl; + }, + + hasSecurityClass( + _nodeId: number, + _securityClass: SecurityClass, + ): MaybeNotKnown { + // We don't actually know. Attempt parsing with all security classes + return true; + }, + + setSecurityClass( + _nodeId: number, + _securityClass: SecurityClass, + _granted: boolean, + ): void { + // Do nothing + }, + }; } private _options: ZnifferOptions; /** The serial port instance */ private serial: ZnifferSerialPortBase | undefined; + private parsingContext: MessageParsingContext; private _destroyPromise: DeferredPromise | undefined; private get wasDestroyed(): boolean { @@ -519,6 +546,11 @@ supported frequencies: ${ data: mpdu.payload, fromEncapsulation: false, nodeId: mpdu.sourceNodeId, + context: { + ownNodeId: destNodeId, + sourceNodeId: mpdu.sourceNodeId, + ...this.parsingContext, + }, }); } catch (e: any) { // Ignore From be5d871e7e1463028f77def77f65da7b9651db55 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Fri, 11 Oct 2024 16:42:33 +0200 Subject: [PATCH 12/60] refactor: that escalated quickly --- packages/cc/src/cc/AssociationCC.ts | 2 + packages/cc/src/cc/ConfigurationCC.ts | 3 + .../cc/src/cc/MultiChannelAssociationCC.ts | 2 + packages/cc/src/cc/MultiChannelCC.ts | 2 + packages/cc/src/cc/Security2CC.ts | 155 ++++++++++++------ packages/cc/src/cc/SecurityCC.ts | 69 +++++--- .../core/src/abstractions/ICommandClass.ts | 16 +- packages/host/src/ZWaveHost.ts | 24 +-- packages/serial/src/message/Message.ts | 3 +- packages/testing/src/MockController.ts | 75 ++++++--- packages/testing/src/MockNode.ts | 87 ++++++---- packages/testing/src/MockZWaveFrame.ts | 8 +- .../lib/controller/MockControllerBehaviors.ts | 9 +- packages/zwave-js/src/lib/driver/Driver.ts | 53 ++++-- .../src/lib/driver/MessageGenerators.ts | 2 + .../driver/SerialAPICommandMachine.test.ts | 8 +- .../src/lib/driver/Transaction.test.ts | 20 +-- .../src/lib/node/MockNodeBehaviors.ts | 8 +- .../src/lib/test/cc/AssociationCC.test.ts | 12 +- .../test/cc/AssociationGroupInfoCC.test.ts | 14 +- .../zwave-js/src/lib/test/cc/BasicCC.test.ts | 7 +- .../src/lib/test/cc/BatteryCC.test.ts | 8 +- .../src/lib/test/cc/BinarySensorCC.test.ts | 10 +- .../src/lib/test/cc/BinarySwitchCC.test.ts | 9 +- .../zwave-js/src/lib/test/cc/CRC16CC.test.ts | 8 +- .../src/lib/test/cc/CentralSceneCC.test.ts | 13 +- .../src/lib/test/cc/ColorSwitchCC.test.ts | 15 +- .../cc/CommandClass.persistValues.test.ts | 1 + .../src/lib/test/cc/CommandClass.test.ts | 4 +- .../src/lib/test/cc/DoorLockCC.test.ts | 18 +- .../src/lib/test/cc/DoorLockLoggingCC.test.ts | 6 +- .../src/lib/test/cc/EntryControlCC.test.ts | 12 +- .../zwave-js/src/lib/test/cc/FibaroCC.test.ts | 5 +- .../lib/test/cc/HumidityControlModeCC.test.ts | 11 +- .../HumidityControlOperatingStateCC.test.ts | 3 +- .../test/cc/HumidityControlSetpointCC.test.ts | 18 +- .../src/lib/test/cc/IndicatorCC.test.ts | 11 +- .../src/lib/test/cc/LanguageCC.test.ts | 9 +- .../test/cc/ManufacturerSpecificCC.test.ts | 3 +- .../zwave-js/src/lib/test/cc/MeterCC.test.ts | 59 +++++-- .../test/cc/MultiChannelAssociationCC.test.ts | 22 ++- .../src/lib/test/cc/MultiChannelCC.test.ts | 11 +- .../lib/test/cc/MultilevelSwitchCC.test.ts | 15 +- .../src/lib/test/cc/NoOperationCC.test.ts | 6 +- .../src/lib/test/cc/PowerlevelCC.test.ts | 11 +- .../src/lib/test/cc/SceneActivationCC.test.ts | 6 +- .../cc/SceneActuatorConfigurationCC.test.ts | 8 +- .../cc/SceneControllerConfigurationCC.test.ts | 8 +- .../lib/test/cc/ThermostatFanModeCC.test.ts | 8 +- .../lib/test/cc/ThermostatFanStateCC.test.ts | 4 +- .../zwave-js/src/lib/test/cc/TimeCC.test.ts | 7 +- .../zwave-js/src/lib/test/cc/WakeUpCC.test.ts | 6 +- .../src/lib/test/cc/ZWavePlusCC.test.ts | 2 +- .../test/compliance/decodeLowerS2Keys.test.ts | 29 +++- .../discardInsecureCommands.test.ts | 14 +- .../secureNodeSecureEndpoint.test.ts | 21 ++- .../test/driver/assemblePartialCCs.test.ts | 13 +- .../driver/computeNetCCPayloadSize.test.ts | 2 + .../test/driver/highestSecurityClass.test.ts | 11 +- ...noreCCVersion0ForKnownSupportedCCs.test.ts | 47 ++++-- .../driver/nodeAsleepBlockNonceReport.test.ts | 10 +- .../test/driver/s0AndS2Encapsulation.test.ts | 25 ++- .../lib/test/driver/s0Encapsulation.test.ts | 18 +- .../driver/s0EncapsulationTwoNodes.test.ts | 12 +- .../src/lib/test/driver/s2Collisions.test.ts | 61 +++++-- .../lib/test/node/Node.handleCommand.test.ts | 2 + test/decodeMessage.ts | 2 +- 67 files changed, 805 insertions(+), 378 deletions(-) diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index d562a8353434..598def511cd2 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -1,4 +1,5 @@ import type { + CCParsingContext, EndpointId, MaybeNotKnown, MessageRecord, @@ -673,6 +674,7 @@ export class AssociationCCReport extends AssociationCC { public mergePartialCCs( applHost: ZWaveApplicationHost, partials: AssociationCCReport[], + _ctx: CCParsingContext, ): void { // Concat the list of nodes this.nodeIds = [...partials, this] diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 5bbf9fc9a114..d53fd55d8c61 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -1,6 +1,7 @@ import type { ParamInfoMap } from "@zwave-js/config"; import { type CCEncodingContext, + type CCParsingContext, CommandClasses, ConfigValueFormat, type ConfigurationMetadata, @@ -2393,6 +2394,7 @@ export class ConfigurationCCNameReport extends ConfigurationCC { public mergePartialCCs( applHost: ZWaveApplicationHost, partials: ConfigurationCCNameReport[], + _ctx: CCParsingContext, ): void { // Concat the name this.name = [...partials, this] @@ -2553,6 +2555,7 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { public mergePartialCCs( applHost: ZWaveApplicationHost, partials: ConfigurationCCInfoReport[], + _ctx: CCParsingContext, ): void { // Concat the info this.info = [...partials, this] diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index dbf4afab230e..800531c337bb 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -1,5 +1,6 @@ import type { CCEncodingContext, + CCParsingContext, EndpointId, MessageRecord, SupervisionResult, @@ -843,6 +844,7 @@ export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { public mergePartialCCs( applHost: ZWaveApplicationHost, partials: MultiChannelAssociationCCReport[], + _ctx: CCParsingContext, ): void { // Concat the list of nodes this.nodeIds = [...partials, this] diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 2cea58c8d0f3..f50a55317da3 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -1,6 +1,7 @@ import { type ApplicationNodeInformation, type CCEncodingContext, + type CCParsingContext, CommandClasses, type GenericDeviceClass, type MaybeNotKnown, @@ -1117,6 +1118,7 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC { public mergePartialCCs( applHost: ZWaveApplicationHost, partials: MultiChannelCCEndPointFindReport[], + _ctx: CCParsingContext, ): void { // Concat the list of end points this.foundEndpoints = [...partials, this] diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 7f18f63882cf..6141ea78a909 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -35,6 +35,7 @@ import { type MaybeNotKnown, NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, + type SecurityManagers, encodeCCList, } from "@zwave-js/core/safe"; import type { @@ -52,7 +53,6 @@ import { type CCResponseRole, CommandClass, type CommandClassDeserializationOptions, - type CommandClassOptions, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -122,57 +122,41 @@ function getAuthenticationData( unencryptedPayload.copy(ret, offset, 0); return ret; } - function getSecurityManager( - host: ZWaveHost, + ownNodeId: number, + securityManagers: SecurityManagers, destination: MulticastDestination | number, ): SecurityManager2 | undefined { - const longRange = isLongRangeNodeId(host.ownNodeId) + const longRange = isLongRangeNodeId(ownNodeId) || isLongRangeNodeId( isArray(destination) ? destination[0] : destination, ); return longRange - ? host.securityManagerLR - : host.securityManager2; + ? securityManagers.securityManagerLR + : securityManagers.securityManager2; } /** Validates that a sequence number is not a duplicate and updates the SPAN table if it is accepted. Returns the previous sequence number if there is one. */ function validateSequenceNumber( this: Security2CC, + securityManager: SecurityManager2, sequenceNumber: number, ): number | undefined { - const securityManager = getSecurityManager(this.host, this.nodeId); - validatePayload.withReason( `Duplicate command (sequence number ${sequenceNumber})`, )( - !securityManager!.isDuplicateSinglecast( + !securityManager.isDuplicateSinglecast( this.nodeId as number, sequenceNumber, ), ); // Not a duplicate, store it - return securityManager!.storeSequenceNumber( + return securityManager.storeSequenceNumber( this.nodeId as number, sequenceNumber, ); } -function assertSecurity(this: Security2CC, options: CommandClassOptions): void { - const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; - if (!this.host.ownNodeId) { - throw new ZWaveError( - `Secure commands (S2) can only be ${verb} when the controller's node id is known!`, - ZWaveErrorCodes.Driver_NotReady, - ); - } else if (!getSecurityManager(this.host, this.nodeId)) { - throw new ZWaveError( - `Secure commands (S2) can only be ${verb} when the network keys are configured!`, - ZWaveErrorCodes.Driver_NoSecurity, - ); - } -} - const MAX_DECRYPT_ATTEMPTS_SINGLECAST = 5; const MAX_DECRYPT_ATTEMPTS_MULTICAST = 5; const MAX_DECRYPT_ATTEMPTS_SC_FOLLOWUP = 1; @@ -210,6 +194,7 @@ export class Security2CCAPI extends CCAPI { this.assertPhysicalEndpoint(this.endpoint); const securityManager = getSecurityManager( + this.applHost.ownNodeId, this.applHost, this.endpoint.nodeId, ); @@ -228,6 +213,7 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCNonceReport(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + securityManagers: this.applHost, SOS: true, MOS: false, receiverEI, @@ -274,6 +260,7 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCNonceReport(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + securityManagers: this.applHost, SOS: false, MOS: true, }); @@ -317,6 +304,7 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCMessageEncapsulation(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + securityManagers: this.applHost, extensions: [ new MPANExtension({ groupId, @@ -377,7 +365,12 @@ export class Security2CCAPI extends CCAPI { if (MultiChannelCC.requiresEncapsulation(cc)) { cc = MultiChannelCC.encapsulate(this.applHost, cc); } - cc = Security2CC.encapsulate(this.applHost, cc, { securityClass }); + cc = Security2CC.encapsulate( + this.applHost, + cc, + this.applHost, + { securityClass }, + ); const response = await this.applHost.sendCommand< Security2CCCommandsSupportedReport @@ -617,9 +610,53 @@ export class Security2CCAPI extends CCAPI { export class Security2CC extends CommandClass { declare ccCommand: Security2Command; + protected assertSecurity( + options: + | (CCCommandOptions & { securityManagers: SecurityManagers }) + | CommandClassDeserializationOptions, + ): SecurityManager2 { + const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; + if (!this.host.ownNodeId) { + throw new ZWaveError( + `Secure commands (S2) can only be ${verb} when the controller's node id is known!`, + ZWaveErrorCodes.Driver_NotReady, + ); + } + + let ret: SecurityManager2 | undefined; + if (gotDeserializationOptions(options)) { + ret = getSecurityManager( + this.host.ownNodeId, + options.context, + this.nodeId, + )!; + } else { + ret = getSecurityManager( + this.host.ownNodeId, + options.securityManagers, + this.nodeId, + )!; + } + + if (!ret) { + throw new ZWaveError( + `Secure commands (S2) can only be ${verb} when the security manager is set up!`, + ZWaveErrorCodes.Driver_NoSecurity, + ); + } + + return ret; + } + public async interview( applHost: ZWaveApplicationHost, ): Promise { + const securityManager = getSecurityManager( + applHost.ownNodeId, + applHost, + this.nodeId, + ); + const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; const api = CCAPI.create( @@ -629,8 +666,6 @@ export class Security2CC extends CommandClass { ).withOptions({ priority: MessagePriority.NodeQuery, }); - const securityManager = getSecurityManager(applHost, node.id); - // Only on the highest security class the response includes the supported commands const secClass = node.getHighestSecurityClass(); let hasReceivedSecureCommands = false; @@ -907,6 +942,7 @@ export class Security2CC extends CommandClass { public static encapsulate( host: ZWaveHost, cc: CommandClass, + securityManagers: SecurityManagers, options?: { securityClass?: SecurityClass; multicastOutOfSync?: boolean; @@ -941,6 +977,7 @@ export class Security2CC extends CommandClass { const ret = new Security2CCMessageEncapsulation(host, { nodeId, encapsulated: cc, + securityManagers, securityClass: options?.securityClass, extensions, verifyDelivery: options?.verifyDelivery, @@ -959,6 +996,7 @@ export class Security2CC extends CommandClass { export interface Security2CCMessageEncapsulationOptions extends CCCommandOptions { + securityManagers: Readonly; /** Can be used to override the default security class for the command */ securityClass?: SecurityClass; extensions?: Security2Extension[]; @@ -1040,8 +1078,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { super(host, options); // Make sure that we can send/receive secure commands - assertSecurity.call(this, options); - this.securityManager = getSecurityManager(host, this.nodeId)!; + this.securityManager = this.assertSecurity(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -1181,6 +1218,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { // Don't accept duplicate Singlecast commands prevSequenceNumber = validateSequenceNumber.call( this, + this.securityManager, this._sequenceNumber, ); @@ -1915,16 +1953,19 @@ export class Security2CCMessageEncapsulation extends Security2CC { // @publicAPI export type Security2CCNonceReportOptions = - | { - MOS: boolean; - SOS: true; - receiverEI: Buffer; - } - | { - MOS: true; - SOS: false; - receiverEI?: undefined; - }; + & { securityManagers: SecurityManagers } + & ( + | { + MOS: boolean; + SOS: true; + receiverEI: Buffer; + } + | { + MOS: true; + SOS: false; + receiverEI?: undefined; + } + ); @CCCommand(Security2Command.NonceReport) export class Security2CCNonceReport extends Security2CC { @@ -1937,14 +1978,17 @@ export class Security2CCNonceReport extends Security2CC { super(host, options); // Make sure that we can send/receive secure commands - assertSecurity.call(this, options); - this.securityManager = getSecurityManager(host, this.nodeId)!; + this.securityManager = this.assertSecurity(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this._sequenceNumber = this.payload[0]; // Don't accept duplicate commands - validateSequenceNumber.call(this, this._sequenceNumber); + validateSequenceNumber.call( + this, + this.securityManager, + this._sequenceNumber, + ); this.MOS = !!(this.payload[1] & 0b10); this.SOS = !!(this.payload[1] & 0b1); @@ -1969,7 +2013,7 @@ export class Security2CCNonceReport extends Security2CC { } } - private securityManager: SecurityManager2; + private securityManager!: SecurityManager2; private _sequenceNumber: number | undefined; /** * Return the sequence number of this command. @@ -2018,30 +2062,43 @@ export class Security2CCNonceReport extends Security2CC { } } +// @publicAPI +export interface Security2CCNonceGetOptions { + securityManagers: Readonly; +} + @CCCommand(Security2Command.NonceGet) @expectedCCResponse(Security2CCNonceReport) export class Security2CCNonceGet extends Security2CC { // TODO: A node sending this command MUST accept a delay up to + // 250 ms before receiving the Security 2 Nonce Report Command. - public constructor(host: ZWaveHost, options: CCCommandOptions) { + public constructor( + host: ZWaveHost, + options: + | CommandClassDeserializationOptions + | (CCCommandOptions & Security2CCNonceGetOptions), + ) { super(host, options); // Make sure that we can send/receive secure commands - assertSecurity.call(this, options); - this.securityManager = getSecurityManager(host, this.nodeId)!; + this.securityManager = this.assertSecurity(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this._sequenceNumber = this.payload[0]; // Don't accept duplicate commands - validateSequenceNumber.call(this, this._sequenceNumber); + validateSequenceNumber.call( + this, + this.securityManager, + this._sequenceNumber, + ); } else { // No options here } } - private securityManager: SecurityManager2; + private securityManager!: SecurityManager2; private _sequenceNumber: number | undefined; /** * Return the sequence number of this command. diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 48738e6b3bfa..04e9e37fc26a 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -119,6 +119,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { : SecurityCCCommandEncapsulation )(this.applHost, { nodeId: this.endpoint.nodeId, + securityManager: this.applHost.securityManager!, encapsulated, }); await this.applHost.sendCommand(cc, this.commandOptions); @@ -238,6 +239,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { cc = new SecurityCCCommandEncapsulation(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + securityManager: this.applHost.securityManager!, encapsulated: cc, }); } @@ -272,6 +274,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { const cc = new SecurityCCCommandEncapsulation(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + securityManager: this.applHost.securityManager!, encapsulated: keySet, alternativeNetworkKey: Buffer.alloc(16, 0), }); @@ -338,10 +341,36 @@ export class SecurityCC extends CommandClass { declare ccCommand: SecurityCommand; // Force singlecast for the Security CC declare nodeId: number; - // Define the securityManager as existing - declare host: ZWaveHost & { - securityManager: SecurityManager; - }; + + protected assertSecurity( + options: + | (CCCommandOptions & { securityManager: SecurityManager }) + | CommandClassDeserializationOptions, + ): SecurityManager { + const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; + if (!this.host.ownNodeId) { + throw new ZWaveError( + `Secure commands (S0) can only be ${verb} when the controller's node id is known!`, + ZWaveErrorCodes.Driver_NotReady, + ); + } + + let ret: SecurityManager | undefined; + if (gotDeserializationOptions(options)) { + ret = options.context.securityManager; + } else { + ret = options.securityManager; + } + + if (!ret) { + throw new ZWaveError( + `Secure commands (S0) can only be ${verb} when the security manager is set up!`, + ZWaveErrorCodes.Driver_NoSecurity, + ); + } + + return ret; + } public async interview( applHost: ZWaveApplicationHost, @@ -502,11 +531,13 @@ export class SecurityCC extends CommandClass { /** Encapsulates a command that should be sent encrypted */ public static encapsulate( host: ZWaveHost, + securityManager: SecurityManager, cc: CommandClass, ): SecurityCCCommandEncapsulation { // TODO: When to return a SecurityCCCommandEncapsulationNonceGet? const ret = new SecurityCCCommandEncapsulation(host, { nodeId: cc.nodeId, + securityManager, encapsulated: cc, }); @@ -571,6 +602,7 @@ export class SecurityCCNonceGet extends SecurityCC {} export interface SecurityCCCommandEncapsulationOptions extends CCCommandOptions { + securityManager: SecurityManager; encapsulated: CommandClass; alternativeNetworkKey?: Buffer; } @@ -597,18 +629,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { ) { super(host, options); - const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; - if (!(this.host.ownNodeId as unknown)) { - throw new ZWaveError( - `Secure commands (S0) can only be ${verb} when the controller's node id is known!`, - ZWaveErrorCodes.Driver_NotReady, - ); - } else if (!(this.host.securityManager as unknown)) { - throw new ZWaveError( - `Secure commands (S0) can only be ${verb} when the network key for the applHost is set`, - ZWaveErrorCodes.Driver_NoSecurity, - ); - } + this.securityManager = this.assertSecurity(options); if (gotDeserializationOptions(options)) { // HALF_NONCE_SIZE bytes iv, 1 byte frame control, at least 1 CC byte, 1 byte nonce id, 8 bytes auth code @@ -621,7 +642,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { const authCode = this.payload.subarray(-8); // Retrieve the used nonce from the nonce store - const nonce = this.host.securityManager.getNonce(nonceId); + const nonce = this.securityManager.getNonce(nonceId); // Only accept the message if the nonce hasn't expired validatePayload.withReason( `Nonce ${ @@ -631,10 +652,10 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { } expired, cannot decode security encapsulated command.`, )(!!nonce); // and mark the nonce as used - this.host.securityManager.deleteNonce(nonceId); + this.securityManager.deleteNonce(nonceId); - this.authKey = this.host.securityManager.authKey; - this.encryptionKey = this.host.securityManager.encryptionKey; + this.authKey = this.securityManager.authKey; + this.encryptionKey = this.securityManager.encryptionKey; // Validate the encrypted data const authData = getAuthenticationData( @@ -677,12 +698,14 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { options.alternativeNetworkKey, ); } else { - this.authKey = this.host.securityManager.authKey; - this.encryptionKey = this.host.securityManager.encryptionKey; + this.authKey = this.securityManager.authKey; + this.encryptionKey = this.securityManager.encryptionKey; } } } + private securityManager: SecurityManager; + private sequenced: boolean | undefined; private secondFrame: boolean | undefined; private sequenceCounter: number | undefined; @@ -695,7 +718,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { public get nonceId(): number | undefined { if (!this.nonce) return undefined; - return this.host.securityManager.getNonceId(this.nonce); + return this.securityManager.getNonceId(this.nonce); } public nonce: Buffer | undefined; diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts index d6e1255dfc49..271ffb84315e 100644 --- a/packages/core/src/abstractions/ICommandClass.ts +++ b/packages/core/src/abstractions/ICommandClass.ts @@ -5,11 +5,23 @@ import type { NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, } from "../consts"; +import { type SecurityManager } from "../security/Manager"; +import { type SecurityManager2 } from "../security/Manager2"; import { type SecurityClass } from "../security/SecurityClass"; import { type MaybeNotKnown } from "../values/Primitive"; +/** Allows accessing the security manager instances */ +export interface SecurityManagers { + /** Management of Security S0 keys and nonces */ + securityManager?: SecurityManager; + /** Management of Security S2 keys and nonces (Z-Wave Classic) */ + securityManager2?: SecurityManager2; + /** Management of Security S2 keys and nonces (Z-Wave Long Range) */ + securityManagerLR?: SecurityManager2; +} + /** Additional context needed for deserializing CCs */ -export interface CCParsingContext { +export interface CCParsingContext extends Readonly { sourceNodeId: number; ownNodeId: number; @@ -32,7 +44,7 @@ export interface CCParsingContext { /** Additional context needed for serializing CCs */ // FIXME: Lot of duplication between the CC and message contexts -export interface CCEncodingContext { +export interface CCEncodingContext extends Readonly { getHighestSecurityClass(nodeId: number): MaybeNotKnown; hasSecurityClass( diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 4535b01300d6..ae20e8865dcf 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -5,8 +5,7 @@ import type { ICommandClass, NodeIDType, NodeId, - SecurityManager, - SecurityManager2, + SecurityManagers, SendCommandOptions, SendCommandReturnType, ValueDB, @@ -22,16 +21,6 @@ export interface HostIDs { homeId: number; } -/** Allows accessing the security manager instances */ -export interface SecurityManagers { - /** Management of Security S0 keys and nonces */ - readonly securityManager: SecurityManager | undefined; - /** Management of Security S2 keys and nonces (Z-Wave Classic) */ - readonly securityManager2: SecurityManager2 | undefined; - /** Management of Security S2 keys and nonces (Z-Wave Long Range) */ - readonly securityManagerLR: SecurityManager2 | undefined; -} - // FIXME: This should not be needed. Instead have the driver set callback IDs during sendMessage /** Allows generating a new callback ID */ export interface GetNextCallbackId { @@ -43,9 +32,7 @@ export interface GetNextCallbackId { } /** Host application abstractions to be used in Serial API and CC implementations */ -export interface ZWaveHost - extends HostIDs, SecurityManagers, GetNextCallbackId -{ +export interface ZWaveHost extends HostIDs, GetNextCallbackId { /** How many bytes a node ID occupies in serial API commands */ readonly nodeIdType?: NodeIDType; @@ -106,7 +93,12 @@ export interface GetAllNodes { /** A more featureful version of the ZWaveHost interface, which is meant to be used on the controller application side. */ export interface ZWaveApplicationHost - extends ZWaveValueHost, ZWaveHost, GetNode, GetAllNodes + extends + ZWaveValueHost, + ZWaveHost, + GetNode, + GetAllNodes, + SecurityManagers { /** Gives access to the configuration files */ configManager: ConfigManager; diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 02ac86cee630..0a0ff5fb503c 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -4,6 +4,7 @@ import { type MessagePriority, type NodeId, type SecurityClass, + type SecurityManagers, ZWaveError, ZWaveErrorCodes, createReflectionDecorator, @@ -86,7 +87,7 @@ export type MessageOptions = | MessageCreationOptions | MessageDeserializationOptions; -export interface MessageEncodingContext { +export interface MessageEncodingContext extends Readonly { getHighestSecurityClass(nodeId: number): MaybeNotKnown; hasSecurityClass( diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 18f17a09e7d8..43319c92b751 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -1,4 +1,11 @@ -import { type ICommandClass } from "@zwave-js/core"; +import { + type ICommandClass, + type MaybeNotKnown, + NOT_KNOWN, + SecurityClass, + type SecurityManagers, + securityClassOrder, +} from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; import { Message, @@ -56,9 +63,6 @@ export class MockController { this.host = { ownNodeId: options.ownNodeId ?? 1, homeId: options.homeId ?? 0x7e571000, - securityManager: undefined, - securityManager2: undefined, - securityManagerLR: undefined, // nodes: this.nodes as any, getNextCallbackId: () => 1, // getNextSupervisionSessionId: (nodeId) => { @@ -100,24 +104,53 @@ export class MockController { ...options.capabilities, }; - this.parsingContext = { - // We don't care about security classes on the mock controller - getHighestSecurityClass: () => undefined, - hasSecurityClass: () => false, - setSecurityClass: () => {}, - }; + const securityClasses = new Map>(); this.encodingContext = { - // We don't care about security classes on the mock controller - getHighestSecurityClass: () => undefined, - hasSecurityClass: () => false, - setSecurityClass: () => {}, + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown { + return ( + securityClasses.get(nodeId)?.get(securityClass) ?? NOT_KNOWN + ); + }, + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void { + if (!securityClasses.has(nodeId)) { + securityClasses.set(nodeId, new Map()); + } + securityClasses.get(nodeId)!.set(securityClass, granted); + }, + getHighestSecurityClass( + nodeId: number, + ): MaybeNotKnown { + const map = securityClasses.get(nodeId); + if (!map?.size) return undefined; + let missingSome = false; + for (const secClass of securityClassOrder) { + if (map.get(secClass) === true) return secClass; + if (!map.has(secClass)) { + missingSome = true; + } + } + // If we don't have the info for every security class, we don't know the highest one yet + return missingSome ? undefined : SecurityClass.None; + }, + }; + this.parsingContext = { + ...this.encodingContext, }; void this.execute(); } - private parsingContext: MessageParsingContext; - private encodingContext: MessageEncodingContext; + public securityManagers: SecurityManagers = {}; + + public encodingContext: MessageEncodingContext; + public parsingContext: MessageParsingContext; public readonly serial: MockPortBinding; private readonly serialParser: SerialAPIParser; @@ -485,10 +518,7 @@ export class MockController { await wait(node.capabilities.txDelay); - const unlazy = unlazyMockZWaveFrame( - frame, - this.encodingContext, - ); + const unlazy = unlazyMockZWaveFrame(frame); onTransmit?.(unlazy); node.onControllerFrame(unlazy).catch((e) => { console.error(e); @@ -500,10 +530,7 @@ export class MockController { await wait(node.capabilities.txDelay); - const unlazy = unlazyMockZWaveFrame( - frame, - this.encodingContext, - ); + const unlazy = unlazyMockZWaveFrame(frame); onTransmit?.(unlazy); this.onNodeFrame(node, unlazy).catch((e) => { console.error(e); diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 7b944cc79c5f..3270e351a07d 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -1,5 +1,14 @@ import type { CommandClass } from "@zwave-js/cc"; -import { type CommandClassInfo, type CommandClasses } from "@zwave-js/core"; +import { + type CCEncodingContext, + type CommandClassInfo, + type CommandClasses, + type MaybeNotKnown, + NOT_KNOWN, + SecurityClass, + type SecurityManagers, + securityClassOrder, +} from "@zwave-js/core"; import type { ZWaveHost } from "@zwave-js/host"; import { TimedExpectation } from "@zwave-js/shared"; import { isDeepStrictEqual } from "node:util"; @@ -105,45 +114,49 @@ export class MockNode { this.controller = options.controller; // A node's host is a bit more specialized than the controller's host. - // const securityClasses = new Map>(); this.host = { ...this.controller.host, ownNodeId: this.id, __internalIsMockNode: true, // // Mimic the behavior of ZWaveNode, but for arbitrary node IDs - // hasSecurityClass( - // nodeId: number, - // securityClass: SecurityClass, - // ): MaybeNotKnown { - // return ( - // securityClasses.get(nodeId)?.get(securityClass) ?? NOT_KNOWN - // ); - // }, - // setSecurityClass( - // nodeId: number, - // securityClass: SecurityClass, - // granted: boolean, - // ): void { - // if (!securityClasses.has(nodeId)) { - // securityClasses.set(nodeId, new Map()); - // } - // securityClasses.get(nodeId)!.set(securityClass, granted); - // }, - // getHighestSecurityClass( - // nodeId: number, - // ): MaybeNotKnown { - // const map = securityClasses.get(nodeId); - // if (!map?.size) return undefined; - // let missingSome = false; - // for (const secClass of securityClassOrder) { - // if (map.get(secClass) === true) return secClass; - // if (!map.has(secClass)) { - // missingSome = true; - // } - // } - // // If we don't have the info for every security class, we don't know the highest one yet - // return missingSome ? undefined : SecurityClass.None; - // }, + }; + + const securityClasses = new Map>(); + + this.encodingContext = { + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown { + return ( + securityClasses.get(nodeId)?.get(securityClass) ?? NOT_KNOWN + ); + }, + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void { + if (!securityClasses.has(nodeId)) { + securityClasses.set(nodeId, new Map()); + } + securityClasses.get(nodeId)!.set(securityClass, granted); + }, + getHighestSecurityClass( + nodeId: number, + ): MaybeNotKnown { + const map = securityClasses.get(nodeId); + if (!map?.size) return undefined; + let missingSome = false; + for (const secClass of securityClassOrder) { + if (map.get(secClass) === true) return secClass; + if (!map.has(secClass)) { + missingSome = true; + } + } + // If we don't have the info for every security class, we don't know the highest one yet + return missingSome ? undefined : SecurityClass.None; + }, }; const { @@ -184,6 +197,10 @@ export class MockNode { public readonly controller: MockController; public readonly capabilities: MockNodeCapabilities; + public securityManagers: SecurityManagers = {}; + + public encodingContext: CCEncodingContext; + private behaviors: MockNodeBehavior[] = []; public readonly implementedCCs = new Map< diff --git a/packages/testing/src/MockZWaveFrame.ts b/packages/testing/src/MockZWaveFrame.ts index 1e2015300ee4..37221f783560 100644 --- a/packages/testing/src/MockZWaveFrame.ts +++ b/packages/testing/src/MockZWaveFrame.ts @@ -1,5 +1,4 @@ import { type CommandClass } from "@zwave-js/cc"; -import { type MessageEncodingContext } from "@zwave-js/serial"; /** * Is used to simulate communication between a {@link MockController} and a {@link MockNode}. @@ -26,7 +25,7 @@ export interface LazyMockZWaveRequestFrame { /** Whether an ACK is requested from the destination */ ackRequested: boolean; /** The Command Class contained in the frame */ - payload: CommandClass | ((ctx: MessageEncodingContext) => CommandClass); + payload: CommandClass | (() => CommandClass); } export interface MockZWaveAckFrame { @@ -45,7 +44,7 @@ export enum MockZWaveFrameType { } export function createMockZWaveRequestFrame( - payload: CommandClass | ((ctx: MessageEncodingContext) => CommandClass), + payload: CommandClass | (() => CommandClass), options: Partial> = {}, ): LazyMockZWaveRequestFrame { const { repeaters = [], ackRequested = true } = options; @@ -71,12 +70,11 @@ export function createMockZWaveAckFrame( export function unlazyMockZWaveFrame( frame: LazyMockZWaveFrame, - ctx: MessageEncodingContext, ): MockZWaveFrame { if (frame.type === MockZWaveFrameType.ACK) return frame; let payload = frame.payload; if (typeof payload === "function") { - payload = payload(ctx); + payload = payload(); } return { ...frame, diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index 08de3dbeb329..d1cb17ba97c8 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -14,7 +14,7 @@ import { isZWaveError, } from "@zwave-js/core"; import { type ZWaveHost } from "@zwave-js/host"; -import { type MessageEncodingContext, MessageOrigin } from "@zwave-js/serial"; +import { MessageOrigin } from "@zwave-js/serial"; import { MOCK_FRAME_ACK_TIMEOUT, type MockController, @@ -90,8 +90,8 @@ function createLazySendDataPayload( controller: MockController, node: MockNode, msg: SendDataRequest | SendDataMulticastRequest, -): (ctx: MessageEncodingContext) => CommandClass { - return (ctx: MessageEncodingContext) => { +): () => CommandClass { + return () => { try { const cmd = CommandClass.from(node.host, { nodeId: controller.host.ownNodeId, @@ -100,7 +100,8 @@ function createLazySendDataPayload( context: { ownNodeId: controller.host.ownNodeId, sourceNodeId: node.id, - ...ctx, + ...node.encodingContext, + ...node.securityManagers, }, }); // Store the command because assertReceivedHostMessage needs it diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 2a8a2649c455..20df64e49aba 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -709,6 +709,28 @@ export class Driver extends TypedEventEmitter private messageParsingContext: MessageParsingContext; private messageEncodingContext: MessageEncodingContext; + private getCCEncodingContext() { + // FIXME: The type system isn't helping here. We need the security managers to encode CCs + // but not for messages, yet those implicitly encode CCs + return { + ...this.messageEncodingContext, + securityManager: this.securityManager, + securityManager2: this.securityManager2, + securityManagerLR: this.securityManagerLR, + }; + } + + private getCCParsingContext() { + // FIXME: The type system isn't helping here. We need the security managers to decode CCs + // but not for messages, yet those implicitly decode CCs + return { + ...this.messageParsingContext, + securityManager: this.securityManager, + securityManager2: this.securityManager2, + securityManagerLR: this.securityManagerLR, + }; + } + // We have multiple queues to achieve multiple "layers" of communication priority: // The default queue for most messages private queue: TransactionQueue; @@ -3444,7 +3466,7 @@ export class Driver extends TypedEventEmitter msg = Message.from(this, { data, sdkVersion: this._controller?.sdkVersion, - ctx: this.messageParsingContext, + ctx: this.getCCParsingContext(), }, this._requestContext); if (isCommandClassContainer(msg)) { // Whether successful or not, a message from a node should update last seen @@ -4410,7 +4432,7 @@ export class Driver extends TypedEventEmitter command.mergePartialCCs(this, session, { ownNodeId: this.ownNodeId, sourceNodeId: msg.command.nodeId as number, - ...this.messageParsingContext, + ...this.getCCParsingContext(), }); // Ensure there are no errors assertValidCCs(msg); @@ -5243,17 +5265,22 @@ ${handlers.length} left`, maybeS2 = true; } if (maybeS2 && Security2CC.requiresEncapsulation(cmd)) { - cmd = Security2CC.encapsulate(this, cmd, { - securityClass: options.s2OverrideSecurityClass, - multicastOutOfSync: !!options.s2MulticastOutOfSync, - multicastGroupId: options.s2MulticastGroupId, - verifyDelivery: options.s2VerifyDelivery, - }); + cmd = Security2CC.encapsulate( + this, + cmd, + this, + { + securityClass: options.s2OverrideSecurityClass, + multicastOutOfSync: !!options.s2MulticastOutOfSync, + multicastGroupId: options.s2MulticastGroupId, + verifyDelivery: options.s2VerifyDelivery, + }, + ); } // This check will return false for S2-encapsulated commands if (SecurityCC.requiresEncapsulation(cmd)) { - cmd = SecurityCC.encapsulate(this, cmd); + cmd = SecurityCC.encapsulate(this, this.securityManager!, cmd); } } return cmd; @@ -5738,7 +5765,7 @@ ${handlers.length} left`, ): Promise { const machine = createSerialAPICommandMachine( msg, - msg.serialize(this.messageEncodingContext), + msg.serialize(this.getCCEncodingContext()), { sendData: (data) => this.writeSerial(data), sendDataAbort: () => this.abortSendData(), @@ -5937,7 +5964,7 @@ ${handlers.length} left`, // Create the transaction const { generator, resultPromise } = createMessageGenerator( this, - this.messageEncodingContext, + this.getCCEncodingContext(), msg, (msg, _result) => { this.handleSerialAPICommandResult(msg, options, _result); @@ -6295,7 +6322,7 @@ ${handlers.length} left`, try { const abort = new SendDataAbort(this); await this.writeSerial( - abort.serialize(this.messageEncodingContext), + abort.serialize(this.getCCEncodingContext()), ); this.driverLog.logMessage(abort, { direction: "outbound", @@ -6984,7 +7011,7 @@ ${handlers.length} left`, } public exceedsMaxPayloadLength(msg: SendDataMessage): boolean { - return msg.serializeCC(this.messageEncodingContext).length + return msg.serializeCC(this.getCCEncodingContext()).length > this.getMaxPayloadLength(msg); } diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index 72b6b9c0664c..03f00ada2b58 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -606,6 +606,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = const cc = new Security2CCNonceGet(driver, { nodeId: nodeId, endpoint: msg.command.endpointIndex, + securityManagers: driver, }); const nonceResp = yield* sendCommandGenerator< Security2CCNonceReport @@ -834,6 +835,7 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = if (innerMPANState) { const cc = new Security2CCMessageEncapsulation(driver, { nodeId, + securityManagers: driver, extensions: [ new MPANExtension({ groupId, diff --git a/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts b/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts index 73a1ca3d9c77..bbb96eb3eabb 100644 --- a/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts +++ b/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts @@ -440,10 +440,12 @@ testPlans.forEach((plan) => { } // And create a test machine with it - const msg = JSON.parse(match.groups.json); + const msgSelector = JSON.parse(match.groups.json); + // @ts-ignore + const message: Message = messages[msgSelector.resp][msgSelector.cb]; const machine = createSerialAPICommandMachine( - // @ts-ignore - messages[msg.resp][msg.cb], + message, + message.serialize({} as any), implementations, machineParams, ); diff --git a/packages/zwave-js/src/lib/driver/Transaction.test.ts b/packages/zwave-js/src/lib/driver/Transaction.test.ts index ef0d707d25d7..b564e5ad7a8d 100644 --- a/packages/zwave-js/src/lib/driver/Transaction.test.ts +++ b/packages/zwave-js/src/lib/driver/Transaction.test.ts @@ -49,8 +49,8 @@ test("should compare priority, then the timestamp", (t) => { controller: { nodes: new Map(), }, - get nodes() { - return driverMock.controller.nodes; + getNode(nodeId: number) { + return driverMock.controller.nodes.get(nodeId); }, getSafeCCVersion() {}, getSupportedCCVersion() {}, @@ -147,8 +147,8 @@ test("NodeQuery comparisons should prioritize listening nodes", (t) => { ], ]), }, - get nodes() { - return driverMock.controller.nodes; + getNode(nodeId: number) { + return driverMock.controller.nodes.get(nodeId); }, getSafeCCVersion() {}, getSupportedCCVersion() {}, @@ -260,8 +260,8 @@ test("Messages in the wakeup queue should be preferred over lesser priorities on ], ]), }, - get nodes() { - return driverMock.controller.nodes; + getNode(nodeId: number) { + return driverMock.controller.nodes.get(nodeId); }, getSafeCCVersion() {}, getSupportedCCVersion() {}, @@ -356,8 +356,8 @@ test("Controller message should be preferred over messages for sleeping nodes", ], ]), }, - get nodes() { - return driverMock.controller.nodes; + getNode(nodeId: number) { + return driverMock.controller.nodes.get(nodeId); }, getSafeCCVersion() {}, getSupportedCCVersion() {}, @@ -401,8 +401,8 @@ test("should capture a stack trace where it was created", (t) => { controller: { nodes: new Map(), }, - get nodes() { - return driverMock.controller.nodes; + getNode(nodeId: number) { + return driverMock.controller.nodes.get(nodeId); }, getSafeCCVersion() {}, getSupportedCCVersion() {}, diff --git a/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts b/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts index 327e3afeebb4..faaea53e90d5 100644 --- a/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts +++ b/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts @@ -133,7 +133,11 @@ const respondToS0ZWavePlusCCGet: MockNodeBehavior = { installerIcon: 0x0000, userIcon: 0x0000, }); - cc = SecurityCC.encapsulate(self.host, cc); + cc = SecurityCC.encapsulate( + self.host, + self.securityManagers.securityManager!, + cc, + ); return { action: "sendCC", cc, ackRequested: true }; } }, @@ -157,7 +161,7 @@ const respondToS2ZWavePlusCCGet: MockNodeBehavior = { installerIcon: 0x0000, userIcon: 0x0000, }); - cc = Security2CC.encapsulate(self.host, cc); + cc = Security2CC.encapsulate(self.host, cc, self.securityManagers); return { action: "sendCC", cc }; } }, diff --git a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts index 2d272ee5865f..c983331c5a5e 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts @@ -31,7 +31,7 @@ test("the SupportedGroupingsGet command should serialize correctly", (t) => { AssociationCommand.SupportedGroupingsGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedGroupingsReport command should be deserialized correctly", (t) => { @@ -44,6 +44,7 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t const cc = new AssociationCCSupportedGroupingsReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.groupCount, 7); @@ -65,7 +66,7 @@ test("the Set command should serialize correctly", (t) => { 5, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command should serialize correctly", (t) => { const cc = new AssociationCCGet(host, { @@ -78,7 +79,7 @@ test("the Get command should serialize correctly", (t) => { 9, // group ID ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly", (t) => { @@ -97,6 +98,7 @@ test("the Report command should be deserialized correctly", (t) => { const cc = new AssociationCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.groupId, 5); @@ -121,7 +123,7 @@ test("the Remove command should serialize correctly", (t) => { 5, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Remove command should serialize correctly (empty node list)", (t) => { @@ -135,7 +137,7 @@ test("the Remove command should serialize correctly (empty node list)", (t) => { 5, // group id ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); // test("deserializing an unsupported command should return an unspecified version of AssociationCC", (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts index d50418b49435..901f4419d375 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts @@ -36,7 +36,7 @@ test("the NameGet command should serialize correctly", (t) => { 7, // group id ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the NameReport command should be deserialized correctly", (t) => { @@ -57,6 +57,7 @@ test("the NameReport command should be deserialized correctly", (t) => { const cc = new AssociationGroupInfoCCNameReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.groupId, 7); @@ -77,7 +78,7 @@ test("the InfoGet command should serialize correctly (no flag set)", (t) => { 7, // group id ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the InfoGet command should serialize correctly (refresh cache flag set)", (t) => { @@ -94,7 +95,7 @@ test("the InfoGet command should serialize correctly (refresh cache flag set)", 7, // group id ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the InfoGet command should serialize correctly (list mode flag set)", (t) => { @@ -111,7 +112,7 @@ test("the InfoGet command should serialize correctly (list mode flag set)", (t) 0, // group id is ignored ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Info Report command should be deserialized correctly", (t) => { @@ -143,6 +144,7 @@ test("the Info Report command should be deserialized correctly", (t) => { const cc = new AssociationGroupInfoCCInfoReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.groups.length, 2); @@ -168,7 +170,7 @@ test("the CommandListGet command should serialize correctly", (t) => { 6, // group id ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CommandListReport command should be deserialized correctly", (t) => { @@ -188,6 +190,7 @@ test("the CommandListReport command should be deserialized correctly", (t) => { const cc = new AssociationGroupInfoCCCommandListReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.groupId, 7); @@ -206,6 +209,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new AssociationGroupInfoCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, AssociationGroupInfoCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts index 4f81fc6a1134..9d89bb144a52 100644 --- a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts @@ -31,7 +31,7 @@ test("the Get command should serialize correctly", (t) => { BasicCommand.Get, // CC Command ]), ); - t.deepEqual(basicCC.serialize(), expected); + t.deepEqual(basicCC.serialize({} as any), expected); }); test("the Set command should serialize correctly", (t) => { @@ -45,7 +45,7 @@ test("the Set command should serialize correctly", (t) => { 55, // target value ]), ); - t.deepEqual(basicCC.serialize(), expected); + t.deepEqual(basicCC.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { @@ -58,6 +58,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const basicCC = new BasicCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(basicCC.currentValue, 55); @@ -77,6 +78,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { const basicCC = new BasicCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(basicCC.currentValue, 55); @@ -92,6 +94,7 @@ test("deserializing an unsupported command should return an unspecified version const basicCC: any = new BasicCC(host, { nodeId: 2, data: serializedCC, + context: {} as any, }); t.is(basicCC.constructor, BasicCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts index 66cb5c62f775..7a52ff0a36f5 100644 --- a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts @@ -18,7 +18,7 @@ test("the Get command should serialize correctly", (t) => { CommandClasses.Battery, // CC BatteryCommand.Get, // CC Command ]); - t.deepEqual(batteryCC.serialize(), expected); + t.deepEqual(batteryCC.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly: when the battery is not low", (t) => { @@ -30,6 +30,7 @@ test("the Report command (v1) should be deserialized correctly: when the battery const batteryCC = new BatteryCC(host, { nodeId: 7, data: ccData, + context: {} as any, }) as BatteryCCReport; t.is(batteryCC.level, 55); @@ -45,6 +46,7 @@ test("the Report command (v1) should be deserialized correctly: when the battery const batteryCC = new BatteryCC(host, { nodeId: 7, data: ccData, + context: {} as any, }) as BatteryCCReport; t.is(batteryCC.level, 0); @@ -62,6 +64,7 @@ test("the Report command (v2) should be deserialized correctly: all flags set", const batteryCC = new BatteryCC(host, { nodeId: 7, data: ccData, + context: {} as any, }) as BatteryCCReport; t.true(batteryCC.rechargeable); @@ -82,6 +85,7 @@ test("the Report command (v2) should be deserialized correctly: charging status" const batteryCC = new BatteryCC(host, { nodeId: 7, data: ccData, + context: {} as any, }) as BatteryCCReport; t.is(batteryCC.chargingStatus, BatteryChargingStatus.Maintaining); @@ -98,6 +102,7 @@ test("the Report command (v2) should be deserialized correctly: recharge or repl const batteryCC = new BatteryCC(host, { nodeId: 7, data: ccData, + context: {} as any, }) as BatteryCCReport; t.is(batteryCC.rechargeOrReplace, BatteryReplacementStatus.Now); @@ -111,6 +116,7 @@ test("deserializing an unsupported command should return an unspecified version const basicCC: any = new BatteryCC(host, { nodeId: 7, data: serializedCC, + context: {} as any, }); t.is(basicCC.constructor, BatteryCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts index a2ab44a14af6..073cf4ec7f4d 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts @@ -30,7 +30,7 @@ test("the Get command should serialize correctly (no sensor type)", (t) => { BinarySensorType.Any, // sensor type ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command should serialize correctly", (t) => { @@ -41,7 +41,7 @@ test("the Get command should serialize correctly", (t) => { const expected = buildCCBuffer( Buffer.from([BinarySensorCommand.Get, BinarySensorType.CO]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { @@ -54,6 +54,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const cc = new BinarySensorCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.value, true); @@ -70,6 +71,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { const cc = new BinarySensorCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.value, false); @@ -83,7 +85,7 @@ test("the SupportedGet command should serialize correctly", (t) => { BinarySensorCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedReport command should be deserialized correctly", (t) => { @@ -97,6 +99,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { const cc = new BinarySensorCCSupportedReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.deepEqual(cc.supportedSensorTypes, [ @@ -115,6 +118,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new BinarySensorCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, BinarySensorCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts index f192a0a26a47..2f31b08bd569 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts @@ -27,7 +27,7 @@ test("the Get command should serialize correctly", (t) => { BinarySwitchCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (no duration)", (t) => { @@ -43,7 +43,7 @@ test("the Set command should serialize correctly (no duration)", (t) => { 0xff, // default duration ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly", (t) => { @@ -61,7 +61,7 @@ test("the Set command should serialize correctly", (t) => { duration.serializeSet(), ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { @@ -74,6 +74,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const cc = new BinarySwitchCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.currentValue, true); @@ -93,6 +94,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { const cc = new BinarySwitchCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.currentValue, true); @@ -108,6 +110,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new BinarySwitchCC(host, { nodeId: 2, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, BinarySwitchCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts index 72fa106040cd..4a48f506f282 100644 --- a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts @@ -25,7 +25,7 @@ test("should match the specs", (t) => { // SDS13783 contains the following sample encapsulated command: const basicCCGet = new BasicCCGet(host, { nodeId: 1 }); const crc16 = CRC16CC.encapsulate(host, basicCCGet); - const serialized = crc16.serialize(); + const serialized = crc16.serialize({} as any); const expected = Buffer.from("560120024d26", "hex"); t.deepEqual(serialized, expected); }); @@ -38,11 +38,12 @@ test("serialization and deserialization should be compatible", (t) => { const crc16 = CRC16CC.encapsulate(host, basicCCSet); t.is(crc16.nodeId, basicCCSet.nodeId); t.is(crc16.encapsulated, basicCCSet); - const serialized = crc16.serialize(); + const serialized = crc16.serialize({} as any); const deserialized = CommandClass.from(host, { nodeId: basicCCSet.nodeId as number, data: serialized, + context: {} as any, }); t.is(deserialized.nodeId, basicCCSet.nodeId); const deserializedPayload = (deserialized as CRC16CCCommandEncapsulation) @@ -60,12 +61,13 @@ test("deserializing a CC with a wrong checksum should result in an invalid CC", const crc16 = CRC16CC.encapsulate(host, basicCCSet); t.is(crc16.nodeId, basicCCSet.nodeId); t.is(crc16.encapsulated, basicCCSet); - const serialized = crc16.serialize(); + const serialized = crc16.serialize({} as any); serialized[serialized.length - 1] ^= 0xff; const decoded = CommandClass.from(host, { nodeId: basicCCSet.nodeId as number, data: serialized, + context: {} as any, }); t.true(decoded instanceof InvalidCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts index 233d338e5e1f..0df8766b8eba 100644 --- a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts @@ -33,7 +33,7 @@ test("the ConfigurationGet command should serialize correctly", (t) => { CentralSceneCommand.ConfigurationGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ConfigurationSet command should serialize correctly (flags set)", (t) => { @@ -47,7 +47,7 @@ test("the ConfigurationSet command should serialize correctly (flags set)", (t) 0b1000_0000, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ConfigurationSet command should serialize correctly (flags not set)", (t) => { @@ -61,7 +61,7 @@ test("the ConfigurationSet command should serialize correctly (flags not set)", 0, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ConfigurationReport command should be deserialized correctly", (t) => { @@ -74,6 +74,7 @@ test("the ConfigurationReport command should be deserialized correctly", (t) => const cc = new CentralSceneCCConfigurationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.slowRefresh, true); @@ -88,7 +89,7 @@ test("the SupportedGet command should serialize correctly", (t) => { CentralSceneCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedReport command should be deserialized correctly", (t) => { @@ -106,6 +107,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { const cc = new CentralSceneCCSupportedReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.sceneCount, 2); @@ -128,6 +130,7 @@ test("the Notification command should be deserialized correctly", (t) => { const cc = new CentralSceneCCNotification(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.sequenceNumber, 7); @@ -149,6 +152,7 @@ test("the Notification command should be deserialized correctly (KeyHeldDown)", const cc = new CentralSceneCCNotification(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.sequenceNumber, 7); @@ -164,6 +168,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new CentralSceneCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, CentralSceneCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts index e361794a6589..e16845b17130 100644 --- a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts @@ -39,7 +39,7 @@ test("the SupportedGet command should serialize correctly", (t) => { ColorSwitchCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedReport command should deserialize correctly", (t) => { @@ -53,6 +53,7 @@ test("the SupportedReport command should deserialize correctly", (t) => { const cc = new ColorSwitchCCSupportedReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.deepEqual(cc.supportedColorComponents, [ @@ -81,7 +82,7 @@ test("the Get command should serialize correctly", (t) => { 2, // Color Component ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should deserialize correctly (version 1)", (t) => { @@ -95,6 +96,7 @@ test("the Report command should deserialize correctly (version 1)", (t) => { const cc = new ColorSwitchCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.colorComponent, ColorComponent.Red); @@ -116,6 +118,7 @@ test("the Report command should deserialize correctly (version 3)", (t) => { const cc = new ColorSwitchCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.colorComponent, ColorComponent.Red); @@ -144,7 +147,7 @@ test("the Set command should serialize correctly (without duration)", (t) => { 0xff, // duration: default ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (version 2)", (t) => { @@ -167,7 +170,7 @@ test("the Set command should serialize correctly (version 2)", (t) => { 0b0000_0001, // duration: 1 ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the StartLevelChange command should serialize correctly", (t) => { @@ -190,7 +193,7 @@ test("the StartLevelChange command should serialize correctly", (t) => { 0b0000_0001, // duration: 1 ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the StopLevelChange command should serialize correctly", (t) => { @@ -205,7 +208,7 @@ test("the StopLevelChange command should serialize correctly", (t) => { 0b0000_0010, // color: red ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the setValue API verifies that targetColor isn't set with non-numeric keys", async (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts index e5309f307398..2e22d9589137 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts @@ -100,6 +100,7 @@ test(`persistValues() should not store values marked as "events" (non-stateful)` CentralSceneKeys.KeyPressed, 1, // scene number ]), + context: {} as any, }); // Central Scene should use the value notification event instead of added/updated diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts index 1c1686546186..b15ad4d12f21 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts @@ -40,7 +40,7 @@ test(`creating and serializing should work for unspecified commands`, (t) => { callbackId: 0xfe, }); t.deepEqual( - msg.serialize(), + msg.serialize({} as any), Buffer.from("010c001302055d0201020325fe63", "hex"), ); }); @@ -50,6 +50,7 @@ test("from() returns an un-specialized instance when receiving a non-implemented const cc = CommandClass.from(host, { data: Buffer.from("78030100", "hex"), nodeId: 5, + context: {} as any, }); t.is(cc.constructor, CommandClass); t.is(cc.nodeId, 5); @@ -64,6 +65,7 @@ test("from() does not throw when the CC is implemented", (t) => { // CRC-16 with BasicCC data: Buffer.from("560120024d26", "hex"), nodeId: 5, + context: {} as any, }) ); }); diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts index eb6244b39568..702bb1a61f9c 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts @@ -46,7 +46,7 @@ test("the OperationGet command should serialize correctly", (t) => { DoorLockCommand.OperationGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the OperationSet command should serialize correctly", (t) => { @@ -60,7 +60,7 @@ test("the OperationSet command should serialize correctly", (t) => { 0x20, // target value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the OperationReport command (v1-v3) should be deserialized correctly", (t) => { @@ -77,6 +77,7 @@ test("the OperationReport command (v1-v3) should be deserialized correctly", (t) const cc = new DoorLockCCOperationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.currentMode, DoorLockMode.InsideUnsecuredWithTimeout); @@ -106,6 +107,7 @@ test("the OperationReport command (v4) should be deserialized correctly", (t) => const cc = new DoorLockCCOperationReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); cc.persistValues(host); @@ -134,7 +136,7 @@ test("the ConfigurationGet command should serialize correctly", (t) => { DoorLockCommand.ConfigurationGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ConfigurationReport command (v1-v3) should be deserialized correctly", (t) => { @@ -150,6 +152,7 @@ test("the ConfigurationReport command (v1-v3) should be deserialized correctly", const cc = new DoorLockCCConfigurationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.operationType, DoorLockOperationType.Timed); @@ -185,6 +188,7 @@ test("the ConfigurationReport command must ignore invalid timeouts (constant)", const cc = new DoorLockCCConfigurationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.lockTimeoutConfiguration, undefined); @@ -203,6 +207,7 @@ test("the ConfigurationReport command must ignore invalid timeouts (invalid minu const cc = new DoorLockCCConfigurationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.lockTimeoutConfiguration, undefined); @@ -221,6 +226,7 @@ test("the ConfigurationReport command must ignore invalid timeouts (invalid seco const cc = new DoorLockCCConfigurationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.lockTimeoutConfiguration, undefined); @@ -245,6 +251,7 @@ test("the ConfigurationReport command (v4) should be deserialized correctly", (t const cc = new DoorLockCCConfigurationReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.autoRelockTime, 0xff01); @@ -279,7 +286,7 @@ test("the ConfigurationSet command (v4) should serialize correctly", (t) => { 0b1, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CapabilitiesGet command should serialize correctly", (t) => { @@ -289,7 +296,7 @@ test("the CapabilitiesGet command should serialize correctly", (t) => { DoorLockCommand.CapabilitiesGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CapabilitiesReport command should be deserialized correctly", (t) => { @@ -310,6 +317,7 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { const cc = new DoorLockCCCapabilitiesReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.deepEqual(cc.supportedOperationTypes, [ diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts index 344048ea52f5..c82487f7c8fc 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts @@ -30,7 +30,7 @@ test("the RecordsCountGet command should serialize correctly", (t) => { DoorLockLoggingCommand.RecordsSupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the RecordsCountReport command should be deserialized correctly", (t) => { @@ -43,6 +43,7 @@ test("the RecordsCountReport command should be deserialized correctly", (t) => { const cc = new DoorLockLoggingCCRecordsSupportedReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.recordsCount, 20); @@ -59,7 +60,7 @@ test("the RecordGet command should serialize correctly", (t) => { 1, // Record Number ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the RecordReport command should be deserialized correctly", (t) => { @@ -84,6 +85,7 @@ test("the RecordReport command should be deserialized correctly", (t) => { const cc = new DoorLockLoggingCCRecordReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.recordNumber, 7); diff --git a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts index 4b52b4d1e6b8..5cfb64a224e7 100644 --- a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts @@ -48,6 +48,7 @@ test("the Notification command should deserialize correctly", (t) => { const cc = new EntryControlCCNotification(host, { nodeId: 1, data, + context: {} as any, }); t.deepEqual(cc.sequenceNumber, 1); @@ -65,7 +66,7 @@ test("the ConfigurationGet command should serialize correctly", (t) => { EntryControlCommand.ConfigurationGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ConfigurationSet command should serialize correctly", (t) => { @@ -81,7 +82,7 @@ test("the ConfigurationSet command should serialize correctly", (t) => { 0x2, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ConfigurationReport command should be deserialize correctly", (t) => { @@ -96,6 +97,7 @@ test("the ConfigurationReport command should be deserialize correctly", (t) => { const cc = new EntryControlCCConfigurationReport(host, { nodeId: 1, data, + context: {} as any, }); t.deepEqual(cc.keyCacheSize, 1); @@ -111,7 +113,7 @@ test("the EventSupportedGet command should serialize correctly", (t) => { EntryControlCommand.EventSupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the EventSupportedReport command should be deserialize correctly", (t) => { @@ -135,6 +137,7 @@ test("the EventSupportedReport command should be deserialize correctly", (t) => const cc = new EntryControlCCEventSupportedReport(host, { nodeId: 1, data, + context: {} as any, }); t.deepEqual(cc.supportedDataTypes, [EntryControlDataTypes.ASCII]); @@ -157,7 +160,7 @@ test("the KeySupportedGet command should serialize correctly", (t) => { EntryControlCommand.KeySupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the KeySupportedReport command should be deserialize correctly", (t) => { @@ -172,6 +175,7 @@ test("the KeySupportedReport command should be deserialize correctly", (t) => { const cc = new EntryControlCCKeySupportedReport(host, { nodeId: 1, data, + context: {} as any, }); t.deepEqual(cc.supportedKeys, [1, 3, 4, 6]); diff --git a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts index 0da36b676795..33ca24da25f0 100644 --- a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts @@ -38,7 +38,7 @@ test("the Set Tilt command should serialize correctly", (t) => { 0x63, // Tilt ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly", (t) => { @@ -53,6 +53,7 @@ test("the Report command should be deserialized correctly", (t) => { const cc = CommandClass.from(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.true(cc instanceof FibaroVenetianBlindCCReport); t.is((cc as FibaroVenetianBlindCCReport).position, 0); @@ -89,6 +90,7 @@ test("FibaroVenetianBlindCCSet => FibaroVenetianBlindCCReport = unexpected", (t) 0x07, // Tilt ]), ), + context: {} as any, }); t.false(ccRequest.isExpectedCCResponse(ccResponse)); @@ -108,6 +110,7 @@ test("FibaroVenetianBlindCCGet => FibaroVenetianBlindCCReport = expected", (t) = 0x07, // Tilt ]), ), + context: {} as any, }); t.true(ccRequest.isExpectedCCResponse(ccResponse)); diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts index d5f42b35de02..e4070aa7277c 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts @@ -33,7 +33,7 @@ test("the Get command should serialize correctly", (t) => { HumidityControlModeCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly", (t) => { @@ -47,7 +47,7 @@ test("the Set command should serialize correctly", (t) => { 0x03, // target value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly", (t) => { @@ -60,6 +60,7 @@ test("the Report command should be deserialized correctly", (t) => { const cc = new HumidityControlModeCCReport(host, { nodeId, data: ccData, + context: {} as any, }); t.is(cc.mode, HumidityControlMode.Auto); @@ -75,6 +76,7 @@ test("the Report command should set the correct value", (t) => { const report = new HumidityControlModeCCReport(host, { nodeId, data: ccData, + context: {} as any, }); report.persistValues(host); @@ -95,6 +97,7 @@ test("the Report command should set the correct metadata", (t) => { const cc = new HumidityControlModeCCReport(host, { nodeId, data: ccData, + context: {} as any, }); cc.persistValues(host); @@ -117,7 +120,7 @@ test("the SupportedGet command should serialize correctly", (t) => { HumidityControlModeCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedReport command should be deserialized correctly", (t) => { @@ -130,6 +133,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { const cc = new HumidityControlModeCCSupportedReport(host, { nodeId, data: ccData, + context: {} as any, }); t.deepEqual(cc.supportedModes, [ @@ -148,6 +152,7 @@ test("the SupportedReport command should set the correct metadata", (t) => { const cc = new HumidityControlModeCCSupportedReport(host, { nodeId, data: ccData, + context: {} as any, }); cc.persistValues(host); diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts index 68618f0b605e..b9306f6e4f84 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts @@ -28,7 +28,7 @@ test("the Get command should serialize correctly", (t) => { HumidityControlOperatingStateCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly", (t) => { @@ -41,6 +41,7 @@ test("the Report command should be deserialized correctly", (t) => { const cc = new HumidityControlOperatingStateCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.state, HumidityControlOperatingState.Humidifying); diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts index cf3d3a95f401..3d51bc842047 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts @@ -38,7 +38,7 @@ test("the Get command should serialize correctly", (t) => { HumidityControlSetpointType.Humidifier, // type ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly", (t) => { @@ -57,7 +57,7 @@ test("the Set command should serialize correctly", (t) => { encodeFloatWithScale(57, 1), ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly", (t) => { @@ -73,6 +73,7 @@ test("the Report command should be deserialized correctly", (t) => { const cc = new HumidityControlSetpointCCReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); t.deepEqual(cc.type, HumidityControlSetpointType.Humidifier); @@ -98,6 +99,7 @@ test("the Report command should set the correct value", (t) => { const report = new HumidityControlSetpointCCReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); report.persistValues(host); @@ -129,6 +131,7 @@ test("the Report command should set the correct metadata", (t) => { const report = new HumidityControlSetpointCCReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); report.persistValues(host); @@ -154,7 +157,7 @@ test("the SupportedGet command should serialize correctly", (t) => { HumidityControlSetpointCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedReport command should be deserialized correctly", (t) => { @@ -168,6 +171,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { const cc = new HumidityControlSetpointCCSupportedReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); t.deepEqual(cc.supportedSetpointTypes, [ @@ -187,6 +191,7 @@ test("the SupportedReport command should set the correct value", (t) => { const report = new HumidityControlSetpointCCSupportedReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); report.persistValues(host); @@ -211,7 +216,7 @@ test("the ScaleSupportedGet command should serialize correctly", (t) => { HumidityControlSetpointType.Auto, // type ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the ScaleSupportedReport command should be deserialized correctly", (t) => { @@ -224,6 +229,7 @@ test("the ScaleSupportedReport command should be deserialized correctly", (t) => const cc = new HumidityControlSetpointCCScaleSupportedReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); t.deepEqual(cc.supportedScales, [0, 1]); @@ -249,7 +255,7 @@ test("the CapabilitiesGet command should serialize correctly", (t) => { HumidityControlSetpointType.Auto, // type ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CapabilitiesReport command should be deserialized correctly", (t) => { @@ -266,6 +272,7 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { const cc = new HumidityControlSetpointCCCapabilitiesReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); t.deepEqual(cc.type, HumidityControlSetpointType.Humidifier); @@ -289,6 +296,7 @@ test("the CapabilitiesReport command should set the correct metadata", (t) => { const report = new HumidityControlSetpointCCCapabilitiesReport(host, { nodeId: nodeId, data: ccData, + context: {} as any, }); report.persistValues(host); diff --git a/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts b/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts index 626c640c93f2..a289db4fd407 100644 --- a/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts @@ -30,7 +30,7 @@ test("the Get command (V1) should serialize correctly", (t) => { IndicatorCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command (V2) should serialize correctly", (t) => { @@ -44,7 +44,7 @@ test("the Get command (V2) should serialize correctly", (t) => { 5, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command (v1) should serialize correctly", (t) => { @@ -58,7 +58,7 @@ test("the Set command (v1) should serialize correctly", (t) => { 23, // value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command (v2) should serialize correctly", (t) => { @@ -90,7 +90,7 @@ test("the Set command (v2) should serialize correctly", (t) => { 1, // value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { @@ -103,6 +103,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const cc = new IndicatorCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.indicator0Value, 55); @@ -126,6 +127,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { const cc = new IndicatorCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); // Boolean indicators are only interpreted during persistValues cc.persistValues(host); @@ -152,6 +154,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new IndicatorCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, IndicatorCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts index 200531664cfe..65670b823004 100644 --- a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts @@ -27,7 +27,7 @@ test("the Get command should serialize correctly", (t) => { LanguageCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (w/o country code)", (t) => { @@ -44,7 +44,7 @@ test("the Set command should serialize correctly (w/o country code)", (t) => { 0x75, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (w/ country code)", (t) => { @@ -65,7 +65,7 @@ test("the Set command should serialize correctly (w/ country code)", (t) => { 0x45, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly (w/o country code)", (t) => { @@ -81,6 +81,7 @@ test("the Report command should be deserialized correctly (w/o country code)", ( const cc = new LanguageCCReport(host, { nodeId: 4, data: ccData, + context: {} as any, }); t.is(cc.language, "deu"); @@ -103,6 +104,7 @@ test("the Report command should be deserialized correctly (w/ country code)", (t const cc = new LanguageCCReport(host, { nodeId: 4, data: ccData, + context: {} as any, }); t.is(cc.language, "deu"); @@ -116,6 +118,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new LanguageCC(host, { nodeId: 4, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, LanguageCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts index 2d4e4e041b45..9b81d16e3b1f 100644 --- a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts @@ -25,7 +25,7 @@ test("the Get command should serialize correctly", (t) => { ManufacturerSpecificCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { @@ -43,6 +43,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const cc = new ManufacturerSpecificCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.manufacturerId, 0x0102); diff --git a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts index 2587d4b190a7..90f745908440 100644 --- a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts @@ -37,7 +37,7 @@ test("the Get command (V1) should serialize correctly", (t) => { MeterCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command (V2) should serialize correctly", (t) => { @@ -48,7 +48,7 @@ test("the Get command (V2) should serialize correctly", (t) => { 0b11_000, // Scale ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command (V3) should serialize correctly", (t) => { @@ -59,7 +59,7 @@ test("the Get command (V3) should serialize correctly", (t) => { 0b110_000, // Scale ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command (V4) should serialize correctly", (t) => { @@ -71,7 +71,7 @@ test("the Get command (V4) should serialize correctly", (t) => { 0x1, // Scale 2 ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedGet command should serialize correctly", (t) => { @@ -81,7 +81,7 @@ test("the SupportedGet command should serialize correctly", (t) => { MeterCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Reset command (V2) should serialize correctly", (t) => { @@ -91,7 +91,7 @@ test("the Reset command (V2) should serialize correctly", (t) => { MeterCommand.Reset, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Reset command (V6) should serialize correctly", (t) => { @@ -110,7 +110,7 @@ test("the Reset command (V6) should serialize correctly", (t) => { 123, // 12.3 ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (V1) should be deserialized correctly", (t) => { @@ -122,7 +122,11 @@ test("the Report command (V1) should be deserialized correctly", (t) => { 55, // value ]), ); - const cc = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const cc = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); t.is(cc.type, 3); t.is(cc.scale, 2); @@ -143,7 +147,11 @@ test("the Report command (V2) should be deserialized correctly (no time delta)", 0, ]), ); - const cc = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const cc = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); t.is(cc.type, 3); t.is(cc.scale, 2); @@ -165,7 +173,11 @@ test("the Report command (V2) should be deserialized correctly (with time delta) 54, // previous value ]), ); - const cc = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const cc = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); t.is(cc.type, 3); t.is(cc.scale, 2); @@ -187,7 +199,11 @@ test("the Report command (V3) should be deserialized correctly", (t) => { 54, // previous value ]), ); - const cc = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const cc = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); t.is(cc.scale, 6); }); @@ -205,7 +221,11 @@ test("the Report command (V4) should be deserialized correctly", (t) => { 0b01, // Scale2 ]), ); - const cc = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const cc = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); t.is(cc.scale, 8); }); @@ -224,7 +244,11 @@ test("the Report command should validate that a known meter type is given", (t) ]), ); - const report = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const report = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); // Meter type 31 (does not exist) assertZWaveError(t, () => report.persistValues(host), { @@ -246,7 +270,11 @@ test("the Report command should validate that a known meter scale is given", (t) ]), ); - const report = new MeterCCReport(host, { nodeId: 1, data: ccData }); + const report = new MeterCCReport(host, { + nodeId: 1, + data: ccData, + context: {} as any, + }); // Meter type 4, Scale 8 (does not exist) assertZWaveError(t, () => report.persistValues(host), { @@ -278,6 +306,7 @@ test("the SupportedReport command (V2/V3) should be deserialized correctly", (t) const cc = new MeterCCSupportedReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.type, 21); @@ -300,6 +329,7 @@ test("the SupportedReport command (V4/V5) should be deserialized correctly", (t) const cc = new MeterCCSupportedReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.type, 21); @@ -337,6 +367,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new MeterCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, MeterCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts index 4b51e7bdfecd..89d5907970a5 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts @@ -31,7 +31,7 @@ test("the SupportedGroupingsGet command should serialize correctly", (t) => { MultiChannelAssociationCommand.SupportedGroupingsGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedGroupingsReport command should be deserialized correctly", (t) => { @@ -44,6 +44,7 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t const cc = new MultiChannelAssociationCCSupportedGroupingsReport(host, { nodeId: 4, data: ccData, + context: {} as any, }); t.is(cc.groupCount, 7); @@ -65,7 +66,7 @@ test("the Set command should serialize correctly (node IDs only)", (t) => { 5, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (endpoint addresses only)", (t) => { @@ -96,7 +97,7 @@ test("the Set command should serialize correctly (endpoint addresses only)", (t) 0b11010111, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (both options)", (t) => { @@ -132,7 +133,7 @@ test("the Set command should serialize correctly (both options)", (t) => { 0b11010111, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command should serialize correctly", (t) => { @@ -146,7 +147,7 @@ test("the Get command should serialize correctly", (t) => { 9, // group ID ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly (node IDs only)", (t) => { @@ -165,6 +166,7 @@ test("the Report command should be deserialized correctly (node IDs only)", (t) const cc = new MultiChannelAssociationCCReport(host, { nodeId: 4, data: ccData, + context: {} as any, }); t.is(cc.groupId, 5); @@ -193,6 +195,7 @@ test("the Report command should be deserialized correctly (endpoint addresses on const cc = new MultiChannelAssociationCCReport(host, { nodeId: 4, data: ccData, + context: {} as any, }); t.deepEqual(cc.nodeIds, []); @@ -230,6 +233,7 @@ test("the Report command should be deserialized correctly (both options)", (t) = const cc = new MultiChannelAssociationCCReport(host, { nodeId: 4, data: ccData, + context: {} as any, }); t.deepEqual(cc.nodeIds, [1, 5, 9]); @@ -261,7 +265,7 @@ test("the Remove command should serialize correctly (node IDs only)", (t) => { 5, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Remove command should serialize correctly (endpoint addresses only)", (t) => { @@ -292,7 +296,7 @@ test("the Remove command should serialize correctly (endpoint addresses only)", 0b11010111, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Remove command should serialize correctly (both options)", (t) => { @@ -328,7 +332,7 @@ test("the Remove command should serialize correctly (both options)", (t) => { 0b11010111, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Remove command should serialize correctly (both empty)", (t) => { @@ -342,7 +346,7 @@ test("the Remove command should serialize correctly (both empty)", (t) => { 5, // group id ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); // test("deserializing an unsupported command should return an unspecified version of MultiChannelAssociationCC", (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts index 954209ab8e4f..ab793e0f5bbc 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts @@ -46,7 +46,7 @@ test("the EndPointGet command should serialize correctly", (t) => { MultiChannelCommand.EndPointGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CapabilityGet command should serialize correctly", (t) => { @@ -60,7 +60,7 @@ test("the CapabilityGet command should serialize correctly", (t) => { 7, // EndPoint ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the EndPointFind command should serialize correctly", (t) => { @@ -76,7 +76,7 @@ test("the EndPointFind command should serialize correctly", (t) => { 0x02, // specificClass ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CommandEncapsulation command should serialize correctly", (t) => { @@ -96,7 +96,7 @@ test("the CommandEncapsulation command should serialize correctly", (t) => { 5, // target value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the AggregatedMembersGet command should serialize correctly", (t) => { @@ -110,7 +110,7 @@ test("the AggregatedMembersGet command should serialize correctly", (t) => { 6, // EndPoint ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CommandEncapsulation command should also accept V1CommandEncapsulation as a response", (t) => { @@ -156,6 +156,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new MultiChannelCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, MultiChannelCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts index 93b6be08e3f3..196bf26ea02c 100644 --- a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts @@ -30,7 +30,7 @@ test("the Get command should serialize correctly", (t) => { MultilevelSwitchCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (no duration)", (t) => { @@ -46,7 +46,7 @@ test("the Set command should serialize correctly (no duration)", (t) => { 0xff, // default duration ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command (V2) should serialize correctly", (t) => { @@ -63,7 +63,7 @@ test("the Set command (V2) should serialize correctly", (t) => { 0x81, // 2 minutes ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (V1) should be deserialized correctly", (t) => { @@ -76,6 +76,7 @@ test("the Report command (V1) should be deserialized correctly", (t) => { const cc = new MultilevelSwitchCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.currentValue, 55); @@ -95,6 +96,7 @@ test("the Report command (v4) should be deserialized correctly", (t) => { const cc = new MultilevelSwitchCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.currentValue, 55); @@ -112,7 +114,7 @@ test("the StopLevelChange command should serialize correctly", (t) => { MultilevelSwitchCommand.StopLevelChange, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the StartLevelChange command (V2) should serialize correctly (down, ignore start level, with duration)", (t) => { @@ -132,7 +134,7 @@ test("the StartLevelChange command (V2) should serialize correctly (down, ignore 3, // 3 sec ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the SupportedGet command should serialize correctly", (t) => { @@ -144,7 +146,7 @@ test("the SupportedGet command should serialize correctly", (t) => { MultilevelSwitchCommand.SupportedGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("deserializing an unsupported command should return an unspecified version of MultilevelSwitchCC", (t) => { @@ -154,6 +156,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new MultilevelSwitchCC(host, { nodeId: 2, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, MultilevelSwitchCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts b/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts index 48f3900391af..d64dbae3f886 100644 --- a/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts @@ -19,12 +19,14 @@ test("the CC should serialize correctly", (t) => { const expected = buildCCBuffer( Buffer.from([]), // No command! ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the CC should be deserialized correctly", (t) => { const ccData = buildCCBuffer( Buffer.from([]), // No command! ); - t.notThrows(() => new NoOperationCC(host, { nodeId: 2, data: ccData })); + t.notThrows(() => + new NoOperationCC(host, { nodeId: 2, data: ccData, context: {} as any }) + ); }); diff --git a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts index 8f1e9fd10aea..84e196f00247 100644 --- a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts @@ -28,7 +28,7 @@ test("the Get command should serialize correctly", (t) => { PowerlevelCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set NormalPower command should serialize correctly", (t) => { @@ -43,7 +43,7 @@ test("the Set NormalPower command should serialize correctly", (t) => { 0, // timeout (ignored) ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set NormalPower command with timeout should serialize correctly", (t) => { @@ -59,7 +59,7 @@ test("the Set NormalPower command with timeout should serialize correctly", (t) 0x00, // timeout ignored ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set Custom power command should serialize correctly", (t) => { @@ -75,7 +75,7 @@ test("the Set Custom power command should serialize correctly", (t) => { 50, // timeout ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command should be deserialized correctly (NormalPower)", (t) => { @@ -89,6 +89,7 @@ test("the Report command should be deserialized correctly (NormalPower)", (t) => const cc = new PowerlevelCCReport(host, { nodeId: 5, data: ccData, + context: {} as any, }); t.is(cc.powerlevel, Powerlevel["Normal Power"]); @@ -106,6 +107,7 @@ test("the Report command should be deserialized correctly (custom power)", (t) = const cc = new PowerlevelCCReport(host, { nodeId: 5, data: ccData, + context: {} as any, }); t.is(cc.powerlevel, Powerlevel["-3 dBm"]); @@ -119,6 +121,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new PowerlevelCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, PowerlevelCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts index e9180c52f289..816011639a55 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts @@ -30,7 +30,7 @@ test("the Set command (without Duration) should serialize correctly", (t) => { 0xff, // default duration ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command (with Duration) should serialize correctly", (t) => { @@ -46,7 +46,7 @@ test("the Set command (with Duration) should serialize correctly", (t) => { 0x80, // 1 minute ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should be deserialized correctly", (t) => { @@ -60,6 +60,7 @@ test("the Set command should be deserialized correctly", (t) => { const cc = new SceneActivationCCSet(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.sceneId, 15); @@ -73,6 +74,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new SceneActivationCC(host, { nodeId: 2, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, SceneActivationCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts index 399f0d56083e..e07fbbe8552d 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts @@ -31,7 +31,7 @@ test("the Get command should serialize correctly", (t) => { 1, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly with level", (t) => { @@ -50,7 +50,7 @@ test("the Set command should serialize correctly with level", (t) => { 0x00, // level ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly with undefined level", (t) => { @@ -69,7 +69,7 @@ test("the Set command should serialize correctly with undefined level", (t) => { 0xff, // level ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { @@ -84,6 +84,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const cc = new SceneActuatorConfigurationCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.sceneId, 55); @@ -98,6 +99,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new SceneActuatorConfigurationCC(host, { nodeId: 2, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, SceneActuatorConfigurationCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts index be0075a97f40..43bd787b9846 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts @@ -44,7 +44,7 @@ test("the Get command should serialize correctly", (t) => { 0b0000_0001, ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test.skip("the Get command should throw if GroupId > groupCount", (t) => { @@ -74,7 +74,7 @@ test("the Set command should serialize correctly", (t) => { 0x05, // dimming duration ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly with undefined duration", (t) => { @@ -93,7 +93,7 @@ test("the Set command should serialize correctly with undefined duration", (t) = 0xff, // dimming duration ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test.skip("the Set command should throw if GroupId > groupCount", (t) => { @@ -123,6 +123,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { const cc = new SceneControllerConfigurationCCReport(host, { nodeId: 2, data: ccData, + context: {} as any, }); t.is(cc.groupId, 3); @@ -138,6 +139,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new SceneControllerConfigurationCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, SceneControllerConfigurationCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts index 1e599143259c..8e30ed351239 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts @@ -27,7 +27,7 @@ test("the Get command should serialize correctly", (t) => { ThermostatFanModeCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (off = false)", (t) => { @@ -42,7 +42,7 @@ test("the Set command should serialize correctly (off = false)", (t) => { 0x04, // target value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Set command should serialize correctly (off = true)", (t) => { @@ -57,7 +57,7 @@ test("the Set command should serialize correctly (off = true)", (t) => { 0b1000_0100, // target value ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1-v2) should be deserialized correctly", (t) => { @@ -75,6 +75,7 @@ test("the Report command (v1-v2) should be deserialized correctly", (t) => { { nodeId: 1, data: ccData, + context: {} as any, }, ); @@ -92,6 +93,7 @@ test("the Report command (v3-v5) should be deserialized correctly", (t) => { const cc = new ThermostatFanModeCCReport(host, { nodeId: 5, data: ccData, + context: {} as any, }); t.is(cc.mode, ThermostatFanMode["Auto high"]); diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts index 7c90dca3e40e..4b17d6c55f25 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts @@ -27,7 +27,7 @@ test("the Get command should serialize correctly", (t) => { ThermostatFanStateCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the Report command (v1 - v2) should be deserialized correctly", (t) => { @@ -40,6 +40,7 @@ test("the Report command (v1 - v2) should be deserialized correctly", (t) => { const cc = new ThermostatFanStateCCReport(host, { nodeId: 1, data: ccData, + context: {} as any, }); t.is(cc.state, ThermostatFanState["Idle / off"]); @@ -52,6 +53,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new ThermostatFanStateCC(host, { nodeId: 1, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, ThermostatFanStateCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts index 0b204d306502..c7837be7fe59 100644 --- a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts @@ -28,7 +28,7 @@ test("the TimeGet command should serialize correctly", (t) => { TimeCommand.TimeGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the TimeReport command should be deserialized correctly", (t) => { @@ -43,6 +43,7 @@ test("the TimeReport command should be deserialized correctly", (t) => { const cc = new TimeCCTimeReport(host, { nodeId: 8, data: ccData, + context: {} as any, }); t.is(cc.hour, 14); @@ -57,7 +58,7 @@ test("the DateGet command should serialize correctly", (t) => { TimeCommand.DateGet, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); test("the DateReport command should be deserialized correctly", (t) => { @@ -73,6 +74,7 @@ test("the DateReport command should be deserialized correctly", (t) => { const cc = new TimeCCDateReport(host, { nodeId: 8, data: ccData, + context: {} as any, }); t.is(cc.year, 1989); @@ -87,6 +89,7 @@ test("deserializing an unsupported command should return an unspecified version const cc: any = new TimeCC(host, { nodeId: 8, data: serializedCC, + context: {} as any, }); t.is(cc.constructor, TimeCC); }); diff --git a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts index f81708cf33ef..ec097feedd1a 100644 --- a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts @@ -42,10 +42,8 @@ test("SecurityCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { }; const ccRequest = SecurityCC.encapsulate( - { - ...host, - securityManager, - } as any, + host, + securityManager as any, new WakeUpCCNoMoreInformation(host, { nodeId: 2, endpoint: 2, diff --git a/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts b/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts index 066c2aa59612..c8339cc93297 100644 --- a/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts @@ -23,7 +23,7 @@ test("The Get command should serialize correctly", (t) => { ZWavePlusCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize(), expected); + t.deepEqual(cc.serialize({} as any), expected); }); // describe.skip(`interview()`, () => { diff --git a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts index c299f7530787..6c4309fe816d 100644 --- a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts @@ -47,11 +47,31 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = sm2Node; + mockNode.securityManagers.securityManager2 = sm2Node; // The fixtures define Access Control as granted, but we want the node to send commands using Unauthenticated - mockNode.host.getHighestSecurityClass = () => + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; + // Create a security manager for the controller + const smCtrlr = new SecurityManager2(); + // Copy keys from the driver + smCtrlr.setKey( + SecurityClass.S2_AccessControl, + driver.options.securityKeys!.S2_AccessControl!, + ); + smCtrlr.setKey( + SecurityClass.S2_Authenticated, + driver.options.securityKeys!.S2_Authenticated!, + ); + smCtrlr.setKey( + SecurityClass.S2_Unauthenticated, + driver.options.securityKeys!.S2_Unauthenticated!, + ); + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; + // Respond to S2 Nonce Get const respondToS2NonceGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { @@ -61,6 +81,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -79,7 +100,7 @@ integrationTest( type: SPANState.LocalEI, receiverEI: controllerEI, }); - mockNode.host.securityManager2!.setSPANState( + mockNode.securityManagers.securityManager2!.setSPANState( mockController.host.ownNodeId, { type: SPANState.RemoteEI, @@ -94,6 +115,7 @@ integrationTest( let cc = new Security2CCMessageEncapsulation(mockNode.host, { nodeId: mockController.host.ownNodeId, encapsulated: innerCC, + securityManagers: mockNode.securityManagers, }); await mockNode.sendToController( @@ -136,6 +158,7 @@ integrationTest( cc = new Security2CCMessageEncapsulation(mockNode.host, { nodeId: mockController.host.ownNodeId, encapsulated: innerCC, + securityManagers: mockNode.securityManagers, }); await mockNode.sendToController( diff --git a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts index 47a527cda2f9..b2c99abb29b6 100644 --- a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts @@ -44,8 +44,8 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; // Create a security manager for the controller @@ -63,9 +63,10 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; // Respond to Nonce Get const respondToNonceGet: MockNodeBehavior = { @@ -76,6 +77,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -101,6 +103,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -128,6 +131,7 @@ integrationTest( nodeId: mockController.host.ownNodeId, currentValue: 99, }), + mockNode.securityManagers, ); await mockNode.sendToController( createMockZWaveRequestFrame(nodeToHost, { diff --git a/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts b/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts index f05e0fa95292..b6ad15a97827 100644 --- a/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts @@ -95,8 +95,8 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; // Create a security manager for the controller @@ -114,9 +114,10 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; // Respond to Nonce Get const respondToNonceGet: MockNodeBehavior = { @@ -127,6 +128,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -152,6 +154,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -173,7 +176,9 @@ integrationTest( instanceof Security2CCCommandsSupportedGet ) { const isHighestGranted = receivedCC.securityClass - === self.host.getHighestSecurityClass(self.id); + === self.encodingContext.getHighestSecurityClass( + self.id, + ); const cc = Security2CC.encapsulate( self.host, @@ -192,6 +197,7 @@ integrationTest( .map(([ccId]) => ccId) : [], }), + self.securityManagers, ); return { action: "sendCC", cc }; } @@ -215,6 +221,7 @@ integrationTest( identicalCapabilities: false, individualCount: self.endpoints.size, }), + self.securityManagers, ); return { action: "sendCC", cc }; } @@ -240,6 +247,7 @@ integrationTest( foundEndpoints: [...self.endpoints.keys()], reportsToFollow: 0, }), + self.securityManagers, ); return { action: "sendCC", cc }; } @@ -275,6 +283,7 @@ integrationTest( ...endpoint.implementedCCs.keys(), ], }), + self.securityManagers, ); return { action: "sendCC", cc }; } diff --git a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts index f3be78f262a8..f8e80f92bb93 100644 --- a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts @@ -73,6 +73,7 @@ test.serial( 2, 3, ]), + context: {} as any, }); const msg = new ApplicationCommandRequest(driver, { command: cc, @@ -97,6 +98,7 @@ test.serial( 2, 3, ]), + context: {} as any, }); const msg = new ApplicationCommandRequest(driver, { command: cc, @@ -121,6 +123,7 @@ test.serial( 2, 3, ]), + context: {} as any, }); const cc2 = new AssociationCCReport(driver, { nodeId: 2, @@ -134,6 +137,7 @@ test.serial( 5, 6, ]), + context: {} as any, }); const msg1 = new ApplicationCommandRequest(driver, { command: cc1, @@ -171,10 +175,11 @@ test.serial("supports nested partial/non-partial CCs", (t) => { const cc1 = new BasicCCSet(driver, { nodeId: 2, targetValue: 25 }); const cc = new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + securityManager: driver.securityManager!, encapsulated: {} as any, }); cc.encapsulated = undefined as any; - cc["decryptedCCBytes"] = cc1.serialize(); + cc["decryptedCCBytes"] = cc1.serialize({} as any); const msg = new ApplicationCommandRequest(driver, { command: cc, }); @@ -185,6 +190,7 @@ test.serial("supports nested partial/partial CCs (part 1)", (t) => { const { driver } = t.context; const cc = new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + securityManager: driver.securityManager!, encapsulated: {} as any, }); cc.encapsulated = undefined as any; @@ -208,6 +214,7 @@ test.serial("supports nested partial/partial CCs (part 2)", (t) => { const { driver } = t.context; const cc = new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + securityManager: driver.securityManager!, encapsulated: {} as any, }); cc.encapsulated = undefined as any; @@ -243,6 +250,7 @@ test.serial( 2, 3, ]), + context: {} as any, }); cc.mergePartialCCs = () => { throw new ZWaveError( @@ -273,6 +281,7 @@ test.serial( 2, 3, ]), + context: {} as any, }); cc.mergePartialCCs = () => { throw new ZWaveError( @@ -303,6 +312,7 @@ test.serial( 2, 3, ]), + context: {} as any, }); cc.mergePartialCCs = () => { throw new ZWaveError( @@ -331,6 +341,7 @@ test.serial("passes other errors during merging through", (t) => { 2, 3, ]), + context: {} as any, }); cc.mergePartialCCs = () => { throw new ZWaveError("invalid", ZWaveErrorCodes.Argument_Invalid); diff --git a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts index aaee35298ca0..db026916a45b 100644 --- a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts +++ b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts @@ -46,6 +46,7 @@ test("should compute the correct net payload sizes", (t) => { const testMsg1 = new SendDataRequest(driver, { command: new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + securityManager: driver.securityManager!, encapsulated: {} as any, }), transmitOptions: TransmitOptions.DEFAULT, @@ -61,6 +62,7 @@ test("should compute the correct net payload sizes", (t) => { const testMsg2 = new SendDataRequest(driver, { command: new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + securityManager: driver.securityManager!, encapsulated: multiChannelCC, }), transmitOptions: TransmitOptions.NoRoute, diff --git a/packages/zwave-js/src/lib/test/driver/highestSecurityClass.test.ts b/packages/zwave-js/src/lib/test/driver/highestSecurityClass.test.ts index 99c06cc7f5ca..ff1324a68050 100644 --- a/packages/zwave-js/src/lib/test/driver/highestSecurityClass.test.ts +++ b/packages/zwave-js/src/lib/test/driver/highestSecurityClass.test.ts @@ -88,8 +88,9 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => SecurityClass.None; + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => + SecurityClass.None; // Create a security manager for the controller const smCtrlr = new SecurityManager2(); @@ -106,8 +107,10 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => NOT_KNOWN; + controller.securityManagers.securityManager2 = smCtrlr; + controller.encodingContext.getHighestSecurityClass = + controller.parsingContext.getHighestSecurityClass = + () => NOT_KNOWN; }, testBody: async (t, driver, node, mockController, mockNode) => { diff --git a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts index 943f0472c536..7a9128f339fd 100644 --- a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts @@ -54,8 +54,8 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; // Create a security manager for the controller @@ -65,9 +65,10 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; // Respond to Nonce Get const respondToNonceGet: MockNodeBehavior = { @@ -78,6 +79,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -103,6 +105,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -135,7 +138,11 @@ integrationTest( ], }, ); - cc = Security2CC.encapsulate(self.host, cc); + cc = Security2CC.encapsulate( + self.host, + cc, + self.securityManagers, + ); return { action: "sendCC", cc }; } }, @@ -161,7 +168,11 @@ integrationTest( ccVersion: 0, }, ); - cc = Security2CC.encapsulate(self.host, cc); + cc = Security2CC.encapsulate( + self.host, + cc, + self.securityManagers, + ); return { action: "sendCC", cc }; } }, @@ -194,7 +205,7 @@ integrationTest( networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - mockNode.host.securityManager = sm0Node; + mockNode.securityManagers.securityManager = sm0Node; // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ @@ -202,7 +213,7 @@ integrationTest( networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - controller.host.securityManager = sm0Ctrlr; + controller.securityManagers.securityManager = sm0Ctrlr; // Respond to S0 Nonce Get const respondToS0NonceGet: MockNodeBehavior = { @@ -263,7 +274,11 @@ integrationTest( controlledCCs: [], }, ); - const cc = SecurityCC.encapsulate(self.host, response); + const cc = SecurityCC.encapsulate( + self.host, + self.securityManagers.securityManager!, + response, + ); cc.nonce = receiverNonce; await self.sendToController( createMockZWaveRequestFrame(cc, { @@ -321,7 +336,11 @@ integrationTest( }, ); - const cc = SecurityCC.encapsulate(self.host, response); + const cc = SecurityCC.encapsulate( + self.host, + self.securityManagers.securityManager!, + response, + ); cc.nonce = receiverNonce; await self.sendToController( createMockZWaveRequestFrame(cc, { @@ -342,7 +361,11 @@ integrationTest( if ( receivedCC instanceof SecurityCCCommandEncapsulation ) { - receivedCC.mergePartialCCs(undefined as any, []); + receivedCC.mergePartialCCs( + undefined as any, + [], + {} as any, + ); } return undefined; diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts index 8692762b305a..609a43751e99 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts @@ -31,7 +31,7 @@ integrationTest( networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - mockNode.host.securityManager = sm0Node; + mockNode.securityManagers.securityManager = sm0Node; // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ @@ -39,7 +39,7 @@ integrationTest( networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - controller.host.securityManager = sm0Ctrlr; + controller.securityManagers.securityManager = sm0Ctrlr; // Respond to S0 Nonce Get const respondToS0NonceGet: MockNodeBehavior = { @@ -67,7 +67,11 @@ integrationTest( receivedCC instanceof SecurityCCCommandEncapsulation ) { - receivedCC.mergePartialCCs(undefined as any, []); + receivedCC.mergePartialCCs( + undefined as any, + [], + {} as any, + ); } // This just decodes - we need to call further handlers return undefined; diff --git a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts index fab63ac425c9..1a1d7d816152 100644 --- a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts @@ -49,8 +49,8 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = sm2Node; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = sm2Node; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; const sm0Node = new SecurityManager({ @@ -58,7 +58,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - mockNode.host.securityManager = sm0Node; + mockNode.securityManagers.securityManager = sm0Node; // Create a security manager for the controller const smCtrlr = new SecurityManager2(); @@ -75,16 +75,17 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; const sm0Ctrlr = new SecurityManager({ ownNodeId: controller.host.ownNodeId, networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - controller.host.securityManager = sm0Ctrlr; + controller.securityManagers.securityManager = sm0Ctrlr; // Respond to S0 Nonce Get const respondToS0NonceGet: MockNodeBehavior = { @@ -109,7 +110,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { handleCC(controller, self, receivedCC) { // We don't support sequenced commands here if (receivedCC instanceof SecurityCCCommandEncapsulation) { - receivedCC.mergePartialCCs(undefined as any, []); + receivedCC.mergePartialCCs(undefined as any, [], {} as any); } return undefined; }, @@ -125,6 +126,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -150,6 +152,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -174,7 +177,11 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { moreUpdatesFollow: false, status: SupervisionStatus.Success, }); - cc = Security2CC.encapsulate(self.host, cc); + cc = Security2CC.encapsulate( + self.host, + cc, + self.securityManagers, + ); return { action: "sendCC", cc }; } }, diff --git a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts index 1f5d451ecec9..2a2beb460f22 100644 --- a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts @@ -31,7 +31,7 @@ integrationTest("Communication via Security S0 works", { networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - mockNode.host.securityManager = sm0Node; + mockNode.securityManagers.securityManager = sm0Node; // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ @@ -39,7 +39,7 @@ integrationTest("Communication via Security S0 works", { networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - controller.host.securityManager = sm0Ctrlr; + controller.securityManagers.securityManager = sm0Ctrlr; // Respond to S0 Nonce Get const respondToS0NonceGet: MockNodeBehavior = { @@ -96,7 +96,11 @@ integrationTest("Communication via Security S0 works", { controlledCCs: [], }, ); - const cc = SecurityCC.encapsulate(self.host, response); + const cc = SecurityCC.encapsulate( + self.host, + self.securityManagers.securityManager!, + response, + ); cc.nonce = receiverNonce; await self.sendToController( @@ -144,7 +148,11 @@ integrationTest("Communication via Security S0 works", { nodeId: controller.host.ownNodeId, currentValue: ++queryCount, }); - const cc = SecurityCC.encapsulate(self.host, response); + const cc = SecurityCC.encapsulate( + self.host, + self.securityManagers.securityManager!, + response, + ); cc.nonce = receiverNonce; await self.sendToController( @@ -164,7 +172,7 @@ integrationTest("Communication via Security S0 works", { handleCC(controller, self, receivedCC) { // We don't support sequenced commands here if (receivedCC instanceof SecurityCCCommandEncapsulation) { - receivedCC.mergePartialCCs(undefined as any, []); + receivedCC.mergePartialCCs(undefined as any, [], {} as any); } // This just decodes - we need to call further handlers return undefined; diff --git a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts index f7bb62b37dec..ee4c54b8d1a9 100644 --- a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts @@ -52,7 +52,7 @@ integrationTest( networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - mockNode.host.securityManager = sm0Node; + mockNode.securityManagers.securityManager = sm0Node; // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ @@ -60,7 +60,7 @@ integrationTest( networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); - controller.host.securityManager = sm0Ctrlr; + controller.securityManagers.securityManager = sm0Ctrlr; // Respond to S0 Nonce Get const respondToS0NonceGet: MockNodeBehavior = { @@ -123,6 +123,7 @@ integrationTest( ); const cc = SecurityCC.encapsulate( self.host, + self.securityManagers.securityManager!, response, ); cc.nonce = receiverNonce; @@ -184,6 +185,7 @@ integrationTest( }); const cc = SecurityCC.encapsulate( self.host, + self.securityManagers.securityManager!, response, ); cc.nonce = receiverNonce; @@ -207,7 +209,11 @@ integrationTest( if ( receivedCC instanceof SecurityCCCommandEncapsulation ) { - receivedCC.mergePartialCCs(undefined as any, []); + receivedCC.mergePartialCCs( + undefined as any, + [], + {} as any, + ); } // This just decodes - we need to call further handlers return undefined; diff --git a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts index 74992534b704..ff95961456db 100644 --- a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts @@ -56,8 +56,8 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; // Create a security manager for the controller @@ -75,9 +75,10 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; // Respond to Nonce Get const respondToNonceGet: MockNodeBehavior = { @@ -88,6 +89,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -113,6 +115,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -142,7 +145,11 @@ integrationTest( status: SupervisionStatus.Success, }, ); - cc = Security2CC.encapsulate(self.host, cc); + cc = Security2CC.encapsulate( + self.host, + cc, + self.securityManagers, + ); return { action: "sendCC", cc }; } }, @@ -167,6 +174,7 @@ integrationTest( nodeId: mockController.host.ownNodeId, currentValue: true, }), + mockNode.securityManagers, ); const p1 = mockNode.sendToController( createMockZWaveRequestFrame(nodeToHost, { @@ -221,8 +229,8 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; // Create a security manager for the controller @@ -240,9 +248,10 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.securityManagers.securityManager2 = smCtrlr; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; // Respond to Nonce Get const respondToNonceGet: MockNodeBehavior = { @@ -253,6 +262,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -278,6 +288,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -307,6 +318,7 @@ integrationTest( nodeId: mockController.host.ownNodeId, currentValue: 99, }), + mockNode.securityManagers, ); const p1 = mockNode.sendToController( createMockZWaveRequestFrame(nodeToHost, { @@ -355,8 +367,8 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - mockNode.host.securityManager2 = smNode; - mockNode.host.getHighestSecurityClass = () => + mockNode.securityManagers.securityManager2 = smNode; + mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; // Create a security manager for the controller @@ -374,9 +386,9 @@ integrationTest( SecurityClass.S2_Unauthenticated, driver.options.securityKeys!.S2_Unauthenticated!, ); - controller.host.securityManager2 = smCtrlr; - controller.host.getHighestSecurityClass = () => - SecurityClass.S2_Unauthenticated; + controller.parsingContext.getHighestSecurityClass = + controller.encodingContext.getHighestSecurityClass = + () => SecurityClass.S2_Unauthenticated; // Respond to Nonce Get const respondToNonceGet: MockNodeBehavior = { @@ -387,6 +399,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -412,6 +425,7 @@ integrationTest( ); const cc = new Security2CCNonceReport(self.host, { nodeId: controller.host.ownNodeId, + securityManagers: self.securityManagers, SOS: true, MOS: false, receiverEI: nonce, @@ -441,7 +455,11 @@ integrationTest( status: SupervisionStatus.Success, }, ); - cc = Security2CC.encapsulate(self.host, cc); + cc = Security2CC.encapsulate( + self.host, + cc, + self.securityManagers, + ); return { action: "sendCC", cc }; } }, @@ -475,9 +493,16 @@ integrationTest( nodeToHost = SupervisionCC.encapsulate( mockNode.host, nodeToHost, + driver.getNextSupervisionSessionId( + mockController.host.ownNodeId, + ), false, ); - nodeToHost = Security2CC.encapsulate(mockNode.host, nodeToHost); + nodeToHost = Security2CC.encapsulate( + mockNode.host, + nodeToHost, + mockNode.securityManagers, + ); const report = mockNode.sendToController( createMockZWaveRequestFrame(nodeToHost, { diff --git a/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts b/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts index 51e2d32c93c8..4f02cb584b6a 100644 --- a/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts @@ -73,6 +73,7 @@ test.serial( BinarySwitchCommand.Report, 0xff, ]), + context: {} as any, }, ); await node.handleCommand(command); @@ -124,6 +125,7 @@ test.serial( { nodeId: node.id, data: buf, + context: {} as any, }, ); diff --git a/test/decodeMessage.ts b/test/decodeMessage.ts index 90942ac69462..004d2108724a 100644 --- a/test/decodeMessage.ts +++ b/test/decodeMessage.ts @@ -95,7 +95,7 @@ import { Message } from "@zwave-js/serial"; const msg = Message.from(host, { data }); if (isCommandClassContainer(msg)) { - msg.command.mergePartialCCs(host, []); + msg.command.mergePartialCCs(host, [], {} as any); } msg; debugger; From 190e7cd37b72b8c000bf86a26d98123b110e0e31 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Fri, 11 Oct 2024 23:10:10 +0200 Subject: [PATCH 13/60] fix: decoding messages manually --- test/decodeMessage.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/decodeMessage.ts b/test/decodeMessage.ts index 004d2108724a..ebc5967220c4 100644 --- a/test/decodeMessage.ts +++ b/test/decodeMessage.ts @@ -5,8 +5,11 @@ import "zwave-js"; import { isCommandClassContainer } from "@zwave-js/cc"; import { ConfigManager } from "@zwave-js/config"; import { + CCParsingContext, + NodeIDType, SPANState, SecurityClass, + SecurityManager, SecurityManager2, generateAuthKey, generateEncryptionKey, @@ -19,7 +22,7 @@ import { Message } from "@zwave-js/serial"; // The data to decode const data = Buffer.from( - "012900a8000102209f035a0112c1a5ab925f01ee99f1c610bc6c0422f7fd5923f8f1688d1999114000b5d5", + "011100a800000100820343050200a7007f7f25", "hex", ); // The nonce needed to decode it @@ -53,7 +56,7 @@ import { Message } from "@zwave-js/serial"; }); console.log(Message.getMessageLength(data)); - const host: any = { + const host = { getSafeCCVersion: () => 1, getSupportedCCVersion: () => 1, configManager, @@ -81,21 +84,24 @@ import { Message } from "@zwave-js/serial"; get nodes() { return host.controller.nodes; }, + isCCSecure: () => true, + nodeIdType: NodeIDType.Long, + }; + const ctx = { securityManager: { getNonce: () => nonce, deleteNonce() {}, authKey: generateAuthKey(networkKey), encryptionKey: generateEncryptionKey(networkKey), - }, + } as unknown as SecurityManager, securityManager2: sm2, getHighestSecurityClass: () => SecurityClass.S2_AccessControl, hasSecurityClass: () => true, - isCCSecure: () => true, }; - const msg = Message.from(host, { data }); + const msg = Message.from(host as any, { data, ctx: ctx as any }); if (isCommandClassContainer(msg)) { - msg.command.mergePartialCCs(host, [], {} as any); + msg.command.mergePartialCCs(host as any, [], {} as any); } msg; debugger; From d6aca0c503ba5b0112d96f3e2757814bd0483b21 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Fri, 11 Oct 2024 23:48:38 +0200 Subject: [PATCH 14/60] refactor: move getDeviceConfig to CCParsing/EncodingContext --- packages/cc/src/cc/AlarmSensorCC.ts | 3 +- packages/cc/src/cc/AssociationCC.ts | 4 +- packages/cc/src/cc/AssociationGroupInfoCC.ts | 3 +- packages/cc/src/cc/BarrierOperatorCC.ts | 3 +- packages/cc/src/cc/BasicCC.ts | 5 +- packages/cc/src/cc/BatteryCC.ts | 3 +- packages/cc/src/cc/BinarySensorCC.ts | 3 +- packages/cc/src/cc/BinarySwitchCC.ts | 5 +- packages/cc/src/cc/CRC16CC.ts | 7 ++- packages/cc/src/cc/CentralSceneCC.ts | 3 +- .../cc/src/cc/ClimateControlScheduleCC.ts | 7 ++- packages/cc/src/cc/ClockCC.ts | 3 +- packages/cc/src/cc/ColorSwitchCC.ts | 12 ++-- packages/cc/src/cc/ConfigurationCC.ts | 4 +- packages/cc/src/cc/DoorLockCC.ts | 3 +- packages/cc/src/cc/DoorLockLoggingCC.ts | 3 +- packages/cc/src/cc/EnergyProductionCC.ts | 7 +-- packages/cc/src/cc/EntryControlCC.ts | 5 +- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 3 +- packages/cc/src/cc/HumidityControlModeCC.ts | 3 +- .../src/cc/HumidityControlOperatingStateCC.ts | 2 + .../cc/src/cc/HumidityControlSetpointCC.ts | 3 +- packages/cc/src/cc/InclusionControllerCC.ts | 11 ++-- packages/cc/src/cc/IndicatorCC.ts | 3 +- packages/cc/src/cc/IrrigationCC.ts | 3 +- packages/cc/src/cc/LanguageCC.ts | 3 +- packages/cc/src/cc/LockCC.ts | 3 +- .../cc/src/cc/ManufacturerProprietaryCC.ts | 7 ++- packages/cc/src/cc/ManufacturerSpecificCC.ts | 7 +-- packages/cc/src/cc/MeterCC.ts | 5 +- .../cc/src/cc/MultiChannelAssociationCC.ts | 4 +- packages/cc/src/cc/MultiChannelCC.ts | 26 ++++----- packages/cc/src/cc/MultiCommandCC.ts | 7 ++- packages/cc/src/cc/MultilevelSensorCC.ts | 5 +- packages/cc/src/cc/MultilevelSwitchCC.ts | 7 ++- packages/cc/src/cc/NodeNamingCC.ts | 3 +- packages/cc/src/cc/NotificationCC.ts | 5 +- packages/cc/src/cc/PowerlevelCC.ts | 7 ++- packages/cc/src/cc/ProtectionCC.ts | 5 +- packages/cc/src/cc/SceneActivationCC.ts | 7 ++- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 3 +- .../src/cc/SceneControllerConfigurationCC.ts | 3 +- packages/cc/src/cc/ScheduleEntryLockCC.ts | 8 +-- packages/cc/src/cc/Security2CC.ts | 4 +- packages/cc/src/cc/SecurityCC.ts | 8 +-- packages/cc/src/cc/SoundSwitchCC.ts | 3 +- packages/cc/src/cc/SupervisionCC.ts | 3 +- packages/cc/src/cc/ThermostatFanModeCC.ts | 3 +- packages/cc/src/cc/ThermostatFanStateCC.ts | 2 + packages/cc/src/cc/ThermostatModeCC.ts | 3 +- .../cc/src/cc/ThermostatOperatingStateCC.ts | 2 + packages/cc/src/cc/ThermostatSetbackCC.ts | 3 +- packages/cc/src/cc/ThermostatSetpointCC.ts | 5 +- packages/cc/src/cc/TimeCC.ts | 7 +-- packages/cc/src/cc/TimeParametersCC.ts | 3 +- packages/cc/src/cc/TransportServiceCC.ts | 4 +- packages/cc/src/cc/UserCodeCC.ts | 3 +- packages/cc/src/cc/VersionCC.ts | 3 +- packages/cc/src/cc/WakeUpCC.ts | 3 +- packages/cc/src/cc/WindowCoveringCC.ts | 7 +-- packages/cc/src/cc/ZWavePlusCC.ts | 3 +- packages/cc/src/cc/ZWaveProtocolCC.ts | 3 +- .../cc/manufacturerProprietary/FibaroCC.ts | 3 +- packages/cc/src/lib/CommandClass.ts | 4 +- .../core/src/abstractions/ICommandClass.ts | 45 +-------------- packages/host/src/ZWaveHost.ts | 56 ++++++++++++++++++- packages/serial/src/message/Message.ts | 8 ++- packages/testing/src/MockController.ts | 2 +- packages/testing/src/MockNode.ts | 3 +- .../zwave-js/src/lib/controller/Controller.ts | 16 ++++++ .../src/lib/driver/MessageGenerators.ts | 2 +- .../application/ApplicationCommandRequest.ts | 2 +- .../application/ApplicationUpdateRequest.ts | 2 +- .../BridgeApplicationCommandRequest.ts | 2 +- .../application/SerialAPIStartedRequest.ts | 2 +- .../serialapi/application/ShutdownMessages.ts | 2 +- .../GetControllerCapabilitiesMessages.ts | 2 +- .../GetControllerVersionMessages.ts | 2 +- .../capability/GetLongRangeNodesMessages.ts | 2 +- .../capability/GetProtocolVersionMessages.ts | 2 +- .../GetSerialApiCapabilitiesMessages.ts | 2 +- .../GetSerialApiInitDataMessages.ts | 2 +- .../serialapi/capability/HardResetRequest.ts | 2 +- .../capability/LongRangeChannelMessages.ts | 2 +- .../capability/SerialAPISetupMessages.ts | 2 +- .../SetApplicationNodeInformationRequest.ts | 2 +- .../SetLongRangeShadowNodeIDsRequest.ts | 2 +- .../memory/GetControllerIdMessages.ts | 2 +- .../misc/GetBackgroundRSSIMessages.ts | 2 +- .../misc/SetRFReceiveModeMessages.ts | 2 +- .../misc/SetSerialApiTimeoutsMessages.ts | 2 +- .../AssignPriorityReturnRouteMessages.ts | 2 +- .../AssignPrioritySUCReturnRouteMessages.ts | 2 +- .../network-mgmt/AssignReturnRouteMessages.ts | 2 +- .../AssignSUCReturnRouteMessages.ts | 14 ++--- .../network-mgmt/DeleteReturnRouteMessages.ts | 2 +- .../DeleteSUCReturnRouteMessages.ts | 14 ++--- .../GetNodeProtocolInfoMessages.ts | 2 +- .../network-mgmt/GetPriorityRouteMessages.ts | 2 +- .../network-mgmt/GetRoutingInfoMessages.ts | 2 +- .../network-mgmt/GetSUCNodeIdMessages.ts | 2 +- .../network-mgmt/IsFailedNodeMessages.ts | 2 +- .../network-mgmt/RemoveFailedNodeMessages.ts | 2 +- .../RemoveNodeFromNetworkRequest.ts | 2 +- .../network-mgmt/ReplaceFailedNodeRequest.ts | 2 +- .../network-mgmt/RequestNodeInfoMessages.ts | 2 +- .../RequestNodeNeighborUpdateMessages.ts | 2 +- .../network-mgmt/SetLearnModeMessages.ts | 2 +- .../network-mgmt/SetPriorityRouteMessages.ts | 2 +- .../network-mgmt/SetSUCNodeIDMessages.ts | 2 +- .../nvm/ExtNVMReadLongBufferMessages.ts | 2 +- .../nvm/ExtNVMReadLongByteMessages.ts | 2 +- .../nvm/ExtNVMWriteLongBufferMessages.ts | 2 +- .../nvm/ExtNVMWriteLongByteMessages.ts | 2 +- .../nvm/ExtendedNVMOperationsMessages.ts | 2 +- .../nvm/FirmwareUpdateNVMMessages.ts | 2 +- .../src/lib/serialapi/nvm/GetNVMIdMessages.ts | 2 +- .../serialapi/nvm/NVMOperationsMessages.ts | 2 +- .../transport/SendDataBridgeMessages.ts | 3 +- .../serialapi/transport/SendDataMessages.ts | 2 +- .../transport/SendTestFrameMessages.ts | 2 +- test/decodeMessage.ts | 1 - 122 files changed, 318 insertions(+), 245 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 882cae2b90d8..e72e6838f67b 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -13,6 +12,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 598def511cd2..2973946d542f 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -1,12 +1,10 @@ import type { - CCParsingContext, EndpointId, MaybeNotKnown, MessageRecord, SupervisionResult, } from "@zwave-js/core/safe"; import { - type CCEncodingContext, CommandClasses, MAX_NODES, type MessageOrCCLogEntry, @@ -16,6 +14,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index bf51e322b7b0..48d4c11c5184 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -13,6 +12,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 7460357c2ab4..069c1798fb6b 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MaybeUnknown, @@ -16,6 +15,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index ab22966d166f..1f4789c27dcb 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -15,6 +14,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -494,7 +495,7 @@ export class BasicCCReport extends BasicCC { ]); if ( - this.version < 2 && this.host.getDeviceConfig?.( + this.version < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index f6e9eea873f0..e886fc23ab76 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -1,6 +1,5 @@ import { timespan } from "@zwave-js/core"; import type { - CCEncodingContext, MessageOrCCLogEntry, MessageRecord, SinglecastCC, @@ -15,6 +14,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index a41f35dcd442..8f5dac71ed38 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -12,6 +11,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 82ebc60ea16e..ac48bcd4c957 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -16,6 +15,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -340,7 +341,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC { ]); if ( - this.version < 2 && this.host.getDeviceConfig?.( + this.version < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index fd9de6776bb0..a837942ac43a 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CRC16_CCITT, CommandClasses, EncapsulationFlags, @@ -7,7 +6,11 @@ import { type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; +import type { + CCEncodingContext, + ZWaveHost, + ZWaveValueHost, +} from "@zwave-js/host/safe"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 9c90374d3952..9cb13ddbe7b5 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -16,6 +15,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index b510dbd69185..638a6e496e28 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -10,7 +9,11 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; +import type { + CCEncodingContext, + ZWaveHost, + ZWaveValueHost, +} from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index e7162708c393..c93fc9e760e4 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -1,5 +1,4 @@ import type { - CCEncodingContext, MessageOrCCLogEntry, SupervisionResult, } from "@zwave-js/core/safe"; @@ -12,6 +11,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index bf9f30d21290..981d57de4718 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -15,12 +15,10 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type MaybeNotKnown, - encodeBitMask, -} from "@zwave-js/core/safe"; +import { type MaybeNotKnown, encodeBitMask } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -1027,7 +1025,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC { ).serializeSet(); if ( - this.version < 2 && this.host.getDeviceConfig?.( + this.version < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { @@ -1126,7 +1124,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { ]); if ( - this.version < 3 && this.host.getDeviceConfig?.( + this.version < 3 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index d53fd55d8c61..884fecf00ed2 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -1,7 +1,5 @@ import type { ParamInfoMap } from "@zwave-js/config"; import { - type CCEncodingContext, - type CCParsingContext, CommandClasses, ConfigValueFormat, type ConfigurationMetadata, @@ -27,6 +25,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 987c1074907d..7b7a556cce7f 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, type EndpointId, @@ -17,6 +16,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index ebb14e2d5bd8..839bf5ab2729 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -10,6 +9,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index dec599ee0662..e6a2f0d1d39f 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -7,11 +7,10 @@ import { parseFloatWithScale, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type MaybeNotKnown, -} from "@zwave-js/core/safe"; +import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index 17248fb74086..7bd6c77d48a8 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -15,6 +14,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -416,7 +417,7 @@ export class EntryControlCCNotification extends EntryControlCC { // But as always - manufacturers don't care and send ASCII data with 0 bytes... // We also need to disable the strict validation for some devices to make them work - const noStrictValidation = !!this.host.getDeviceConfig?.( + const noStrictValidation = !!options.context.getDeviceConfig?.( this.nodeId as number, )?.compat?.disableStrictEntryControlDataValidation; diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index 3e35daefec92..b5f4e36f4168 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CRC16_CCITT, CommandClasses, type MaybeNotKnown, @@ -11,6 +10,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index 479f0b42c89d..a71ce737c586 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -14,6 +13,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index 4c93b6085bfa..bea9929450d2 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -8,6 +8,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 07d822b94029..e56dd16f7b31 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -19,6 +18,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index 0ac2f402fa2a..14c73c821e7b 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -3,11 +3,12 @@ import { type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type MaybeNotKnown, -} from "@zwave-js/core/safe"; -import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host"; +import { type MaybeNotKnown } from "@zwave-js/core/safe"; +import type { + CCEncodingContext, + ZWaveHost, + ZWaveValueHost, +} from "@zwave-js/host"; import { getEnumMemberName } from "@zwave-js/shared"; import { CCAPI } from "../lib/API"; import { diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 79c28a2e5942..4ce8882a0a55 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -1,6 +1,5 @@ import type { ConfigManager } from "@zwave-js/config"; import { - type CCEncodingContext, CommandClasses, type EndpointId, Indicator, @@ -18,6 +17,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 12872db26eca..63e1274deea0 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -17,6 +16,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index feb07f8aeae7..9544b28d1abf 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -1,5 +1,4 @@ import type { - CCEncodingContext, MessageOrCCLogEntry, MessageRecord, SupervisionResult, @@ -14,6 +13,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 3ec0aba6c3b3..04ca006022ab 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -12,6 +11,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index 04b21a234a8c..b9530afba754 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -1,11 +1,14 @@ import { - type CCEncodingContext, CommandClasses, ZWaveError, ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveApplicationHost, ZWaveHost } from "@zwave-js/host/safe"; +import type { + CCEncodingContext, + ZWaveApplicationHost, + ZWaveHost, +} from "@zwave-js/host/safe"; import { staticExtends } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, type CCAPIEndpoint, type CCAPINode } from "../lib/API"; diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 9fe8115c790f..2016cae76270 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -1,7 +1,4 @@ -import type { - CCEncodingContext, - MessageOrCCLogEntry, -} from "@zwave-js/core/safe"; +import type { MessageOrCCLogEntry } from "@zwave-js/core/safe"; import { CommandClasses, type MaybeNotKnown, @@ -12,6 +9,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index f2984b4818b3..ef9ba16b36a3 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -11,7 +11,6 @@ import { timespan, } from "@zwave-js/core"; import { - type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -27,6 +26,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -939,7 +940,7 @@ export class MeterCCReport extends MeterCC { ?? getUnknownMeterScale(this.scale); // Filter out unknown meter types and scales, unless the strict validation is disabled - const measurementValidation = !this.host.getDeviceConfig?.( + const measurementValidation = !applHost.getDeviceConfig?.( this.nodeId as number, )?.compat?.disableStrictMeasurementValidation; diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 800531c337bb..c11dc4c6d9cb 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -1,6 +1,4 @@ import type { - CCEncodingContext, - CCParsingContext, EndpointId, MessageRecord, SupervisionResult, @@ -18,6 +16,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index f50a55317da3..36d880b8ba11 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -1,7 +1,5 @@ import { type ApplicationNodeInformation, - type CCEncodingContext, - type CCParsingContext, CommandClasses, type GenericDeviceClass, type MaybeNotKnown, @@ -21,6 +19,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -1335,7 +1335,7 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); if ( - this.host.getDeviceConfig?.(this.nodeId as number)?.compat + options.context.getDeviceConfig?.(this.nodeId as number)?.compat ?.treatDestinationEndpointAsSource ) { // This device incorrectly uses the destination field to indicate the source endpoint @@ -1366,16 +1366,6 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { this.encapsulated = options.encapsulated; options.encapsulated.encapsulatingCC = this as any; this.destination = options.destination; - - if ( - this.host.getDeviceConfig?.(this.nodeId as number)?.compat - ?.treatDestinationEndpointAsSource - ) { - // This device incorrectly responds from the endpoint we've passed as our source endpoint - if (typeof this.destination === "number") { - this.endpointIndex = this.destination; - } - } } } @@ -1384,6 +1374,16 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { public destination: MultiChannelCCDestination; public serialize(ctx: CCEncodingContext): Buffer { + if ( + ctx.getDeviceConfig?.(this.nodeId as number)?.compat + ?.treatDestinationEndpointAsSource + ) { + // This device incorrectly responds from the endpoint we've passed as our source endpoint + if (typeof this.destination === "number") { + this.endpointIndex = this.destination; + } + } + const destination = typeof this.destination === "number" // The destination is a single number ? this.destination & 0b0111_1111 diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index 00a3e2322ac0..6be8722f0665 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -1,12 +1,15 @@ import { - type CCEncodingContext, CommandClasses, EncapsulationFlags, type MaybeNotKnown, type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; +import type { + CCEncodingContext, + ZWaveHost, + ZWaveValueHost, +} from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 20af5b949c96..9ff747b24521 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -7,7 +7,6 @@ import { timespan, } from "@zwave-js/core"; import type { - CCEncodingContext, EndpointId, MessageOrCCLogEntry, MessageRecord, @@ -27,6 +26,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -663,7 +664,7 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { ) ?? getUnknownScale(this.scale); // Filter out unknown sensor types and scales, unless the strict validation is disabled - const measurementValidation = !this.host.getDeviceConfig?.( + const measurementValidation = !applHost.getDeviceConfig?.( this.nodeId as number, )?.compat?.disableStrictMeasurementValidation; diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 5ef903e049e7..7f4e9803c80d 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -15,6 +14,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -656,7 +657,7 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { ]); if ( - this.version < 2 && this.host.getDeviceConfig?.( + this.version < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { @@ -818,7 +819,7 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { ]); if ( - this.version < 2 && this.host.getDeviceConfig?.( + this.version < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index c946e9fc5c3a..5e9264765418 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -11,6 +10,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index d6bcea0000b0..b3bc6c935fa6 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -10,7 +10,6 @@ import { timespan, } from "@zwave-js/core"; import { - type CCEncodingContext, CommandClasses, Duration, type EndpointId, @@ -33,6 +32,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -1073,7 +1074,7 @@ export class NotificationCCReport extends NotificationCC { } } else { // V1 Alarm, check if there is a compat option to map this V1 report to a V2+ report - const mapping = this.host.getDeviceConfig?.( + const mapping = applHost.getDeviceConfig?.( this.nodeId as number, )?.compat?.alarmMapping; const match = mapping?.find( diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index 4775ff2cb9af..75ab8ade70ae 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -10,7 +9,11 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; +import type { + CCEncodingContext, + ZWaveHost, + ZWaveValueHost, +} from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { PhysicalCCAPI } from "../lib/API"; diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 2477a6e2c38e..999386c76751 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, MAX_NODES, type MaybeNotKnown, @@ -16,6 +15,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -533,7 +534,7 @@ export class ProtectionCCSet extends ProtectionCC { ]); if ( - this.version < 2 && this.host.getDeviceConfig?.( + this.version < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index bbc72147dba8..214a96b4570e 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -1,5 +1,4 @@ import type { - CCEncodingContext, MessageOrCCLogEntry, MessageRecord, SupervisionResult, @@ -11,7 +10,11 @@ import { ValueMetadata, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveHost, ZWaveValueHost } from "@zwave-js/host/safe"; +import type { + CCEncodingContext, + ZWaveHost, + ZWaveValueHost, +} from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 95d71893b148..3f50e80a8edf 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, type MaybeNotKnown, @@ -13,6 +12,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index cce384d115a9..a72caa1d88e7 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, type EndpointId, @@ -14,6 +13,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 522adf425eaf..c983aa21af15 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -12,12 +12,10 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type EndpointId, - type MaybeNotKnown, -} from "@zwave-js/core/safe"; +import { type EndpointId, type MaybeNotKnown } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 6141ea78a909..1c2f4a0e2ec7 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -29,8 +29,6 @@ import { validatePayload, } from "@zwave-js/core"; import { - type CCEncodingContext, - type CCParsingContext, EncapsulationFlags, type MaybeNotKnown, NODE_ID_BROADCAST, @@ -39,6 +37,8 @@ import { encodeCCList, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 04e9e37fc26a..c834720a6f18 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -20,12 +20,10 @@ import { parseCCList, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type CCParsingContext, - type MaybeNotKnown, -} from "@zwave-js/core/safe"; +import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index 0f8bd9bdb5fd..c502e51d5a2e 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -13,6 +12,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index fd8adc44d865..7d21e646ed73 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, Duration, EncapsulationFlags, @@ -21,6 +20,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index a9ac85577a04..ee9be03274bc 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -15,6 +14,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index 7a459e45c5dc..486ff24d5e22 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -9,6 +9,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index de1caf2c039c..ef7e11ba38c7 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -16,6 +15,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index 5eaeef5dd98f..d8627a218d83 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -8,6 +8,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index be0bf10c97b7..d9a871f3ef0c 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -11,6 +10,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index a1c5a234a6bc..2d91233b0ea7 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -20,6 +19,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, @@ -652,7 +653,7 @@ export class ThermostatSetpointCCSet extends ThermostatSetpointCC { public serialize(ctx: CCEncodingContext): Buffer { // If a config file overwrites how the float should be encoded, use that information - const override = this.host.getDeviceConfig?.(this.nodeId as number) + const override = ctx.getDeviceConfig?.(this.nodeId as number) ?.compat?.overrideFloatEncoding; this.payload = Buffer.concat([ Buffer.from([this.setpointType & 0b1111]), diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 26891e3d7766..790fd72d55c4 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -10,11 +10,10 @@ import { getDSTInfo, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type MaybeNotKnown, -} from "@zwave-js/core/safe"; +import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 220db50f94ab..c8f27f8485fc 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -8,13 +8,14 @@ import { validatePayload, } from "@zwave-js/core"; import { - type CCEncodingContext, type ControlsCC, type EndpointId, type MaybeNotKnown, type SupportsCC, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/TransportServiceCC.ts b/packages/cc/src/cc/TransportServiceCC.ts index 35ee6ac9ae3b..069937806715 100644 --- a/packages/cc/src/cc/TransportServiceCC.ts +++ b/packages/cc/src/cc/TransportServiceCC.ts @@ -1,6 +1,4 @@ import { - type CCEncodingContext, - type CCParsingContext, CRC16_CCITT, CommandClasses, type MessageOrCCLogEntry, @@ -10,6 +8,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 574cd7f93dd4..3512541ea310 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type EndpointId, type MaybeNotKnown, @@ -17,6 +16,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index bb0c700db0c3..fa1d319c4c68 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -17,6 +16,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 5b01c972a56e..c808d5f2f645 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -11,6 +10,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index a7a39a5e90e0..d7b83ad0c22a 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -10,11 +10,10 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import { - type CCEncodingContext, - type MaybeNotKnown, -} from "@zwave-js/core/safe"; +import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index 444bb813a869..caa2a2850b64 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeNotKnown, type MessageOrCCLogEntry, @@ -7,6 +6,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/cc/ZWaveProtocolCC.ts b/packages/cc/src/cc/ZWaveProtocolCC.ts index de7b0cc5f4a2..fd67ea05be4e 100644 --- a/packages/cc/src/cc/ZWaveProtocolCC.ts +++ b/packages/cc/src/cc/ZWaveProtocolCC.ts @@ -1,6 +1,5 @@ import { type BasicDeviceClass, - type CCEncodingContext, CommandClasses, type DataRate, type FLiRS, @@ -21,7 +20,7 @@ import { parseNodeProtocolInfoAndDeviceClass, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { type CCCommandOptions, CommandClass, diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 9c5ceda98dc7..367b71979d64 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -1,5 +1,4 @@ import { - type CCEncodingContext, CommandClasses, type MaybeUnknown, type MessageOrCCLogEntry, @@ -12,6 +11,8 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 691df0c94bed..09ff3d2b0387 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -1,7 +1,5 @@ import { type BroadcastCC, - type CCEncodingContext, - type CCParsingContext, CommandClasses, type ControlsCC, EncapsulationFlags, @@ -36,6 +34,8 @@ import { valueIdToString, } from "@zwave-js/core"; import type { + CCEncodingContext, + CCParsingContext, ZWaveApplicationHost, ZWaveHost, ZWaveValueHost, diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts index 271ffb84315e..0a49ce54c035 100644 --- a/packages/core/src/abstractions/ICommandClass.ts +++ b/packages/core/src/abstractions/ICommandClass.ts @@ -20,54 +20,11 @@ export interface SecurityManagers { securityManagerLR?: SecurityManager2; } -/** Additional context needed for deserializing CCs */ -export interface CCParsingContext extends Readonly { - sourceNodeId: number; - ownNodeId: number; - - /** If known, the frame type of the containing message */ - frameType?: FrameType; - - getHighestSecurityClass(nodeId: number): MaybeNotKnown; - - hasSecurityClass( - nodeId: number, - securityClass: SecurityClass, - ): MaybeNotKnown; - - setSecurityClass( - nodeId: number, - securityClass: SecurityClass, - granted: boolean, - ): void; -} - -/** Additional context needed for serializing CCs */ -// FIXME: Lot of duplication between the CC and message contexts -export interface CCEncodingContext extends Readonly { - getHighestSecurityClass(nodeId: number): MaybeNotKnown; - - hasSecurityClass( - nodeId: number, - securityClass: SecurityClass, - ): MaybeNotKnown; - - setSecurityClass( - nodeId: number, - securityClass: SecurityClass, - granted: boolean, - ): void; -} - /** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ export interface ICommandClass { + nodeId: number | MulticastDestination; ccId: CommandClasses; ccCommand?: number; - - serialize(ctx: CCEncodingContext): Buffer; - nodeId: number | MulticastDestination; - expectsCCResponse(): boolean; - isExpectedCCResponse(received: ICommandClass): boolean; } export type SinglecastCC = T & { diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index ae20e8865dcf..1a9805e0feaf 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -2,9 +2,12 @@ import type { ConfigManager, DeviceConfig } from "@zwave-js/config"; import type { CommandClasses, ControllerLogger, + FrameType, ICommandClass, + MaybeNotKnown, NodeIDType, NodeId, + SecurityClass, SecurityManagers, SendCommandOptions, SendCommandReturnType, @@ -31,6 +34,54 @@ export interface GetNextCallbackId { getNextCallbackId(): number; } +/** Allows querying device configuration for a node */ +export interface GetDeviceConfig { + getDeviceConfig?: (nodeId: number) => DeviceConfig | undefined; +} + +/** Additional context needed for deserializing CCs */ +export interface CCParsingContext + extends Readonly, GetDeviceConfig +{ + sourceNodeId: number; + ownNodeId: number; + + /** If known, the frame type of the containing message */ + frameType?: FrameType; + + getHighestSecurityClass(nodeId: number): MaybeNotKnown; + + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown; + + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void; +} + +/** Additional context needed for serializing CCs */ +// FIXME: Lot of duplication between the CC and message contexts +export interface CCEncodingContext + extends Readonly, GetDeviceConfig +{ + getHighestSecurityClass(nodeId: number): MaybeNotKnown; + + hasSecurityClass( + nodeId: number, + securityClass: SecurityClass, + ): MaybeNotKnown; + + setSecurityClass( + nodeId: number, + securityClass: SecurityClass, + granted: boolean, + ): void; +} + /** Host application abstractions to be used in Serial API and CC implementations */ export interface ZWaveHost extends HostIDs, GetNextCallbackId { /** How many bytes a node ID occupies in serial API commands */ @@ -66,8 +117,6 @@ export interface ZWaveHost extends HostIDs, GetNextCallbackId { endpointIndex?: number, ): boolean; - getDeviceConfig?: (nodeId: number) => DeviceConfig | undefined; - __internalIsMockNode?: boolean; } @@ -98,7 +147,8 @@ export interface ZWaveApplicationHost ZWaveHost, GetNode, GetAllNodes, - SecurityManagers + SecurityManagers, + GetDeviceConfig { /** Gives access to the configuration files */ configManager: ConfigManager; diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 0a0ff5fb503c..ce08473afd8d 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -11,7 +11,11 @@ import { getNodeTag, highResTimestamp, } from "@zwave-js/core"; -import type { ZWaveApplicationHost, ZWaveHost } from "@zwave-js/host"; +import type { + GetDeviceConfig, + ZWaveApplicationHost, + ZWaveHost, +} from "@zwave-js/host"; import type { JSONObject, TypedClassDecorator } from "@zwave-js/shared/safe"; import { num2hex, staticExtends } from "@zwave-js/shared/safe"; import { MessageHeaders } from "../MessageHeaders"; @@ -34,7 +38,7 @@ export enum MessageOrigin { Host, } -export interface MessageParsingContext { +export interface MessageParsingContext extends GetDeviceConfig { getHighestSecurityClass(nodeId: number): MaybeNotKnown; hasSecurityClass( diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 43319c92b751..4e2c5f27b9e5 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -6,7 +6,7 @@ import { type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { Message, type MessageEncodingContext, diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 3270e351a07d..acc65ac6c7de 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -1,6 +1,5 @@ import type { CommandClass } from "@zwave-js/cc"; import { - type CCEncodingContext, type CommandClassInfo, type CommandClasses, type MaybeNotKnown, @@ -9,7 +8,7 @@ import { type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { TimedExpectation } from "@zwave-js/shared"; import { isDeepStrictEqual } from "node:util"; import type { CCIdToCapabilities } from "./CCSpecificCapabilities"; diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index 2618142275fb..27a0cbde2a71 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -5166,9 +5166,17 @@ export class ZWaveController await this.deleteSUCReturnRoutes(nodeId); try { + // Some controllers have a bug where they incorrectly respond + // to an AssignSUCReturnRouteRequest with DeleteSUCReturnRoute + const disableCallbackFunctionTypeCheck = !!this.driver + .getDeviceConfig?.(this.ownNodeId!) + ?.compat + ?.disableCallbackFunctionTypeCheck + ?.includes(FunctionType.AssignSUCReturnRoute); const result = await this.driver.sendMessage( new AssignSUCReturnRouteRequest(this.driver, { nodeId, + disableCallbackFunctionTypeCheck, }), ); @@ -5366,9 +5374,17 @@ export class ZWaveController }); try { + // Some controllers have a bug where they incorrectly respond + // to an DeleteSUCReturnRouteRequest with a different function type + const disableCallbackFunctionTypeCheck = !!this.driver + .getDeviceConfig?.(this.ownNodeId!) + ?.compat + ?.disableCallbackFunctionTypeCheck + ?.includes(FunctionType.DeleteSUCReturnRoute); const result = await this.driver.sendMessage( new DeleteSUCReturnRouteRequest(this.driver, { nodeId, + disableCallbackFunctionTypeCheck, }), ); diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index 03f00ada2b58..cd167fd97f0e 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -28,7 +28,6 @@ import { TransportServiceTimeouts, } from "@zwave-js/cc/TransportServiceCC"; import { - type CCEncodingContext, CommandClasses, EncapsulationFlags, MessagePriority, @@ -43,6 +42,7 @@ import { ZWaveErrorCodes, mergeSupervisionResults, } from "@zwave-js/core"; +import { CCEncodingContext } from "@zwave-js/host"; import type { Message } from "@zwave-js/serial"; import { getErrorMessage } from "@zwave-js/shared"; import { wait } from "alcalzone-shared/async"; diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts index 69c834f00e0e..e15041d2f481 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts @@ -10,7 +10,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts index e8c71dcfdccb..35322f558ab5 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts @@ -11,7 +11,7 @@ import { parseNodeID, parseNodeUpdatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { type DeserializingMessageConstructor, FunctionType, diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index 26907ad3d95e..2ce445c70a44 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -13,7 +13,7 @@ import { parseNodeBitMask, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts index 028f0782a53a..36d527de35b7 100644 --- a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts @@ -5,7 +5,7 @@ import { encodeCCList, parseCCList, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts b/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts index ee6fd3212a26..451ced5ea763 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts @@ -1,5 +1,5 @@ import { type MessageOrCCLogEntry, MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts index 15b08a5a3be3..4444d06cc54e 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts @@ -1,5 +1,5 @@ import { ControllerCapabilityFlags, MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts index d642a83493e2..d8602a61d982 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts index f92b098ffc3e..b5a972f64db5 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts @@ -5,7 +5,7 @@ import { encodeLongRangeNodeBitMask, parseLongRangeNodeBitMask, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts index 8bd2d83b8630..4cdc82d706dd 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts @@ -1,6 +1,6 @@ import type { ProtocolType } from "@zwave-js/core"; import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts index 032a2b2ec4dc..a64d8c8a537e 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeBitMask, parseBitMask } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts index 9059e4cdaca2..9cf1d438eff9 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts @@ -12,7 +12,7 @@ import { getChipTypeAndVersion, getZWaveChipType, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts index d3239e31cc51..e31b5bca07d2 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts @@ -1,6 +1,6 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts index d21ba28d63cb..66f1c2b887bb 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts @@ -5,7 +5,7 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { LongRangeChannel } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts index 45cc16b23240..e6dccde3f51f 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts @@ -10,7 +10,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts index 5ea1fed5107b..1090bc287438 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts @@ -5,7 +5,7 @@ import { encodeCCList, getCCName, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts index c20cdc92cfb0..cfd4867d3506 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeBitMask, parseBitMask } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts index 69274cfe548b..a773356f5570 100644 --- a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts @@ -1,6 +1,6 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID, parseNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts index 3a112049ea14..85ab055e0394 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts @@ -5,7 +5,7 @@ import { type RSSI, rssiToString, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts index fa739bca700e..a0d38503627b 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts index d404f2c4df34..51fe4c7b6779 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts index b13bb529c9ed..e9b422ff0ad0 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts @@ -9,7 +9,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts index 9419a8bad89a..7c99cba9f6ed 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts @@ -9,7 +9,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts index 1b5f49f8e216..56be550a1e8e 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts index 87f5f8eed0d1..f92b45cf6116 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts @@ -4,7 +4,7 @@ import { TransmitStatus, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, type INodeQuery, @@ -52,6 +52,7 @@ export class AssignSUCReturnRouteRequestBase extends Message { export interface AssignSUCReturnRouteRequestOptions extends MessageBaseOptions { nodeId: number; + disableCallbackFunctionTypeCheck?: boolean; } function testAssignSUCReturnRouteCallback( @@ -59,13 +60,7 @@ function testAssignSUCReturnRouteCallback( callback: Message, ): boolean { // Some controllers have a bug where they incorrectly respond with DeleteSUCReturnRoute - if ( - callback.host - .getDeviceConfig?.(callback.host.ownNodeId) - ?.compat - ?.disableCallbackFunctionTypeCheck - ?.includes(FunctionType.AssignSUCReturnRoute) - ) { + if (sent.disableCallbackFunctionTypeCheck) { return true; } return callback.functionType === FunctionType.AssignSUCReturnRoute; @@ -88,10 +83,13 @@ export class AssignSUCReturnRouteRequest extends AssignSUCReturnRouteRequestBase this.callbackId = this.payload[1]; } else { this.nodeId = options.nodeId; + this.disableCallbackFunctionTypeCheck = + options.disableCallbackFunctionTypeCheck; } } public nodeId: number; + public readonly disableCallbackFunctionTypeCheck?: boolean; public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts index ac4f162d59d3..0076727b5b2b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts index 3ae23032c893..97f257d03620 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts @@ -4,7 +4,7 @@ import { TransmitStatus, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, @@ -54,6 +54,7 @@ export class DeleteSUCReturnRouteRequestBase extends Message { export interface DeleteSUCReturnRouteRequestOptions extends MessageBaseOptions { nodeId: number; + disableCallbackFunctionTypeCheck?: boolean; } function testDeleteSUCReturnRouteCallback( @@ -61,13 +62,7 @@ function testDeleteSUCReturnRouteCallback( callback: Message, ): boolean { // Some controllers have a bug where they incorrectly respond with DeleteSUCReturnRoute - if ( - callback.host - .getDeviceConfig?.(callback.host.ownNodeId) - ?.compat - ?.disableCallbackFunctionTypeCheck - ?.includes(FunctionType.DeleteSUCReturnRoute) - ) { + if (sent.disableCallbackFunctionTypeCheck) { return true; } return callback.functionType === FunctionType.DeleteSUCReturnRoute; @@ -90,10 +85,13 @@ export class DeleteSUCReturnRouteRequest extends DeleteSUCReturnRouteRequestBase this.callbackId = this.payload[1]; } else { this.nodeId = options.nodeId; + this.disableCallbackFunctionTypeCheck = + options.disableCallbackFunctionTypeCheck; } } public nodeId: number; + public readonly disableCallbackFunctionTypeCheck?: boolean; public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts index e0a626774bfd..6b3a43d28384 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts @@ -12,7 +12,7 @@ import { parseNodeID, parseNodeProtocolInfo, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts index 14d83002fe59..fee49d13a9e5 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts @@ -10,7 +10,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts index 2b65ddc1f5e0..b2871ffc33aa 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts @@ -5,7 +5,7 @@ import { encodeNodeID, parseNodeBitMask, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts index 28333e29ce96..b00bedf331d8 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID, parseNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts index e59a0d815b04..e398a7ab1c8a 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts index 84417476f442..780647d1985f 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts index 108620c64bef..819b822898b8 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts @@ -3,7 +3,7 @@ import { MessagePriority, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts index 746de9e2d7e9..9cbb3b5f9ad6 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts index 2c3ba3ab2ee0..f0dd1280f89d 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts @@ -4,7 +4,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, type INodeQuery, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts index e61290136e0f..ae80831ec69d 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts @@ -1,6 +1,6 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, MultiStageCallback, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts index e306028923db..bf7636dde05b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts @@ -5,7 +5,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts index 1124d8808d9b..2559d9d16c74 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts @@ -10,7 +10,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index 1952297c54ec..2c46d081d314 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts index c4c84b3d0721..ede3d70151a7 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts index cd748277f557..454d7536e8ec 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts index 280acbee33d6..e54df3d590bb 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts index a8919c8aaa48..b0d7ceea7ad7 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts index 9f51e2e18408..5f1cdfe1dcc2 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts index 53b257187d2d..65473867a8c3 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts @@ -7,7 +7,7 @@ import { createSimpleReflectionDecorator, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageBaseOptions, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts index 8dfa52d06847..764e032b7ffd 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts @@ -1,5 +1,5 @@ import { type MessageOrCCLogEntry, MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts index 08d3f3a95f11..475752b4c1f4 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts index bf1f38d62029..2bc655051dfd 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts @@ -1,6 +1,5 @@ import type { CommandClass, ICommandClassContainer } from "@zwave-js/cc"; import { - type CCEncodingContext, MAX_NODES, type MessageOrCCLogEntry, MessagePriority, @@ -13,7 +12,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts index 1dc8c44b766b..bc03bc274db4 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts @@ -16,7 +16,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts index 9e067aab6f8e..2c95db804162 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts @@ -6,7 +6,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/test/decodeMessage.ts b/test/decodeMessage.ts index ebc5967220c4..5c1ede129e40 100644 --- a/test/decodeMessage.ts +++ b/test/decodeMessage.ts @@ -5,7 +5,6 @@ import "zwave-js"; import { isCommandClassContainer } from "@zwave-js/cc"; import { ConfigManager } from "@zwave-js/config"; import { - CCParsingContext, NodeIDType, SPANState, SecurityClass, From 68c06a0c29d6e3a6a5622c0cf99d61635fdd8cf8 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Fri, 11 Oct 2024 23:54:48 +0200 Subject: [PATCH 15/60] refactor: rename ICommandClass to CCId --- packages/cc/src/lib/CommandClass.ts | 4 ++-- .../core/src/abstractions/ICommandClass.ts | 11 ++++------- packages/core/src/consts/Transmission.ts | 4 ++-- packages/host/src/ZWaveHost.ts | 10 +++++----- packages/testing/src/MockController.ts | 6 +++--- .../zwave-js/src/lib/controller/Controller.ts | 4 ++-- packages/zwave-js/src/lib/driver/Driver.ts | 18 +++++++++--------- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 09ff3d2b0387..b10457deb035 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -1,5 +1,6 @@ import { type BroadcastCC, + type CCId, CommandClasses, type ControlsCC, EncapsulationFlags, @@ -8,7 +9,6 @@ import { type GetAllEndpoints, type GetCCs, type GetEndpoint, - type ICommandClass, type ListenBehavior, type MessageOrCCLogEntry, type MessageRecord, @@ -142,7 +142,7 @@ export type CCNode = & QueryNodeStatus; // @publicAPI -export class CommandClass implements ICommandClass { +export class CommandClass implements CCId { // empty constructor to parse messages public constructor(host: ZWaveHost, options: CommandClassOptions) { this.host = host; diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts index 0a49ce54c035..e66bdce35195 100644 --- a/packages/core/src/abstractions/ICommandClass.ts +++ b/packages/core/src/abstractions/ICommandClass.ts @@ -1,14 +1,11 @@ import type { CommandClasses } from "../capabilities/CommandClasses"; import type { - FrameType, MulticastDestination, NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, } from "../consts"; import { type SecurityManager } from "../security/Manager"; import { type SecurityManager2 } from "../security/Manager2"; -import { type SecurityClass } from "../security/SecurityClass"; -import { type MaybeNotKnown } from "../values/Primitive"; /** Allows accessing the security manager instances */ export interface SecurityManagers { @@ -21,20 +18,20 @@ export interface SecurityManagers { } /** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ -export interface ICommandClass { +export interface CCId { nodeId: number | MulticastDestination; ccId: CommandClasses; ccCommand?: number; } -export type SinglecastCC = T & { +export type SinglecastCC = T & { nodeId: number; }; -export type MulticastCC = T & { +export type MulticastCC = T & { nodeId: MulticastDestination; }; -export type BroadcastCC = T & { +export type BroadcastCC = T & { nodeId: typeof NODE_ID_BROADCAST | typeof NODE_ID_BROADCAST_LR; }; diff --git a/packages/core/src/consts/Transmission.ts b/packages/core/src/consts/Transmission.ts index fdab874520a1..fe6863fd625c 100644 --- a/packages/core/src/consts/Transmission.ts +++ b/packages/core/src/consts/Transmission.ts @@ -1,6 +1,6 @@ import { num2hex } from "@zwave-js/shared/safe"; import { isObject } from "alcalzone-shared/typeguards"; -import type { ICommandClass } from "../abstractions/ICommandClass"; +import type { CCId } from "../abstractions/ICommandClass"; import type { ProtocolDataRate } from "../capabilities/Protocols"; import { type SecurityClass } from "../security/SecurityClass"; import { Duration } from "../values/Duration"; @@ -297,7 +297,7 @@ export type SendCommandOptions = reportTimeoutMs?: number; }; -export type SendCommandReturnType = +export type SendCommandReturnType = undefined extends TResponse ? SupervisionResult | undefined : TResponse | undefined; diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 1a9805e0feaf..013fff02d9d1 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -1,9 +1,9 @@ import type { ConfigManager, DeviceConfig } from "@zwave-js/config"; import type { + CCId, CommandClasses, ControllerLogger, FrameType, - ICommandClass, MaybeNotKnown, NodeIDType, NodeId, @@ -161,13 +161,13 @@ export interface ZWaveApplicationHost /** Whether the node with the given ID is the controller */ isControllerNode(nodeId: number): boolean; - sendCommand( - command: ICommandClass, + sendCommand( + command: CCId, options?: SendCommandOptions, ): Promise>; - waitForCommand( - predicate: (cc: ICommandClass) => boolean, + waitForCommand( + predicate: (cc: CCId) => boolean, timeout: number, ): Promise; diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 4e2c5f27b9e5..461794186c30 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -1,5 +1,5 @@ import { - type ICommandClass, + type CCId, type MaybeNotKnown, NOT_KNOWN, SecurityClass, @@ -348,10 +348,10 @@ export class MockController { * * @param timeout The number of milliseconds to wait. If the timeout elapses, the returned promise will be rejected */ - public async expectNodeCC( + public async expectNodeCC( node: MockNode, timeout: number, - predicate: (cc: ICommandClass) => cc is T, + predicate: (cc: CCId) => cc is T, ): Promise { const ret = await this.expectNodeFrame( node, diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index 27a0cbde2a71..1df131eb36df 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -42,13 +42,13 @@ import { import { type IndicatorObject } from "@zwave-js/cc/IndicatorCC"; import { BasicDeviceClass, + type CCId, CommandClasses, type ControllerCapabilities, ControllerRole, ControllerStatus, EMPTY_ROUTE, type Firmware, - type ICommandClass, LongRangeChannel, MAX_NODES, type MaybeNotKnown, @@ -9691,7 +9691,7 @@ export class ZWaveController const supportsS2 = supportedCCs.includes(CommandClasses["Security 2"]); let initTimeout: number; - let initPredicate: (cc: ICommandClass) => boolean; + let initPredicate: (cc: CCId) => boolean; // KEX Get must be received: // - no later than 10..30 seconds after the inclusion if S0 is supported diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 20df64e49aba..b556c82c055a 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -49,13 +49,13 @@ import { externalConfigDir, } from "@zwave-js/config"; import { + type CCId, CommandClasses, ControllerLogger, ControllerRole, ControllerStatus, Duration, EncapsulationFlags, - type ICommandClass, type KeyPair, type LogConfig, MAX_SUPERVISION_SESSION_ID, @@ -544,7 +544,7 @@ interface AwaitedThing { type AwaitedMessageHeader = AwaitedThing; type AwaitedMessageEntry = AwaitedThing; -type AwaitedCommandEntry = AwaitedThing; +type AwaitedCommandEntry = AwaitedThing; export type AwaitedBootloaderChunkEntry = AwaitedThing; interface TransportServiceSession { @@ -6158,7 +6158,7 @@ ${handlers.length} left`, * @param options (optional) Options regarding the message transmission */ private async sendCommandInternal< - TResponse extends ICommandClass = ICommandClass, + TResponse extends CCId = CCId, >( command: CommandClass, options: Omit< @@ -6242,7 +6242,7 @@ ${handlers.length} left`, * @param options (optional) Options regarding the message transmission */ public async sendCommand< - TResponse extends ICommandClass | undefined = undefined, + TResponse extends CCId | undefined = undefined, >( command: CommandClass, options?: SendCommandOptions, @@ -6441,12 +6441,12 @@ ${handlers.length} left`, * @param timeout The number of milliseconds to wait. If the timeout elapses, the returned promise will be rejected * @param predicate A predicate function to test all incoming command classes */ - public waitForCommand( - predicate: (cc: ICommandClass) => boolean, + public waitForCommand( + predicate: (cc: CCId) => boolean, timeout: number, ): Promise { return new Promise((resolve, reject) => { - const promise = createDeferredPromise(); + const promise = createDeferredPromise(); const entry: AwaitedCommandEntry = { predicate, handler: (cc) => promise.resolve(cc), @@ -6480,8 +6480,8 @@ ${handlers.length} left`, * Calls the given handler function every time a CommandClass is received that matches the given predicate. * @param predicate A predicate function to test all incoming command classes */ - public registerCommandHandler( - predicate: (cc: ICommandClass) => boolean, + public registerCommandHandler( + predicate: (cc: CCId) => boolean, handler: (cc: T) => void, ): { unregister: () => void; From 3fd80064e6189ce3778b517b78007b8f97b4553a Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Sat, 12 Oct 2024 00:12:52 +0200 Subject: [PATCH 16/60] refactor: move nodeIdType to message parsing contexts --- packages/host/src/ZWaveHost.ts | 5 ++--- packages/serial/src/message/Message.ts | 7 +++++++ packages/testing/src/MockController.ts | 3 +++ packages/zwave-js/src/lib/driver/Driver.ts | 6 ++++++ .../application/ApplicationCommandRequest.ts | 4 ++-- .../application/ApplicationUpdateRequest.ts | 10 +++++----- .../application/BridgeApplicationCommandRequest.ts | 4 ++-- .../lib/serialapi/memory/GetControllerIdMessages.ts | 8 ++++++-- .../network-mgmt/AddNodeToNetworkRequest.ts | 4 ++-- .../AssignPriorityReturnRouteMessages.ts | 4 ++-- .../AssignPrioritySUCReturnRouteMessages.ts | 2 +- .../network-mgmt/AssignReturnRouteMessages.ts | 4 ++-- .../network-mgmt/AssignSUCReturnRouteMessages.ts | 2 +- .../network-mgmt/DeleteReturnRouteMessages.ts | 2 +- .../network-mgmt/DeleteSUCReturnRouteMessages.ts | 2 +- .../network-mgmt/GetNodeProtocolInfoMessages.ts | 4 ++-- .../network-mgmt/GetPriorityRouteMessages.ts | 4 ++-- .../serialapi/network-mgmt/GetRoutingInfoMessages.ts | 2 +- .../serialapi/network-mgmt/GetSUCNodeIdMessages.ts | 4 ++-- .../serialapi/network-mgmt/IsFailedNodeMessages.ts | 2 +- .../network-mgmt/RemoveFailedNodeMessages.ts | 2 +- .../network-mgmt/RemoveNodeFromNetworkRequest.ts | 2 +- .../network-mgmt/ReplaceFailedNodeRequest.ts | 2 +- .../network-mgmt/RequestNodeInfoMessages.ts | 4 ++-- .../RequestNodeNeighborUpdateMessages.ts | 2 +- .../network-mgmt/SetPriorityRouteMessages.ts | 4 ++-- .../serialapi/network-mgmt/SetSUCNodeIDMessages.ts | 2 +- .../serialapi/transport/SendDataBridgeMessages.ts | 8 ++++---- .../src/lib/serialapi/transport/SendDataMessages.ts | 12 ++++++------ .../lib/serialapi/transport/SendTestFrameMessages.ts | 4 ++-- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 6 +++++- 31 files changed, 77 insertions(+), 54 deletions(-) diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 013fff02d9d1..4100ffa0668b 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -84,9 +84,6 @@ export interface CCEncodingContext /** Host application abstractions to be used in Serial API and CC implementations */ export interface ZWaveHost extends HostIDs, GetNextCallbackId { - /** How many bytes a node ID occupies in serial API commands */ - readonly nodeIdType?: NodeIDType; - /** * Retrieves the maximum version of a command class that can be used to communicate with a node. * Returns 1 if the node claims that it does not support a CC. @@ -155,6 +152,8 @@ export interface ZWaveApplicationHost options: ZWaveHostOptions; + readonly nodeIdType?: NodeIDType; + // TODO: There's probably a better fitting name for this now controllerLog: ControllerLogger; diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index ce08473afd8d..c85495d3fa05 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -2,6 +2,7 @@ import { type MaybeNotKnown, type MessageOrCCLogEntry, type MessagePriority, + NodeIDType, type NodeId, type SecurityClass, type SecurityManagers, @@ -39,6 +40,9 @@ export enum MessageOrigin { } export interface MessageParsingContext extends GetDeviceConfig { + /** How many bytes a node ID occupies in serial API commands */ + nodeIdType: NodeIDType; + getHighestSecurityClass(nodeId: number): MaybeNotKnown; hasSecurityClass( @@ -92,6 +96,9 @@ export type MessageOptions = | MessageDeserializationOptions; export interface MessageEncodingContext extends Readonly { + /** How many bytes a node ID occupies in serial API commands */ + nodeIdType: NodeIDType; + getHighestSecurityClass(nodeId: number): MaybeNotKnown; hasSecurityClass( diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 461794186c30..e58fdd991181 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -2,6 +2,7 @@ import { type CCId, type MaybeNotKnown, NOT_KNOWN, + NodeIDType, SecurityClass, type SecurityManagers, securityClassOrder, @@ -106,6 +107,8 @@ export class MockController { const securityClasses = new Map>(); this.encodingContext = { + // TODO: LR is not supported in mocks + nodeIdType: NodeIDType.Short, hasSecurityClass( nodeId: number, securityClass: SecurityClass, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index b556c82c055a..85e33fe98910 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -656,6 +656,9 @@ export class Driver extends TypedEventEmitter }); this.messageParsingContext = { + get nodeIdType() { + return this.nodeIdType; + }, getHighestSecurityClass: (nodeId) => this.getHighestSecurityClass(nodeId), hasSecurityClass: (nodeId, securityClass) => @@ -664,6 +667,9 @@ export class Driver extends TypedEventEmitter this.setSecurityClass(nodeId, securityClass, granted), }; this.messageEncodingContext = { + get nodeIdType() { + return this.nodeIdType; + }, getHighestSecurityClass: (nodeId) => this.getHighestSecurityClass(nodeId), hasSecurityClass: (nodeId, securityClass) => diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts index e15041d2f481..239b5465b3b0 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts @@ -86,7 +86,7 @@ export class ApplicationCommandRequest extends Message let offset = 1; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); offset += nodeIdBytes; @@ -147,7 +147,7 @@ export class ApplicationCommandRequest extends Message const serializedCC = this.command.serialize(ctx); const nodeId = encodeNodeID( this.getNodeId() ?? this.host.ownNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); this.payload = Buffer.concat([ Buffer.from([statusByte]), diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts index 35322f558ab5..388b0998b66c 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts @@ -108,7 +108,7 @@ export class ApplicationUpdateRequestWithNodeInfo if (gotDeserializationOptions(options)) { this.nodeInformation = parseNodeUpdatePayload( this.payload, - this.host.nodeIdType, + options.ctx.nodeIdType, ); this.nodeId = this.nodeInformation.nodeId; } else { @@ -123,7 +123,7 @@ export class ApplicationUpdateRequestWithNodeInfo public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeUpdatePayload( this.nodeInformation, - this.host.nodeIdType, + ctx.nodeIdType, ); return super.serialize(ctx); } @@ -159,7 +159,7 @@ export class ApplicationUpdateRequestNodeRemoved ) { super(host, options); - const { nodeId } = parseNodeID(this.payload, host.nodeIdType, 0); + const { nodeId } = parseNodeID(this.payload, options.ctx.nodeIdType, 0); this.nodeId = nodeId; // byte 1/2 is 0, meaning unknown } @@ -178,7 +178,7 @@ class ApplicationUpdateRequestSmartStartHomeIDReceivedBase let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); offset += nodeIdBytes; @@ -251,7 +251,7 @@ export class ApplicationUpdateRequestSUCIdChanged ) { super(host, options); - const { nodeId } = parseNodeID(this.payload, host.nodeIdType, 0); + const { nodeId } = parseNodeID(this.payload, options.ctx.nodeIdType, 0); this.sucNodeID = nodeId; // byte 1/2 is 0, meaning unknown } diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index 2ce445c70a44..19bb33d6ea7b 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -62,11 +62,11 @@ export class BridgeApplicationCommandRequest extends Message let offset = 1; const { nodeId: destinationNodeId, bytesRead: dstNodeIdBytes } = - parseNodeID(this.payload, host.nodeIdType, offset); + parseNodeID(this.payload, options.ctx.nodeIdType, offset); offset += dstNodeIdBytes; const { nodeId: sourceNodeId, bytesRead: srcNodeIdBytes } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); offset += srcNodeIdBytes; diff --git a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts index a773356f5570..ac508cf2c38c 100644 --- a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts @@ -35,7 +35,11 @@ export class GetControllerIdResponse extends Message { if (gotDeserializationOptions(options)) { // The payload is 4 bytes home id, followed by the controller node id this.homeId = this.payload.readUInt32BE(0); - const { nodeId } = parseNodeID(this.payload, host.nodeIdType, 4); + const { nodeId } = parseNodeID( + this.payload, + options.ctx.nodeIdType, + 4, + ); this.ownNodeId = nodeId; } else { this.homeId = options.homeId; @@ -47,7 +51,7 @@ export class GetControllerIdResponse extends Message { public ownNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.ownNodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.ownNodeId, ctx.nodeIdType); const homeId = Buffer.allocUnsafe(4); homeId.writeUInt32BE(this.homeId, 0); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts index cd91b3056995..9cb15e8e3a4e 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts @@ -292,7 +292,7 @@ export class AddNodeToNetworkRequestStatusReport case AddNodeStatus.Done: { const { nodeId } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, 2, ); this.statusContext = { nodeId }; @@ -304,7 +304,7 @@ export class AddNodeToNetworkRequestStatusReport // the payload contains a node information frame this.statusContext = parseNodeUpdatePayload( this.payload.subarray(2), - host.nodeIdType, + options.ctx.nodeIdType, ); break; } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts index e9b422ff0ad0..023228bfb33a 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts @@ -101,10 +101,10 @@ export class AssignPriorityReturnRouteRequest public routeSpeed: ZWaveDataRate; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); const destinationNodeId = encodeNodeID( this.destinationNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); this.payload = Buffer.concat([ nodeId, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts index 7c99cba9f6ed..317ad56061bc 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts @@ -92,7 +92,7 @@ export class AssignPrioritySUCReturnRouteRequest public routeSpeed: ZWaveDataRate; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([ nodeId, Buffer.from([ diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts index 56be550a1e8e..0ee6d45b4e66 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts @@ -79,10 +79,10 @@ export class AssignReturnRouteRequest extends AssignReturnRouteRequestBase public destinationNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); const destinationNodeId = encodeNodeID( this.destinationNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); this.payload = Buffer.concat([ diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts index f92b45cf6116..a23df14c1ffe 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts @@ -92,7 +92,7 @@ export class AssignSUCReturnRouteRequest extends AssignSUCReturnRouteRequestBase public readonly disableCallbackFunctionTypeCheck?: boolean; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts index 0076727b5b2b..eb7c5e4f55b5 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts @@ -70,7 +70,7 @@ export class DeleteReturnRouteRequest extends DeleteReturnRouteRequestBase public nodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts index 97f257d03620..6914ef7e3220 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts @@ -94,7 +94,7 @@ export class DeleteSUCReturnRouteRequest extends DeleteSUCReturnRouteRequestBase public readonly disableCallbackFunctionTypeCheck?: boolean; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts index 6b3a43d28384..c023656bf70f 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts @@ -44,7 +44,7 @@ export class GetNodeProtocolInfoRequest extends Message { super(host, options); if (gotDeserializationOptions(options)) { this.requestedNodeId = - parseNodeID(this.payload, this.host.nodeIdType, 0).nodeId; + parseNodeID(this.payload, options.ctx.nodeIdType, 0).nodeId; } else { this.requestedNodeId = options.requestedNodeId; } @@ -55,7 +55,7 @@ export class GetNodeProtocolInfoRequest extends Message { public requestedNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - this.payload = encodeNodeID(this.requestedNodeId, this.host.nodeIdType); + this.payload = encodeNodeID(this.requestedNodeId, ctx.nodeIdType); return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts index fee49d13a9e5..1c53c22e77e7 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts @@ -53,7 +53,7 @@ export class GetPriorityRouteRequest extends Message { public serialize(ctx: MessageEncodingContext): Buffer { this.payload = encodeNodeID( this.destinationNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); return super.serialize(ctx); @@ -79,7 +79,7 @@ export class GetPriorityRouteResponse extends Message { let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); offset += nodeIdBytes; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts index b2871ffc33aa..6f0562d2b69b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts @@ -40,7 +40,7 @@ export class GetRoutingInfoRequest extends Message { public removeBadLinks: boolean; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.sourceNodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.sourceNodeId, ctx.nodeIdType); const optionsByte = (this.removeBadLinks ? 0b1000_0000 : 0) | (this.removeNonRepeaters ? 0b0100_0000 : 0); this.payload = Buffer.concat([ diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts index b00bedf331d8..def39a624d9c 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts @@ -33,7 +33,7 @@ export class GetSUCNodeIdResponse extends Message { if (gotDeserializationOptions(options)) { this.sucNodeId = parseNodeID( this.payload, - this.host.nodeIdType, + options.ctx.nodeIdType, 0, ).nodeId; } else { @@ -45,7 +45,7 @@ export class GetSUCNodeIdResponse extends Message { public sucNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - this.payload = encodeNodeID(this.sucNodeId, this.host.nodeIdType); + this.payload = encodeNodeID(this.sucNodeId, ctx.nodeIdType); return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts index e398a7ab1c8a..b9a8b35cd6bf 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts @@ -30,7 +30,7 @@ export class IsFailedNodeRequest extends Message { public failedNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - this.payload = encodeNodeID(this.failedNodeId, this.host.nodeIdType); + this.payload = encodeNodeID(this.failedNodeId, ctx.nodeIdType); return super.serialize(ctx); } } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts index 780647d1985f..4c22cef3d57b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts @@ -79,7 +79,7 @@ export class RemoveFailedNodeRequest extends RemoveFailedNodeRequestBase { public failedNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.failedNodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.failedNodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts index 819b822898b8..f5a3f772f48c 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts @@ -153,7 +153,7 @@ export class RemoveNodeFromNetworkRequestStatusReport // the payload contains the node ID const { nodeId } = parseNodeID( this.payload.subarray(2), - this.host.nodeIdType, + options.ctx.nodeIdType, ); this.statusContext = { nodeId }; break; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts index 9cbb3b5f9ad6..3fb5c36334d2 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts @@ -78,7 +78,7 @@ export class ReplaceFailedNodeRequest extends ReplaceFailedNodeRequestBase { public failedNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.failedNodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.failedNodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts index f0dd1280f89d..224a69ef46c0 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts @@ -92,7 +92,7 @@ export class RequestNodeInfoRequest extends Message implements INodeQuery { if (gotDeserializationOptions(options)) { this.nodeId = parseNodeID( this.payload, - this.host.nodeIdType, + options.ctx.nodeIdType, 0, ).nodeId; } else { @@ -108,7 +108,7 @@ export class RequestNodeInfoRequest extends Message implements INodeQuery { } public serialize(ctx: MessageEncodingContext): Buffer { - this.payload = encodeNodeID(this.nodeId, this.host.nodeIdType); + this.payload = encodeNodeID(this.nodeId, ctx.nodeIdType); return super.serialize(ctx); } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts index ae80831ec69d..c9c3dba83ddb 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts @@ -65,7 +65,7 @@ export class RequestNodeNeighborUpdateRequest public discoveryTimeout: number; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts index 2559d9d16c74..ef3a47b1b142 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts @@ -83,7 +83,7 @@ export class SetPriorityRouteRequest extends Message { public serialize(ctx: MessageEncodingContext): Buffer { const nodeId = encodeNodeID( this.destinationNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); if (this.repeaters == undefined || this.routeSpeed == undefined) { // Remove the priority route @@ -140,7 +140,7 @@ export class SetPriorityRouteResponse extends Message // Byte(s) 0/1 are the node ID - this is missing from the Host API specs const { /* nodeId, */ bytesRead } = parseNodeID( this.payload, - this.host.nodeIdType, + options.ctx.nodeIdType, 0, ); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index 2c46d081d314..232ff74bf97e 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -79,7 +79,7 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { public transmitOptions: TransmitOptions; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.sucNodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.sucNodeId, ctx.nodeIdType); this.payload = Buffer.concat([ nodeId, Buffer.from([ diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts index 2bc655051dfd..11d5c137cfa7 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts @@ -129,11 +129,11 @@ export class SendDataBridgeRequest public serialize(ctx: MessageEncodingContext): Buffer { const sourceNodeId = encodeNodeID( this.sourceNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); const destinationNodeId = encodeNodeID( this.command.nodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); const serializedCC = this.serializeCC(ctx); @@ -370,10 +370,10 @@ export class SendDataMulticastBridgeRequest< const serializedCC = this.serializeCC(ctx); const sourceNodeId = encodeNodeID( this.sourceNodeId, - this.host.nodeIdType, + ctx.nodeIdType, ); const destinationNodeIDs = this.command.nodeId.map((id) => - encodeNodeID(id, this.host.nodeIdType) + encodeNodeID(id, ctx.nodeIdType) ); this.payload = Buffer.concat([ diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts index bc03bc274db4..185aa18abce8 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts @@ -90,7 +90,7 @@ export class SendDataRequest let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); offset += nodeIdBytes; @@ -162,7 +162,7 @@ export class SendDataRequest // Cache the serialized CC, so we can check if it needs to be fragmented private _serializedCC: Buffer | undefined; /** @internal */ - public serializeCC(ctx: MessageEncodingContext): Buffer { + public serializeCC(ctx: CCEncodingContext): Buffer { if (!this._serializedCC) { this._serializedCC = this.command.serialize(ctx); } @@ -176,7 +176,7 @@ export class SendDataRequest } public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.command.nodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.command.nodeId, ctx.nodeIdType); const serializedCC = this.serializeCC(ctx); this.payload = Buffer.concat([ nodeId, @@ -380,7 +380,7 @@ export class SendDataMulticastRequest< for (let i = 0; i < numNodeIDs; i++) { const { nodeId, bytesRead } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); nodeIds.push(nodeId); @@ -469,7 +469,7 @@ export class SendDataMulticastRequest< // Cache the serialized CC, so we can check if it needs to be fragmented private _serializedCC: Buffer | undefined; /** @internal */ - public serializeCC(ctx: MessageEncodingContext): Buffer { + public serializeCC(ctx: CCEncodingContext): Buffer { if (!this._serializedCC) { this._serializedCC = this.command.serialize(ctx); } @@ -485,7 +485,7 @@ export class SendDataMulticastRequest< public serialize(ctx: MessageEncodingContext): Buffer { const serializedCC = this.serializeCC(ctx); const destinationNodeIDs = this.command.nodeId.map((id) => - encodeNodeID(id, this.host.nodeIdType) + encodeNodeID(id, ctx.nodeIdType) ); this.payload = Buffer.concat([ // # of target nodes, not # of bytes diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts index 2c95db804162..0de40ddb557c 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts @@ -55,7 +55,7 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, - host.nodeIdType, + options.ctx.nodeIdType, offset, ); offset += nodeIdBytes; @@ -73,7 +73,7 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { public powerlevel: Powerlevel; public serialize(ctx: MessageEncodingContext): Buffer { - const nodeId = encodeNodeID(this.testNodeId, this.host.nodeIdType); + const nodeId = encodeNodeID(this.testNodeId, ctx.nodeIdType); this.payload = Buffer.concat([ nodeId, Buffer.from([ diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 3a0c4425dd44..6cba9fd74472 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -25,6 +25,7 @@ import { isLongRangeNodeId, securityClassIsS2, } from "@zwave-js/core"; +import { CCParsingContext } from "@zwave-js/host"; import { type MessageParsingContext, type ZWaveSerialPortImplementation, @@ -234,7 +235,10 @@ export class Zniffer extends TypedEventEmitter { /** The serial port instance */ private serial: ZnifferSerialPortBase | undefined; - private parsingContext: MessageParsingContext; + private parsingContext: Omit< + CCParsingContext, + "ownNodeId" | "sourceNodeId" + >; private _destroyPromise: DeferredPromise | undefined; private get wasDestroyed(): boolean { From 38c1699bb1e649a92b3c50294a340fbc29ec1622 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Sun, 13 Oct 2024 23:05:16 +0200 Subject: [PATCH 17/60] refactor: rename ZWaveValueHost to GetValueDB --- packages/cc/src/cc/AlarmSensorCC.ts | 8 ++--- packages/cc/src/cc/AssociationCC.ts | 14 ++++---- packages/cc/src/cc/AssociationGroupInfoCC.ts | 14 ++++---- packages/cc/src/cc/BarrierOperatorCC.ts | 14 ++++---- packages/cc/src/cc/BasicCC.ts | 6 ++-- packages/cc/src/cc/BatteryCC.ts | 6 ++-- packages/cc/src/cc/BinarySensorCC.ts | 8 ++--- packages/cc/src/cc/BinarySwitchCC.ts | 6 ++-- packages/cc/src/cc/CRC16CC.ts | 4 +-- packages/cc/src/cc/CentralSceneCC.ts | 10 +++--- .../cc/src/cc/ClimateControlScheduleCC.ts | 14 ++++---- packages/cc/src/cc/ClockCC.ts | 6 ++-- packages/cc/src/cc/ColorSwitchCC.ts | 14 ++++---- packages/cc/src/cc/ConfigurationCC.ts | 26 +++++++-------- packages/cc/src/cc/DoorLockCC.ts | 12 +++---- packages/cc/src/cc/DoorLockLoggingCC.ts | 8 ++--- packages/cc/src/cc/EnergyProductionCC.ts | 6 ++-- packages/cc/src/cc/EntryControlCC.ts | 12 +++---- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 22 ++++++------- packages/cc/src/cc/HumidityControlModeCC.ts | 8 ++--- .../src/cc/HumidityControlOperatingStateCC.ts | 4 +-- .../cc/src/cc/HumidityControlSetpointCC.ts | 18 +++++------ packages/cc/src/cc/InclusionControllerCC.ts | 10 ++---- packages/cc/src/cc/IndicatorCC.ts | 16 +++++----- packages/cc/src/cc/IrrigationCC.ts | 32 +++++++++---------- packages/cc/src/cc/LanguageCC.ts | 6 ++-- packages/cc/src/cc/LockCC.ts | 6 ++-- packages/cc/src/cc/ManufacturerSpecificCC.ts | 8 ++--- packages/cc/src/cc/MeterCC.ts | 10 +++--- .../cc/src/cc/MultiChannelAssociationCC.ts | 12 +++---- packages/cc/src/cc/MultiChannelCC.ts | 24 +++++++------- packages/cc/src/cc/MultiCommandCC.ts | 4 +-- packages/cc/src/cc/MultilevelSensorCC.ts | 12 +++---- packages/cc/src/cc/MultilevelSwitchCC.ts | 10 +++--- packages/cc/src/cc/NodeNamingCC.ts | 10 +++--- packages/cc/src/cc/NotificationCC.ts | 14 ++++---- packages/cc/src/cc/PowerlevelCC.ts | 10 +++--- packages/cc/src/cc/ProtectionCC.ts | 16 +++++----- packages/cc/src/cc/SceneActivationCC.ts | 4 +-- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 8 ++--- .../src/cc/SceneControllerConfigurationCC.ts | 8 ++--- packages/cc/src/cc/ScheduleEntryLockCC.ts | 30 ++++++++--------- packages/cc/src/cc/Security2CC.ts | 24 +++++++------- packages/cc/src/cc/SecurityCC.ts | 14 ++++---- packages/cc/src/cc/SoundSwitchCC.ts | 16 +++++----- packages/cc/src/cc/SupervisionCC.ts | 6 ++-- packages/cc/src/cc/ThermostatFanModeCC.ts | 8 ++--- packages/cc/src/cc/ThermostatFanStateCC.ts | 4 +-- packages/cc/src/cc/ThermostatModeCC.ts | 8 ++--- .../cc/src/cc/ThermostatOperatingStateCC.ts | 4 +-- packages/cc/src/cc/ThermostatSetbackCC.ts | 6 ++-- packages/cc/src/cc/ThermostatSetpointCC.ts | 14 ++++---- packages/cc/src/cc/TimeCC.ts | 10 +++--- packages/cc/src/cc/TimeParametersCC.ts | 6 ++-- packages/cc/src/cc/TransportServiceCC.ts | 12 +++---- packages/cc/src/cc/UserCodeCC.ts | 28 ++++++++-------- packages/cc/src/cc/VersionCC.ts | 12 +++---- packages/cc/src/cc/WakeUpCC.ts | 8 ++--- packages/cc/src/cc/WindowCoveringCC.ts | 14 ++++---- packages/cc/src/cc/ZWavePlusCC.ts | 4 +-- .../cc/manufacturerProprietary/FibaroCC.ts | 6 ++-- packages/cc/src/lib/CommandClass.ts | 28 ++++++++-------- packages/host/src/ZWaveHost.ts | 4 +-- 63 files changed, 361 insertions(+), 365 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index e72e6838f67b..6b1dd04460fe 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -14,9 +14,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -352,7 +352,7 @@ export class AlarmSensorCCReport extends AlarmSensorCC { public readonly severity: number | undefined; public readonly duration: number | undefined; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sensor type": getEnumMemberName(AlarmSensorType, this.sensorType), "alarm state": this.state, @@ -428,7 +428,7 @@ export class AlarmSensorCCGet extends AlarmSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -472,7 +472,7 @@ export class AlarmSensorCCSupportedReport extends AlarmSensorCC { return true; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 2973946d542f..827c8c25e60f 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { distinct } from "alcalzone-shared/arrays"; @@ -527,7 +527,7 @@ export class AssociationCCSet extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "group id": this.groupId || "all groups", "node ids": this.nodeIds.length @@ -600,7 +600,7 @@ export class AssociationCCRemove extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "group id": this.groupId || "all groups", "node ids": this.nodeIds && this.nodeIds.length @@ -692,7 +692,7 @@ export class AssociationCCReport extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -739,7 +739,7 @@ export class AssociationCCGet extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "group id": this.groupId }, @@ -780,7 +780,7 @@ export class AssociationCCSupportedGroupingsReport extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "group count": this.groupCount }, @@ -822,7 +822,7 @@ export class AssociationCCSpecificGroupReport extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { group: this.group }, diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 48d4c11c5184..f95228ecda74 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -14,9 +14,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { cpp2js, getEnumMemberName, num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -523,7 +523,7 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -564,7 +564,7 @@ export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "group id": this.groupId }, @@ -668,7 +668,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -745,7 +745,7 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.groupId != undefined) { message["group id"] = this.groupId; @@ -832,7 +832,7 @@ export class AssociationGroupInfoCCCommandListReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -894,7 +894,7 @@ export class AssociationGroupInfoCCCommandListGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 069c1798fb6b..d059ef5dfb78 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -17,9 +17,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, @@ -576,7 +576,7 @@ export class BarrierOperatorCCSet extends BarrierOperatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "target state": this.targetState }, @@ -628,7 +628,7 @@ export class BarrierOperatorCCReport extends BarrierOperatorCC { @ccValue(BarrierOperatorCCValues.position) public readonly position: MaybeUnknown; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -664,7 +664,7 @@ export class BarrierOperatorCCSignalingCapabilitiesReport @ccValue(BarrierOperatorCCValues.supportedSubsystemTypes) public readonly supportedSubsystemTypes: readonly SubsystemType[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -719,7 +719,7 @@ export class BarrierOperatorCCEventSignalingSet extends BarrierOperatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -765,7 +765,7 @@ export class BarrierOperatorCCEventSignalingReport extends BarrierOperatorCC { public readonly subsystemType: SubsystemType; public readonly subsystemState: SubsystemState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -817,7 +817,7 @@ export class BarrierOperatorCCEventSignalingGet extends BarrierOperatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 1f4789c27dcb..eb9ee869cf87 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { type AllOrNone, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -383,7 +383,7 @@ export class BasicCCSet extends BasicCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "target value": this.targetValue }, @@ -506,7 +506,7 @@ export class BasicCCReport extends BasicCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current value": maybeUnknownToString(this.currentValue), }; diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index e886fc23ab76..32cdb2a63554 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { type AllOrNone, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { @@ -554,7 +554,7 @@ export class BatteryCCReport extends BatteryCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { level: this.level, "is low": this.isLow, @@ -643,7 +643,7 @@ export class BatteryCCHealthReport extends BatteryCC { private readonly temperatureScale: number | undefined; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 8f5dac71ed38..d3cb12a2a620 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -13,9 +13,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -398,7 +398,7 @@ export class BinarySensorCCReport extends BinarySensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -452,7 +452,7 @@ export class BinarySensorCCGet extends BinarySensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -504,7 +504,7 @@ export class BinarySensorCCSupportedReport extends BinarySensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index ac48bcd4c957..361f10cdd272 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -17,9 +17,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import type { AllOrNone } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -352,7 +352,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "target value": this.targetValue, }; @@ -427,7 +427,7 @@ export class BinarySwitchCCReport extends BinarySwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current value": maybeUnknownToString(this.currentValue), }; diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index a837942ac43a..e14ebd90b301 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -8,8 +8,8 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetValueDB, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { CCAPI } from "../lib/API"; import { @@ -165,7 +165,7 @@ export class CRC16CCCommandEncapsulation extends CRC16CC { return super.computeEncapsulationOverhead() + 2; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), // Hide the default payload line diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 9cb13ddbe7b5..e487b3d45b5e 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -17,9 +17,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -342,7 +342,7 @@ export class CentralSceneCCNotification extends CentralSceneCC { public readonly sceneNumber: number; public readonly slowRefresh: boolean | undefined; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, "key attribute": getEnumMemberName( @@ -438,7 +438,7 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC { return this._supportedKeyAttributes; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "scene count": this.sceneCount, "supports slow refresh": maybeUnknownToString( @@ -476,7 +476,7 @@ export class CentralSceneCCConfigurationReport extends CentralSceneCC { @ccValue(CentralSceneCCValues.slowRefresh) public readonly slowRefresh: boolean; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "slow refresh": this.slowRefresh }, @@ -522,7 +522,7 @@ export class CentralSceneCCConfigurationSet extends CentralSceneCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "slow refresh": this.slowRefresh }, diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index 638a6e496e28..85d3acb77fdf 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -11,8 +11,8 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetValueDB, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -264,7 +264,7 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -315,7 +315,7 @@ export class ClimateControlScheduleCCReport extends ClimateControlScheduleCC { ) public readonly schedule: readonly Switchpoint[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -371,7 +371,7 @@ export class ClimateControlScheduleCCGet extends ClimateControlScheduleCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { weekday: getEnumMemberName(Weekday, this.weekday) }, @@ -395,7 +395,7 @@ export class ClimateControlScheduleCCChangedReport public readonly changeCounter: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "change counter": this.changeCounter }, @@ -431,7 +431,7 @@ export class ClimateControlScheduleCCOverrideReport @ccValue(ClimateControlScheduleCCValues.overrideState) public readonly overrideState: SetbackState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -493,7 +493,7 @@ export class ClimateControlScheduleCCOverrideSet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index c93fc9e760e4..0e950770ea40 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -13,9 +13,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -184,7 +184,7 @@ export class ClockCCSet extends ClockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -228,7 +228,7 @@ export class ClockCCReport extends ClockCC { public readonly hour: number; public readonly minute: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 981d57de4718..42ae69f3b70a 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -19,9 +19,9 @@ import { type MaybeNotKnown, encodeBitMask } from "@zwave-js/core/safe"; import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -719,7 +719,7 @@ export class ColorSwitchCCSupportedReport extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -868,7 +868,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "color component": getEnumMemberName( ColorComponent, @@ -936,7 +936,7 @@ export class ColorSwitchCCGet extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1036,7 +1036,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const [key, value] of Object.entries(this.colorTable)) { const realKey: string = key in ColorComponentMap @@ -1135,7 +1135,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "color component": getEnumMemberName( ColorComponent, @@ -1186,7 +1186,7 @@ export class ColorSwitchCCStopLevelChange extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 884fecf00ed2..e87db14c05bd 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -27,9 +27,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -1749,7 +1749,7 @@ export class ConfigurationCCReport extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1808,7 +1808,7 @@ export class ConfigurationCCGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "parameter #": this.parameter }, @@ -1932,7 +1932,7 @@ export class ConfigurationCCSet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "parameter #": this.parameter, "reset to default": this.resetToDefault, @@ -2096,7 +2096,7 @@ export class ConfigurationCCBulkSet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { handshake: this.handshake, "reset to default": this.resetToDefault, @@ -2224,7 +2224,7 @@ export class ConfigurationCCBulkReport extends ConfigurationCC { return this._values; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "handshake response": this._isHandshakeResponse, "default values": this._defaultValues, @@ -2290,7 +2290,7 @@ export class ConfigurationCCBulkGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { parameters: this.parameters.join(", ") }, @@ -2402,7 +2402,7 @@ export class ConfigurationCCNameReport extends ConfigurationCC { .reduce((prev, cur) => prev + cur, ""); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2438,7 +2438,7 @@ export class ConfigurationCCNameGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "parameter #": this.parameter }, @@ -2563,7 +2563,7 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { .reduce((prev, cur) => prev + cur, ""); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2599,7 +2599,7 @@ export class ConfigurationCCInfoGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "parameter #": this.parameter }, @@ -2866,7 +2866,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "parameter #": this.parameter, "next param #": this.nextParameter, @@ -2928,7 +2928,7 @@ export class ConfigurationCCPropertiesGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "parameter #": this.parameter }, diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 7b7a556cce7f..4d068e8cd3cb 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -18,9 +18,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -860,7 +860,7 @@ export class DoorLockCCOperationSet extends DoorLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -973,7 +973,7 @@ export class DoorLockCCOperationReport extends DoorLockCC { @ccValue(DoorLockCCValues.lockTimeout) public readonly lockTimeout?: number; // in seconds - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current mode": getEnumMemberName(DoorLockMode, this.currentMode), "active outside handles": this.outsideHandlesCanOpenDoor.join(", "), @@ -1124,7 +1124,7 @@ export class DoorLockCCConfigurationReport extends DoorLockCC { return true; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "operation type": getEnumMemberName( DoorLockOperationType, @@ -1279,7 +1279,7 @@ export class DoorLockCCConfigurationSet extends DoorLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const insideHandles = isArray( this.insideHandlesCanOpenDoorConfiguration, ) @@ -1403,7 +1403,7 @@ export class DoorLockCCCapabilitiesReport extends DoorLockCC { @ccValue(DoorLockCCValues.blockToBlockSupported) public readonly blockToBlockSupported: boolean; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index 839bf5ab2729..afbff7ba8477 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -11,9 +11,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { isPrintableASCII, num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -246,7 +246,7 @@ export class DoorLockLoggingCCRecordsSupportedReport extends DoorLockLoggingCC { @ccValue(DoorLockLoggingCCValues.recordsCount) public readonly recordsCount: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -322,7 +322,7 @@ export class DoorLockLoggingCCRecordReport extends DoorLockLoggingCC { public readonly recordNumber: number; public readonly record?: DoorLockLoggingRecord; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (!this.record) { @@ -396,7 +396,7 @@ export class DoorLockLoggingCCRecordGet extends DoorLockLoggingCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "record number": this.recordNumber }, diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index e6a2f0d1d39f..c2589975505a 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -11,9 +11,9 @@ import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host"; import { getEnumMemberName, pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -250,7 +250,7 @@ export class EnergyProductionCCReport extends EnergyProductionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -305,7 +305,7 @@ export class EnergyProductionCCGet extends EnergyProductionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index 7bd6c77d48a8..61476642e4f0 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { buffer2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -470,7 +470,7 @@ export class EntryControlCCNotification extends EntryControlCC { public readonly eventType: EntryControlEventTypes; public readonly eventData?: Buffer | string; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, "data type": this.dataType, @@ -517,7 +517,7 @@ export class EntryControlCCKeySupportedReport extends EntryControlCC { @ccValue(EntryControlCCValues.supportedKeys) public readonly supportedKeys: readonly number[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "supported keys": this.supportedKeys.toString() }, @@ -605,7 +605,7 @@ export class EntryControlCCEventSupportedReport extends EntryControlCC { public readonly minKeyCacheTimeout: number; public readonly maxKeyCacheTimeout: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -649,7 +649,7 @@ export class EntryControlCCConfigurationReport extends EntryControlCC { @ccValue(EntryControlCCValues.keyCacheTimeout) public readonly keyCacheTimeout: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -702,7 +702,7 @@ export class EntryControlCCConfigurationSet extends EntryControlCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index b5f4e36f4168..b4ada9b05177 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -12,9 +12,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -462,7 +462,7 @@ export class FirmwareUpdateMetaDataCCMetaDataReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": this.manufacturerId, "firmware id": this.firmwareId, @@ -528,7 +528,7 @@ export class FirmwareUpdateMetaDataCCRequestReport public resume?: boolean; public nonSecureTransfer?: boolean; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { status: getEnumMemberName( FirmwareUpdateRequestStatus, @@ -641,7 +641,7 @@ export class FirmwareUpdateMetaDataCCRequestGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), @@ -688,7 +688,7 @@ export class FirmwareUpdateMetaDataCCGet extends FirmwareUpdateMetaDataCC { public readonly numReports: number; public readonly reportNumber: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -762,7 +762,7 @@ export class FirmwareUpdateMetaDataCCReport extends FirmwareUpdateMetaDataCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -793,7 +793,7 @@ export class FirmwareUpdateMetaDataCCStatusReport /** The wait time in seconds before the node becomes available for communication after the update */ public readonly waitTime?: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { status: getEnumMemberName(FirmwareUpdateStatus, this.status), }; @@ -834,7 +834,7 @@ export class FirmwareUpdateMetaDataCCActivationReport public readonly activationStatus: FirmwareUpdateActivationStatus; public readonly hardwareVersion?: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), @@ -911,7 +911,7 @@ export class FirmwareUpdateMetaDataCCActivationSet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), @@ -945,7 +945,7 @@ export class FirmwareUpdateMetaDataCCPrepareReport public readonly status: FirmwareDownloadStatus; public readonly checksum: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1010,7 +1010,7 @@ export class FirmwareUpdateMetaDataCCPrepareGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index a71ce737c586..4933f8d1645f 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -15,9 +15,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -311,7 +311,7 @@ export class HumidityControlModeCCSet extends HumidityControlModeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -336,7 +336,7 @@ export class HumidityControlModeCCReport extends HumidityControlModeCC { @ccValue(HumidityControlModeCCValues.mode) public readonly mode: HumidityControlMode; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -393,7 +393,7 @@ export class HumidityControlModeCCSupportedReport return this._supportedModes; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index bea9929450d2..b003a8b47baf 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -10,9 +10,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { @@ -182,7 +182,7 @@ export class HumidityControlOperatingStateCCReport @ccValue(HumidityControlOperatingStateCCValues.state) public readonly state: HumidityControlOperatingState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index e56dd16f7b31..8b6177bafc78 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -20,9 +20,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -559,7 +559,7 @@ export class HumidityControlSetpointCCSet extends HumidityControlSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { ...super.toLogEntry(host), @@ -641,7 +641,7 @@ export class HumidityControlSetpointCCReport extends HumidityControlSetpointCC { return this._value; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { ...super.toLogEntry(host), @@ -700,7 +700,7 @@ export class HumidityControlSetpointCCGet extends HumidityControlSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -734,7 +734,7 @@ export class HumidityControlSetpointCCSupportedReport public readonly supportedSetpointTypes: readonly HumidityControlSetpointType[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -780,7 +780,7 @@ export class HumidityControlSetpointCCScaleSupportedReport public readonly supportedScales: readonly number[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const supportedScales = this.supportedScales.map((scale) => getScale(scale) ); @@ -832,7 +832,7 @@ export class HumidityControlSetpointCCScaleSupportedGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -911,7 +911,7 @@ export class HumidityControlSetpointCCCapabilitiesReport return this._maxValueScale; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const minValueScale = getScale(this.minValueScale); const maxValueScale = getScale(this.maxValueScale); return { @@ -965,7 +965,7 @@ export class HumidityControlSetpointCCCapabilitiesGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index 14c73c821e7b..2902bdb40f55 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -4,11 +4,7 @@ import { validatePayload, } from "@zwave-js/core"; import { type MaybeNotKnown } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - ZWaveHost, - ZWaveValueHost, -} from "@zwave-js/host"; +import type { CCEncodingContext, GetValueDB, ZWaveHost } from "@zwave-js/host"; import { getEnumMemberName } from "@zwave-js/shared"; import { CCAPI } from "../lib/API"; import { @@ -126,7 +122,7 @@ export class InclusionControllerCCComplete extends InclusionControllerCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -176,7 +172,7 @@ export class InclusionControllerCCInitiate extends InclusionControllerCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 4ce8882a0a55..899ab78cd35a 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -19,9 +19,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -970,7 +970,7 @@ export class IndicatorCCSet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.indicator0Value != undefined) { message["indicator 0 value"] = this.indicator0Value; @@ -1184,7 +1184,7 @@ export class IndicatorCCReport extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.indicator0Value != undefined) { message["indicator 0 value"] = this.indicator0Value; @@ -1239,7 +1239,7 @@ export class IndicatorCCGet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1322,7 +1322,7 @@ export class IndicatorCCSupportedReport extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1382,7 +1382,7 @@ export class IndicatorCCSupportedGet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1448,7 +1448,7 @@ export class IndicatorCCDescriptionReport extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1505,7 +1505,7 @@ export class IndicatorCCDescriptionGet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 63e1274deea0..06ae78420436 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -18,9 +18,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -1374,7 +1374,7 @@ export class IrrigationCCSystemInfoReport extends IrrigationCC { @ccValue(IrrigationCCValues.maxValveTableSize) public readonly maxValveTableSize: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1481,7 +1481,7 @@ export class IrrigationCCSystemStatusReport extends IrrigationCC { @ccValue(IrrigationCCValues.firstOpenZoneId) public firstOpenZoneId?: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "system voltage": `${this.systemVoltage} V`, "active sensors": [ @@ -1592,7 +1592,7 @@ export class IrrigationCCSystemConfigSet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "master valve delay": `${this.masterValveDelay} s`, "high pressure threshold": `${this.highPressureThreshold} kPa`, @@ -1667,7 +1667,7 @@ export class IrrigationCCSystemConfigReport extends IrrigationCC { @ccValue(IrrigationCCValues.moistureSensorPolarity) public readonly moistureSensorPolarity?: IrrigationSensorPolarity; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "master valve delay": `${this.masterValveDelay} s`, "high pressure threshold": `${this.highPressureThreshold} kPa`, @@ -1802,7 +1802,7 @@ export class IrrigationCCValveInfoReport extends IrrigationCC { return true; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "valve ID": this.valveId, connected: this.connected, @@ -1876,7 +1876,7 @@ export class IrrigationCCValveInfoGet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1956,7 +1956,7 @@ export class IrrigationCCValveConfigSet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2089,7 +2089,7 @@ export class IrrigationCCValveConfigReport extends IrrigationCC { public useRainSensor: boolean; public useMoistureSensor: boolean; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2147,7 +2147,7 @@ export class IrrigationCCValveConfigGet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2199,7 +2199,7 @@ export class IrrigationCCValveRun extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "valve ID": this.valveId, }; @@ -2258,7 +2258,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "table ID": this.tableId, }; @@ -2299,7 +2299,7 @@ export class IrrigationCCValveTableReport extends IrrigationCC { public readonly tableId: number; public readonly entries: ValveTableEntry[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "table ID": this.tableId, }; @@ -2362,7 +2362,7 @@ export class IrrigationCCValveTableGet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2411,7 +2411,7 @@ export class IrrigationCCValveTableRun extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2460,7 +2460,7 @@ export class IrrigationCCSystemShutoff extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 9544b28d1abf..9e2d61d0d8e2 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -15,9 +15,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -229,7 +229,7 @@ export class LanguageCCSet extends LanguageCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { language: this.language }; if (this._country != undefined) { message.country = this._country; @@ -263,7 +263,7 @@ export class LanguageCCReport extends LanguageCC { @ccValue(LanguageCCValues.country) public readonly country: MaybeNotKnown; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { language: this.language }; if (this.country != undefined) { message.country = this.country; diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 04ca006022ab..396d7e4ffd37 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -13,9 +13,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -214,7 +214,7 @@ export class LockCCSet extends LockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { locked: this.locked }, @@ -236,7 +236,7 @@ export class LockCCReport extends LockCC { @ccValue(LockCCValues.locked) public readonly locked: boolean; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { locked: this.locked }, diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 2016cae76270..e6dc00837481 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -11,9 +11,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -275,7 +275,7 @@ export class ManufacturerSpecificCCReport extends ManufacturerSpecificCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -322,7 +322,7 @@ export class ManufacturerSpecificCCDeviceSpecificReport ) public readonly deviceId: string; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -369,7 +369,7 @@ export class ManufacturerSpecificCCDeviceSpecificGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index ef9ba16b36a3..b3581a0ca070 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -28,9 +28,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -1060,7 +1060,7 @@ export class MeterCCReport extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const scale = getMeterScale(this.type, this.scale) ?? getUnknownMeterScale(this.scale); @@ -1160,7 +1160,7 @@ export class MeterCCGet extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.rateType != undefined) { message["rate type"] = getEnumMemberName(RateType, this.rateType); @@ -1322,7 +1322,7 @@ export class MeterCCSupportedReport extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "meter type": getMeterName(this.type), "supports reset": this.supportsReset, @@ -1420,7 +1420,7 @@ export class MeterCCReset extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.type != undefined) { message.type = getMeterName(this.type); diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index c11dc4c6d9cb..ca61eab9cb3e 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -18,9 +18,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -677,7 +677,7 @@ export class MultiChannelAssociationCCSet extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -756,7 +756,7 @@ export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "group id": this.groupId || "(all groups)", }; @@ -872,7 +872,7 @@ export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -921,7 +921,7 @@ export class MultiChannelAssociationCCGet extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "group id": this.groupId }, @@ -964,7 +964,7 @@ export class MultiChannelAssociationCCSupportedGroupingsReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "group count": this.groupCount }, diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 36d880b8ba11..06e1f295643a 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -21,9 +21,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { distinct } from "alcalzone-shared/arrays"; @@ -868,7 +868,7 @@ export class MultiChannelCCEndPointReport extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "endpoint count (individual)": this.individualCount, "count is dynamic": this.countIsDynamic, @@ -978,7 +978,7 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1039,7 +1039,7 @@ export class MultiChannelCCCapabilityGet extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { endpoint: this.requestedEndpoint }, @@ -1126,7 +1126,7 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC { .reduce((prev, cur) => prev.concat(...cur), []); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1178,7 +1178,7 @@ export class MultiChannelCCEndPointFind extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1218,7 +1218,7 @@ export class MultiChannelCCAggregatedMembersReport extends MultiChannelCC { ) public readonly members: readonly number[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1264,7 +1264,7 @@ export class MultiChannelCCAggregatedMembersGet extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { endpoint: this.requestedEndpoint }, @@ -1396,7 +1396,7 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1430,7 +1430,7 @@ export class MultiChannelCCV1Report extends MultiChannelCC { public readonly requestedCC: CommandClasses; public readonly endpointCount: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1481,7 +1481,7 @@ export class MultiChannelCCV1Get extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { CC: getCCName(this.requestedCC) }, @@ -1566,7 +1566,7 @@ export class MultiChannelCCV1CommandEncapsulation extends MultiChannelCC { return super.computeEncapsulationOverhead() + 1; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { source: this.endpointIndex }, diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index 6be8722f0665..0d4b29297848 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -7,8 +7,8 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetValueDB, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; @@ -160,7 +160,7 @@ export class MultiCommandCCCommandEncapsulation extends MultiCommandCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), // Hide the default payload line diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 9ff747b24521..9b99abe5194e 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -28,9 +28,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -736,7 +736,7 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -809,7 +809,7 @@ export class MultilevelSensorCCGet extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord = {}; if ( this.sensorType != undefined @@ -868,7 +868,7 @@ export class MultilevelSensorCCSupportedSensorReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -932,7 +932,7 @@ export class MultilevelSensorCCSupportedScaleReport extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -983,7 +983,7 @@ export class MultilevelSensorCCGetSupportedScale extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 7f4e9803c80d..881afd75778a 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -668,7 +668,7 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "target value": this.targetValue, }; @@ -735,7 +735,7 @@ export class MultilevelSwitchCCReport extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current value": maybeUnknownToString(this.currentValue), }; @@ -830,7 +830,7 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { startLevel: `${this.startLevel}${ this.ignoreStartLevel ? " (ignored)" : "" @@ -874,7 +874,7 @@ export class MultilevelSwitchCCSupportedReport extends MultilevelSwitchCC { return true; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 5e9264765418..3e8a82e719b0 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -12,9 +12,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -319,7 +319,7 @@ export class NodeNamingAndLocationCCNameSet extends NodeNamingAndLocationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { name: this.name }, @@ -347,7 +347,7 @@ export class NodeNamingAndLocationCCNameReport extends NodeNamingAndLocationCC { @ccValue(NodeNamingAndLocationCCValues.name) public readonly name: string; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { name: this.name }, @@ -412,7 +412,7 @@ export class NodeNamingAndLocationCCLocationSet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { location: this.location }, @@ -442,7 +442,7 @@ export class NodeNamingAndLocationCCLocationReport @ccValue(NodeNamingAndLocationCCValues.location) public readonly location: string; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { location: this.location }, diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index b3bc6c935fa6..8ed35e4c5cf6 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -34,9 +34,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -942,7 +942,7 @@ export class NotificationCCSet extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1144,7 +1144,7 @@ export class NotificationCCReport extends NotificationCC { public sequenceNumber: number | undefined; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord = {}; if (this.alarmType) { message = { @@ -1498,7 +1498,7 @@ export class NotificationCCGet extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.alarmType != undefined) { message["V1 alarm type"] = this.alarmType; @@ -1582,7 +1582,7 @@ export class NotificationCCSupportedReport extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1715,7 +1715,7 @@ export class NotificationCCEventSupportedReport extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1768,7 +1768,7 @@ export class NotificationCCEventSupportedGet extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index 75ab8ade70ae..891e4064f66c 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -11,8 +11,8 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetValueDB, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -260,7 +260,7 @@ export class PowerlevelCCSet extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "power level": getEnumMemberName(Powerlevel, this.powerlevel), }; @@ -312,7 +312,7 @@ export class PowerlevelCCReport extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "power level": getEnumMemberName(Powerlevel, this.powerlevel), }; @@ -369,7 +369,7 @@ export class PowerlevelCCTestNodeSet extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -426,7 +426,7 @@ export class PowerlevelCCTestNodeReport extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 999386c76751..57af99a13e3e 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -17,9 +17,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -545,7 +545,7 @@ export class ProtectionCCSet extends ProtectionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { local: getEnumMemberName(LocalProtectionState, this.local), }; @@ -579,7 +579,7 @@ export class ProtectionCCReport extends ProtectionCC { @ccValue(ProtectionCCValues.rfProtectionState) public readonly rf?: RFProtectionState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { local: getEnumMemberName(LocalProtectionState, this.local), }; @@ -654,7 +654,7 @@ export class ProtectionCCSupportedReport extends ProtectionCC { @ccValue(ProtectionCCValues.supportedRFStates) public readonly supportedRFStates: RFProtectionState[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -693,7 +693,7 @@ export class ProtectionCCExclusiveControlReport extends ProtectionCC { @ccValue(ProtectionCCValues.exclusiveControlNodeId) public readonly exclusiveControlNodeId: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -743,7 +743,7 @@ export class ProtectionCCExclusiveControlSet extends ProtectionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -767,7 +767,7 @@ export class ProtectionCCTimeoutReport extends ProtectionCC { @ccValue(ProtectionCCValues.timeout) public readonly timeout: Timeout; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { timeout: this.timeout.toString() }, @@ -813,7 +813,7 @@ export class ProtectionCCTimeoutSet extends ProtectionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { timeout: this.timeout.toString() }, diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index 214a96b4570e..7529d2f610cf 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -12,8 +12,8 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetValueDB, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -174,7 +174,7 @@ export class SceneActivationCCSet extends SceneActivationCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "scene id": this.sceneId }; if (this.dimmingDuration != undefined) { message["dimming duration"] = this.dimmingDuration.toString(); diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 3f50e80a8edf..737a74454df9 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -14,9 +14,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -400,7 +400,7 @@ export class SceneActuatorConfigurationCCSet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { sceneId: this.sceneId, dimmingDuration: this.dimmingDuration.toString(), @@ -466,7 +466,7 @@ export class SceneActuatorConfigurationCCReport return true; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { sceneId: this.sceneId, }; @@ -533,7 +533,7 @@ export class SceneActuatorConfigurationCCGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "scene id": this.sceneId }, diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index a72caa1d88e7..c2bb55350432 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -15,9 +15,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -532,7 +532,7 @@ export class SceneControllerConfigurationCCSet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -584,7 +584,7 @@ export class SceneControllerConfigurationCCReport return true; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -645,7 +645,7 @@ export class SceneControllerConfigurationCCGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "group id": this.groupId }, diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index c983aa21af15..e12e109f63af 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -16,9 +16,9 @@ import { type EndpointId, type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host"; import { type AllOrNone, @@ -969,7 +969,7 @@ export class ScheduleEntryLockCCEnableSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1012,7 +1012,7 @@ export class ScheduleEntryLockCCEnableAllSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1070,7 +1070,7 @@ export class ScheduleEntryLockCCSupportedReport extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "no. of weekday schedule slots": this.numWeekDaySlots, "no. of day-of-year schedule slots": this.numYearDaySlots, @@ -1172,7 +1172,7 @@ export class ScheduleEntryLockCCWeekDayScheduleSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.action === ScheduleEntryLockSetAction.Erase) { message = { @@ -1299,7 +1299,7 @@ export class ScheduleEntryLockCCWeekDayScheduleReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.weekday == undefined) { message = { @@ -1365,7 +1365,7 @@ export class ScheduleEntryLockCCWeekDayScheduleGet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1478,7 +1478,7 @@ export class ScheduleEntryLockCCYearDayScheduleSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.action === ScheduleEntryLockSetAction.Erase) { message = { @@ -1642,7 +1642,7 @@ export class ScheduleEntryLockCCYearDayScheduleReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.startYear !== undefined) { message = { @@ -1711,7 +1711,7 @@ export class ScheduleEntryLockCCYearDayScheduleGet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1761,7 +1761,7 @@ export class ScheduleEntryLockCCTimeOffsetSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1810,7 +1810,7 @@ export class ScheduleEntryLockCCTimeOffsetReport extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1920,7 +1920,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleSet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.action === ScheduleEntryLockSetAction.Erase) { message = { @@ -2055,7 +2055,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (!this.weekdays) { message = { @@ -2123,7 +2123,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleGet return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 1c2f4a0e2ec7..53b5a59ea927 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -39,9 +39,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; @@ -1699,7 +1699,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { ); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, }; @@ -2046,7 +2046,7 @@ export class Security2CCNonceReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, SOS: this.SOS, @@ -2121,7 +2121,7 @@ export class Security2CCNonceGet extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "sequence number": this.sequenceNumber }, @@ -2207,7 +2207,7 @@ export class Security2CCKEXReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2337,7 +2337,7 @@ export class Security2CCKEXSet extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2386,7 +2386,7 @@ export class Security2CCKEXFail extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { reason: getEnumMemberName(KEXFailType, this.failType) }, @@ -2430,7 +2430,7 @@ export class Security2CCPublicKeyReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2477,7 +2477,7 @@ export class Security2CCNetworkKeyReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2523,7 +2523,7 @@ export class Security2CCNetworkKeyGet extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2574,7 +2574,7 @@ export class Security2CCTransferEnd extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -2620,7 +2620,7 @@ export class Security2CCCommandsSupportedReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index c834720a6f18..d313a76d06af 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -24,9 +24,9 @@ import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; @@ -584,7 +584,7 @@ export class SecurityCCNonceReport extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { nonce: buffer2hex(this.nonce) }, @@ -811,7 +811,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { return super.computeEncapsulationOverhead() + 18; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.nonceId != undefined) { message["nonce id"] = this.nonceId; @@ -879,7 +879,7 @@ export class SecurityCCSchemeReport extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), // Hide the default payload line @@ -905,7 +905,7 @@ export class SecurityCCSchemeGet extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), // Hide the default payload line @@ -931,7 +931,7 @@ export class SecurityCCSchemeInherit extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), // Hide the default payload line @@ -1053,7 +1053,7 @@ export class SecurityCCCommandsSupportedReport extends SecurityCC { .reduce((prev, cur) => prev.concat(...cur), []); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index c502e51d5a2e..30156c65ea3a 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -14,9 +14,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -503,7 +503,7 @@ export class SoundSwitchCCTonesNumberReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "# of tones": this.toneCount }, @@ -560,7 +560,7 @@ export class SoundSwitchCCToneInfoReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -612,7 +612,7 @@ export class SoundSwitchCCToneInfoGet extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "tone id": this.toneId }, @@ -656,7 +656,7 @@ export class SoundSwitchCCConfigurationSet extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -705,7 +705,7 @@ export class SoundSwitchCCConfigurationReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -757,7 +757,7 @@ export class SoundSwitchCCTonePlaySet extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "tone id": this.toneId, }; @@ -791,7 +791,7 @@ export class SoundSwitchCCTonePlayReport extends SoundSwitchCC { @ccValue(SoundSwitchCCValues.volume) public volume?: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "tone id": this.toneId, }; diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 7d21e646ed73..7f9298bfd33a 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -22,9 +22,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { PhysicalCCAPI } from "../lib/API"; @@ -344,7 +344,7 @@ export class SupervisionCCReport extends SupervisionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "session id": this.sessionId, "more updates follow": this.moreUpdatesFollow, @@ -437,7 +437,7 @@ export class SupervisionCCGet extends SupervisionCC { return super.computeEncapsulationOverhead() + 2; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index ee9be03274bc..f62676424b18 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -374,7 +374,7 @@ export class ThermostatFanModeCCSet extends ThermostatFanModeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatFanMode, this.mode), }; @@ -407,7 +407,7 @@ export class ThermostatFanModeCCReport extends ThermostatFanModeCC { @ccValue(ThermostatFanModeCCValues.turnedOff) public readonly off: boolean | undefined; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatFanMode, this.mode), }; @@ -457,7 +457,7 @@ export class ThermostatFanModeCCSupportedReport extends ThermostatFanModeCC { @ccValue(ThermostatFanModeCCValues.supportedFanModes) public readonly supportedModes: ThermostatFanMode[]; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index 486ff24d5e22..ae9e018c2ea4 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -11,9 +11,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { @@ -169,7 +169,7 @@ export class ThermostatFanStateCCReport extends ThermostatFanStateCC { @ccValue(ThermostatFanStateCCValues.fanState) public readonly state: ThermostatFanState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { state: getEnumMemberName(ThermostatFanState, this.state), }; diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index ef7e11ba38c7..c187bd27e8c2 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -17,9 +17,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -374,7 +374,7 @@ export class ThermostatModeCCSet extends ThermostatModeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatMode, this.mode), }; @@ -496,7 +496,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatMode, this.mode), }; @@ -568,7 +568,7 @@ export class ThermostatModeCCSupportedReport extends ThermostatModeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index d8627a218d83..a5aa480648f1 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -10,9 +10,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { @@ -180,7 +180,7 @@ export class ThermostatOperatingStateCCReport @ccValue(ThermostatOperatingStateCCValues.operatingState) public readonly state: ThermostatOperatingState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index d9a871f3ef0c..00708f136305 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -12,9 +12,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -240,7 +240,7 @@ export class ThermostatSetbackCCSet extends ThermostatSetbackCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -276,7 +276,7 @@ export class ThermostatSetbackCCReport extends ThermostatSetbackCC { /** The offset from the setpoint in 0.1 Kelvin or a special mode */ public readonly setbackState: SetbackState; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 2d91233b0ea7..e849557952f3 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -21,9 +21,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -662,7 +662,7 @@ export class ThermostatSetpointCCSet extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { ...super.toLogEntry(host), @@ -758,7 +758,7 @@ export class ThermostatSetpointCCReport extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { ...super.toLogEntry(host), @@ -814,7 +814,7 @@ export class ThermostatSetpointCCGet extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -900,7 +900,7 @@ export class ThermostatSetpointCCCapabilitiesReport return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const minValueScale = getScale(this.minValueScale); const maxValueScale = getScale(this.maxValueScale); return { @@ -949,7 +949,7 @@ export class ThermostatSetpointCCCapabilitiesGet extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1032,7 +1032,7 @@ export class ThermostatSetpointCCSupportedReport extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 790fd72d55c4..2a00c7242a9a 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -14,9 +14,9 @@ import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -272,7 +272,7 @@ export class TimeCCTimeReport extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -334,7 +334,7 @@ export class TimeCCDateReport extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -409,7 +409,7 @@ export class TimeCCTimeOffsetSet extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -493,7 +493,7 @@ export class TimeCCTimeOffsetReport extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index c8f27f8485fc..ad7d8dbaef22 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -16,9 +16,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -297,7 +297,7 @@ export class TimeParametersCCReport extends TimeParametersCC { return this._dateAndTime; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -394,7 +394,7 @@ export class TimeParametersCCSet extends TimeParametersCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/TransportServiceCC.ts b/packages/cc/src/cc/TransportServiceCC.ts index 069937806715..8c6302c47efa 100644 --- a/packages/cc/src/cc/TransportServiceCC.ts +++ b/packages/cc/src/cc/TransportServiceCC.ts @@ -10,9 +10,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { buffer2hex } from "@zwave-js/shared/safe"; import { @@ -227,7 +227,7 @@ export class TransportServiceCCFirstSegment extends TransportServiceCC { ); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -429,7 +429,7 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { ); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -500,7 +500,7 @@ export class TransportServiceCCSegmentRequest extends TransportServiceCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -542,7 +542,7 @@ export class TransportServiceCCSegmentComplete extends TransportServiceCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "session ID": this.sessionId }, @@ -579,7 +579,7 @@ export class TransportServiceCCSegmentWait extends TransportServiceCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "pending segments": this.pendingSegments }, diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 3512541ea310..31411b18a75e 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -18,9 +18,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, @@ -1300,7 +1300,7 @@ export class UserCodeCCSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1404,7 +1404,7 @@ export class UserCodeCCReport extends UserCodeCC return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1449,7 +1449,7 @@ export class UserCodeCCGet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "user id": this.userId }, @@ -1497,7 +1497,7 @@ export class UserCodeCCUsersNumberReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "supported users": this.supportedUsers }, @@ -1661,7 +1661,7 @@ export class UserCodeCCCapabilitiesReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1722,7 +1722,7 @@ export class UserCodeCCKeypadModeSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { mode: getEnumMemberName(KeypadMode, this.keypadMode) }, @@ -1781,7 +1781,7 @@ export class UserCodeCCKeypadModeReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -1832,7 +1832,7 @@ export class UserCodeCCAdminCodeSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "admin code": userCodeToLogString(this.adminCode) }, @@ -1877,7 +1877,7 @@ export class UserCodeCCAdminCodeReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "admin code": userCodeToLogString(this.adminCode) }, @@ -1922,7 +1922,7 @@ export class UserCodeCCUserCodeChecksumReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { "user code checksum": num2hex(this.userCodeChecksum) }, @@ -1991,7 +1991,7 @@ export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const { userId, userIdStatus, userCode } of this.userCodes) { message[`code #${userId}`] = `${ @@ -2050,7 +2050,7 @@ export class UserCodeCCExtendedUserCodeReport extends UserCodeCC { public readonly userCodes: readonly UserCode[]; public readonly nextUserId: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const { userId, userIdStatus, userCode } of this.userCodes) { message[`code #${userId}`] = `${ @@ -2104,7 +2104,7 @@ export class UserCodeCCExtendedUserCodeGet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index fa1d319c4c68..5db3e9c3c915 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -18,9 +18,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -764,7 +764,7 @@ export class VersionCCReport extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "library type": getEnumMemberName( ZWaveLibraryTypes, @@ -820,7 +820,7 @@ export class VersionCCCommandClassReport extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -872,7 +872,7 @@ export class VersionCCCommandClassGet extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { CC: getCCName(this.requestedCC) }, @@ -914,7 +914,7 @@ export class VersionCCCapabilitiesReport extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -994,7 +994,7 @@ export class VersionCCZWaveSoftwareReport extends VersionCC { @ccValue(VersionCCValues.applicationBuildNumber) public readonly applicationBuildNumber: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "SDK version": this.sdkVersion, }; diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index c808d5f2f645..44b43af3282c 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -12,9 +12,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -395,7 +395,7 @@ export class WakeUpCCIntervalSet extends WakeUpCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -425,7 +425,7 @@ export class WakeUpCCIntervalReport extends WakeUpCC { @ccValue(WakeUpCCValues.controllerNodeId) public readonly controllerNodeId: number; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -501,7 +501,7 @@ export class WakeUpCCIntervalCapabilitiesReport extends WakeUpCC { @ccValue(WakeUpCCValues.wakeUpOnDemandSupported) public readonly wakeUpOnDemandSupported: boolean; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index d7b83ad0c22a..04c9a0bf89c5 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -14,9 +14,9 @@ import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -733,7 +733,7 @@ export class WindowCoveringCCSupportedReport extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -790,7 +790,7 @@ export class WindowCoveringCCReport extends WindowCoveringCC { ) public readonly duration: Duration; - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -843,7 +843,7 @@ export class WindowCoveringCCGet extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { @@ -923,7 +923,7 @@ export class WindowCoveringCCSet extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const { parameter, value } of this.targetValues) { message[getEnumMemberName(WindowCoveringParameter, parameter)] = @@ -986,7 +986,7 @@ export class WindowCoveringCCStartLevelChange extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { parameter: getEnumMemberName( WindowCoveringParameter, @@ -1036,7 +1036,7 @@ export class WindowCoveringCCStopLevelChange extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index caa2a2850b64..d2539d9c6fcd 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -8,9 +8,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -234,7 +234,7 @@ export class ZWavePlusCCReport extends ZWavePlusCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { return { ...super.toLogEntry(host), message: { diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 367b71979d64..5637f0e15a9b 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -13,9 +13,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -427,7 +427,7 @@ export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { return super.serialize(ctx); } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.position != undefined) { message.position = this.position; @@ -501,7 +501,7 @@ export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { return this._tilt; } - public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.position != undefined) { message.position = this.position; diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index b10457deb035..cb57cebe9812 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -36,9 +36,9 @@ import { import type { CCEncodingContext, CCParsingContext, + GetValueDB, ZWaveApplicationHost, ZWaveHost, - ZWaveValueHost, } from "@zwave-js/host"; import { MessageOrigin } from "@zwave-js/serial"; import { @@ -310,7 +310,7 @@ export class CommandClass implements CCId { } /** Whether the interview for this CC was previously completed */ - public isInterviewComplete(host: ZWaveValueHost): boolean { + public isInterviewComplete(host: GetValueDB): boolean { return !!this.getValueDB(host).getValue({ commandClass: this.ccId, endpoint: this.endpointIndex, @@ -320,7 +320,7 @@ export class CommandClass implements CCId { /** Marks the interview for this CC as complete or not */ public setInterviewComplete( - host: ZWaveValueHost, + host: GetValueDB, complete: boolean, ): void { this.getValueDB(host).setValue( @@ -495,7 +495,7 @@ export class CommandClass implements CCId { } /** Generates a representation of this CC for the log */ - public toLogEntry(_host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(_host?: GetValueDB): MessageOrCCLogEntry { let tag = this.constructor.name; const message: MessageRecord = {}; if (this.constructor === CommandClass) { @@ -672,7 +672,7 @@ export class CommandClass implements CCId { } /** Returns the value DB for this CC's node */ - protected getValueDB(host: ZWaveValueHost): ValueDB { + protected getValueDB(host: GetValueDB): ValueDB { if (this.isSinglecast()) { try { return host.getValueDB(this.nodeId); @@ -695,7 +695,7 @@ export class CommandClass implements CCId { * @param meta Will be used in place of the predefined metadata when given */ protected ensureMetadata( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, meta?: ValueMetadata, ): void { @@ -711,7 +711,7 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected removeMetadata( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, ): void { const valueDB = this.getValueDB(host); @@ -725,7 +725,7 @@ export class CommandClass implements CCId { * @param meta Will be used in place of the predefined metadata when given */ protected setMetadata( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, meta?: ValueMetadata, ): void { @@ -739,7 +739,7 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected getMetadata( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, ): T | undefined { const valueDB = this.getValueDB(host); @@ -752,7 +752,7 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected setValue( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, value: unknown, ): void { @@ -766,7 +766,7 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected removeValue( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, ): void { const valueDB = this.getValueDB(host); @@ -779,7 +779,7 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected getValue( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, ): T | undefined { const valueDB = this.getValueDB(host); @@ -792,7 +792,7 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected getValueTimestamp( - host: ZWaveValueHost, + host: GetValueDB, ccValue: CCValue, ): number | undefined { const valueDB = this.getValueDB(host); @@ -1221,7 +1221,7 @@ export class InvalidCC extends CommandClass { } public readonly reason?: string | ZWaveErrorCodes; - public toLogEntry(_host?: ZWaveValueHost): MessageOrCCLogEntry { + public toLogEntry(_host?: GetValueDB): MessageOrCCLogEntry { return { tags: [this.ccName, "INVALID"], message: this.reason != undefined diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 4100ffa0668b..2b4ab479172a 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -118,7 +118,7 @@ export interface ZWaveHost extends HostIDs, GetNextCallbackId { } /** Host application abstractions that provide support for reading and writing values to a database */ -export interface ZWaveValueHost { +export interface GetValueDB { /** Returns the value DB which belongs to the node with the given ID, or throws if the Value DB cannot be accessed */ getValueDB(nodeId: number): ValueDB; @@ -140,7 +140,7 @@ export interface GetAllNodes { /** A more featureful version of the ZWaveHost interface, which is meant to be used on the controller application side. */ export interface ZWaveApplicationHost extends - ZWaveValueHost, + GetValueDB, ZWaveHost, GetNode, GetAllNodes, From a4400a8c11613ef5ec9c526c471aca505c32ea22 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 10:50:53 +0200 Subject: [PATCH 18/60] chore: add codeshift to rename imports across monorepo --- packages/maintenance/package.json | 2 + .../src/codeshifts/renameImport.ts | 68 ++ yarn.lock | 845 +++++++++++++++++- 3 files changed, 901 insertions(+), 14 deletions(-) create mode 100644 packages/maintenance/src/codeshifts/renameImport.ts diff --git a/packages/maintenance/package.json b/packages/maintenance/package.json index e6b3370bf0a9..f3c6d591c685 100644 --- a/packages/maintenance/package.json +++ b/packages/maintenance/package.json @@ -42,6 +42,7 @@ "@dprint/typescript": "^0.93.0", "@types/fs-extra": "^11.0.4", "@types/globrex": "^0.1.4", + "@types/jscodeshift": "^0.12.0", "@types/node": "^18.19.55", "@types/yargs": "^17.0.33", "@zwave-js/core": "workspace:*", @@ -56,6 +57,7 @@ "execa": "^5.1.1", "fs-extra": "^11.2.0", "globrex": "^0.1.2", + "jscodeshift": "^17.0.0", "json5": "^2.2.3", "piscina": "^4.7.0", "reflect-metadata": "^0.2.2", diff --git a/packages/maintenance/src/codeshifts/renameImport.ts b/packages/maintenance/src/codeshifts/renameImport.ts new file mode 100644 index 000000000000..3ad54ce682c6 --- /dev/null +++ b/packages/maintenance/src/codeshifts/renameImport.ts @@ -0,0 +1,68 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { API, FileInfo, JSCodeshift, Options, Transform } from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + { + from, + to, + typeOnly = false, + }: Options, +) => { + if (!from || !to) { + throw new Error("Both 'from' and 'to' are required options"); + } + + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + let imp = root + .find( + j.ImportDeclaration, + { importKind: typeOnly ? "type" : undefined }, + ) + .find(j.ImportSpecifier, { + imported: { + name: from, + }, + }); + + return imp.replaceWith(({ node }) => { + node.imported.name = to; + return node; + }).toSource(); + + // return ( + // j(file.source) + // .find(j.FunctionDeclaration) + // // Target a particular function declaration + // .filter(({ node: functionDeclaration }) => functionDeclaration.id.name === functionName) + // .replaceWith(({ node: functionDeclaration }) => { + // // Create a function call expression statement + // const functionCallExpressionStatement = j.expressionStatement( + // j.callExpression(j.identifier(functionNameToCall), []) + // ); + + // // Create a comment and add it as a leading comment to the function call expression + // const commentLine = j.commentLine(comment); + // functionCallExpressionStatement.comments = [commentLine]; + + // // Append the function call expression to the function declaration's existing body + // functionDeclaration.body.body = [...functionDeclaration.body.body, functionCallExpressionStatement]; + // return functionDeclaration; + // }) + // .toSource() + // ); +}; + +export default transform; +export const parser = "ts"; diff --git a/yarn.lock b/yarn.lock index 186ad3491e5a..c141033089bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -220,6 +220,16 @@ __metadata: languageName: node linkType: hard +"@ampproject/remapping@npm:^2.2.0": + version: 2.3.0 + resolution: "@ampproject/remapping@npm:2.3.0" + dependencies: + "@jridgewell/gen-mapping": "npm:^0.3.5" + "@jridgewell/trace-mapping": "npm:^0.3.24" + checksum: 10/f3451525379c68a73eb0a1e65247fbf28c0cccd126d93af21c75fceff77773d43c0d4a2d51978fb131aff25b5f2cb41a9fe48cc296e61ae65e679c4f6918b0ab + languageName: node + linkType: hard + "@babel/code-frame@npm:^7.0.0": version: 7.14.5 resolution: "@babel/code-frame@npm:7.14.5" @@ -229,6 +239,187 @@ __metadata: languageName: node linkType: hard +"@babel/code-frame@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/code-frame@npm:7.25.7" + dependencies: + "@babel/highlight": "npm:^7.25.7" + picocolors: "npm:^1.0.0" + checksum: 10/000fb8299fb35b6217d4f6c6580dcc1fa2f6c0f82d0a54b8a029966f633a8b19b490a7a906b56a94e9d8bee91c3bc44c74c44c33fb0abaa588202f6280186291 + languageName: node + linkType: hard + +"@babel/compat-data@npm:^7.25.7": + version: 7.25.8 + resolution: "@babel/compat-data@npm:7.25.8" + checksum: 10/269fcb0d89e02e36c8a11e0c1b960a6b4204e88f59f20c374d28f8e318f4cd5ded42dfedc4b54162065e6a10f71c0de651f5ed3f9b45d3a4b52240196df85726 + languageName: node + linkType: hard + +"@babel/core@npm:^7.24.7": + version: 7.25.8 + resolution: "@babel/core@npm:7.25.8" + dependencies: + "@ampproject/remapping": "npm:^2.2.0" + "@babel/code-frame": "npm:^7.25.7" + "@babel/generator": "npm:^7.25.7" + "@babel/helper-compilation-targets": "npm:^7.25.7" + "@babel/helper-module-transforms": "npm:^7.25.7" + "@babel/helpers": "npm:^7.25.7" + "@babel/parser": "npm:^7.25.8" + "@babel/template": "npm:^7.25.7" + "@babel/traverse": "npm:^7.25.7" + "@babel/types": "npm:^7.25.8" + convert-source-map: "npm:^2.0.0" + debug: "npm:^4.1.0" + gensync: "npm:^1.0.0-beta.2" + json5: "npm:^2.2.3" + semver: "npm:^6.3.1" + checksum: 10/31eb1a8ca1a3cc0026060720eb290e68205d95c5c00fbd831e69ddc0810f5920b8eb2749db1889ac0a0312b6eddbf321d18a996a88858f3b75c9582bef9ec1e4 + languageName: node + linkType: hard + +"@babel/generator@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/generator@npm:7.25.7" + dependencies: + "@babel/types": "npm:^7.25.7" + "@jridgewell/gen-mapping": "npm:^0.3.5" + "@jridgewell/trace-mapping": "npm:^0.3.25" + jsesc: "npm:^3.0.2" + checksum: 10/01542829621388077fa8a7464970c1db0f748f1482968dddf5332926afe4003f953cbe08e3bbbb0a335b11eba0126c9a81779bd1c5baed681a9ccec4ae63b217 + languageName: node + linkType: hard + +"@babel/helper-annotate-as-pure@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-annotate-as-pure@npm:7.25.7" + dependencies: + "@babel/types": "npm:^7.25.7" + checksum: 10/38044806cab33032391c46861cd0a36adb960525b00bc03f2f3d4380c983bf17971cdabc431e58b93a328ef24bd0271f1dc3a8c1c1ea6cab49d04702961451d8 + languageName: node + linkType: hard + +"@babel/helper-compilation-targets@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-compilation-targets@npm:7.25.7" + dependencies: + "@babel/compat-data": "npm:^7.25.7" + "@babel/helper-validator-option": "npm:^7.25.7" + browserslist: "npm:^4.24.0" + lru-cache: "npm:^5.1.1" + semver: "npm:^6.3.1" + checksum: 10/bbf9be8480da3f9a89e36e9ea2e1c76601014c1074ccada7c2edb1adeb3b62bc402cc4abaf8d16760734b25eceb187a9510ce44f6a7a6f696ccc74f69283625b + languageName: node + linkType: hard + +"@babel/helper-create-class-features-plugin@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-create-class-features-plugin@npm:7.25.7" + dependencies: + "@babel/helper-annotate-as-pure": "npm:^7.25.7" + "@babel/helper-member-expression-to-functions": "npm:^7.25.7" + "@babel/helper-optimise-call-expression": "npm:^7.25.7" + "@babel/helper-replace-supers": "npm:^7.25.7" + "@babel/helper-skip-transparent-expression-wrappers": "npm:^7.25.7" + "@babel/traverse": "npm:^7.25.7" + semver: "npm:^6.3.1" + peerDependencies: + "@babel/core": ^7.0.0 + checksum: 10/76e3bb727d7541d38acaa9b6ecff88f70e62370396dd22511837b90a556c6815a7efd6fd25b499bf1c8b02cdb18c575781a6aba0c442c38a2129a403b5bf9b1e + languageName: node + linkType: hard + +"@babel/helper-member-expression-to-functions@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-member-expression-to-functions@npm:7.25.7" + dependencies: + "@babel/traverse": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + checksum: 10/f953a0ddbcfbaae835033b54fdbf42cc3aea08c554875fccfc02ed4b1e5fe3ee06abf1b7a8419314357841fabc9efdbcbb8afdf07c4f216a73164a45a147562b + languageName: node + linkType: hard + +"@babel/helper-module-imports@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-module-imports@npm:7.25.7" + dependencies: + "@babel/traverse": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + checksum: 10/94556712c27058ea35a1a39e21a3a9f067cd699405b64333d7d92b2b3d2f24d6f0ffa51aedba0b908e320acb1854e70d296259622e636fb021eeae9a6d996f01 + languageName: node + linkType: hard + +"@babel/helper-module-transforms@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-module-transforms@npm:7.25.7" + dependencies: + "@babel/helper-module-imports": "npm:^7.25.7" + "@babel/helper-simple-access": "npm:^7.25.7" + "@babel/helper-validator-identifier": "npm:^7.25.7" + "@babel/traverse": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0 + checksum: 10/480309b1272ceaa985de1393f0e4c41aede0d5921ca644cec5aeaf43c8e4192b6dd56a58ef6d7e9acd02a43184ab45d3b241fc8c3a0a00f9dbb30235fd8a1181 + languageName: node + linkType: hard + +"@babel/helper-optimise-call-expression@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-optimise-call-expression@npm:7.25.7" + dependencies: + "@babel/types": "npm:^7.25.7" + checksum: 10/8da0d9f5aae15991678ad1bbe58e52cd62a0ed36871075756d9684c0a7a65988ed81bab53ad6436c39a470d3cd690694dd2b07147817217e3ca87178a129c509 + languageName: node + linkType: hard + +"@babel/helper-plugin-utils@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-plugin-utils@npm:7.25.7" + checksum: 10/e1b0ea5e67b05378d6360e3fc370e99bfb247eed9f68145b5cce541da703424e1887fb6fc60ab2f7f743c72dcbfbed79d3032af43f2c251c229c734dc2572a5b + languageName: node + linkType: hard + +"@babel/helper-replace-supers@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-replace-supers@npm:7.25.7" + dependencies: + "@babel/helper-member-expression-to-functions": "npm:^7.25.7" + "@babel/helper-optimise-call-expression": "npm:^7.25.7" + "@babel/traverse": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0 + checksum: 10/87b65c7b278fabcb67458e592082a0b4532d5400acbb51e496ea47763077d0a64dc0531d32bafcb1d51f04d61d4715dadb1fd0301bc8449c26fcfd06913eb45e + languageName: node + linkType: hard + +"@babel/helper-simple-access@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-simple-access@npm:7.25.7" + dependencies: + "@babel/traverse": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + checksum: 10/42da1c358f2516337a4f2927c77ebb952907543b9f85d7cb1e2b5b5f6d808cdc081ee66a73e2ecdf48c315d9b0c2a81a857d5e1923ea210b8e81aba5e6cd2b53 + languageName: node + linkType: hard + +"@babel/helper-skip-transparent-expression-wrappers@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-skip-transparent-expression-wrappers@npm:7.25.7" + dependencies: + "@babel/traverse": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + checksum: 10/466c81d09981bfb9e10aa6697ecb621389ff92a86187daaca34a969ca990d7327ebe931e87f7d52a200e499542d398469478d83dfaaa244d2f49df4e078490b3 + languageName: node + linkType: hard + +"@babel/helper-string-parser@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-string-parser@npm:7.25.7" + checksum: 10/2b8de9fa86c3f3090a349f1ce6e8ee2618a95355cbdafc6f228d82fa4808c84bf3d1d25290c6616d0a18b26b6cfeb6ec2aeebf01404bc8c60051d0094209f0e6 + languageName: node + linkType: hard + "@babel/helper-validator-identifier@npm:^7.14.5": version: 7.14.5 resolution: "@babel/helper-validator-identifier@npm:7.14.5" @@ -236,13 +427,30 @@ __metadata: languageName: node linkType: hard -"@babel/helper-validator-identifier@npm:^7.24.7": +"@babel/helper-validator-identifier@npm:^7.24.7, @babel/helper-validator-identifier@npm:^7.25.7": version: 7.25.7 resolution: "@babel/helper-validator-identifier@npm:7.25.7" checksum: 10/ec6934cc47fc35baaeb968414a372b064f14f7b130cf6489a014c9486b0fd2549b3c6c682cc1fc35080075e8e38d96aeb40342d63d09fc1a62510c8ce25cde1e languageName: node linkType: hard +"@babel/helper-validator-option@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helper-validator-option@npm:7.25.7" + checksum: 10/3c46cbdd666d176f90a0b7e952a0c6e92184b66633336eca79aca243d1f86085ec339a6e45c3d44efa9e03f1829b470a350ddafa70926af6bbf1ac611284f8d3 + languageName: node + linkType: hard + +"@babel/helpers@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/helpers@npm:7.25.7" + dependencies: + "@babel/template": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + checksum: 10/2632909f83aa99e8b0da4e10e5ab7fc4f0274e6497bb0f17071e004e037d25e4a595583620261dc21410a526fb32b4f7063c3e15e60ed7890a6f9b8ad52312c5 + languageName: node + linkType: hard + "@babel/highlight@npm:^7.14.5": version: 7.14.5 resolution: "@babel/highlight@npm:7.14.5" @@ -254,6 +462,229 @@ __metadata: languageName: node linkType: hard +"@babel/highlight@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/highlight@npm:7.25.7" + dependencies: + "@babel/helper-validator-identifier": "npm:^7.25.7" + chalk: "npm:^2.4.2" + js-tokens: "npm:^4.0.0" + picocolors: "npm:^1.0.0" + checksum: 10/823be2523d246dbf80aab3cc81c2a36c6111b16ac2949ef06789da54387824c2bfaa88c6627cdeb4ba7151d047a5d6765e49ebd0b478aba09759250111e65e08 + languageName: node + linkType: hard + +"@babel/parser@npm:^7.24.7, @babel/parser@npm:^7.25.7, @babel/parser@npm:^7.25.8": + version: 7.25.8 + resolution: "@babel/parser@npm:7.25.8" + dependencies: + "@babel/types": "npm:^7.25.8" + bin: + parser: ./bin/babel-parser.js + checksum: 10/0396eb71e379903cedb43862f84ebb1bec809c41e82b4894d2e6e83b8e8bc636ba6eff45382e615baefdb2399ede76ca82247ecc3a9877ac16eb3140074a3276 + languageName: node + linkType: hard + +"@babel/plugin-syntax-flow@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/plugin-syntax-flow@npm:7.25.7" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/ce96b984445c712bb5fdc70a8c7e8a58759db17d1e31386caae5c93b062ab447421831e9527949b0d3d7750ac0a4eacfde00f40ca86392381fec7c5d39455e9c + languageName: node + linkType: hard + +"@babel/plugin-syntax-jsx@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/plugin-syntax-jsx@npm:7.25.7" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/243476a943a84b6b86e99076301e66f48268e8799564053e8feccab90da7944a0b42c91360216dbfb0b2958bbd0ed100d2c7b2db688dab83d19ff2745d4892eb + languageName: node + linkType: hard + +"@babel/plugin-syntax-typescript@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/plugin-syntax-typescript@npm:7.25.7" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/f1492336230920cc4daa6e7aa3571253fb0c0fd05a1d0a7b5dc0a5b907f31945235ee8bf09c83f7738b89943a2320a61dda95e0db2b6310b07040aeda6be4f44 + languageName: node + linkType: hard + +"@babel/plugin-transform-class-properties@npm:^7.24.7": + version: 7.25.7 + resolution: "@babel/plugin-transform-class-properties@npm:7.25.7" + dependencies: + "@babel/helper-create-class-features-plugin": "npm:^7.25.7" + "@babel/helper-plugin-utils": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/fe1dbbd77275ade96964fec0c85a1f14e2dac0c6565bccddf00680e43c2e906d289dd9d483aff6359420cef2a044b4aaaeb303f64a3a1a005601c018188368e7 + languageName: node + linkType: hard + +"@babel/plugin-transform-flow-strip-types@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/plugin-transform-flow-strip-types@npm:7.25.7" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + "@babel/plugin-syntax-flow": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/af709749aa23deb6aaf8a34818a7de240f80e1877927b55afc566758e64cdf46738385b4f39ad94c9198ae1215f011a76ad3a779ac4a48092d349f53ef942ce0 + languageName: node + linkType: hard + +"@babel/plugin-transform-modules-commonjs@npm:^7.24.7, @babel/plugin-transform-modules-commonjs@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/plugin-transform-modules-commonjs@npm:7.25.7" + dependencies: + "@babel/helper-module-transforms": "npm:^7.25.7" + "@babel/helper-plugin-utils": "npm:^7.25.7" + "@babel/helper-simple-access": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/4b3d038b55bfe5553e9eea360cc1b3dd689068256a9bce1939061ab1dfa194fea0b7b54f10c53b0af0be44508fd0037022c32709a6d96ac1277fb9c7de0f510c + languageName: node + linkType: hard + +"@babel/plugin-transform-nullish-coalescing-operator@npm:^7.24.7": + version: 7.25.8 + resolution: "@babel/plugin-transform-nullish-coalescing-operator@npm:7.25.8" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/d742fedc1abf404d7f40065cdff9afc521236607f0d06c48d1e471f43d3a7471010d1651ba4758d80c73347a39dc278d86c43a9c814382ded4e9c7c519ace021 + languageName: node + linkType: hard + +"@babel/plugin-transform-optional-chaining@npm:^7.24.7": + version: 7.25.8 + resolution: "@babel/plugin-transform-optional-chaining@npm:7.25.8" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + "@babel/helper-skip-transparent-expression-wrappers": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/ffb5d81e6dbb28907d5346c8e12a1ed1ea0e30170fbe609d48d0466cdbc9d11b5774c8781682693f7cf7bd39da6111980e54813af96c6b3086dc769369c67d28 + languageName: node + linkType: hard + +"@babel/plugin-transform-private-methods@npm:^7.24.7": + version: 7.25.7 + resolution: "@babel/plugin-transform-private-methods@npm:7.25.7" + dependencies: + "@babel/helper-create-class-features-plugin": "npm:^7.25.7" + "@babel/helper-plugin-utils": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/79506a74334dc77f6c53f44109f0a3fcf6c50410faa5dd5e5d17ac4b73194098de509f5515a7aed3724a4bfa5dd246517e22a1dff4c20fc052df7a189bf2160d + languageName: node + linkType: hard + +"@babel/plugin-transform-typescript@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/plugin-transform-typescript@npm:7.25.7" + dependencies: + "@babel/helper-annotate-as-pure": "npm:^7.25.7" + "@babel/helper-create-class-features-plugin": "npm:^7.25.7" + "@babel/helper-plugin-utils": "npm:^7.25.7" + "@babel/helper-skip-transparent-expression-wrappers": "npm:^7.25.7" + "@babel/plugin-syntax-typescript": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/2648da981cd71c2100a4ea496684f2c0b939fc77eb4bb9cc8f113d433eab17d4930d2e5ed8d280606bcedef58df99002a64dc92579c6cc7f6c6ee71ceaa77418 + languageName: node + linkType: hard + +"@babel/preset-flow@npm:^7.24.7": + version: 7.25.7 + resolution: "@babel/preset-flow@npm:7.25.7" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + "@babel/helper-validator-option": "npm:^7.25.7" + "@babel/plugin-transform-flow-strip-types": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/b96e1a4bcd7a5bf868def9ea9e1097f0b96d8d3e5458668268a47906f68fd43617601274511dcf3cb47f519ef9d6ed88788282610ad926b864f9c8149c4a04b8 + languageName: node + linkType: hard + +"@babel/preset-typescript@npm:^7.24.7": + version: 7.25.7 + resolution: "@babel/preset-typescript@npm:7.25.7" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.25.7" + "@babel/helper-validator-option": "npm:^7.25.7" + "@babel/plugin-syntax-jsx": "npm:^7.25.7" + "@babel/plugin-transform-modules-commonjs": "npm:^7.25.7" + "@babel/plugin-transform-typescript": "npm:^7.25.7" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/cf6501971f696800096f3b3aef4f7e2c774210b4204bb3a076b2f253970d6649c28003de3afc620b7c7ad67fb346083819c89bae2c644f59995ddb64d6003541 + languageName: node + linkType: hard + +"@babel/register@npm:^7.24.6": + version: 7.25.7 + resolution: "@babel/register@npm:7.25.7" + dependencies: + clone-deep: "npm:^4.0.1" + find-cache-dir: "npm:^2.0.0" + make-dir: "npm:^2.1.0" + pirates: "npm:^4.0.6" + source-map-support: "npm:^0.5.16" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/bb375399aea6d13b92eb4e40befb5ca8ec226d753aa3ff8d9be2c284805a133e3afe7128a7b103af7abb164868c273bd80ea9a9e55a9ec38ef17df4b977f1cd7 + languageName: node + linkType: hard + +"@babel/template@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/template@npm:7.25.7" + dependencies: + "@babel/code-frame": "npm:^7.25.7" + "@babel/parser": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + checksum: 10/49e1e88d2eac17d31ae28d6cf13d6d29c1f49384c4f056a6751c065d6565c351e62c01ce6b11fef5edb5f3a77c87e114ea7326ca384fa618b4834e10cf9b20f3 + languageName: node + linkType: hard + +"@babel/traverse@npm:^7.25.7": + version: 7.25.7 + resolution: "@babel/traverse@npm:7.25.7" + dependencies: + "@babel/code-frame": "npm:^7.25.7" + "@babel/generator": "npm:^7.25.7" + "@babel/parser": "npm:^7.25.7" + "@babel/template": "npm:^7.25.7" + "@babel/types": "npm:^7.25.7" + debug: "npm:^4.3.1" + globals: "npm:^11.1.0" + checksum: 10/5b2d332fcd6bc78e6500c997e79f7e2a54dfb357e06f0908cb7f0cdd9bb54e7fd3c5673f45993849d433d01ea6076a6d04b825958f0cfa01288ad55ffa5c286f + languageName: node + linkType: hard + +"@babel/types@npm:^7.25.7, @babel/types@npm:^7.25.8": + version: 7.25.8 + resolution: "@babel/types@npm:7.25.8" + dependencies: + "@babel/helper-string-parser": "npm:^7.25.7" + "@babel/helper-validator-identifier": "npm:^7.25.7" + to-fast-properties: "npm:^2.0.0" + checksum: 10/973108dbb189916bb87360f2beff43ae97f1b08f1c071bc6499d363cce48b3c71674bf3b59dfd617f8c5062d1c76dc2a64232bc07b6ccef831fd0c06162d44d9 + languageName: node + linkType: hard + "@colors/colors@npm:1.6.0, @colors/colors@npm:^1.6.0": version: 1.6.0 resolution: "@colors/colors@npm:1.6.0" @@ -900,6 +1331,48 @@ __metadata: languageName: node linkType: hard +"@jridgewell/gen-mapping@npm:^0.3.5": + version: 0.3.5 + resolution: "@jridgewell/gen-mapping@npm:0.3.5" + dependencies: + "@jridgewell/set-array": "npm:^1.2.1" + "@jridgewell/sourcemap-codec": "npm:^1.4.10" + "@jridgewell/trace-mapping": "npm:^0.3.24" + checksum: 10/81587b3c4dd8e6c60252122937cea0c637486311f4ed208b52b62aae2e7a87598f63ec330e6cd0984af494bfb16d3f0d60d3b21d7e5b4aedd2602ff3fe9d32e2 + languageName: node + linkType: hard + +"@jridgewell/resolve-uri@npm:^3.1.0": + version: 3.1.2 + resolution: "@jridgewell/resolve-uri@npm:3.1.2" + checksum: 10/97106439d750a409c22c8bff822d648f6a71f3aa9bc8e5129efdc36343cd3096ddc4eeb1c62d2fe48e9bdd4db37b05d4646a17114ecebd3bbcacfa2de51c3c1d + languageName: node + linkType: hard + +"@jridgewell/set-array@npm:^1.2.1": + version: 1.2.1 + resolution: "@jridgewell/set-array@npm:1.2.1" + checksum: 10/832e513a85a588f8ed4f27d1279420d8547743cc37fcad5a5a76fc74bb895b013dfe614d0eed9cb860048e6546b798f8f2652020b4b2ba0561b05caa8c654b10 + languageName: node + linkType: hard + +"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.14": + version: 1.5.0 + resolution: "@jridgewell/sourcemap-codec@npm:1.5.0" + checksum: 10/4ed6123217569a1484419ac53f6ea0d9f3b57e5b57ab30d7c267bdb27792a27eb0e4b08e84a2680aa55cc2f2b411ffd6ec3db01c44fdc6dc43aca4b55f8374fd + languageName: node + linkType: hard + +"@jridgewell/trace-mapping@npm:^0.3.24, @jridgewell/trace-mapping@npm:^0.3.25": + version: 0.3.25 + resolution: "@jridgewell/trace-mapping@npm:0.3.25" + dependencies: + "@jridgewell/resolve-uri": "npm:^3.1.0" + "@jridgewell/sourcemap-codec": "npm:^1.4.14" + checksum: 10/dced32160a44b49d531b80a4a2159dceab6b3ddf0c8e95a0deae4b0e894b172defa63d5ac52a19c2068e1fe7d31ea4ba931fbeec103233ecb4208953967120fc + languageName: node + linkType: hard + "@leichtgewicht/ip-codec@npm:^2.0.1": version: 2.0.4 resolution: "@leichtgewicht/ip-codec@npm:2.0.4" @@ -1680,6 +2153,16 @@ __metadata: languageName: node linkType: hard +"@types/jscodeshift@npm:^0.12.0": + version: 0.12.0 + resolution: "@types/jscodeshift@npm:0.12.0" + dependencies: + ast-types: "npm:^0.14.1" + recast: "npm:^0.20.3" + checksum: 10/1e0fd4a5ee2863db792ad5666fa98ee61d3d5a4d5f24a9b8d11cf6ebae25bff55a3e5e27a59fef3aed37637458e7ab52b30181640be39cddbe9956f4a47fd1ab + languageName: node + linkType: hard + "@types/json-logic-js@npm:^2.0.7": version: 2.0.7 resolution: "@types/json-logic-js@npm:2.0.7" @@ -2162,6 +2645,7 @@ __metadata: "@dprint/typescript": "npm:^0.93.0" "@types/fs-extra": "npm:^11.0.4" "@types/globrex": "npm:^0.1.4" + "@types/jscodeshift": "npm:^0.12.0" "@types/node": "npm:^18.19.55" "@types/yargs": "npm:^17.0.33" "@zwave-js/core": "workspace:*" @@ -2176,6 +2660,7 @@ __metadata: execa: "npm:^5.1.1" fs-extra: "npm:^11.2.0" globrex: "npm:^0.1.2" + jscodeshift: "npm:^17.0.0" json5: "npm:^2.2.3" piscina: "npm:^4.7.0" reflect-metadata: "npm:^0.2.2" @@ -2798,6 +3283,24 @@ __metadata: languageName: node linkType: hard +"ast-types@npm:0.14.2, ast-types@npm:^0.14.1": + version: 0.14.2 + resolution: "ast-types@npm:0.14.2" + dependencies: + tslib: "npm:^2.0.1" + checksum: 10/7c74b3090c90aa600b49a7a8cecc99e329f190600bcaa75ad087472a1a5a7ef23795a17ea00a74c2a8e822b336cd4f874e2e1b815a9877b4dba5e401566b0433 + languageName: node + linkType: hard + +"ast-types@npm:^0.16.1": + version: 0.16.1 + resolution: "ast-types@npm:0.16.1" + dependencies: + tslib: "npm:^2.0.1" + checksum: 10/f569b475eb1c8cb93888cb6e7b7e36dc43fa19a77e4eb132cbff6e3eb1598ca60f850db6e60b070e5a0ee8c1559fca921dac0916e576f2f104e198793b0bdd8d + languageName: node + linkType: hard + "async-sema@npm:^3.1.1": version: 3.1.1 resolution: "async-sema@npm:3.1.1" @@ -2982,6 +3485,20 @@ __metadata: languageName: node linkType: hard +"browserslist@npm:^4.24.0": + version: 4.24.0 + resolution: "browserslist@npm:4.24.0" + dependencies: + caniuse-lite: "npm:^1.0.30001663" + electron-to-chromium: "npm:^1.5.28" + node-releases: "npm:^2.0.18" + update-browserslist-db: "npm:^1.1.0" + bin: + browserslist: cli.js + checksum: 10/26c1b8ba257a0b51b102080ba9d42945af2abaa8c4cf6da21cd47b3f123fc1e81640203b293214356c2c17d9d265bb3a5ed428b6d302f383576dd6ce8fd5036c + languageName: node + linkType: hard + "buffer-from@npm:^1.0.0": version: 1.1.1 resolution: "buffer-from@npm:1.1.1" @@ -3116,6 +3633,13 @@ __metadata: languageName: node linkType: hard +"caniuse-lite@npm:^1.0.30001663": + version: 1.0.30001668 + resolution: "caniuse-lite@npm:1.0.30001668" + checksum: 10/4a14acbc999a855e6a91a3ae4ca670f202ceabb4b0e75f8eaef153fafe33ae5ea0de7ac99c078d6b724c8f60b14b1ea24d7c544398e5fd077c418e3f029559ff + languageName: node + linkType: hard + "cbor@npm:^9.0.1": version: 9.0.2 resolution: "cbor@npm:9.0.2" @@ -3328,6 +3852,17 @@ __metadata: languageName: node linkType: hard +"clone-deep@npm:^4.0.1": + version: 4.0.1 + resolution: "clone-deep@npm:4.0.1" + dependencies: + is-plain-object: "npm:^2.0.4" + kind-of: "npm:^6.0.2" + shallow-clone: "npm:^3.0.0" + checksum: 10/770f912fe4e6f21873c8e8fbb1e99134db3b93da32df271d00589ea4a29dbe83a9808a322c93f3bcaf8584b8b4fa6fc269fc8032efbaa6728e0c9886c74467d2 + languageName: node + linkType: hard + "clone@npm:^1.0.2": version: 1.0.4 resolution: "clone@npm:1.0.4" @@ -3557,6 +4092,13 @@ __metadata: languageName: node linkType: hard +"commondir@npm:^1.0.1": + version: 1.0.1 + resolution: "commondir@npm:1.0.1" + checksum: 10/4620bc4936a4ef12ce7dfcd272bb23a99f2ad68889a4e4ad766c9f8ad21af982511934d6f7050d4a8bde90011b1c15d56e61a1b4576d9913efbf697a20172d6c + languageName: node + linkType: hard + "compare-func@npm:^2.0.0": version: 2.0.0 resolution: "compare-func@npm:2.0.0" @@ -3636,6 +4178,13 @@ __metadata: languageName: node linkType: hard +"convert-source-map@npm:^2.0.0": + version: 2.0.0 + resolution: "convert-source-map@npm:2.0.0" + checksum: 10/c987be3ec061348cdb3c2bfb924bec86dea1eacad10550a85ca23edb0fe3556c3a61c7399114f3331ccb3499d7fd0285ab24566e5745929412983494c3926e15 + languageName: node + linkType: hard + "convert-to-spaces@npm:^2.0.1": version: 2.0.1 resolution: "convert-to-spaces@npm:2.0.1" @@ -4083,6 +4632,13 @@ __metadata: languageName: node linkType: hard +"electron-to-chromium@npm:^1.5.28": + version: 1.5.36 + resolution: "electron-to-chromium@npm:1.5.36" + checksum: 10/659f637b7384714d5a732de0e5baca007fa1ae741faa4a0f9eb576d65a6a6d30c553caae27df5df7307c65484c0fbcd2ac453df27848d04f7dd27b81dea072a2 + languageName: node + linkType: hard + "electron-to-chromium@npm:^1.5.4": version: 1.5.24 resolution: "electron-to-chromium@npm:1.5.24" @@ -4510,7 +5066,7 @@ __metadata: languageName: node linkType: hard -"esprima@npm:^4.0.0, esprima@npm:^4.0.1": +"esprima@npm:^4.0.0, esprima@npm:^4.0.1, esprima@npm:~4.0.0": version: 4.0.1 resolution: "esprima@npm:4.0.1" bin: @@ -4826,6 +5382,17 @@ __metadata: languageName: node linkType: hard +"find-cache-dir@npm:^2.0.0": + version: 2.1.0 + resolution: "find-cache-dir@npm:2.1.0" + dependencies: + commondir: "npm:^1.0.1" + make-dir: "npm:^2.0.0" + pkg-dir: "npm:^3.0.0" + checksum: 10/60ad475a6da9f257df4e81900f78986ab367d4f65d33cf802c5b91e969c28a8762f098693d7a571b6e4dd4c15166c2da32ae2d18b6766a18e2071079448fdce4 + languageName: node + linkType: hard + "find-node-modules@npm:^2.1.2": version: 2.1.2 resolution: "find-node-modules@npm:2.1.2" @@ -4850,6 +5417,15 @@ __metadata: languageName: node linkType: hard +"find-up@npm:^3.0.0": + version: 3.0.0 + resolution: "find-up@npm:3.0.0" + dependencies: + locate-path: "npm:^3.0.0" + checksum: 10/38eba3fe7a66e4bc7f0f5a1366dc25508b7cfc349f852640e3678d26ad9a6d7e2c43eff0a472287de4a9753ef58f066a0ea892a256fa3636ad51b3fe1e17fae9 + languageName: node + linkType: hard + "find-up@npm:^4.1.0": version: 4.1.0 resolution: "find-up@npm:4.1.0" @@ -4910,6 +5486,13 @@ __metadata: languageName: node linkType: hard +"flow-parser@npm:0.*": + version: 0.248.1 + resolution: "flow-parser@npm:0.248.1" + checksum: 10/bc54edb5fb842ee467b67459bba7bbc54e66eef81ed4ba87e6d28f10306fd32d925b80a10522200c134a51bdd512723d88887fb2275b89b54b89281cd38751cd + languageName: node + linkType: hard + "fn.name@npm:1.x.x": version: 1.1.0 resolution: "fn.name@npm:1.1.0" @@ -5064,6 +5647,13 @@ __metadata: languageName: node linkType: hard +"gensync@npm:^1.0.0-beta.2": + version: 1.0.0-beta.2 + resolution: "gensync@npm:1.0.0-beta.2" + checksum: 10/17d8333460204fbf1f9160d067e1e77f908a5447febb49424b8ab043026049835c9ef3974445c57dbd39161f4d2b04356d7de12b2eecaa27a7a7ea7d871cbedd + languageName: node + linkType: hard + "get-caller-file@npm:^2.0.5": version: 2.0.5 resolution: "get-caller-file@npm:2.0.5" @@ -5218,6 +5808,13 @@ __metadata: languageName: node linkType: hard +"globals@npm:^11.1.0": + version: 11.12.0 + resolution: "globals@npm:11.12.0" + checksum: 10/9f054fa38ff8de8fa356502eb9d2dae0c928217b8b5c8de1f09f5c9b6c8a96d8b9bd3afc49acbcd384a98a81fea713c859e1b09e214c60509517bb8fc2bc13c2 + languageName: node + linkType: hard + "globals@npm:^14.0.0": version: 14.0.0 resolution: "globals@npm:14.0.0" @@ -5867,6 +6464,15 @@ __metadata: languageName: node linkType: hard +"is-plain-object@npm:^2.0.4": + version: 2.0.4 + resolution: "is-plain-object@npm:2.0.4" + dependencies: + isobject: "npm:^3.0.1" + checksum: 10/2a401140cfd86cabe25214956ae2cfee6fbd8186809555cd0e84574f88de7b17abacb2e477a6a658fa54c6083ecbda1e6ae404c7720244cd198903848fca70ca + languageName: node + linkType: hard + "is-plain-object@npm:^5.0.0": version: 5.0.0 resolution: "is-plain-object@npm:5.0.0" @@ -5946,6 +6552,13 @@ __metadata: languageName: node linkType: hard +"isobject@npm:^3.0.1": + version: 3.0.1 + resolution: "isobject@npm:3.0.1" + checksum: 10/db85c4c970ce30693676487cca0e61da2ca34e8d4967c2e1309143ff910c207133a969f9e4ddb2dc6aba670aabce4e0e307146c310350b298e74a31f7d464703 + languageName: node + linkType: hard + "jiti@npm:^1.19.1": version: 1.21.0 resolution: "jiti@npm:1.21.0" @@ -6006,6 +6619,39 @@ __metadata: languageName: node linkType: hard +"jscodeshift@npm:^17.0.0": + version: 17.0.0 + resolution: "jscodeshift@npm:17.0.0" + dependencies: + "@babel/core": "npm:^7.24.7" + "@babel/parser": "npm:^7.24.7" + "@babel/plugin-transform-class-properties": "npm:^7.24.7" + "@babel/plugin-transform-modules-commonjs": "npm:^7.24.7" + "@babel/plugin-transform-nullish-coalescing-operator": "npm:^7.24.7" + "@babel/plugin-transform-optional-chaining": "npm:^7.24.7" + "@babel/plugin-transform-private-methods": "npm:^7.24.7" + "@babel/preset-flow": "npm:^7.24.7" + "@babel/preset-typescript": "npm:^7.24.7" + "@babel/register": "npm:^7.24.6" + flow-parser: "npm:0.*" + graceful-fs: "npm:^4.2.4" + micromatch: "npm:^4.0.7" + neo-async: "npm:^2.5.0" + picocolors: "npm:^1.0.1" + recast: "npm:^0.23.9" + temp: "npm:^0.9.4" + write-file-atomic: "npm:^5.0.1" + peerDependencies: + "@babel/preset-env": ^7.1.6 + peerDependenciesMeta: + "@babel/preset-env": + optional: true + bin: + jscodeshift: bin/jscodeshift.js + checksum: 10/d47000c33775336332e1ee431354881ce25a42354a82c712e109f598eac90be747d412c85428e1fa0302136823e44e4f42487746d62752120cd6879665bcef0a + languageName: node + linkType: hard + "jsesc@npm:^3.0.2": version: 3.0.2 resolution: "jsesc@npm:3.0.2" @@ -6242,6 +6888,16 @@ __metadata: languageName: node linkType: hard +"locate-path@npm:^3.0.0": + version: 3.0.0 + resolution: "locate-path@npm:3.0.0" + dependencies: + p-locate: "npm:^3.0.0" + path-exists: "npm:^3.0.0" + checksum: 10/53db3996672f21f8b0bf2a2c645ae2c13ffdae1eeecfcd399a583bce8516c0b88dcb4222ca6efbbbeb6949df7e46860895be2c02e8d3219abd373ace3bfb4e11 + languageName: node + linkType: hard + "locate-path@npm:^5.0.0": version: 5.0.0 resolution: "locate-path@npm:5.0.0" @@ -6431,6 +7087,15 @@ __metadata: languageName: node linkType: hard +"lru-cache@npm:^5.1.1": + version: 5.1.1 + resolution: "lru-cache@npm:5.1.1" + dependencies: + yallist: "npm:^3.0.2" + checksum: 10/951d2673dcc64a7fb888bf3d13bc2fdf923faca97d89cdb405ba3dfff77e2b26e5798d405e78fcd7094c9e7b8b4dab2ddc5a4f8a11928af24a207b7c738ca3f8 + languageName: node + linkType: hard + "lru-cache@npm:^6.0.0": version: 6.0.0 resolution: "lru-cache@npm:6.0.0" @@ -6440,6 +7105,16 @@ __metadata: languageName: node linkType: hard +"make-dir@npm:^2.0.0, make-dir@npm:^2.1.0": + version: 2.1.0 + resolution: "make-dir@npm:2.1.0" + dependencies: + pify: "npm:^4.0.1" + semver: "npm:^5.6.0" + checksum: 10/043548886bfaf1820323c6a2997e6d2fa51ccc2586ac14e6f14634f7458b4db2daf15f8c310e2a0abd3e0cddc64df1890d8fc7263033602c47bb12cbfcf86aab + languageName: node + linkType: hard + "make-dir@npm:^3.1.0": version: 3.1.0 resolution: "make-dir@npm:3.1.0" @@ -6603,7 +7278,7 @@ __metadata: languageName: node linkType: hard -"micromatch@npm:~4.0.8": +"micromatch@npm:^4.0.7, micromatch@npm:~4.0.8": version: 4.0.8 resolution: "micromatch@npm:4.0.8" dependencies: @@ -6809,6 +7484,17 @@ __metadata: languageName: node linkType: hard +"mkdirp@npm:^0.5.1": + version: 0.5.6 + resolution: "mkdirp@npm:0.5.6" + dependencies: + minimist: "npm:^1.2.6" + bin: + mkdirp: bin/cmd.js + checksum: 10/0c91b721bb12c3f9af4b77ebf73604baf350e64d80df91754dc509491ae93bf238581e59c7188360cec7cb62fc4100959245a42cfe01834efedc5e9d068376c2 + languageName: node + linkType: hard + "mkdirp@npm:^1.0.3, mkdirp@npm:^1.0.4": version: 1.0.4 resolution: "mkdirp@npm:1.0.4" @@ -6894,6 +7580,13 @@ __metadata: languageName: node linkType: hard +"neo-async@npm:^2.5.0": + version: 2.6.2 + resolution: "neo-async@npm:2.6.2" + checksum: 10/1a7948fea86f2b33ec766bc899c88796a51ba76a4afc9026764aedc6e7cde692a09067031e4a1bf6db4f978ccd99e7f5b6c03fe47ad9865c3d4f99050d67e002 + languageName: node + linkType: hard + "nested-error-stacks@npm:^2.1.1": version: 2.1.1 resolution: "nested-error-stacks@npm:2.1.1" @@ -7210,7 +7903,7 @@ __metadata: languageName: node linkType: hard -"p-limit@npm:^2.2.0": +"p-limit@npm:^2.0.0, p-limit@npm:^2.2.0": version: 2.3.0 resolution: "p-limit@npm:2.3.0" dependencies: @@ -7237,6 +7930,15 @@ __metadata: languageName: node linkType: hard +"p-locate@npm:^3.0.0": + version: 3.0.0 + resolution: "p-locate@npm:3.0.0" + dependencies: + p-limit: "npm:^2.0.0" + checksum: 10/83991734a9854a05fe9dbb29f707ea8a0599391f52daac32b86f08e21415e857ffa60f0e120bfe7ce0cc4faf9274a50239c7895fc0d0579d08411e513b83a4ae + languageName: node + linkType: hard + "p-locate@npm:^4.1.0": version: 4.1.0 resolution: "p-locate@npm:4.1.0" @@ -7402,6 +8104,13 @@ __metadata: languageName: node linkType: hard +"path-exists@npm:^3.0.0": + version: 3.0.0 + resolution: "path-exists@npm:3.0.0" + checksum: 10/96e92643aa34b4b28d0de1cd2eba52a1c5313a90c6542d03f62750d82480e20bfa62bc865d5cfc6165f5fcd5aeb0851043c40a39be5989646f223300021bae0a + languageName: node + linkType: hard + "path-exists@npm:^4.0.0": version: 4.0.0 resolution: "path-exists@npm:4.0.0" @@ -7484,7 +8193,7 @@ __metadata: languageName: node linkType: hard -"picocolors@npm:^1.0.1": +"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1": version: 1.1.0 resolution: "picocolors@npm:1.1.0" checksum: 10/a2ad60d94d185c30f2a140b19c512547713fb89b920d32cc6cf658fa786d63a37ba7b8451872c3d9fc34883971fb6e5878e07a20b60506e0bb2554dce9169ccb @@ -7528,6 +8237,20 @@ __metadata: languageName: node linkType: hard +"pify@npm:^4.0.1": + version: 4.0.1 + resolution: "pify@npm:4.0.1" + checksum: 10/8b97cbf9dc6d4c1320cc238a2db0fc67547f9dc77011729ff353faf34f1936ea1a4d7f3c63b2f4980b253be77bcc72ea1e9e76ee3fd53cce2aafb6a8854d07ec + languageName: node + linkType: hard + +"pirates@npm:^4.0.6": + version: 4.0.6 + resolution: "pirates@npm:4.0.6" + checksum: 10/d02dda76f4fec1cbdf395c36c11cf26f76a644f9f9a1bfa84d3167d0d3154d5289aacc72677aa20d599bb4a6937a471de1b65c995e2aea2d8687cbcd7e43ea5f + languageName: node + linkType: hard + "piscina@npm:^4.7.0": version: 4.7.0 resolution: "piscina@npm:4.7.0" @@ -7540,6 +8263,15 @@ __metadata: languageName: node linkType: hard +"pkg-dir@npm:^3.0.0": + version: 3.0.0 + resolution: "pkg-dir@npm:3.0.0" + dependencies: + find-up: "npm:^3.0.0" + checksum: 10/70c9476ffefc77552cc6b1880176b71ad70bfac4f367604b2b04efd19337309a4eec985e94823271c7c0e83946fa5aeb18cd360d15d10a5d7533e19344bfa808 + languageName: node + linkType: hard + "plur@npm:^5.1.0": version: 5.1.0 resolution: "plur@npm:5.1.0" @@ -7738,6 +8470,31 @@ __metadata: languageName: node linkType: hard +"recast@npm:^0.20.3": + version: 0.20.5 + resolution: "recast@npm:0.20.5" + dependencies: + ast-types: "npm:0.14.2" + esprima: "npm:~4.0.0" + source-map: "npm:~0.6.1" + tslib: "npm:^2.0.1" + checksum: 10/7b270187e12f06ba0f5695590158005170a49a5996ab5d30ec4af2a2b1db8b0f74b1449b7eb6984f6d381438448e05cb46dcbf9b647fc49c6fc5139b2e40fca0 + languageName: node + linkType: hard + +"recast@npm:^0.23.9": + version: 0.23.9 + resolution: "recast@npm:0.23.9" + dependencies: + ast-types: "npm:^0.16.1" + esprima: "npm:~4.0.0" + source-map: "npm:~0.6.1" + tiny-invariant: "npm:^1.3.3" + tslib: "npm:^2.0.1" + checksum: 10/d60584be179d81a82fbe58b5bbe009aa42831ee114a21a3e3a22bda91334e0b8a1a4610dca8ecb7f9ea1426da4febc08134d3003085ad6ecee478d1808eb8796 + languageName: node + linkType: hard + "redent@npm:^3.0.0": version: 3.0.0 resolution: "redent@npm:3.0.0" @@ -8040,6 +8797,17 @@ __metadata: languageName: node linkType: hard +"rimraf@npm:~2.6.2": + version: 2.6.3 + resolution: "rimraf@npm:2.6.3" + dependencies: + glob: "npm:^7.1.3" + bin: + rimraf: ./bin.js + checksum: 10/756419f2fa99aa119c46a9fc03e09d84ecf5421a80a72d1944c5088c9e4671e77128527a900a313ed9d3fdbdd37e2ae05486cd7e9116d5812d8c31f2399d7c86 + languageName: node + linkType: hard + "run-async@npm:^2.2.0, run-async@npm:^2.4.0": version: 2.4.1 resolution: "run-async@npm:2.4.1" @@ -8134,7 +8902,16 @@ __metadata: languageName: node linkType: hard -"semver@npm:^6.0.0": +"semver@npm:^5.6.0": + version: 5.7.2 + resolution: "semver@npm:5.7.2" + bin: + semver: bin/semver + checksum: 10/fca14418a174d4b4ef1fecb32c5941e3412d52a4d3d85165924ce3a47fbc7073372c26faf7484ceb4bbc2bde25880c6b97e492473dc7e9708fdfb1c6a02d546e + languageName: node + linkType: hard + +"semver@npm:^6.0.0, semver@npm:^6.3.1": version: 6.3.1 resolution: "semver@npm:6.3.1" bin: @@ -8245,6 +9022,15 @@ __metadata: languageName: node linkType: hard +"shallow-clone@npm:^3.0.0": + version: 3.0.1 + resolution: "shallow-clone@npm:3.0.1" + dependencies: + kind-of: "npm:^6.0.2" + checksum: 10/e066bd540cfec5e1b0f78134853e0d892d1c8945fb9a926a579946052e7cb0c70ca4fc34f875a8083aa7910d751805d36ae64af250a6de6f3d28f9fa7be6c21b + languageName: node + linkType: hard + "shebang-command@npm:^2.0.0": version: 2.0.0 resolution: "shebang-command@npm:2.0.0" @@ -8374,7 +9160,7 @@ __metadata: languageName: node linkType: hard -"source-map-support@npm:^0.5.21": +"source-map-support@npm:^0.5.16, source-map-support@npm:^0.5.21": version: 0.5.21 resolution: "source-map-support@npm:0.5.21" dependencies: @@ -8733,6 +9519,16 @@ __metadata: languageName: node linkType: hard +"temp@npm:^0.9.4": + version: 0.9.4 + resolution: "temp@npm:0.9.4" + dependencies: + mkdirp: "npm:^0.5.1" + rimraf: "npm:~2.6.2" + checksum: 10/38d40564656c6e8e3caee41c592b3cc076d257ab4746ae4a6a179c44eb4a6d3e8a19a08c7716c8e88756bb898d6e56dd0a9e0408249bbcb3c990a178c34d0571 + languageName: node + linkType: hard + "text-extensions@npm:^2.0.0": version: 2.4.0 resolution: "text-extensions@npm:2.4.0" @@ -8796,6 +9592,13 @@ __metadata: languageName: node linkType: hard +"tiny-invariant@npm:^1.3.3": + version: 1.3.3 + resolution: "tiny-invariant@npm:1.3.3" + checksum: 10/5e185c8cc2266967984ce3b352a4e57cb89dad5a8abb0dea21468a6ecaa67cd5bb47a3b7a85d08041008644af4f667fb8b6575ba38ba5fb00b3b5068306e59fe + languageName: node + linkType: hard + "tinyexec@npm:^0.3.0": version: 0.3.0 resolution: "tinyexec@npm:0.3.0" @@ -8822,6 +9625,13 @@ __metadata: languageName: node linkType: hard +"to-fast-properties@npm:^2.0.0": + version: 2.0.0 + resolution: "to-fast-properties@npm:2.0.0" + checksum: 10/be2de62fe58ead94e3e592680052683b1ec986c72d589e7b21e5697f8744cdbf48c266fa72f6c15932894c10187b5f54573a3bcf7da0bfd964d5caf23d436168 + languageName: node + linkType: hard + "to-regex-range@npm:^5.0.1": version: 5.0.1 resolution: "to-regex-range@npm:5.0.1" @@ -8919,6 +9729,13 @@ __metadata: languageName: node linkType: hard +"tslib@npm:^2.0.1, tslib@npm:^2.6.3": + version: 2.7.0 + resolution: "tslib@npm:2.7.0" + checksum: 10/9a5b47ddac65874fa011c20ff76db69f97cf90c78cff5934799ab8894a5342db2d17b4e7613a087046bc1d133d21547ddff87ac558abeec31ffa929c88b7fce6 + languageName: node + linkType: hard + "tslib@npm:^2.1.0": version: 2.4.0 resolution: "tslib@npm:2.4.0" @@ -8933,13 +9750,6 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.6.3": - version: 2.7.0 - resolution: "tslib@npm:2.7.0" - checksum: 10/9a5b47ddac65874fa011c20ff76db69f97cf90c78cff5934799ab8894a5342db2d17b4e7613a087046bc1d133d21547ddff87ac558abeec31ffa929c88b7fce6 - languageName: node - linkType: hard - "tsutils@npm:^3.21.0": version: 3.21.0 resolution: "tsutils@npm:3.21.0" @@ -9448,6 +10258,13 @@ __metadata: languageName: node linkType: hard +"yallist@npm:^3.0.2": + version: 3.1.1 + resolution: "yallist@npm:3.1.1" + checksum: 10/9af0a4329c3c6b779ac4736c69fae4190ac03029fa27c1aef4e6bcc92119b73dea6fe5db5fe881fb0ce2a0e9539a42cdf60c7c21eda04d1a0b8c082e38509efb + languageName: node + linkType: hard + "yallist@npm:^4.0.0": version: 4.0.0 resolution: "yallist@npm:4.0.0" From 694a24168a54c144f4db0536352259f4dc9f0cc6 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 10:51:14 +0200 Subject: [PATCH 19/60] refactor: add ownNodeId to contexts --- packages/cc/src/cc/Security2CC.ts | 13 ++++++++----- packages/cc/src/cc/SecurityCC.ts | 4 ++-- packages/host/src/ZWaveHost.ts | 7 ++++--- packages/serial/src/message/Message.ts | 7 +++++-- packages/testing/src/MockController.ts | 2 ++ packages/testing/src/MockNode.ts | 2 ++ .../src/lib/controller/MockControllerBehaviors.ts | 1 - packages/zwave-js/src/lib/driver/Driver.ts | 10 +++++++--- .../application/ApplicationCommandRequest.ts | 3 +-- .../application/BridgeApplicationCommandRequest.ts | 1 - .../src/lib/serialapi/transport/SendDataMessages.ts | 2 -- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 5 +++-- 12 files changed, 34 insertions(+), 23 deletions(-) diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 53b5a59ea927..9ac457e24f39 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -616,7 +616,10 @@ export class Security2CC extends CommandClass { | CommandClassDeserializationOptions, ): SecurityManager2 { const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; - if (!this.host.ownNodeId) { + const ownNodeId = gotDeserializationOptions(options) + ? options.context.ownNodeId + : this.host.ownNodeId; + if (ownNodeId) { throw new ZWaveError( `Secure commands (S2) can only be ${verb} when the controller's node id is known!`, ZWaveErrorCodes.Driver_NotReady, @@ -626,13 +629,13 @@ export class Security2CC extends CommandClass { let ret: SecurityManager2 | undefined; if (gotDeserializationOptions(options)) { ret = getSecurityManager( - this.host.ownNodeId, + ownNodeId, options.context, this.nodeId, )!; } else { ret = getSecurityManager( - this.host.ownNodeId, + ownNodeId, options.securityManagers, this.nodeId, )!; @@ -1626,9 +1629,9 @@ export class Security2CCMessageEncapsulation extends Security2CC { const messageLength = this.computeEncapsulationOverhead() + serializedCC.length; const authData = getAuthenticationData( - this.host.ownNodeId, + ctx.ownNodeId, destinationTag, - this.host.homeId, + ctx.homeId, messageLength, unencryptedPayload, ); diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index d313a76d06af..5b79992c24f1 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -661,7 +661,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { nonce!, this.ccCommand, this.nodeId, - this.host.ownNodeId, + options.context.ownNodeId, encryptedPayload, ); const expectedAuthCode = computeMAC(authData, this.authKey); @@ -785,7 +785,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { senderNonce, this.nonce, this.ccCommand, - this.host.ownNodeId, + ctx.ownNodeId, this.nodeId, ciphertext, ); diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 2b4ab479172a..3cfc3163801e 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -41,10 +41,9 @@ export interface GetDeviceConfig { /** Additional context needed for deserializing CCs */ export interface CCParsingContext - extends Readonly, GetDeviceConfig + extends Readonly, GetDeviceConfig, HostIDs { sourceNodeId: number; - ownNodeId: number; /** If known, the frame type of the containing message */ frameType?: FrameType; @@ -66,7 +65,7 @@ export interface CCParsingContext /** Additional context needed for serializing CCs */ // FIXME: Lot of duplication between the CC and message contexts export interface CCEncodingContext - extends Readonly, GetDeviceConfig + extends Readonly, GetDeviceConfig, HostIDs { getHighestSecurityClass(nodeId: number): MaybeNotKnown; @@ -141,6 +140,8 @@ export interface GetAllNodes { export interface ZWaveApplicationHost extends GetValueDB, + HostIDs, + GetNextCallbackId, ZWaveHost, GetNode, GetAllNodes, diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index c85495d3fa05..5e91068d8aaf 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -14,6 +14,7 @@ import { } from "@zwave-js/core"; import type { GetDeviceConfig, + HostIDs, ZWaveApplicationHost, ZWaveHost, } from "@zwave-js/host"; @@ -39,7 +40,7 @@ export enum MessageOrigin { Host, } -export interface MessageParsingContext extends GetDeviceConfig { +export interface MessageParsingContext extends GetDeviceConfig, HostIDs { /** How many bytes a node ID occupies in serial API commands */ nodeIdType: NodeIDType; @@ -95,7 +96,9 @@ export type MessageOptions = | MessageCreationOptions | MessageDeserializationOptions; -export interface MessageEncodingContext extends Readonly { +export interface MessageEncodingContext + extends Readonly, HostIDs +{ /** How many bytes a node ID occupies in serial API commands */ nodeIdType: NodeIDType; diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index e58fdd991181..6b52f2ab1913 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -107,6 +107,8 @@ export class MockController { const securityClasses = new Map>(); this.encodingContext = { + homeId: this.host.homeId, + ownNodeId: this.host.ownNodeId, // TODO: LR is not supported in mocks nodeIdType: NodeIDType.Short, hasSecurityClass( diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index acc65ac6c7de..2a48d34632ce 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -123,6 +123,8 @@ export class MockNode { const securityClasses = new Map>(); this.encodingContext = { + homeId: this.controller.host.homeId, + ownNodeId: this.id, hasSecurityClass( nodeId: number, securityClass: SecurityClass, diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index d1cb17ba97c8..ce4b8f3a4e97 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -98,7 +98,6 @@ function createLazySendDataPayload( data: msg.payload, origin: MessageOrigin.Host, context: { - ownNodeId: controller.host.ownNodeId, sourceNodeId: node.id, ...node.encodingContext, ...node.securityManagers, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 85e33fe98910..feef8c71339a 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -109,6 +109,7 @@ import { wasControllerReset, } from "@zwave-js/core"; import type { + HostIDs, NodeSchedulePollOptions, ZWaveApplicationHost, } from "@zwave-js/host"; @@ -712,14 +713,16 @@ export class Driver extends TypedEventEmitter /** The serial port instance */ private serial: ZWaveSerialPortBase | undefined; - private messageParsingContext: MessageParsingContext; - private messageEncodingContext: MessageEncodingContext; + private messageParsingContext: Omit; + private messageEncodingContext: Omit; private getCCEncodingContext() { // FIXME: The type system isn't helping here. We need the security managers to encode CCs // but not for messages, yet those implicitly encode CCs return { ...this.messageEncodingContext, + ownNodeId: this.controller.ownNodeId!, + homeId: this.controller.homeId!, securityManager: this.securityManager, securityManager2: this.securityManager2, securityManagerLR: this.securityManagerLR, @@ -731,6 +734,8 @@ export class Driver extends TypedEventEmitter // but not for messages, yet those implicitly decode CCs return { ...this.messageParsingContext, + ownNodeId: this.controller.ownNodeId!, + homeId: this.controller.homeId!, securityManager: this.securityManager, securityManager2: this.securityManager2, securityManagerLR: this.securityManagerLR, @@ -4436,7 +4441,6 @@ export class Driver extends TypedEventEmitter this.partialCCSessions.delete(partialSessionKey!); try { command.mergePartialCCs(this, session, { - ownNodeId: this.ownNodeId, sourceNodeId: msg.command.nodeId as number, ...this.getCCParsingContext(), }); diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts index 239b5465b3b0..6f6c084bfa1c 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts @@ -97,7 +97,6 @@ export class ApplicationCommandRequest extends Message nodeId, origin: options.origin, context: { - ownNodeId: this.host.ownNodeId, sourceNodeId: nodeId, ...options.ctx, }, @@ -146,7 +145,7 @@ export class ApplicationCommandRequest extends Message const serializedCC = this.command.serialize(ctx); const nodeId = encodeNodeID( - this.getNodeId() ?? this.host.ownNodeId, + this.getNodeId() ?? ctx.ownNodeId, ctx.nodeIdType, ); this.payload = Buffer.concat([ diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index 19bb33d6ea7b..b5ce537d0457 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -77,7 +77,6 @@ export class BridgeApplicationCommandRequest extends Message nodeId: sourceNodeId, origin: options.origin, context: { - ownNodeId: this.host.ownNodeId, sourceNodeId, ...options.ctx, }, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts index 185aa18abce8..e99c46ac1afe 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts @@ -110,7 +110,6 @@ export class SendDataRequest data: this.payload, origin: options.origin, context: { - ownNodeId: host.ownNodeId, sourceNodeId: nodeId, ...options.ctx, }, @@ -407,7 +406,6 @@ export class SendDataMulticastRequest< data: this.payload, origin: options.origin, context: { - ownNodeId: host.ownNodeId, sourceNodeId: NODE_ID_BROADCAST, // FIXME: Unknown? ...options.ctx, }, diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 6cba9fd74472..b960fb39b495 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -25,7 +25,7 @@ import { isLongRangeNodeId, securityClassIsS2, } from "@zwave-js/core"; -import { CCParsingContext } from "@zwave-js/host"; +import { CCParsingContext, HostIDs } from "@zwave-js/host"; import { type MessageParsingContext, type ZWaveSerialPortImplementation, @@ -237,7 +237,7 @@ export class Zniffer extends TypedEventEmitter { private serial: ZnifferSerialPortBase | undefined; private parsingContext: Omit< CCParsingContext, - "ownNodeId" | "sourceNodeId" + keyof HostIDs | "sourceNodeId" >; private _destroyPromise: DeferredPromise | undefined; @@ -551,6 +551,7 @@ supported frequencies: ${ fromEncapsulation: false, nodeId: mpdu.sourceNodeId, context: { + homeId: mpdu.homeId, ownNodeId: destNodeId, sourceNodeId: mpdu.sourceNodeId, ...this.parsingContext, From 872e3bc8a09bc1f488d4e536af64c026ce01cdb8 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 10:53:58 +0200 Subject: [PATCH 20/60] refactor: reuse applHost instance --- packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 5637f0e15a9b..a591a52fd18c 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -258,7 +258,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { - const instance = new SubConstructor(this.host, { + const instance = new SubConstructor(applHost, { nodeId: node.id, }); await instance.interview(applHost); @@ -276,7 +276,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { - const instance = new SubConstructor(this.host, { + const instance = new SubConstructor(applHost, { nodeId: node.id, }); await instance.refreshValues(applHost); @@ -357,7 +357,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { direction: "outbound", }); const resp = await applHost.sendCommand( - new FibaroVenetianBlindCCGet(this.host, { + new FibaroVenetianBlindCCGet(applHost, { nodeId: this.nodeId, endpoint: this.endpointIndex, }), From 5b234308e3db611ae569105dea2310eff399ee7f Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 11:21:48 +0200 Subject: [PATCH 21/60] refactor: handle callback ID in the driver, allow undefined --- packages/host/src/ZWaveHost.ts | 3 +- packages/host/src/mocks.ts | 1 - packages/serial/src/message/Message.ts | 41 ++++++++----------- packages/testing/src/MockController.ts | 10 ----- .../lib/controller/MockControllerBehaviors.ts | 6 +-- packages/zwave-js/src/lib/driver/Driver.ts | 5 +++ .../serialapi/capability/HardResetRequest.ts | 5 ++- .../network-mgmt/AddNodeToNetworkRequest.ts | 4 +- .../AssignPriorityReturnRouteMessages.ts | 5 ++- .../AssignPrioritySUCReturnRouteMessages.ts | 5 ++- .../network-mgmt/AssignReturnRouteMessages.ts | 3 +- .../AssignSUCReturnRouteMessages.ts | 4 +- .../network-mgmt/DeleteReturnRouteMessages.ts | 3 +- .../DeleteSUCReturnRouteMessages.ts | 4 +- .../network-mgmt/RemoveFailedNodeMessages.ts | 1 + .../RemoveNodeFromNetworkRequest.ts | 1 + .../network-mgmt/ReplaceFailedNodeRequest.ts | 1 + .../RequestNodeNeighborUpdateMessages.ts | 7 +++- .../network-mgmt/SetLearnModeMessages.ts | 5 ++- .../network-mgmt/SetSUCNodeIDMessages.ts | 1 + .../transport/SendDataBridgeMessages.ts | 10 +++-- .../serialapi/transport/SendDataMessages.ts | 12 ++++-- .../transport/SendTestFrameMessages.ts | 5 ++- .../invalidCallbackFunctionTypes.test.ts | 8 ++-- .../lib/test/driver/controllerJammed.test.ts | 6 +-- .../driver/sendDataAbortAfterTimeout.test.ts | 4 +- .../driver/sendDataMissingResponse.test.ts | 6 +-- .../src/lib/zniffer/CCParsingContext.ts | 8 ---- 28 files changed, 88 insertions(+), 86 deletions(-) diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 3cfc3163801e..d52683ac5ad1 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -82,7 +82,7 @@ export interface CCEncodingContext } /** Host application abstractions to be used in Serial API and CC implementations */ -export interface ZWaveHost extends HostIDs, GetNextCallbackId { +export interface ZWaveHost extends HostIDs { /** * Retrieves the maximum version of a command class that can be used to communicate with a node. * Returns 1 if the node claims that it does not support a CC. @@ -141,7 +141,6 @@ export interface ZWaveApplicationHost extends GetValueDB, HostIDs, - GetNextCallbackId, ZWaveHost, GetNode, GetAllNodes, diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index ca4fde2e9296..8b5c5ecf7ef3 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -101,7 +101,6 @@ export function createTestingHost< getSupportedCCVersion: options.getSupportedCCVersion ?? options.getSafeCCVersion ?? (() => 100), - getNextCallbackId: createWrappingCounter(0xff), getValueDB: (nodeId) => { if (!valueDBCache.has(nodeId)) { valueDBCache.set( diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 5e91068d8aaf..2612685c93cb 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -194,7 +194,7 @@ export class Message { this.expectedCallback = options.expectedCallback ?? getExpectedCallback(this); - this._callbackId = options.callbackId; + this.callbackId = options.callbackId; this.payload = options.payload || Buffer.allocUnsafe(0); } @@ -214,28 +214,23 @@ export class Message { | undefined; public payload: Buffer; // TODO: Length limit 255 - private _callbackId: number | undefined; - /** - * Used to map requests to responses. - * - * WARNING: Accessing this property will generate a new callback ID if this message had none. - * If you want to compare the callback ID, use `hasCallbackId()` beforehand to check if the callback ID is already defined. - */ - public get callbackId(): number { - if (this._callbackId == undefined) { - this._callbackId = this.host.getNextCallbackId(); + /** Used to map requests to callbacks */ + public callbackId: number | undefined; + + protected assertCallbackId(): asserts this is this & { + callbackId: number; + } { + if (this.callbackId == undefined) { + throw new ZWaveError( + "Callback ID required but not set", + ZWaveErrorCodes.PacketFormat_Invalid, + ); } - return this._callbackId; - } - public set callbackId(v: number | undefined) { - this._callbackId = v; } - /** - * Tests whether this message's callback ID is defined - */ - public hasCallbackId(): boolean { - return this._callbackId != undefined; + /** Returns whether the callback ID is set */ + public hasCallbackId(): this is this & { callbackId: number } { + return this.callbackId != undefined; } /** @@ -429,11 +424,7 @@ export class Message { // To prevent this from triggering the unresponsive controller detection we need to forward these messages as if they were correct if (msg.functionType !== 0 as any) { // If a received request included a callback id, enforce that the response contains the same - if ( - this.hasCallbackId() - && (!msg.hasCallbackId() - || this._callbackId !== msg._callbackId) - ) { + if (this.callbackId !== msg.callbackId) { return false; } } diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 6b52f2ab1913..500bb7342c22 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -65,16 +65,6 @@ export class MockController { ownNodeId: options.ownNodeId ?? 1, homeId: options.homeId ?? 0x7e571000, // nodes: this.nodes as any, - getNextCallbackId: () => 1, - // 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)) { diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index ce4b8f3a4e97..32a65a043966 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -350,7 +350,7 @@ const handleSendData: MockControllerBehavior = { ); const cb = new SendDataRequestTransmitReport(host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK : TransmitStatus.NoAck, @@ -449,7 +449,7 @@ const handleSendDataMulticast: MockControllerBehavior = { ); const cb = new SendDataMulticastRequestTransmitReport(host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK : TransmitStatus.NoAck, @@ -610,7 +610,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { if (expectCallback) { const cb = new AssignSUCReturnRouteRequestTransmitReport(host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK : TransmitStatus.NoAck, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index feef8c71339a..2d2f2912a586 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -5773,6 +5773,11 @@ ${handlers.length} left`, msg: Message, transactionSource?: string, ): Promise { + // Give the command a callback ID if it needs one + if (msg.needsCallbackId() && !msg.hasCallbackId()) { + msg.callbackId = this.getNextCallbackId(); + } + const machine = createSerialAPICommandMachine( msg, msg.serialize(this.getCCEncodingContext()), diff --git a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts index e31b5bca07d2..7791b71c480c 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts @@ -39,6 +39,7 @@ export class HardResetRequestBase extends Message { @expectedCallback(FunctionType.HardReset) export class HardResetRequest extends HardResetRequestBase { public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); this.payload = Buffer.from([this.callbackId]); return super.serialize(ctx); } @@ -47,7 +48,7 @@ export class HardResetRequest extends HardResetRequestBase { return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -66,7 +67,7 @@ export class HardResetCallback extends HardResetRequestBase { return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts index 9cb15e8e3a4e..1dd0ddf9ca03 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts @@ -153,6 +153,7 @@ export class AddNodeToNetworkRequest extends AddNodeToNetworkRequestBase { public networkWide: boolean = false; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); let data: number = this.addNodeType || AddNodeType.Any; if (this.highPower) data |= AddNodeFlags.HighPower; if (this.networkWide) data |= AddNodeFlags.NetworkWide; @@ -233,6 +234,7 @@ export class AddNodeDSKToNetworkRequest extends AddNodeToNetworkRequestBase { public protocol: Protocols; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); let control: number = AddNodeType.SmartStartDSK; if (this.highPower) control |= AddNodeFlags.HighPower; if (this.networkWide) control |= AddNodeFlags.NetworkWide; @@ -325,7 +327,7 @@ export class AddNodeToNetworkRequestStatusReport ...super.toLogEntry(), message: { status: getEnumMemberName(AddNodeStatus, this.status), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts index 023228bfb33a..4a63dd0c603e 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts @@ -101,6 +101,7 @@ export class AssignPriorityReturnRouteRequest public routeSpeed: ZWaveDataRate; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); const destinationNodeId = encodeNodeID( this.destinationNodeId, @@ -135,7 +136,7 @@ export class AssignPriorityReturnRouteRequest ZWaveDataRate, this.routeSpeed, ), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -194,7 +195,7 @@ export class AssignPriorityReturnRouteRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts index 317ad56061bc..80c73a3b62c5 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts @@ -92,6 +92,7 @@ export class AssignPrioritySUCReturnRouteRequest public routeSpeed: ZWaveDataRate; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([ nodeId, @@ -120,7 +121,7 @@ export class AssignPrioritySUCReturnRouteRequest ZWaveDataRate, this.routeSpeed, ), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -179,7 +180,7 @@ export class AssignPrioritySUCReturnRouteRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts index 0ee6d45b4e66..979d8d2e8c00 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts @@ -79,6 +79,7 @@ export class AssignReturnRouteRequest extends AssignReturnRouteRequestBase public destinationNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); const destinationNodeId = encodeNodeID( this.destinationNodeId, @@ -148,7 +149,7 @@ export class AssignReturnRouteRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts index a23df14c1ffe..5c3415a0f6ab 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts @@ -92,6 +92,7 @@ export class AssignSUCReturnRouteRequest extends AssignSUCReturnRouteRequestBase public readonly disableCallbackFunctionTypeCheck?: boolean; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); @@ -178,6 +179,7 @@ export class AssignSUCReturnRouteRequestTransmitReport public transmitStatus: TransmitStatus; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); this.payload = Buffer.from([this.callbackId, this.transmitStatus]); return super.serialize(ctx); } @@ -186,7 +188,7 @@ export class AssignSUCReturnRouteRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts index eb7c5e4f55b5..d14d827ad6b2 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts @@ -70,6 +70,7 @@ export class DeleteReturnRouteRequest extends DeleteReturnRouteRequestBase public nodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); @@ -130,7 +131,7 @@ export class DeleteReturnRouteRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts index 6914ef7e3220..4faf178924a5 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts @@ -94,6 +94,7 @@ export class DeleteSUCReturnRouteRequest extends DeleteSUCReturnRouteRequestBase public readonly disableCallbackFunctionTypeCheck?: boolean; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); @@ -180,6 +181,7 @@ export class DeleteSUCReturnRouteRequestTransmitReport public readonly transmitStatus: TransmitStatus; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); this.payload = Buffer.from([this.callbackId, this.transmitStatus]); return super.serialize(ctx); } @@ -188,7 +190,7 @@ export class DeleteSUCReturnRouteRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts index 4c22cef3d57b..8bd1d3dc302a 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts @@ -79,6 +79,7 @@ export class RemoveFailedNodeRequest extends RemoveFailedNodeRequestBase { public failedNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.failedNodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts index f5a3f772f48c..e93bc948ee3b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts @@ -115,6 +115,7 @@ export class RemoveNodeFromNetworkRequest public networkWide: boolean = false; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); let data: number = this.removeNodeType || RemoveNodeType.Any; if (this.highPower) data |= RemoveNodeFlags.HighPower; if (this.networkWide) data |= RemoveNodeFlags.NetworkWide; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts index 3fb5c36334d2..84ad94c8138a 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts @@ -78,6 +78,7 @@ export class ReplaceFailedNodeRequest extends ReplaceFailedNodeRequestBase { public failedNodeId: number; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.failedNodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts index c9c3dba83ddb..93c2e14fc8f8 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts @@ -65,6 +65,7 @@ export class RequestNodeNeighborUpdateRequest public discoveryTimeout: number; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType); this.payload = Buffer.concat([nodeId, Buffer.from([this.callbackId])]); return super.serialize(ctx); @@ -77,7 +78,9 @@ export class RequestNodeNeighborUpdateRequest public toLogEntry(): MessageOrCCLogEntry { return { ...super.toLogEntry(), - message: { "callback id": this.callbackId }, + message: { + "callback id": this.callbackId ?? "(not set)", + }, }; } } @@ -113,7 +116,7 @@ export class RequestNodeNeighborUpdateReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "update status": getEnumMemberName( NodeNeighborUpdateStatus, this._updateStatus, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts index bf7636dde05b..b30673379409 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts @@ -84,6 +84,7 @@ export class SetLearnModeRequest extends SetLearnModeRequestBase { public intent: LearnModeIntent; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); this.payload = Buffer.from([ this.intent, this.callbackId, @@ -96,7 +97,7 @@ export class SetLearnModeRequest extends SetLearnModeRequestBase { return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", intent: getEnumMemberName(LearnModeIntent, this.intent), }, }; @@ -155,7 +156,7 @@ export class SetLearnModeCallback extends SetLearnModeRequestBase public toLogEntry(): MessageOrCCLogEntry { const message: MessageRecord = { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", status: getEnumMemberName(LearnModeStatus, this.status), }; if ( diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index 232ff74bf97e..9d87f8c7e265 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -79,6 +79,7 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { public transmitOptions: TransmitOptions; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.sucNodeId, ctx.nodeIdType); this.payload = Buffer.concat([ nodeId, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts index 11d5c137cfa7..eeac3b48923e 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts @@ -127,6 +127,7 @@ export class SendDataBridgeRequest } public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const sourceNodeId = encodeNodeID( this.sourceNodeId, ctx.nodeIdType, @@ -154,7 +155,7 @@ export class SendDataBridgeRequest message: { "source node id": this.sourceNodeId, "transmit options": num2hex(this.transmitOptions), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -221,7 +222,7 @@ export class SendDataBridgeRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName(TransmitStatus, this.transmitStatus) + (this.txReport @@ -367,6 +368,7 @@ export class SendDataMulticastBridgeRequest< } public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const serializedCC = this.serializeCC(ctx); const sourceNodeId = encodeNodeID( this.sourceNodeId, @@ -397,7 +399,7 @@ export class SendDataMulticastBridgeRequest< "source node id": this.sourceNodeId, "target nodes": this.command.nodeId.join(", "), "transmit options": num2hex(this.transmitOptions), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -444,7 +446,7 @@ export class SendDataMulticastBridgeRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts index e99c46ac1afe..33bd3cf5f5e5 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts @@ -175,6 +175,7 @@ export class SendDataRequest } public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.command.nodeId, ctx.nodeIdType); const serializedCC = this.serializeCC(ctx); this.payload = Buffer.concat([ @@ -192,7 +193,7 @@ export class SendDataRequest ...super.toLogEntry(), message: { "transmit options": num2hex(this.transmitOptions), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -252,6 +253,7 @@ export class SendDataRequestTransmitReport extends SendDataRequestBase public txReport: TXReport | undefined; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); this.payload = Buffer.from([ this.callbackId, this.transmitStatus, @@ -274,7 +276,7 @@ export class SendDataRequestTransmitReport extends SendDataRequestBase return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName(TransmitStatus, this.transmitStatus) + (this.txReport @@ -481,6 +483,7 @@ export class SendDataMulticastRequest< } public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const serializedCC = this.serializeCC(ctx); const destinationNodeIDs = this.command.nodeId.map((id) => encodeNodeID(id, ctx.nodeIdType) @@ -504,7 +507,7 @@ export class SendDataMulticastRequest< message: { "target nodes": this.command.nodeId.join(", "), "transmit options": num2hex(this.transmitOptions), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -545,6 +548,7 @@ export class SendDataMulticastRequestTransmitReport } public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); this.payload = Buffer.from([this.callbackId, this._transmitStatus]); return super.serialize(ctx); } @@ -557,7 +561,7 @@ export class SendDataMulticastRequestTransmitReport return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts index 0de40ddb557c..5d9696850430 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts @@ -73,6 +73,7 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { public powerlevel: Powerlevel; public serialize(ctx: MessageEncodingContext): Buffer { + this.assertCallbackId(); const nodeId = encodeNodeID(this.testNodeId, ctx.nodeIdType); this.payload = Buffer.concat([ nodeId, @@ -91,7 +92,7 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { message: { "test node id": this.testNodeId, powerlevel: getEnumMemberName(Powerlevel, this.powerlevel), - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", }, }; } @@ -140,7 +141,7 @@ export class SendTestFrameTransmitReport extends SendTestFrameRequestBase return { ...super.toLogEntry(), message: { - "callback id": this.callbackId, + "callback id": this.callbackId ?? "(not set)", "transmit status": getEnumMemberName( TransmitStatus, this.transmitStatus, diff --git a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts index a2a89584641d..dee44fb2ef58 100644 --- a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts +++ b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts @@ -65,7 +65,7 @@ integrationTest( MockControllerCommunicationState.Sending, ); - const expectCallback = msg.callbackId !== 0; + const expectCallback = !!msg.callbackId; // Send the command to the node const node = controller.nodes.get(msg.getNodeId()!)!; @@ -117,7 +117,7 @@ integrationTest( new DeleteSUCReturnRouteRequestTransmitReport( host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK : TransmitStatus.NoAck, @@ -155,7 +155,7 @@ integrationTest( MockControllerCommunicationState.Sending, ); - const expectCallback = msg.callbackId !== 0; + const expectCallback = !!msg.callbackId; // Send the command to the node const node = controller.nodes.get(msg.getNodeId()!)!; @@ -207,7 +207,7 @@ integrationTest( new DeleteSUCReturnRouteRequestTransmitReport( host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK : TransmitStatus.NoAck, diff --git a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts index 928962da7bbc..6cae0c34b127 100644 --- a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts +++ b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts @@ -82,7 +82,7 @@ integrationTest("update the controller status and wait if TX status is Fail", { ); const cb = new SendDataRequestTransmitReport(host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: TransmitStatus.Fail, txReport: { txTicks: 0, @@ -205,7 +205,7 @@ integrationTest( ); const cb = new SendDataRequestTransmitReport(host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: TransmitStatus.Fail, txReport: { txTicks: 0, @@ -346,7 +346,7 @@ integrationTestMulti( ); const cb = new SendDataRequestTransmitReport(host, { - callbackId: msg.callbackId, + callbackId: msg.callbackId!, transmitStatus: TransmitStatus.Fail, txReport: { txTicks: 0, diff --git a/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts index 77a0802f2ac4..a31756586112 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts @@ -62,7 +62,7 @@ integrationTest( MockControllerCommunicationState.Sending, ); - lastCallbackId = msg.callbackId; + lastCallbackId = msg.callbackId!; // Notify the host that the message was sent const res = new SendDataResponse(host, { @@ -79,7 +79,7 @@ integrationTest( }); setTimeout(() => { - controller.sendToHost(cb.serialize()); + controller.sendMessageToHost(cb); }, 1000); // Put the controller into idle state diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts index 5391538971ea..e0ef16c14cb0 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts @@ -55,7 +55,7 @@ integrationTest( ); } - lastCallbackId = msg.callbackId; + lastCallbackId = msg.callbackId!; return true; } else if (msg instanceof SendDataAbort) { @@ -66,7 +66,7 @@ integrationTest( }); setTimeout(() => { - controller.sendToHost(cb.serialize()); + controller.sendMessageToHost(cb); }, 100); // Put the controller into idle state @@ -149,7 +149,7 @@ integrationTest( ); } - lastCallbackId = msg.callbackId; + lastCallbackId = msg.callbackId!; // Don't send the response or the callback diff --git a/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts b/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts index 0e9cd65853bf..d68d894f5f16 100644 --- a/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts +++ b/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts @@ -66,14 +66,6 @@ export class ZnifferCCParsingContext implements ZWaveHost { // Do nothing } - getNextCallbackId(): number { - throw new Error("Method not implemented."); - } - - getNextSupervisionSessionId(nodeId: number): number { - throw new Error("Method not implemented."); - } - getDeviceConfig(nodeId: number): DeviceConfig | undefined { // Disable strict validation while parsing certain CCs // Most of this stuff isn't actually needed, only the compat flags... From 4c91090aedaa6134bc70865ae2fa0a53f433e391 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 11:41:46 +0200 Subject: [PATCH 22/60] fix: lint --- packages/maintenance/src/codeshifts/renameImport.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/maintenance/src/codeshifts/renameImport.ts b/packages/maintenance/src/codeshifts/renameImport.ts index 3ad54ce682c6..d1214372dab9 100644 --- a/packages/maintenance/src/codeshifts/renameImport.ts +++ b/packages/maintenance/src/codeshifts/renameImport.ts @@ -7,7 +7,13 @@ // examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples -import { API, FileInfo, JSCodeshift, Options, Transform } from "jscodeshift"; +import { + type API, + type FileInfo, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; const transform: Transform = ( file: FileInfo, @@ -25,7 +31,7 @@ const transform: Transform = ( const j: JSCodeshift = api.jscodeshift; const root = j(file.source); - let imp = root + const imp = root .find( j.ImportDeclaration, { importKind: typeOnly ? "type" : undefined }, From 0b398c6c8e2b9c0ea5c4f0bec96821ea1b3cbe3e Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 11:44:35 +0200 Subject: [PATCH 23/60] fix: lint --- packages/cc/src/cc/AlarmSensorCC.ts | 1 - packages/cc/src/cc/AssociationGroupInfoCC.ts | 1 - packages/cc/src/cc/BarrierOperatorCC.ts | 1 - packages/cc/src/cc/BasicCC.ts | 1 - packages/cc/src/cc/BatteryCC.ts | 1 - packages/cc/src/cc/BinarySensorCC.ts | 1 - packages/cc/src/cc/BinarySwitchCC.ts | 1 - packages/cc/src/cc/CentralSceneCC.ts | 1 - packages/cc/src/cc/ClockCC.ts | 1 - packages/cc/src/cc/ColorSwitchCC.ts | 1 - packages/cc/src/cc/DoorLockCC.ts | 1 - packages/cc/src/cc/DoorLockLoggingCC.ts | 1 - packages/cc/src/cc/EnergyProductionCC.ts | 1 - packages/cc/src/cc/EntryControlCC.ts | 1 - packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts | 1 - packages/cc/src/cc/HumidityControlModeCC.ts | 1 - packages/cc/src/cc/HumidityControlOperatingStateCC.ts | 2 -- packages/cc/src/cc/HumidityControlSetpointCC.ts | 1 - packages/cc/src/cc/IndicatorCC.ts | 1 - packages/cc/src/cc/IrrigationCC.ts | 1 - packages/cc/src/cc/LanguageCC.ts | 1 - packages/cc/src/cc/LockCC.ts | 1 - packages/cc/src/cc/ManufacturerSpecificCC.ts | 1 - packages/cc/src/cc/MeterCC.ts | 1 - packages/cc/src/cc/MultilevelSensorCC.ts | 1 - packages/cc/src/cc/MultilevelSwitchCC.ts | 1 - packages/cc/src/cc/NodeNamingCC.ts | 1 - packages/cc/src/cc/NotificationCC.ts | 1 - packages/cc/src/cc/ProtectionCC.ts | 1 - packages/cc/src/cc/SceneActuatorConfigurationCC.ts | 1 - packages/cc/src/cc/SceneControllerConfigurationCC.ts | 1 - packages/cc/src/cc/ScheduleEntryLockCC.ts | 1 - packages/cc/src/cc/SoundSwitchCC.ts | 1 - packages/cc/src/cc/SupervisionCC.ts | 1 - packages/cc/src/cc/ThermostatFanModeCC.ts | 1 - packages/cc/src/cc/ThermostatFanStateCC.ts | 2 -- packages/cc/src/cc/ThermostatModeCC.ts | 1 - packages/cc/src/cc/ThermostatOperatingStateCC.ts | 2 -- packages/cc/src/cc/ThermostatSetbackCC.ts | 4 ---- packages/cc/src/cc/ThermostatSetpointCC.ts | 1 - packages/cc/src/cc/TimeCC.ts | 1 - packages/cc/src/cc/TimeParametersCC.ts | 1 - packages/cc/src/cc/UserCodeCC.ts | 1 - packages/cc/src/cc/VersionCC.ts | 1 - packages/cc/src/cc/WakeUpCC.ts | 1 - packages/cc/src/cc/WindowCoveringCC.ts | 1 - packages/cc/src/cc/ZWavePlusCC.ts | 1 - packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts | 1 - packages/host/src/mocks.ts | 2 +- packages/serial/src/message/Message.ts | 2 +- packages/testing/src/MockController.ts | 2 +- packages/zwave-js/src/lib/driver/MessageGenerators.ts | 2 +- .../lib/serialapi/application/ApplicationCommandRequest.ts | 2 +- .../src/lib/serialapi/application/ApplicationUpdateRequest.ts | 2 +- .../serialapi/application/BridgeApplicationCommandRequest.ts | 2 +- .../src/lib/serialapi/application/SerialAPIStartedRequest.ts | 2 +- .../src/lib/serialapi/application/ShutdownMessages.ts | 2 +- .../serialapi/capability/GetControllerCapabilitiesMessages.ts | 2 +- .../lib/serialapi/capability/GetControllerVersionMessages.ts | 2 +- .../src/lib/serialapi/capability/GetLongRangeNodesMessages.ts | 2 +- .../lib/serialapi/capability/GetProtocolVersionMessages.ts | 2 +- .../serialapi/capability/GetSerialApiCapabilitiesMessages.ts | 2 +- .../lib/serialapi/capability/GetSerialApiInitDataMessages.ts | 2 +- .../zwave-js/src/lib/serialapi/capability/HardResetRequest.ts | 2 +- .../src/lib/serialapi/capability/LongRangeChannelMessages.ts | 2 +- .../src/lib/serialapi/capability/SerialAPISetupMessages.ts | 2 +- .../capability/SetApplicationNodeInformationRequest.ts | 2 +- .../serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts | 2 +- .../src/lib/serialapi/memory/GetControllerIdMessages.ts | 2 +- .../src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts | 2 +- .../src/lib/serialapi/misc/SetRFReceiveModeMessages.ts | 2 +- .../src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts | 2 +- .../network-mgmt/AssignPriorityReturnRouteMessages.ts | 2 +- .../network-mgmt/AssignPrioritySUCReturnRouteMessages.ts | 2 +- .../lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts | 2 +- .../serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts | 2 +- .../lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts | 2 +- .../serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts | 2 +- .../lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts | 2 +- .../lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts | 2 +- .../src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts | 2 +- .../src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts | 2 +- .../src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts | 2 +- .../lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts | 2 +- .../serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts | 2 +- .../lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts | 2 +- .../src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts | 2 +- .../network-mgmt/RequestNodeNeighborUpdateMessages.ts | 2 +- .../src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts | 2 +- .../lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts | 2 +- .../src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts | 2 +- .../src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts | 2 +- .../src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts | 2 +- .../src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts | 2 +- .../src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts | 2 +- .../src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts | 2 +- .../src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts | 2 +- packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts | 2 +- .../zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts | 2 +- .../src/lib/serialapi/transport/SendTestFrameMessages.ts | 2 +- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 3 +-- 101 files changed, 53 insertions(+), 108 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 6b1dd04460fe..0b5af1dfe06c 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -13,7 +13,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index f95228ecda74..ba2189336a84 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -13,7 +13,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index d059ef5dfb78..0277aa7b0598 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -16,7 +16,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index eb9ee869cf87..7a22c787d94d 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -15,7 +15,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 32cdb2a63554..47659f5864c0 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -15,7 +15,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index d3cb12a2a620..80880d78eeac 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -12,7 +12,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 361f10cdd272..8c9d6417518d 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -16,7 +16,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index e487b3d45b5e..5bf263d50f5d 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -16,7 +16,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 0e950770ea40..7357ce02538f 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -12,7 +12,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 42ae69f3b70a..a2da869525b0 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -18,7 +18,6 @@ import { import { type MaybeNotKnown, encodeBitMask } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 4d068e8cd3cb..2a9df7b994f5 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -17,7 +17,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index afbff7ba8477..9272a10eca27 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -10,7 +10,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index c2589975505a..6a1195c1fb57 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -10,7 +10,6 @@ import { import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index 61476642e4f0..cf90c6e35908 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -15,7 +15,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index b4ada9b05177..c3fd2df7fc3c 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -11,7 +11,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index 4933f8d1645f..754ef6ee0fb2 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -14,7 +14,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index b003a8b47baf..9d6b9d8a26c8 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -8,8 +8,6 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { - CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 8b6177bafc78..2fa2eb871178 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -19,7 +19,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 899ab78cd35a..cd8536f2e3e0 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -18,7 +18,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 06ae78420436..ec06da849953 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -17,7 +17,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 9e2d61d0d8e2..47d84199c323 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -14,7 +14,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 396d7e4ffd37..2850e303c2ed 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -12,7 +12,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index e6dc00837481..2aafb863272d 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -10,7 +10,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index b3581a0ca070..063babca4488 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -27,7 +27,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 9b99abe5194e..264811baad24 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -27,7 +27,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index de156299263d..a1d7344a3648 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -15,7 +15,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 3e8a82e719b0..1f866d3fcdd0 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -11,7 +11,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index 8ed35e4c5cf6..cef6211e8f46 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -33,7 +33,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 57af99a13e3e..a9f7b510fbc0 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -16,7 +16,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 737a74454df9..995eef75d8b3 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -13,7 +13,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index c2bb55350432..f929a99bbe7c 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -14,7 +14,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index e12e109f63af..aa97ef95d9ea 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -15,7 +15,6 @@ import { import { type EndpointId, type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index 8eff9eef2066..316f2fae7b23 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -13,7 +13,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 7f9298bfd33a..04eea4b65b64 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -21,7 +21,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index f62676424b18..2840aed7fce6 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -15,7 +15,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index ae9e018c2ea4..afb1ecd94ca3 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -9,8 +9,6 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { - CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index c187bd27e8c2..129d24ff0d24 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -16,7 +16,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index a5aa480648f1..3f27ca9a072b 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -8,8 +8,6 @@ import { validatePayload, } from "@zwave-js/core/safe"; import type { - CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 195fcefb4ccc..83aacaa08136 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -4,14 +4,10 @@ import { type MessageOrCCLogEntry, MessagePriority, type SupervisionResult, - ValueMetadata, - ZWaveError, - ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index e849557952f3..732ccd95dbd3 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -20,7 +20,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 2a00c7242a9a..61e7e6b375eb 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -13,7 +13,6 @@ import { import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index ad7d8dbaef22..7b68467375c8 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -15,7 +15,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 31411b18a75e..7a1302acbd7f 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -17,7 +17,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 5db3e9c3c915..eed3499d5bbc 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -17,7 +17,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 44b43af3282c..1b58e947b19e 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -11,7 +11,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 8b89779f716a..57737fb7e5fb 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -13,7 +13,6 @@ import { import { type MaybeNotKnown } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index d2539d9c6fcd..941c746d8460 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -7,7 +7,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index a591a52fd18c..e8cbf2cf788e 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -12,7 +12,6 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, - CCParsingContext, GetValueDB, ZWaveApplicationHost, ZWaveHost, diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 8b5c5ecf7ef3..9ded504db6dd 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -12,7 +12,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import { createThrowingMap, createWrappingCounter } from "@zwave-js/shared"; +import { createThrowingMap } from "@zwave-js/shared"; import type { ZWaveApplicationHost, ZWaveHost } from "./ZWaveHost"; export interface CreateTestingHostOptions { diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 2612685c93cb..79025b579c8b 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -2,7 +2,7 @@ import { type MaybeNotKnown, type MessageOrCCLogEntry, type MessagePriority, - NodeIDType, + type NodeIDType, type NodeId, type SecurityClass, type SecurityManagers, diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 500bb7342c22..d45c339df373 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -7,7 +7,7 @@ import { type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { Message, type MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index cd167fd97f0e..5d19c49fbf1a 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -42,7 +42,7 @@ import { ZWaveErrorCodes, mergeSupervisionResults, } from "@zwave-js/core"; -import { CCEncodingContext } from "@zwave-js/host"; +import { type CCEncodingContext } from "@zwave-js/host"; import type { Message } from "@zwave-js/serial"; import { getErrorMessage } from "@zwave-js/shared"; import { wait } from "alcalzone-shared/async"; diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts index 6f6c084bfa1c..a958a04ac16f 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts @@ -10,7 +10,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts index 388b0998b66c..7facc83d7aea 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts @@ -11,7 +11,7 @@ import { parseNodeID, parseNodeUpdatePayload, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { type DeserializingMessageConstructor, FunctionType, diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index b5ce537d0457..7bec31bb0a26 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -13,7 +13,7 @@ import { parseNodeBitMask, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts index 36d527de35b7..028f0782a53a 100644 --- a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts @@ -5,7 +5,7 @@ import { encodeCCList, parseCCList, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts b/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts index 451ced5ea763..ee6fd3212a26 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts @@ -1,5 +1,5 @@ import { type MessageOrCCLogEntry, MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts index 4444d06cc54e..15b08a5a3be3 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts @@ -1,5 +1,5 @@ import { ControllerCapabilityFlags, MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts index d8602a61d982..d642a83493e2 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts index b5a972f64db5..f92b098ffc3e 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts @@ -5,7 +5,7 @@ import { encodeLongRangeNodeBitMask, parseLongRangeNodeBitMask, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts index 4cdc82d706dd..8bd2d83b8630 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts @@ -1,6 +1,6 @@ import type { ProtocolType } from "@zwave-js/core"; import { MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts index a64d8c8a537e..032a2b2ec4dc 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeBitMask, parseBitMask } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts index 9cf1d438eff9..9059e4cdaca2 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts @@ -12,7 +12,7 @@ import { getChipTypeAndVersion, getZWaveChipType, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts index 7791b71c480c..ab84895c044f 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts @@ -1,6 +1,6 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts index 66f1c2b887bb..d21ba28d63cb 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts @@ -5,7 +5,7 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { LongRangeChannel } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts index e6dccde3f51f..45cc16b23240 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts @@ -10,7 +10,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts index 1090bc287438..5ea1fed5107b 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts @@ -5,7 +5,7 @@ import { encodeCCList, getCCName, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts index cfd4867d3506..c20cdc92cfb0 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeBitMask, parseBitMask } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts index ac508cf2c38c..608cc7577b5f 100644 --- a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts @@ -1,6 +1,6 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID, parseNodeID } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts index 85ab055e0394..3a112049ea14 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts @@ -5,7 +5,7 @@ import { type RSSI, rssiToString, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts index a0d38503627b..fa739bca700e 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts index 51fe4c7b6779..d404f2c4df34 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts index 4a63dd0c603e..f7c84a4c0fbc 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts @@ -9,7 +9,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts index 80c73a3b62c5..07e27523a566 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts @@ -9,7 +9,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts index 979d8d2e8c00..f3e010e22141 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts index 5c3415a0f6ab..fea2b809285d 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts @@ -4,7 +4,7 @@ import { TransmitStatus, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, type INodeQuery, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts index d14d827ad6b2..60ce6618ab9b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts index 4faf178924a5..fb0a761e61da 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts @@ -4,7 +4,7 @@ import { TransmitStatus, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts index c023656bf70f..4a475bee26d4 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts @@ -12,7 +12,7 @@ import { parseNodeID, parseNodeProtocolInfo, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts index 1c53c22e77e7..56213ede4090 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts @@ -10,7 +10,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts index 6f0562d2b69b..c53adb6ce37e 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts @@ -5,7 +5,7 @@ import { encodeNodeID, parseNodeBitMask, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts index def39a624d9c..e76621862fe5 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID, parseNodeID } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts index b9a8b35cd6bf..27d2333e32d9 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts index 8bd1d3dc302a..0919273eed6d 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts index e93bc948ee3b..5f79092ea3ac 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts @@ -3,7 +3,7 @@ import { MessagePriority, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts index 84ad94c8138a..de05d1f742e1 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts @@ -1,5 +1,5 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts index 224a69ef46c0..ced2a7d7c954 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts @@ -4,7 +4,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, type INodeQuery, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts index 93c2e14fc8f8..5c861605a824 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts @@ -1,6 +1,6 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, MultiStageCallback, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts index b30673379409..29bfc735bc75 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts @@ -5,7 +5,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts index ef3a47b1b142..f168d53ecb4b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts @@ -10,7 +10,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index 9d87f8c7e265..b740f9cd37ac 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts index ede3d70151a7..c4c84b3d0721 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts index 454d7536e8ec..cd748277f557 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts index e54df3d590bb..280acbee33d6 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts index b0d7ceea7ad7..a8919c8aaa48 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts @@ -4,7 +4,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts index 5f1cdfe1dcc2..9f51e2e18408 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts index 65473867a8c3..53b257187d2d 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts @@ -7,7 +7,7 @@ import { createSimpleReflectionDecorator, validatePayload, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageBaseOptions, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts index 764e032b7ffd..8dfa52d06847 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts @@ -1,5 +1,5 @@ import { type MessageOrCCLogEntry, MessagePriority } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts index 475752b4c1f4..08d3f3a95f11 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts @@ -6,7 +6,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts index 5d9696850430..484a2d106c50 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts @@ -6,7 +6,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 57f2d57c56d1..5972a5f080ec 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -25,9 +25,8 @@ import { isLongRangeNodeId, securityClassIsS2, } from "@zwave-js/core"; -import { CCParsingContext, HostIDs } from "@zwave-js/host"; +import { type CCParsingContext, type HostIDs } from "@zwave-js/host"; import { - type MessageParsingContext, type ZWaveSerialPortImplementation, type ZnifferDataMessage, ZnifferFrameType, From 7a2aec781309f99de0f621c722f926692c08c14c Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 11:44:46 +0200 Subject: [PATCH 24/60] fix: infinite recursion --- packages/zwave-js/src/lib/driver/Driver.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 2d2f2912a586..4c95f2825f62 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -657,9 +657,6 @@ export class Driver extends TypedEventEmitter }); this.messageParsingContext = { - get nodeIdType() { - return this.nodeIdType; - }, getHighestSecurityClass: (nodeId) => this.getHighestSecurityClass(nodeId), hasSecurityClass: (nodeId, securityClass) => @@ -668,9 +665,6 @@ export class Driver extends TypedEventEmitter this.setSecurityClass(nodeId, securityClass, granted), }; this.messageEncodingContext = { - get nodeIdType() { - return this.nodeIdType; - }, getHighestSecurityClass: (nodeId) => this.getHighestSecurityClass(nodeId), hasSecurityClass: (nodeId, securityClass) => @@ -713,8 +707,14 @@ export class Driver extends TypedEventEmitter /** The serial port instance */ private serial: ZWaveSerialPortBase | undefined; - private messageParsingContext: Omit; - private messageEncodingContext: Omit; + private messageParsingContext: Omit< + MessageParsingContext, + keyof HostIDs | "nodeIdType" + >; + private messageEncodingContext: Omit< + MessageEncodingContext, + keyof HostIDs | "nodeIdType" + >; private getCCEncodingContext() { // FIXME: The type system isn't helping here. We need the security managers to encode CCs @@ -723,6 +723,7 @@ export class Driver extends TypedEventEmitter ...this.messageEncodingContext, ownNodeId: this.controller.ownNodeId!, homeId: this.controller.homeId!, + nodeIdType: this.nodeIdType, securityManager: this.securityManager, securityManager2: this.securityManager2, securityManagerLR: this.securityManagerLR, @@ -736,6 +737,7 @@ export class Driver extends TypedEventEmitter ...this.messageParsingContext, ownNodeId: this.controller.ownNodeId!, homeId: this.controller.homeId!, + nodeIdType: this.nodeIdType, securityManager: this.securityManager, securityManager2: this.securityManager2, securityManagerLR: this.securityManagerLR, From 88828254ae4f90d1b82fa663fc0dc9c676452836 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 12:28:28 +0200 Subject: [PATCH 25/60] fix: assertSecurity logic --- packages/cc/src/cc/Security2CC.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 9ac457e24f39..570fdefc6d2f 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -619,7 +619,7 @@ export class Security2CC extends CommandClass { const ownNodeId = gotDeserializationOptions(options) ? options.context.ownNodeId : this.host.ownNodeId; - if (ownNodeId) { + if (!ownNodeId) { throw new ZWaveError( `Secure commands (S2) can only be ${verb} when the controller's node id is known!`, ZWaveErrorCodes.Driver_NotReady, From fe84f841b2087b681b78e53248ef959046c61e0a Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 12:46:15 +0200 Subject: [PATCH 26/60] fix: node ID in mock-based S2 tests --- packages/testing/src/MockController.ts | 15 ++++++++++++--- .../src/lib/controller/MockControllerBehaviors.ts | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index d45c339df373..2e29e222fa8f 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -383,10 +383,19 @@ export class MockController { /** Sends a raw buffer to the host/driver and expect an ACK */ public async sendMessageToHost( msg: Message, - delayMs?: number, + fromNode?: MockNode, ): Promise { - const data = msg.serialize(this.encodingContext); - if (delayMs) await wait(delayMs); + let data: Buffer; + if (fromNode) { + data = msg.serialize({ + nodeIdType: this.encodingContext.nodeIdType, + ...fromNode.encodingContext, + }); + // Simulate the frame being transmitted via radio + await wait(fromNode.capabilities.txDelay); + } else { + data = msg.serialize(this.encodingContext); + } this.serial.emitData(data); // TODO: make the timeout match the configured ACK timeout await this.expectHostACK(1000); diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index 32a65a043966..d95ea008f385 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -637,7 +637,7 @@ const forwardCommandClassesToHost: MockControllerBehavior = { // Nodes send commands TO the controller, so we need to fix the node ID before forwarding msg.getNodeId = () => node.id; // Simulate a serialized frame being transmitted via radio before receiving it - await controller.sendMessageToHost(msg, node.capabilities.txDelay); + await controller.sendMessageToHost(msg, node); return true; } }, @@ -661,7 +661,7 @@ const forwardUnsolicitedNIF: MockControllerBehavior = { // Simulate a serialized frame being transmitted via radio before receiving it await controller.sendMessageToHost( updateRequest, - node.capabilities.txDelay, + node, ); return true; } From b968b7bc24c1ff6084d25f134b335661c0258cd8 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 12:55:03 +0200 Subject: [PATCH 27/60] fix: more tests --- .../src/lib/test/driver/sendDataMissingCallbackAbort.test.ts | 2 +- .../src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts index 400cae68b707..6dd90d3264c7 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts @@ -811,7 +811,7 @@ integrationTest( supportsLongRange: true, }); setImmediate(async () => { - await mockController.sendToHost(ret.serialize()); + await mockController.sendMessageToHost(ret); }); // And the ping should eventually succeed diff --git a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts index 0dc97d35cc31..ee69c1b4f7bc 100644 --- a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts +++ b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts @@ -79,7 +79,7 @@ integrationTest( }, }, ); - await mockController.sendToHost(nif.serialize()); + await mockController.sendMessageToHost(nif); await wait(100); From 551b08c59691c1b725f857fbe0a8e69c01cf67a7 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 13:01:42 +0200 Subject: [PATCH 28/60] fix: remove outdated configManager parameter --- packages/cc/src/cc/IndicatorCC.ts | 4 ---- packages/zwave-js/src/lib/test/node/Node.constructor.test.ts | 3 ++- packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index cd8536f2e3e0..20dbb235f188 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -1,4 +1,3 @@ -import type { ConfigManager } from "@zwave-js/config"; import { CommandClasses, type EndpointId, @@ -204,7 +203,6 @@ export const IndicatorCCValues = Object.freeze({ * Looks up the configured metadata for the given indicator and property */ function getIndicatorMetadata( - configManager: ConfigManager, indicatorId: Indicator, propertyId: number, overrideIndicatorLabel?: string, @@ -308,7 +306,6 @@ export class IndicatorCCAPI extends CCAPI { const indicatorId = property; const propertyId = propertyKey; const expectedType = getIndicatorMetadata( - this.applHost.configManager, indicatorId, propertyId, ).type as "number" | "boolean"; @@ -1139,7 +1136,6 @@ export class IndicatorCCReport extends IndicatorCC { : undefined; const metadata = getIndicatorMetadata( - applHost.configManager, value.indicatorId, value.propertyId, overrideIndicatorLabel, diff --git a/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts b/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts index 747d9db73a10..033b5d96228d 100644 --- a/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts @@ -66,9 +66,10 @@ test.serial("stores the given device class", (t) => { const nodeUndef = makeNode(undefined as any); t.is(nodeUndef.deviceClass, undefined); - const devCls = new DeviceClass(driver.configManager, 0x02, 0x01, 0x03); + const devCls = new DeviceClass(0x02, 0x01, 0x03); const nodeWithClass = makeNode(devCls); t.is(nodeWithClass.deviceClass, devCls); + t.is(nodeWithClass.deviceClass?.specific.key, 0x03); nodeUndef.destroy(); nodeWithClass.destroy(); diff --git a/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts b/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts index 2e39e2539d3e..c06730dc4ea4 100644 --- a/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts @@ -47,7 +47,7 @@ test.beforeEach((t) => { const node = new ZWaveNode( 2, driver, - new DeviceClass(driver.configManager, 0x04, 0x01, 0x01), // Portable Remote Controller + new DeviceClass(0x04, 0x01, 0x01), // Portable Remote Controller ); (driver.controller.nodes as ThrowingMap).set( node.id, From 65bc8861dd87b38d325e94adceb22bb1ceb408f7 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 13:16:11 +0200 Subject: [PATCH 29/60] refactor: change IZWaveEndpoint.getNodeUnsafe to GetEndpointNode --- packages/cc/src/lib/API.ts | 10 +++++----- .../core/src/abstractions/IZWaveEndpoint.ts | 20 ++++++++++++++----- packages/zwave-js/src/lib/driver/Driver.ts | 2 +- packages/zwave-js/src/lib/node/Endpoint.ts | 14 +++++++------ .../zwave-js/src/lib/node/VirtualEndpoint.ts | 11 ---------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index 0c30f8daa87d..1ccdd26f630b 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -5,8 +5,6 @@ import { type Duration, type EndpointId, type GetEndpoint, - type IVirtualEndpoint, - type IZWaveEndpoint, type ListenBehavior, type MaybeNotKnown, NODE_ID_BROADCAST, @@ -552,7 +550,9 @@ export class CCAPI { }) as any; } - protected isSinglecast(): this is this & { endpoint: IZWaveEndpoint } { + protected isSinglecast(): this is this & { + endpoint: PhysicalCCAPIEndpoint; + } { return ( !this.endpoint.virtual && typeof this.endpoint.nodeId === "number" @@ -562,7 +562,7 @@ export class CCAPI { } protected isMulticast(): this is this & { - endpoint: IVirtualEndpoint & { + endpoint: VirtualCCAPIEndpoint & { nodeId: number[]; }; } { @@ -570,7 +570,7 @@ export class CCAPI { } protected isBroadcast(): this is this & { - endpoint: IVirtualEndpoint & { + endpoint: VirtualCCAPIEndpoint & { nodeId: typeof NODE_ID_BROADCAST | typeof NODE_ID_BROADCAST_LR; }; } { diff --git a/packages/core/src/abstractions/IZWaveEndpoint.ts b/packages/core/src/abstractions/IZWaveEndpoint.ts index 8b3db82cbed2..d54716695d4f 100644 --- a/packages/core/src/abstractions/IZWaveEndpoint.ts +++ b/packages/core/src/abstractions/IZWaveEndpoint.ts @@ -3,7 +3,7 @@ import type { CommandClasses, } from "../capabilities/CommandClasses"; import type { MulticastDestination } from "../consts"; -import type { IVirtualNode, IZWaveNode } from "./IZWaveNode"; +import type { IVirtualNode, NodeId } from "./IZWaveNode"; /** Identifies an endpoint */ export interface EndpointId { @@ -39,12 +39,22 @@ export interface ModifyCCs { removeCC(cc: CommandClasses): void; } +/** Allows accessing the parent node of the endpoint, if it exists */ +export interface GetEndpointNode { + tryGetNode(): T | undefined; +} + /** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ export interface IZWaveEndpoint - extends EndpointId, SupportsCC, ControlsCC, IsCCSecure, ModifyCCs, GetCCs -{ - getNodeUnsafe(): IZWaveNode | undefined; -} + extends + EndpointId, + SupportsCC, + ControlsCC, + IsCCSecure, + ModifyCCs, + GetCCs, + GetEndpointNode +{} /** Identifies a virtual endpoint */ export interface VirtualEndpointId { diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 4c95f2825f62..2fec34c5ff2f 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -5350,7 +5350,7 @@ ${handlers.length} left`, // Do not persist values for a node or endpoint that does not exist const endpoint = this.tryGetEndpoint(cc); - const node = endpoint?.getNodeUnsafe(); + const node = endpoint?.tryGetNode(); if (!node) return false; // Do not persist values for a CC that was force-removed via config diff --git a/packages/zwave-js/src/lib/node/Endpoint.ts b/packages/zwave-js/src/lib/node/Endpoint.ts index 17d58d8d27a1..2e84cff4d0d4 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.ts @@ -14,6 +14,7 @@ import type { ControlsCC, EndpointId, GetCCs, + GetEndpointNode, IZWaveEndpoint, IsCCSecure, MaybeNotKnown, @@ -53,6 +54,7 @@ export class Endpoint IsCCSecure, ModifyCCs, GetCCs, + GetEndpointNode, IZWaveEndpoint { public constructor( @@ -120,7 +122,7 @@ export class Endpoint /** Can be used to distinguish multiple endpoints of a node */ public get endpointLabel(): string | undefined { - return this.getNodeUnsafe()?.deviceConfig?.endpoints?.get(this.index) + return this.tryGetNode()?.deviceConfig?.endpoints?.get(this.index) ?.label; } @@ -214,7 +216,7 @@ export class Endpoint public wasCCRemovedViaConfig(cc: CommandClasses): boolean { if (this.supportsCC(cc)) return false; - const compatConfig = this.getNodeUnsafe()?.deviceConfig?.compat; + const compatConfig = this.tryGetNode()?.deviceConfig?.compat; if (!compatConfig) return false; const removedEndpoints = compatConfig.removeCCs?.get(cc); @@ -248,7 +250,7 @@ export class Endpoint // an unnecessary Version CC interview for each endpoint or an incorrect V1 for endpoints if (ret === 0 && this.index > 0) { - return this.getNodeUnsafe()!.getCCVersion(cc); + return this.tryGetNode()!.getCCVersion(cc); } return ret; } @@ -452,20 +454,20 @@ export class Endpoint /** * Returns the node this endpoint belongs to (or undefined if the node doesn't exist) */ - public getNodeUnsafe(): ZWaveNode | undefined { + public tryGetNode(): ZWaveNode | undefined { return this.driver.controller.nodes.get(this.nodeId); } /** Z-Wave+ Icon (for management) */ public get installerIcon(): MaybeNotKnown { - return this.getNodeUnsafe()?.getValue( + return this.tryGetNode()?.getValue( ZWavePlusCCValues.installerIcon.endpoint(this.index), ); } /** Z-Wave+ Icon (for end users) */ public get userIcon(): MaybeNotKnown { - return this.getNodeUnsafe()?.getValue( + return this.tryGetNode()?.getValue( ZWavePlusCCValues.userIcon.endpoint(this.index), ); } diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts index ebab4497a7d2..bbb9aacc70ad 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts @@ -259,15 +259,4 @@ export class VirtualEndpoint } return apiMethod.apply(CCAPI, args); } - - /** - * @internal - * DO NOT CALL THIS! - */ - public getNodeUnsafe(): never { - throw new ZWaveError( - `The node of a virtual endpoint cannot be accessed this way!`, - ZWaveErrorCodes.CC_NoNodeID, - ); - } } From c774a1402d31a1b3972072ad1b5cc377193a63b6 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 13:17:07 +0200 Subject: [PATCH 30/60] fix: failing test --- packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts b/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts index 559e5a98a88c..3e68b58bb74f 100644 --- a/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts +++ b/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts @@ -43,7 +43,7 @@ test.serial( wakeUpInterval: 5, }), }); - controller.serial.emitData(req.serialize()); + controller.serial.emitData(req.serialize(driver)); await controller.expectHostACK(1000); t.pass(); }, From b3981fa467642123ef44ded660a808988a3c0f1f Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 13:54:46 +0200 Subject: [PATCH 31/60] refactor: pass ownNodeId where required --- packages/cc/src/cc/Security2CC.ts | 28 ++++++++--- packages/cc/src/cc/SecurityCC.ts | 16 +++++- packages/host/src/ZWaveHost.ts | 2 +- packages/host/src/mocks.ts | 6 +-- packages/testing/src/MockController.ts | 26 +++------- packages/testing/src/MockNode.ts | 3 +- .../zwave-js/src/lib/controller/Controller.ts | 1 + .../lib/controller/MockControllerBehaviors.ts | 18 +++---- packages/zwave-js/src/lib/driver/Driver.ts | 15 +++++- .../src/lib/driver/MessageGenerators.ts | 7 ++- .../src/lib/node/MockNodeBehaviors.ts | 14 ++++-- .../src/lib/node/mockCCBehaviors/Basic.ts | 2 +- .../lib/node/mockCCBehaviors/BinarySensor.ts | 4 +- .../lib/node/mockCCBehaviors/BinarySwitch.ts | 2 +- .../lib/node/mockCCBehaviors/ColorSwitch.ts | 4 +- .../lib/node/mockCCBehaviors/Configuration.ts | 10 ++-- .../node/mockCCBehaviors/EnergyProduction.ts | 2 +- .../src/lib/node/mockCCBehaviors/Meter.ts | 4 +- .../lib/node/mockCCBehaviors/MultiChannel.ts | 6 +-- .../node/mockCCBehaviors/MultilevelSensor.ts | 6 +-- .../node/mockCCBehaviors/MultilevelSwitch.ts | 4 +- .../lib/node/mockCCBehaviors/Notification.ts | 4 +- .../node/mockCCBehaviors/ScheduleEntryLock.ts | 10 ++-- .../lib/node/mockCCBehaviors/SoundSwitch.ts | 10 ++-- .../node/mockCCBehaviors/ThermostatMode.ts | 4 +- .../node/mockCCBehaviors/ThermostatSetback.ts | 2 +- .../mockCCBehaviors/ThermostatSetpoint.ts | 10 ++-- .../src/lib/node/mockCCBehaviors/UserCode.ts | 14 +++--- .../node/mockCCBehaviors/WindowCovering.ts | 2 +- .../BridgeApplicationCommandRequest.ts | 6 ++- .../network-mgmt/SetSUCNodeIDMessages.ts | 10 ++-- .../transport/SendDataBridgeMessages.ts | 8 +-- .../discardUnsupportedReports.test.ts | 12 ++--- .../mapNotificationDoorLock.test.ts | 4 +- .../cc-specific/notificationEnums.test.ts | 42 ++++++++-------- .../notificationIdleManually.test.ts | 8 +-- .../notificationIdleRelated.test.ts | 4 +- .../cc-specific/undefinedTargetValue.test.ts | 2 +- .../cc-specific/unknownNotifications.test.ts | 2 +- .../zwave-js/src/lib/test/cc/WakeUpCC.test.ts | 1 + ...rySensorReportAnyUseFirstSupported.test.ts | 2 +- .../invalidCallbackFunctionTypes.test.ts | 4 +- .../test/compliance/decodeLowerS2Keys.test.ts | 17 ++++--- .../discardInsecureCommands.test.ts | 15 +++--- .../encapsulationAnswerAsAsked.test.ts | 8 +-- .../handleMultiCommandPayload.test.ts | 4 +- .../secureNodeSecureEndpoint.test.ts | 22 ++++++--- .../test/driver/assemblePartialCCs.test.ts | 3 ++ .../driver/computeNetCCPayloadSize.test.ts | 2 + .../createCCValuesUsingKnownVersion.test.ts | 2 +- .../driver/handleNonImplementedCCs.test.ts | 2 +- ...noreCCVersion0ForKnownSupportedCCs.test.ts | 32 +++++++----- .../multiStageResponseNoTimeout.test.ts | 12 ++--- .../driver/nodeAsleepBlockNonceReport.test.ts | 10 ++-- .../driver/nodeAsleepMessageOrder.test.ts | 4 +- .../test/driver/notificationPushNoAGI.test.ts | 2 +- .../driver/reInterviewAssumeAwake.test.ts | 4 +- .../test/driver/s0AndS2Encapsulation.test.ts | 19 ++++--- .../lib/test/driver/s0Encapsulation.test.ts | 16 +++--- .../driver/s0EncapsulationTwoNodes.test.ts | 18 ++++--- .../src/lib/test/driver/s2Collisions.test.ts | 49 ++++++++++++------- .../setValueFailedSupervisionGet.test.ts | 4 +- .../test/driver/setValueNoSupervision.test.ts | 2 +- .../setValueSucceedAfterFailure.test.ts | 4 +- ...setValueSuccessfulSupervisionNoGet.test.ts | 2 +- .../driver/setValueSupervision255Get.test.ts | 8 +-- ...ValueSupervisionSuccessMoreUpdates.test.ts | 2 +- .../driver/setValueSupervisionWorking.test.ts | 4 +- .../driver/targetValueVersionUnknown.test.ts | 4 +- .../src/lib/test/driver/unknownValues.test.ts | 12 ++--- .../lib/test/driver/unresponsiveStick.test.ts | 2 +- .../legacyRefreshActuatorSensorCCs.test.ts | 2 +- 72 files changed, 357 insertions(+), 271 deletions(-) diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 570fdefc6d2f..1a7f1426d655 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -212,6 +212,7 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCNonceReport(this.applHost, { nodeId: this.endpoint.nodeId, + ownNodeId: this.applHost.ownNodeId, endpoint: this.endpoint.index, securityManagers: this.applHost, SOS: true, @@ -259,6 +260,7 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCNonceReport(this.applHost, { nodeId: this.endpoint.nodeId, + ownNodeId: this.applHost.ownNodeId, endpoint: this.endpoint.index, securityManagers: this.applHost, SOS: false, @@ -303,6 +305,7 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCMessageEncapsulation(this.applHost, { nodeId: this.endpoint.nodeId, + ownNodeId: this.applHost.ownNodeId, endpoint: this.endpoint.index, securityManagers: this.applHost, extensions: [ @@ -368,6 +371,7 @@ export class Security2CCAPI extends CCAPI { cc = Security2CC.encapsulate( this.applHost, cc, + this.applHost.ownNodeId, this.applHost, { securityClass }, ); @@ -612,13 +616,16 @@ export class Security2CC extends CommandClass { protected assertSecurity( options: - | (CCCommandOptions & { securityManagers: SecurityManagers }) + | (CCCommandOptions & { + ownNodeId: number; + securityManagers: SecurityManagers; + }) | CommandClassDeserializationOptions, ): SecurityManager2 { const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; const ownNodeId = gotDeserializationOptions(options) ? options.context.ownNodeId - : this.host.ownNodeId; + : options.ownNodeId; if (!ownNodeId) { throw new ZWaveError( `Secure commands (S2) can only be ${verb} when the controller's node id is known!`, @@ -945,6 +952,7 @@ export class Security2CC extends CommandClass { public static encapsulate( host: ZWaveHost, cc: CommandClass, + ownNodeId: number, securityManagers: SecurityManagers, options?: { securityClass?: SecurityClass; @@ -979,6 +987,7 @@ export class Security2CC extends CommandClass { const ret = new Security2CCMessageEncapsulation(host, { nodeId, + ownNodeId, encapsulated: cc, securityManagers, securityClass: options?.securityClass, @@ -999,6 +1008,7 @@ export class Security2CC extends CommandClass { export interface Security2CCMessageEncapsulationOptions extends CCCommandOptions { + ownNodeId: number; securityManagers: Readonly; /** Can be used to override the default security class for the command */ securityClass?: SecurityClass; @@ -1247,8 +1257,8 @@ export class Security2CCMessageEncapsulation extends Security2CC { const authData = getAuthenticationData( sendingNodeId, - this.getDestinationIDRX(), - this.host.homeId, + this.getDestinationIDRX(options.context.ownNodeId), + options.context.homeId, messageLength, unencryptedPayload, ); @@ -1486,8 +1496,8 @@ export class Security2CCMessageEncapsulation extends Security2CC { return ret; } - private getDestinationIDRX(): number { - if (this.isSinglecast()) return this.host.ownNodeId; + private getDestinationIDRX(ownNodeId: number): number { + if (this.isSinglecast()) return ownNodeId; const ret = this.getMulticastGroupId(); if (ret == undefined) { @@ -1956,7 +1966,10 @@ export class Security2CCMessageEncapsulation extends Security2CC { // @publicAPI export type Security2CCNonceReportOptions = - & { securityManagers: SecurityManagers } + & { + ownNodeId: number; + securityManagers: SecurityManagers; + } & ( | { MOS: boolean; @@ -2067,6 +2080,7 @@ export class Security2CCNonceReport extends Security2CC { // @publicAPI export interface Security2CCNonceGetOptions { + ownNodeId: number; securityManagers: Readonly; } diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 5b79992c24f1..2b1d2eac4ed2 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -117,6 +117,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { : SecurityCCCommandEncapsulation )(this.applHost, { nodeId: this.endpoint.nodeId, + ownNodeId: this.applHost.ownNodeId, securityManager: this.applHost.securityManager!, encapsulated, }); @@ -237,6 +238,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { cc = new SecurityCCCommandEncapsulation(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + ownNodeId: this.applHost.ownNodeId, securityManager: this.applHost.securityManager!, encapsulated: cc, }); @@ -272,6 +274,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { const cc = new SecurityCCCommandEncapsulation(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, + ownNodeId: this.applHost.ownNodeId, securityManager: this.applHost.securityManager!, encapsulated: keySet, alternativeNetworkKey: Buffer.alloc(16, 0), @@ -342,11 +345,17 @@ export class SecurityCC extends CommandClass { protected assertSecurity( options: - | (CCCommandOptions & { securityManager: SecurityManager }) + | (CCCommandOptions & { + ownNodeId: number; + securityManager: SecurityManager; + }) | CommandClassDeserializationOptions, ): SecurityManager { const verb = gotDeserializationOptions(options) ? "decoded" : "sent"; - if (!this.host.ownNodeId) { + const ownNodeId = gotDeserializationOptions(options) + ? options.context.ownNodeId + : options.ownNodeId; + if (!ownNodeId) { throw new ZWaveError( `Secure commands (S0) can only be ${verb} when the controller's node id is known!`, ZWaveErrorCodes.Driver_NotReady, @@ -529,12 +538,14 @@ export class SecurityCC extends CommandClass { /** Encapsulates a command that should be sent encrypted */ public static encapsulate( host: ZWaveHost, + ownNodeId: number, securityManager: SecurityManager, cc: CommandClass, ): SecurityCCCommandEncapsulation { // TODO: When to return a SecurityCCCommandEncapsulationNonceGet? const ret = new SecurityCCCommandEncapsulation(host, { nodeId: cc.nodeId, + ownNodeId, securityManager, encapsulated: cc, }); @@ -600,6 +611,7 @@ export class SecurityCCNonceGet extends SecurityCC {} export interface SecurityCCCommandEncapsulationOptions extends CCCommandOptions { + ownNodeId: number; securityManager: SecurityManager; encapsulated: CommandClass; alternativeNetworkKey?: Buffer; diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index d52683ac5ad1..c2bbf99d9f41 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -82,7 +82,7 @@ export interface CCEncodingContext } /** Host application abstractions to be used in Serial API and CC implementations */ -export interface ZWaveHost extends HostIDs { +export interface ZWaveHost { /** * Retrieves the maximum version of a command class that can be used to communicate with a node. * Returns 1 if the node claims that it does not support a CC. diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 9ded504db6dd..765c493a8a65 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -13,11 +13,9 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { createThrowingMap } from "@zwave-js/shared"; -import type { ZWaveApplicationHost, ZWaveHost } from "./ZWaveHost"; +import type { HostIDs, ZWaveApplicationHost, ZWaveHost } from "./ZWaveHost"; -export interface CreateTestingHostOptions { - homeId: ZWaveHost["homeId"]; - ownNodeId: ZWaveHost["ownNodeId"]; +export interface CreateTestingHostOptions extends HostIDs { getSafeCCVersion: ZWaveHost["getSafeCCVersion"]; getSupportedCCVersion?: ZWaveHost["getSupportedCCVersion"]; } diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 2e29e222fa8f..13e0d4e439b6 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -61,10 +61,10 @@ export class MockController { // const valueDBCache = new Map(); // const supervisionSessionIDs = new Map number>(); + this.ownNodeId = options.ownNodeId ?? 1; + this.homeId = options.homeId ?? 0x7e571000; + this.host = { - ownNodeId: options.ownNodeId ?? 1, - homeId: options.homeId ?? 0x7e571000, - // nodes: this.nodes as any, getSafeCCVersion: () => 100, getSupportedCCVersion: (cc, nodeId, endpointIndex = 0) => { if (!this.nodes.has(nodeId)) { @@ -75,19 +75,6 @@ export class MockController { return (endpoint ?? node).implementedCCs.get(cc)?.version ?? 0; }, isCCSecure: () => false, - // getValueDB: (nodeId) => { - // if (!valueDBCache.has(nodeId)) { - // valueDBCache.set( - // nodeId, - // new ValueDB( - // nodeId, - // valuesStorage as any, - // metadataStorage as any, - // ), - // ); - // } - // return valueDBCache.get(nodeId)!; - // }, }; this.capabilities = { @@ -97,8 +84,8 @@ export class MockController { const securityClasses = new Map>(); this.encodingContext = { - homeId: this.host.homeId, - ownNodeId: this.host.ownNodeId, + homeId: this.homeId, + ownNodeId: this.ownNodeId, // TODO: LR is not supported in mocks nodeIdType: NodeIDType.Short, hasSecurityClass( @@ -142,6 +129,9 @@ export class MockController { void this.execute(); } + public homeId: number; + public ownNodeId: number; + public securityManagers: SecurityManagers = {}; public encodingContext: MessageEncodingContext; diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 2a48d34632ce..d7bc77c83284 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -115,7 +115,6 @@ export class MockNode { // A node's host is a bit more specialized than the controller's host. this.host = { ...this.controller.host, - ownNodeId: this.id, __internalIsMockNode: true, // // Mimic the behavior of ZWaveNode, but for arbitrary node IDs }; @@ -123,7 +122,7 @@ export class MockNode { const securityClasses = new Map>(); this.encodingContext = { - homeId: this.controller.host.homeId, + homeId: this.controller.homeId, ownNodeId: this.id, hasSecurityClass( nodeId: number, diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index 1df131eb36df..3b12c50f38bd 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -5112,6 +5112,7 @@ export class ZWaveController Message & SuccessIndicator >( new SetSUCNodeIdRequest(this.driver, { + ownNodeId: this.ownNodeId!, sucNodeId: nodeId, enableSUC, enableSIS, diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index d95ea008f385..ecd8219717be 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -94,7 +94,7 @@ function createLazySendDataPayload( return () => { try { const cmd = CommandClass.from(node.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, data: msg.payload, origin: MessageOrigin.Host, context: { @@ -113,7 +113,7 @@ function createLazySendDataPayload( // The whole CC is not implemented yet. If this happens in tests, it is because we sent a raw CC. try { const cmd = new CommandClass(host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, ccId: msg.payload[0], ccCommand: msg.payload[1], payload: msg.payload.subarray(2), @@ -145,8 +145,8 @@ const respondToGetControllerId: MockControllerBehavior = { async onHostMessage(host, controller, msg) { if (msg instanceof GetControllerIdRequest) { const ret = new GetControllerIdResponse(host, { - homeId: host.homeId, - ownNodeId: host.ownNodeId, + homeId: controller.homeId, + ownNodeId: controller.ownNodeId, }); await controller.sendMessageToHost(ret); return true; @@ -194,7 +194,7 @@ const respondToGetSUCNodeId: MockControllerBehavior = { async onHostMessage(host, controller, msg) { if (msg instanceof GetSUCNodeIdRequest) { const sucNodeId = controller.capabilities.isStaticUpdateController - ? host.ownNodeId + ? controller.ownNodeId : controller.capabilities.sucNodeId; const ret = new GetSUCNodeIdResponse(host, { sucNodeId, @@ -209,7 +209,7 @@ const respondToGetSerialApiInitData: MockControllerBehavior = { async onHostMessage(host, controller, msg) { if (msg instanceof GetSerialApiInitDataRequest) { const nodeIds = new Set(controller.nodes.keys()); - nodeIds.add(host.ownNodeId); + nodeIds.add(controller.ownNodeId); const ret = new GetSerialApiInitDataResponse(host, { zwaveApiVersion: controller.capabilities.zwaveApiVersion, @@ -248,7 +248,7 @@ const respondToSoftReset: MockControllerBehavior = { const respondToGetNodeProtocolInfo: MockControllerBehavior = { async onHostMessage(host, controller, msg) { if (msg instanceof GetNodeProtocolInfoRequest) { - if (msg.requestedNodeId === host.ownNodeId) { + if (msg.requestedNodeId === controller.ownNodeId) { const ret = new GetNodeProtocolInfoResponse(host, { ...determineNIF(), nodeType: NodeType.Controller, @@ -494,7 +494,7 @@ const handleRequestNodeInfo: MockControllerBehavior = { const node = controller.nodes.get(msg.getNodeId()!)!; const command = new ZWaveProtocolCCRequestNodeInformationFrame( node.host, - { nodeId: controller.host.ownNodeId }, + { nodeId: controller.ownNodeId }, ); const frame = createMockZWaveRequestFrame(command, { ackRequested: false, @@ -570,7 +570,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { const node = controller.nodes.get(msg.getNodeId()!)!; const command = new ZWaveProtocolCCAssignSUCReturnRoute(host, { nodeId: node.id, - destinationNodeId: controller.host.ownNodeId, + destinationNodeId: controller.ownNodeId, repeaters: [], // don't care routeIndex: 0, // don't care destinationSpeed: ZWaveDataRate["100k"], diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 2fec34c5ff2f..8ba3052a4841 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -5280,6 +5280,7 @@ ${handlers.length} left`, cmd = Security2CC.encapsulate( this, cmd, + this.ownNodeId, this, { securityClass: options.s2OverrideSecurityClass, @@ -5292,7 +5293,12 @@ ${handlers.length} left`, // This check will return false for S2-encapsulated commands if (SecurityCC.requiresEncapsulation(cmd)) { - cmd = SecurityCC.encapsulate(this, this.securityManager!, cmd); + cmd = SecurityCC.encapsulate( + this, + this.ownNodeId, + this.securityManager!, + cmd, + ); } } return cmd; @@ -6115,6 +6121,7 @@ ${handlers.length} left`, ) { // Prioritize Bridge commands when they are supported msg = new SendDataBridgeRequest(this, { + sourceNodeId: this.ownNodeId, command, maxSendAttempts: this._options.attempts.sendData, }); @@ -6132,6 +6139,7 @@ ${handlers.length} left`, ) { // Prioritize Bridge commands when they are supported msg = new SendDataMulticastBridgeRequest(this, { + sourceNodeId: this.ownNodeId, command, maxSendAttempts: this._options.attempts.sendData, }); @@ -6974,7 +6982,10 @@ ${handlers.length} left`, msg = commandOrMsg; } else { const SendDataConstructor = this.getSendDataSinglecastConstructor(); - msg = new SendDataConstructor(this, { command: commandOrMsg }); + msg = new SendDataConstructor(this, { + sourceNodeId: this.ownNodeId, + command: commandOrMsg, + }); } if (!ignoreEncapsulation) { msg.command = this.encapsulateCommands( diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index 5d19c49fbf1a..26c6c3762ad9 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -605,6 +605,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = // No free nonce, request a new one const cc = new Security2CCNonceGet(driver, { nodeId: nodeId, + ownNodeId: driver.ownNodeId, endpoint: msg.command.endpointIndex, securityManagers: driver, }); @@ -835,6 +836,7 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = if (innerMPANState) { const cc = new Security2CCMessageEncapsulation(driver, { nodeId, + ownNodeId: driver.ownNodeId, securityManagers: driver, extensions: [ new MPANExtension({ @@ -902,7 +904,10 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = }); const ret = new (driver.getSendDataSinglecastConstructor())( driver, - { command: cc }, + { + sourceNodeId: driver.ownNodeId, + command: cc, + }, ); return ret; } else { diff --git a/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts b/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts index 0589bd5b173d..42e73826a39b 100644 --- a/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts +++ b/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts @@ -100,7 +100,7 @@ const respondToZWavePlusCCGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof ZWavePlusCCGet) { const cc = new ZWavePlusCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, zwavePlusVersion: 2, nodeType: ZWavePlusNodeType.Node, roleType: self.capabilities.isListening @@ -124,7 +124,7 @@ const respondToS0ZWavePlusCCGet: MockNodeBehavior = { && receivedCC.encapsulated instanceof ZWavePlusCCGet ) { let cc: CommandClass = new ZWavePlusCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, zwavePlusVersion: 2, nodeType: ZWavePlusNodeType.Node, roleType: self.capabilities.isListening @@ -137,6 +137,7 @@ const respondToS0ZWavePlusCCGet: MockNodeBehavior = { }); cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, cc, ); @@ -152,7 +153,7 @@ const respondToS2ZWavePlusCCGet: MockNodeBehavior = { && receivedCC.encapsulated instanceof ZWavePlusCCGet ) { let cc: CommandClass = new ZWavePlusCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, zwavePlusVersion: 2, nodeType: ZWavePlusNodeType.Node, roleType: self.capabilities.isListening @@ -163,7 +164,12 @@ const respondToS2ZWavePlusCCGet: MockNodeBehavior = { installerIcon: 0x0000, userIcon: 0x0000, }); - cc = Security2CC.encapsulate(self.host, cc, self.securityManagers); + cc = Security2CC.encapsulate( + self.host, + cc, + self.id, + self.securityManagers, + ); return { action: "sendCC", cc }; } }, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts index cccd5e04a575..0f5ab952e176 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts @@ -16,7 +16,7 @@ const respondToBasicGet: MockNodeBehavior = { } const cc = new BasicCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: (self.state.get(StateKeys.currentValue) ?? 0) as number, }); diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts index 93b02bb9d0ed..751d08b98a87 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts @@ -24,7 +24,7 @@ const respondToBinarySensorSupportedGet: MockNodeBehavior = { ), }; const cc = new BinarySensorCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedSensorTypes: capabilities.supportedSensorTypes, }); return { action: "sendCC", cc }; @@ -57,7 +57,7 @@ const respondToBinarySensorGet: MockNodeBehavior = { if (sensorType != undefined) { const value = capabilities.getValue?.(sensorType) ?? false; const cc = new BinarySensorCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: sensorType, value, }); diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts index 416dc35a2e09..a431d87ceab1 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts @@ -33,7 +33,7 @@ const respondToBinarySwitchGet: MockNodeBehavior = { ), }; const cc = new BinarySwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: ( self.state.get(StateKeys.currentValue) ?? capabilities.defaultValue diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts index ffcbad8ee159..04ab347da8d2 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts @@ -36,7 +36,7 @@ const respondToColorSwitchSupportedGet: MockNodeBehavior = { ), }; const cc = new ColorSwitchCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedColorComponents: Object.keys( capabilities.colorComponents, ).map( @@ -75,7 +75,7 @@ const respondToColorSwitchGet: MockNodeBehavior = { const component = receivedCC.colorComponent; if (component in capabilities.colorComponents) { const cc = new ColorSwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, colorComponent: component, currentValue: (self.state.get(StateKeys.component(component)) diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts index 6fa5b3dc00b7..4a5f0a2665a1 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts @@ -51,7 +51,7 @@ const respondToConfigurationGet: MockNodeBehavior = { ?? 0; const cc = new ConfigurationCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter, value, valueSize: paramInfo.valueSize, @@ -138,7 +138,7 @@ const respondToConfigurationNameGet: MockNodeBehavior = { if (!paramInfo) return { action: "fail" }; const cc = new ConfigurationCCNameReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter, name: paramInfo.name ?? "", reportsToFollow: 0, @@ -166,7 +166,7 @@ const respondToConfigurationInfoGet: MockNodeBehavior = { if (!paramInfo) return { action: "fail" }; const cc = new ConfigurationCCInfoReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter, info: paramInfo.info ?? "", reportsToFollow: 0, @@ -198,7 +198,7 @@ const respondToConfigurationPropertiesGet: MockNodeBehavior = { // If the parameter is not supported, respond with the first supported parameter if (!paramInfo) { cc = new ConfigurationCCPropertiesReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter, valueFormat: 0, valueSize: 0, @@ -206,7 +206,7 @@ const respondToConfigurationPropertiesGet: MockNodeBehavior = { }); } else { cc = new ConfigurationCCPropertiesReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter, valueSize: paramInfo.valueSize, valueFormat: paramInfo.format diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts index a25b3b9bf62c..acfc5ad840e5 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts @@ -53,7 +53,7 @@ const respondToEnergyProductionGet: MockNodeBehavior = { ]; const cc = new EnergyProductionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter: receivedCC.parameter, value: result?.value ?? 0, scale: getEnergyProductionScale( diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts index b3bb9097d1f9..281a2638fb97 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts @@ -30,7 +30,7 @@ const respondToMeterSupportedGet: MockNodeBehavior = { ), }; const cc = new MeterCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: capabilities.meterType, supportedScales: capabilities.supportedScales, supportedRateTypes: capabilities.supportedRateTypes, @@ -69,7 +69,7 @@ const respondToMeterGet: MockNodeBehavior = { : value; const cc = new MeterCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: capabilities.meterType, scale, rateType, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts index 1017522d3d84..fc6132e65fab 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts @@ -60,7 +60,7 @@ const respondToMultiChannelCCEndPointGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultiChannelCCEndPointGet) { const cc = new MultiChannelCCEndPointReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, countIsDynamic: false, identicalCapabilities: false, individualCount: self.endpoints.size, @@ -75,7 +75,7 @@ const respondToMultiChannelCCEndPointFind: MockNodeBehavior = { if (receivedCC instanceof MultiChannelCCEndPointFind) { const request = receivedCC; const cc = new MultiChannelCCEndPointFindReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, genericClass: request.genericClass, specificClass: request.specificClass, foundEndpoints: [...self.endpoints.keys()], @@ -93,7 +93,7 @@ const respondToMultiChannelCCCapabilityGet: MockNodeBehavior = { receivedCC.requestedEndpoint, )!; const cc = new MultiChannelCCCapabilityReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, endpointIndex: endpoint.index, genericDeviceClass: endpoint?.capabilities.genericDeviceClass ?? self.capabilities.genericDeviceClass, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts index 417b16a4dc5f..8a1157757b13 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts @@ -25,7 +25,7 @@ const respondToMultilevelSensorGetSupportedSensor: MockNodeBehavior = { ), }; const cc = new MultilevelSensorCCSupportedSensorReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedSensorTypes: Object.keys( capabilities.sensors, ).map((t) => parseInt(t)), @@ -49,7 +49,7 @@ const respondToMultilevelSensorGetSupportedScale: MockNodeBehavior = { const supportedScales = capabilities.sensors[sensorType]?.supportedScales ?? []; const cc = new MultilevelSensorCCSupportedScaleReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sensorType, supportedScales, }); @@ -80,7 +80,7 @@ const respondToMultilevelSensorGet: MockNodeBehavior = { ?? 0; const value = capabilities.getValue?.(sensorType, scale) ?? 0; const cc = new MultilevelSensorCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: sensorType, scale, value, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts index 09bbc13d794a..075f33238104 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts @@ -44,7 +44,7 @@ const respondToMultilevelSwitchGet: MockNodeBehavior = { ?? UNKNOWN_STATE ) as MaybeUnknown; const cc = new MultilevelSwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue, // We don't support transitioning yet targetValue: currentValue, @@ -74,7 +74,7 @@ const respondToMultilevelSwitchSupportedGet: MockNodeBehavior = { ), }; const cc = new MultilevelSwitchCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, switchType: capabilities.primarySwitchType, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts index 6a723b81025a..561697580ea0 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts @@ -24,7 +24,7 @@ const respondToNotificationSupportedGet: MockNodeBehavior = { ), }; const cc = new NotificationCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportsV1Alarm: capabilities.supportsV1Alarm, supportedNotificationTypes: Object.keys( capabilities.notificationTypesAndEvents, @@ -50,7 +50,7 @@ const respondToNotificationEventSupportedGet: MockNodeBehavior = { in capabilities.notificationTypesAndEvents ) { const cc = new NotificationCCEventSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, notificationType: receivedCC.notificationType, supportedEvents: capabilities.notificationTypesAndEvents[ receivedCC.notificationType diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts index 70aa3181fc58..8995a3788bea 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts @@ -59,7 +59,7 @@ const respondToScheduleEntryLockSupportedGet: MockNodeBehavior = { ), }; const cc = new ScheduleEntryLockCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, ...capabilities, }); return { action: "sendCC", cc }; @@ -84,7 +84,7 @@ const respondToScheduleEntryLockTimeOffsetGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof ScheduleEntryLockCCTimeOffsetGet) { const cc = new ScheduleEntryLockCCTimeOffsetReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, standardOffset: (self.state.get(StateKeys.standardOffset) ?? 0) as number, dstOffset: (self.state.get(StateKeys.dstOffset) ?? 0) as number, @@ -196,7 +196,7 @@ const respondToScheduleEntryLockWeekDayScheduleGet: MockNodeBehavior = { ) ?? {}) as AllOrNone; const cc = new ScheduleEntryLockCCWeekDayScheduleReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, userId, slotId, ...schedule, @@ -295,7 +295,7 @@ const respondToScheduleEntryLockYearDayScheduleGet: MockNodeBehavior = { ) ?? {}) as AllOrNone; const cc = new ScheduleEntryLockCCYearDayScheduleReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, userId, slotId, ...schedule, @@ -397,7 +397,7 @@ const respondToScheduleEntryLockDailyRepeatingScheduleGet: MockNodeBehavior = { const cc = new ScheduleEntryLockCCDailyRepeatingScheduleReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, userId, slotId, ...schedule, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts index ffca6b9a851e..1ffce5eef991 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts @@ -48,7 +48,7 @@ const respondToSoundSwitchConfigurationGet: MockNodeBehavior = { ), }; const cc = new SoundSwitchCCConfigurationReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, defaultToneId: (self.state.get(StateKeys.defaultToneId) as number) ?? capabilities.defaultToneId, @@ -88,7 +88,7 @@ const respondToSoundSwitchToneNumberGet: MockNodeBehavior = { ), }; const cc = new SoundSwitchCCTonesNumberReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, toneCount: capabilities.tones.length, }); return { action: "sendCC", cc }; @@ -109,7 +109,7 @@ const respondToSoundSwitchToneInfoGet: MockNodeBehavior = { const tone = capabilities.tones[receivedCC.toneId - 1]; if (tone) { const cc = new SoundSwitchCCToneInfoReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, toneId: receivedCC.toneId, ...tone, }); @@ -179,7 +179,7 @@ const respondToSoundSwitchTonePlaySet: MockNodeBehavior = { const cc = new SoundSwitchCCTonePlayReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, toneId: 0, volume: 0, }, @@ -210,7 +210,7 @@ const respondToSoundSwitchTonePlayGet: MockNodeBehavior = { const cc = new SoundSwitchCCTonePlayReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, toneId: currentState?.toneId ?? 0, volume: currentState?.volume ?? 0, }, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts index 3bca22f5e634..bac3e9bfb740 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts @@ -46,7 +46,7 @@ const respondToThermostatModeGet: MockNodeBehavior = { : undefined; const cc = new ThermostatModeCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, mode, // @ts-expect-error I know... manufacturerData, @@ -68,7 +68,7 @@ const respondToThermostatModeSupportedGet: MockNodeBehavior = { }; const cc = new ThermostatModeCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedModes: capabilities.supportedModes, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts index 6abb57ea0a88..1831e75f3c4a 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts @@ -35,7 +35,7 @@ const respondToThermostatSetbackGet: MockNodeBehavior = { ) as SetbackState; const cc = new ThermostatSetbackCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, setbackType, setbackState, }); diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts index 2209f732c553..36809cef47df 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts @@ -99,14 +99,14 @@ const respondToThermostatSetpointGet: MockNodeBehavior = { let cc: ThermostatSetpointCCReport; if (value !== undefined) { cc = new ThermostatSetpointCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: setpointType, value, scale: scale ?? 0, }); } else { cc = new ThermostatSetpointCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: ThermostatSetpointType["N/A"], scale: 0, value: 0, @@ -129,7 +129,7 @@ const respondToThermostatSetpointSupportedGet: MockNodeBehavior = { }; const cc = new ThermostatSetpointCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedSetpointTypes: Object.keys(capabilities.setpoints).map( (k) => parseInt(k), ), @@ -156,7 +156,7 @@ const respondToThermostatSetpointCapabilitiesGet: MockNodeBehavior = { let cc: ThermostatSetpointCCCapabilitiesReport; if (setpointCaps) { cc = new ThermostatSetpointCCCapabilitiesReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: setpointType, minValue: setpointCaps.minValue, maxValue: setpointCaps.maxValue, @@ -165,7 +165,7 @@ const respondToThermostatSetpointCapabilitiesGet: MockNodeBehavior = { }); } else { cc = new ThermostatSetpointCCCapabilitiesReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: ThermostatSetpointType["N/A"], minValue: 0, maxValue: 0, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts index 7661f011c99b..f12c9537aec6 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts @@ -56,7 +56,7 @@ const respondToUsersNumberGet: MockNodeBehavior = { ), }; const cc = new UserCodeCCUsersNumberReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedUsers: capabilities.numUsers ?? 1, }); return { action: "sendCC", cc }; @@ -78,7 +78,7 @@ const respondToUserGet: MockNodeBehavior = { let cc: UserCodeCCReport; if (capabilities.numUsers >= userId) { cc = new UserCodeCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, userId, userIdStatus: (self.state.get( StateKeys.userIdStatus(userId), @@ -89,7 +89,7 @@ const respondToUserGet: MockNodeBehavior = { }); } else { cc = new UserCodeCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, userId, userIdStatus: UserIDStatus.StatusNotAvailable, }); @@ -138,7 +138,7 @@ const respondToUserCodeCapabilitiesGet: MockNodeBehavior = { ), }; const cc = new UserCodeCCCapabilitiesReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportsAdminCode: capabilities.supportsAdminCode!, supportsAdminCodeDeactivation: capabilities .supportsAdminCodeDeactivation!, @@ -166,7 +166,7 @@ const respondToUserCodeKeypadModeGet: MockNodeBehavior = { ), }; const cc = new UserCodeCCKeypadModeReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, keypadMode: (self.state.get(StateKeys.keypadMode) ?? capabilities.supportedKeypadModes?.[0] ?? KeypadMode.Normal) as KeypadMode, @@ -243,7 +243,7 @@ const respondToUserCodeAdminCodeGet: MockNodeBehavior = { } const cc = new UserCodeCCAdminCodeReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, adminCode: adminCode ?? "", }); return { action: "sendCC", cc }; @@ -290,7 +290,7 @@ const respondToUserCodeUserCodeChecksumGet: MockNodeBehavior = { const checksum = data.length > 0 ? CRC16_CCITT(data) : 0x0000; const cc = new UserCodeCCUserCodeChecksumReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, userCodeChecksum: checksum, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts index a72707d27d06..e58846dc4fff 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts @@ -23,7 +23,7 @@ const respondToWindowCoveringSupportedGet: MockNodeBehavior = { ), }; const cc = new WindowCoveringCCSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedParameters: capabilities.supportedParameters, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index 7bec31bb0a26..2b11230284e6 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -37,6 +37,8 @@ export class BridgeApplicationCommandRequest extends Message options: MessageDeserializationOptions, ) { super(host, options); + this._ownNodeId = options.ctx.ownNodeId; + // if (gotDeserializationOptions(options)) { // first byte is a status flag const status = this.payload[0]; @@ -110,6 +112,8 @@ export class BridgeApplicationCommandRequest extends Message public readonly fromForeignHomeId: boolean; public readonly rssi?: RSSI; + private _ownNodeId: number; + // This needs to be writable or unwrapping MultiChannelCCs crashes public command: SinglecastCC; // TODO: why is this a SinglecastCC? @@ -125,7 +129,7 @@ export class BridgeApplicationCommandRequest extends Message if (this.frameType !== "singlecast") { message.type = this.frameType; } - if (this.targetNodeId !== this.host.ownNodeId) { + if (this.targetNodeId !== this._ownNodeId) { if (typeof this.targetNodeId === "number") { message["target node"] = this.targetNodeId; } else if (this.targetNodeId.length === 1) { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index b740f9cd37ac..20d6e581873b 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -31,7 +31,8 @@ export enum SetSUCNodeIdStatus { } export interface SetSUCNodeIdRequestOptions extends MessageBaseOptions { - sucNodeId?: number; + ownNodeId: number; + sucNodeId: number; enableSUC: boolean; enableSIS: boolean; transmitOptions?: TransmitOptions; @@ -65,11 +66,12 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { ZWaveErrorCodes.Deserialization_NotImplemented, ); } else { - this.sucNodeId = options.sucNodeId ?? host.ownNodeId; + this.sucNodeId = options.sucNodeId; this.enableSUC = options.enableSUC; this.enableSIS = options.enableSIS; this.transmitOptions = options.transmitOptions ?? TransmitOptions.DEFAULT; + this._ownNodeId = options.ownNodeId; } } @@ -78,6 +80,8 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { public enableSIS: boolean; public transmitOptions: TransmitOptions; + private _ownNodeId: number; + public serialize(ctx: MessageEncodingContext): Buffer { this.assertCallbackId(); const nodeId = encodeNodeID(this.sucNodeId, ctx.nodeIdType); @@ -95,7 +99,7 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { } public expectsCallback(): boolean { - if (this.sucNodeId === this.host.ownNodeId) return false; + if (this.sucNodeId === this._ownNodeId) return false; return super.expectsCallback(); } } diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts index eeac3b48923e..c52dd4b459ab 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts @@ -55,7 +55,7 @@ interface SendDataBridgeRequestOptions< CCType extends CommandClass = CommandClass, > extends MessageBaseOptions { command: CCType; - sourceNodeId?: number; + sourceNodeId: number; transmitOptions?: TransmitOptions; maxSendAttempts?: number; } @@ -79,7 +79,7 @@ export class SendDataBridgeRequest ); } - this.sourceNodeId = options.sourceNodeId ?? host.ownNodeId; + this.sourceNodeId = options.sourceNodeId; this.command = options.command; this.transmitOptions = options.transmitOptions @@ -287,7 +287,7 @@ interface SendDataMulticastBridgeRequestOptions extends MessageBaseOptions { command: CCType; - sourceNodeId?: number; + sourceNodeId: number; transmitOptions?: TransmitOptions; maxSendAttempts?: number; } @@ -320,7 +320,7 @@ export class SendDataMulticastBridgeRequest< ); } - this.sourceNodeId = options.sourceNodeId ?? host.ownNodeId; + this.sourceNodeId = options.sourceNodeId; this.command = options.command; this.transmitOptions = options.transmitOptions ?? TransmitOptions.DEFAULT; diff --git a/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts b/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts index e1eecc15007a..d67a0d433b97 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts @@ -25,7 +25,7 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { // Unsupported report from root endpoint let cc: CommandClass = new MultilevelSensorCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, type: 0x01, // Temperature scale: 0x00, // Celsius value: 1.001, @@ -38,13 +38,13 @@ integrationTest( // Report from endpoint 1, unsupported on root cc = new MultilevelSensorCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, type: 0x01, // Temperature scale: 0x00, // Celsius value: 25.12, }); cc = new MultiChannelCCCommandEncapsulation(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, endpoint: 1, destination: 0, encapsulated: cc, @@ -57,13 +57,13 @@ integrationTest( // Unsupported Report from endpoint 1, supported on root cc = new MeterCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, type: 0x01, // Electric scale: 0x00, // kWh value: 1.234, }); cc = new MultiChannelCCCommandEncapsulation(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, endpoint: 1, destination: 0, encapsulated: cc, @@ -76,7 +76,7 @@ integrationTest( // Supported report from root endpoint cc = new MeterCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, type: 0x01, // Electric scale: 0x00, // kWh value: 2.34, diff --git a/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts b/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts index 2828c1904ac6..f8d7f3320652 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts @@ -19,7 +19,7 @@ integrationTest( const valueId = DoorLockCCValues.currentMode.id; let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x01, // Manual Lock Operation }); @@ -34,7 +34,7 @@ integrationTest( t.is(node.getValue(valueId), DoorLockMode.Secured); cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x06, // Keypad Unlock Operation }); diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts index 6a5f2407b92f..f78f514a8311 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts @@ -50,7 +50,7 @@ integrationTest( // Send notifications to the node let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x0f, notificationEvent: 0x01, eventParameters: Buffer.from([0x00]), // Off / Closed @@ -67,7 +67,7 @@ integrationTest( t.is(value, 0x00); cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x0f, notificationEvent: 0x01, eventParameters: Buffer.from([0x01]), // On / Open @@ -125,7 +125,7 @@ integrationTest( // Send notifications to the node let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, eventParameters: Buffer.from([0x00]), // open in regular position @@ -142,7 +142,7 @@ integrationTest( t.is(value, 0x1600); cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, eventParameters: Buffer.from([0x01]), // open in tilt position @@ -158,7 +158,7 @@ integrationTest( t.is(value, 0x1601); cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // open }); @@ -173,7 +173,7 @@ integrationTest( t.is(value, 0x16); cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x17, // closed }); @@ -241,7 +241,7 @@ integrationTest("The 'simple' Door state value works correctly", { const valueSimple = NotificationCCValues.doorStateSimple; let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x01]), // ... in tilt position @@ -260,7 +260,7 @@ integrationTest("The 'simple' Door state value works correctly", { // === cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x00]), // ... in regular position @@ -279,7 +279,7 @@ integrationTest("The 'simple' Door state value works correctly", { // === cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open }); @@ -297,7 +297,7 @@ integrationTest("The 'simple' Door state value works correctly", { // === cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x17, // Window/door is closed }); @@ -347,7 +347,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // Send a notification to the node where the window is not tilted let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x00]), // ... in regular position @@ -367,7 +367,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // Again with tilt cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x01]), // ... in tilt position @@ -388,7 +388,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // Again without tilt cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x00]), // ... in regular position @@ -407,7 +407,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // Again with tilt to be able to detect changes cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x01]), // ... in tilt position @@ -426,7 +426,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // And now without the enum cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x17, // Window/door is closed }); @@ -444,7 +444,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // Again with tilt to be able to detect changes cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open eventParameters: Buffer.from([0x01]), // ... in tilt position @@ -463,7 +463,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // And again without the enum cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open }); @@ -521,7 +521,7 @@ integrationTest( // Send notifications to the node let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x05, notificationEvent: 0x07, eventParameters: Buffer.from([0x02]), // Below low threshold @@ -539,7 +539,7 @@ integrationTest( // Now send one without an event parameter cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x05, notificationEvent: 0x07, }); @@ -554,7 +554,7 @@ integrationTest( t.is(value, 0x01); // cc = new NotificationCCReport(mockNode.host, { - // nodeId: mockController.host.ownNodeId, + // nodeId: mockController.ownNodeId, // notificationType: 0x06, // notificationEvent: 0x16, // open // }); @@ -569,7 +569,7 @@ integrationTest( // t.is(value, 0x16); // cc = new NotificationCCReport(mockNode.host, { - // nodeId: mockController.host.ownNodeId, + // nodeId: mockController.ownNodeId, // notificationType: 0x06, // notificationEvent: 0x17, // closed // }); diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts index 27bb94b6bfd1..35f73d45cfa8 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts @@ -18,7 +18,7 @@ integrationTest("Notification values can get idled manually", { ).id; let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x01, // Smoke Alarm notificationEvent: 0x03, // Smoke alarm test }); @@ -47,7 +47,7 @@ integrationTest("Notification values can get idled manually", { ).id; cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control notificationEvent: 0x16, // Door state }); @@ -81,7 +81,7 @@ integrationTest( ).id; let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x01, // Smoke Alarm notificationEvent: 0x03, // Smoke alarm test }); @@ -109,7 +109,7 @@ integrationTest( ).id; cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control notificationEvent: 0x16, // Door state }); diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts index 31e5fc7f94fb..3b5c77ffc139 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts @@ -23,7 +23,7 @@ integrationTest( ).id; let cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x0b, // Lock jammed }); @@ -38,7 +38,7 @@ integrationTest( t.is(node.getValue(lockStateValueId), 0x0b /* Lock jammed */); cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x06, // Keypad Unlock Operation }); diff --git a/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts b/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts index 77b2cabd358b..9077749337ad 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts @@ -19,7 +19,7 @@ integrationTest( node.valueDB.setValue(targetValueValueID, false); const cc = new BinarySwitchCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: true, }); await mockNode.sendToController( diff --git a/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts b/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts index 82c6a4857b7b..4926670410fc 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts @@ -19,7 +19,7 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { const cc = new NotificationCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0xfd, // Manual Lock Operation }); diff --git a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts index ec097feedd1a..02be66cedd84 100644 --- a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts @@ -43,6 +43,7 @@ test("SecurityCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { const ccRequest = SecurityCC.encapsulate( host, + host.ownNodeId, securityManager as any, new WakeUpCCNoMoreInformation(host, { nodeId: 2, diff --git a/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts b/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts index 063e5f569ba6..6ea72a92123b 100644 --- a/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts +++ b/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts @@ -40,7 +40,7 @@ integrationTest( // Incorrectly respond with 0xFF as the sensor type const cc = new BinarySensorCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, type: BinarySensorType.Any, value: true, }); diff --git a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts index dee44fb2ef58..ef03665fe741 100644 --- a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts +++ b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts @@ -73,7 +73,7 @@ integrationTest( host, { nodeId: node.id, - destinationNodeId: controller.host.ownNodeId, + destinationNodeId: controller.ownNodeId, repeaters: [], // don't care routeIndex: 0, // don't care destinationSpeed: ZWaveDataRate["100k"], @@ -163,7 +163,7 @@ integrationTest( host, { nodeId: node.id, - destinationNodeId: controller.host.ownNodeId, + destinationNodeId: controller.ownNodeId, repeaters: [], // don't care routeIndex: 0, // don't care destinationSpeed: ZWaveDataRate["100k"], diff --git a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts index 6c4309fe816d..b7f2867a0fd8 100644 --- a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts @@ -77,10 +77,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = sm2Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -101,7 +102,7 @@ integrationTest( receiverEI: controllerEI, }); mockNode.securityManagers.securityManager2!.setSPANState( - mockController.host.ownNodeId, + mockController.ownNodeId, { type: SPANState.RemoteEI, receiverEI: controllerEI, @@ -110,10 +111,11 @@ integrationTest( // The node sends an S2-encapsulated command, but with a lower security class than expected let innerCC: CommandClass = new TimeCCTimeGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); let cc = new Security2CCMessageEncapsulation(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, + ownNodeId: mockNode.id, encapsulated: innerCC, securityManagers: mockNode.securityManagers, }); @@ -152,11 +154,12 @@ integrationTest( // Now the node queries our securely supported commands innerCC = new Security2CCCommandsSupportedGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); cc = new Security2CCMessageEncapsulation(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, + ownNodeId: mockNode.id, encapsulated: innerCC, securityManagers: mockNode.securityManagers, }); diff --git a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts index b2c99abb29b6..151ba627d994 100644 --- a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts @@ -73,10 +73,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -99,10 +100,11 @@ integrationTest( === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -128,9 +130,10 @@ integrationTest( let nodeToHost: CommandClass = Security2CC.encapsulate( mockNode.host, new BasicCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 99, }), + mockNode.id, mockNode.securityManagers, ); await mockNode.sendToController( @@ -147,7 +150,7 @@ integrationTest( // Then send an unencypted one that should be discarded nodeToHost = new BasicCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 1, }); diff --git a/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts b/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts index 3463762265f6..113c2b26faf0 100644 --- a/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts @@ -42,7 +42,7 @@ integrationTest( // We know that the driver must respond to Z-Wave Plus Info Get // so we can use that to test const zwpRequest = new ZWavePlusCCGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); const cc = CRC16CC.encapsulate(mockNode.host, zwpRequest); await mockNode.sendToController(createMockZWaveRequestFrame(cc)); @@ -89,7 +89,7 @@ integrationTest( // We know that the driver must respond to Z-Wave Plus Info Get // so we can use that to test const zwpRequest = new ZWavePlusCCGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); const cc = MultiChannelCC.encapsulate(mockNode.host, zwpRequest); (cc as MultiChannelCCCommandEncapsulation).endpointIndex = 2; @@ -139,7 +139,7 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { const basicReport = new BasicCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 0, }); const cc = SupervisionCC.encapsulate(mockNode.host, basicReport); @@ -190,7 +190,7 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { const basicReport = new BasicCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 0, }); const supervised = SupervisionCC.encapsulate( diff --git a/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts b/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts index e2aa64e62b84..5ccefaf26cd4 100644 --- a/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts @@ -32,11 +32,11 @@ integrationTest("All CCs contained in a Multi Command CC are handled", { testBody: async (t, driver, node, mockController, mockNode) => { // This one requires a response const zwpRequest = new ZWavePlusCCGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); // This one updates a value const scaSet = new SceneActivationCCSet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, sceneId: 7, }); const cc = MultiCommandCC.encapsulate(mockNode.host, [ diff --git a/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts b/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts index b6ad15a97827..6b71f4157d8d 100644 --- a/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts @@ -124,10 +124,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -150,10 +151,11 @@ integrationTest( === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -183,7 +185,7 @@ integrationTest( const cc = Security2CC.encapsulate( self.host, new Security2CCCommandsSupportedReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedCCs: isHighestGranted ? [...mockNode.implementedCCs.entries()] .filter( @@ -197,6 +199,7 @@ integrationTest( .map(([ccId]) => ccId) : [], }), + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -216,11 +219,12 @@ integrationTest( const cc = Security2CC.encapsulate( self.host, new MultiChannelCCEndPointReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, countIsDynamic: false, identicalCapabilities: false, individualCount: self.endpoints.size, }), + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -241,12 +245,13 @@ integrationTest( const cc = Security2CC.encapsulate( self.host, new MultiChannelCCEndPointFindReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, genericClass: request.genericClass, specificClass: request.specificClass, foundEndpoints: [...self.endpoints.keys()], reportsToFollow: 0, }), + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -269,7 +274,7 @@ integrationTest( const cc = Security2CC.encapsulate( self.host, new MultiChannelCCCapabilityReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, endpointIndex: endpoint.index, genericDeviceClass: endpoint?.capabilities.genericDeviceClass @@ -283,6 +288,7 @@ integrationTest( ...endpoint.implementedCCs.keys(), ], }), + self.id, self.securityManagers, ); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts index f8e80f92bb93..78494ae333e1 100644 --- a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts @@ -175,6 +175,7 @@ test.serial("supports nested partial/non-partial CCs", (t) => { const cc1 = new BasicCCSet(driver, { nodeId: 2, targetValue: 25 }); const cc = new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, encapsulated: {} as any, }); @@ -190,6 +191,7 @@ test.serial("supports nested partial/partial CCs (part 1)", (t) => { const { driver } = t.context; const cc = new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, encapsulated: {} as any, }); @@ -214,6 +216,7 @@ test.serial("supports nested partial/partial CCs (part 2)", (t) => { const { driver } = t.context; const cc = new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, encapsulated: {} as any, }); diff --git a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts index db026916a45b..12d094559ec5 100644 --- a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts +++ b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts @@ -46,6 +46,7 @@ test("should compute the correct net payload sizes", (t) => { const testMsg1 = new SendDataRequest(driver, { command: new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, encapsulated: {} as any, }), @@ -62,6 +63,7 @@ test("should compute the correct net payload sizes", (t) => { const testMsg2 = new SendDataRequest(driver, { command: new SecurityCCCommandEncapsulation(driver, { nodeId: 2, + ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, encapsulated: multiChannelCC, }), diff --git a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts index e2c657a71e57..4a5d62822cb4 100644 --- a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts +++ b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts @@ -20,7 +20,7 @@ integrationTest("CC values are created using the known CC version", { testBody: async (t, driver, node, mockController, mockNode) => { const batteryReport = new BatteryCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, isLow: true, }); await mockNode.sendToController( diff --git a/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts index 610762ea957f..47ba91182e00 100644 --- a/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts @@ -23,7 +23,7 @@ integrationTest( ); const cc = new CommandClass(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, ccId: CommandClasses["Anti-Theft"], ccCommand: 0x02, // Get payload: Buffer.from([0x00, 0x01]), // Technically invalid diff --git a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts index 7a9128f339fd..5124e74f5e0d 100644 --- a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts @@ -75,10 +75,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -101,10 +102,11 @@ integrationTest( === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -131,7 +133,7 @@ integrationTest( new Security2CCCommandsSupportedReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedCCs: [ // The node supports Version CC securely CommandClasses.Version, @@ -141,6 +143,7 @@ integrationTest( cc = Security2CC.encapsulate( self.host, cc, + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -162,7 +165,7 @@ integrationTest( let cc: CommandClass = new VersionCCCommandClassReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, requestedCC: receivedCC.encapsulated.requestedCC, ccVersion: 0, @@ -171,6 +174,7 @@ integrationTest( cc = Security2CC.encapsulate( self.host, cc, + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -209,7 +213,7 @@ integrationTest( // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ - ownNodeId: controller.host.ownNodeId, + ownNodeId: controller.ownNodeId, networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); @@ -220,11 +224,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof SecurityCCNonceGet) { const nonce = sm0Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, 8, ); const cc = new SecurityCCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, nonce, }); return { action: "sendCC", cc }; @@ -241,7 +245,7 @@ integrationTest( instanceof SecurityCCCommandsSupportedGet ) { const nonceGet = new SecurityCCNonceGet(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, }); await self.sendToController( createMockZWaveRequestFrame(nonceGet, { @@ -266,7 +270,7 @@ integrationTest( new SecurityCCCommandsSupportedReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedCCs: [ // The node supports Version CC securely CommandClasses.Version, @@ -276,6 +280,7 @@ integrationTest( ); const cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, response, ); @@ -304,7 +309,7 @@ integrationTest( ) { await wait(100); const nonceGet = new SecurityCCNonceGet(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, }); await self.sendToController( createMockZWaveRequestFrame(nonceGet, { @@ -329,7 +334,7 @@ integrationTest( new VersionCCCommandClassReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, requestedCC: receivedCC.encapsulated.requestedCC, ccVersion: 0, @@ -338,6 +343,7 @@ integrationTest( const cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, response, ); diff --git a/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts b/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts index c835f75e5036..5b45f9ef9859 100644 --- a/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts +++ b/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts @@ -38,7 +38,7 @@ integrationTest( if (receivedCC instanceof ConfigurationCCNameGet) { await wait(700); let cc = new ConfigurationCCNameReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter: receivedCC.parameter, name: "Test para", reportsToFollow: 1, @@ -52,7 +52,7 @@ integrationTest( await wait(700); cc = new ConfigurationCCNameReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter: receivedCC.parameter, name: "meter", reportsToFollow: 0, @@ -103,7 +103,7 @@ integrationTest( const configCC = new ConfigurationCCNameReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, parameter: receivedCC.parameter, name: "Veeeeeeeeeeeeeeeeeeeeeeeeery loooooooooooooooooong parameter name", @@ -122,7 +122,7 @@ integrationTest( const tsFS = new TransportServiceCCFirstSegment( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId, datagramSize: serialized.length, partialDatagram: segment1, @@ -131,7 +131,7 @@ integrationTest( const tsSS = new TransportServiceCCSubsequentSegment( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId, datagramSize: serialized.length, datagramOffset: segment1.length, @@ -186,7 +186,7 @@ integrationTest("GET requests DO time out if there's no matching response", { if (receivedCC instanceof ConfigurationCCNameGet) { // This is not the response you're looking for const cc = new BasicCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: 1, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts index 609a43751e99..8d5c8c740bd3 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts @@ -35,7 +35,7 @@ integrationTest( // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ - ownNodeId: controller.host.ownNodeId, + ownNodeId: controller.ownNodeId, networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); @@ -46,11 +46,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof SecurityCCNonceGet) { const nonce = sm0Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, 8, ); const cc = new SecurityCCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, nonce, }); return { action: "sendCC", cc }; @@ -86,7 +86,7 @@ integrationTest( mockNode.autoAckControllerFrames = false; let nonceRequest = new SecurityCCNonceGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); await mockNode.sendToController( createMockZWaveRequestFrame(nonceRequest, { @@ -124,7 +124,7 @@ integrationTest( // And subsequent requests must be answered nonceRequest = new SecurityCCNonceGet(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); await mockNode.sendToController( createMockZWaveRequestFrame(nonceRequest, { diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts index 412b62834e73..2612e9463eae 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts @@ -174,7 +174,7 @@ integrationTest( const cc: CommandClass = new WakeUpCCWakeUpNotification( mockNode10.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }, ); mockNode10.sendToController(createMockZWaveRequestFrame(cc, { @@ -309,7 +309,7 @@ integrationTest( const cc: CommandClass = new WakeUpCCWakeUpNotification( mockNode10.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }, ); mockNode10.sendToController(createMockZWaveRequestFrame(cc, { diff --git a/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts b/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts index 6c93deb2f757..8c3655868a75 100644 --- a/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts +++ b/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts @@ -36,7 +36,7 @@ integrationTest( const notificationType = receivedCC.notificationType || 0x06; const cc = new NotificationCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, notificationType, notificationEvent: notificationType === 0x06 ? 0x06 /* Keypad unlock */ diff --git a/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts b/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts index 476b895f32a3..5c8b1d94c5f7 100644 --- a/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts +++ b/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts @@ -26,7 +26,7 @@ integrationTest("Assume a node to be awake at the start of a re-interview", { // Send a WakeUpNotification to the node to trigger the interview const cc = new WakeUpCCWakeUpNotification(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); await mockNode.sendToController( createMockZWaveRequestFrame(cc, { @@ -48,7 +48,7 @@ integrationTest("Assume a node to be awake at the start of a re-interview", { }); const cc = new WakeUpCCWakeUpNotification(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); await mockNode.sendToController( createMockZWaveRequestFrame(cc, { diff --git a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts index 1a1d7d816152..0815debba5ad 100644 --- a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts @@ -81,7 +81,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { () => SecurityClass.S2_Unauthenticated; const sm0Ctrlr = new SecurityManager({ - ownNodeId: controller.host.ownNodeId, + ownNodeId: controller.ownNodeId, networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); @@ -92,11 +92,11 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { handleCC(controller, self, receivedCC) { if (receivedCC instanceof SecurityCCNonceGet) { const nonce = sm0Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, 8, ); const cc = new SecurityCCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, nonce, }); return { action: "sendCC", cc }; @@ -122,10 +122,11 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = sm2Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -148,10 +149,11 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = sm2Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -172,7 +174,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { && receivedCC.encapsulated instanceof SupervisionCCGet ) { let cc: CommandClass = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.encapsulated.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, @@ -180,6 +182,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { cc = Security2CC.encapsulate( self.host, cc, + self.id, self.securityManagers, ); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts index 2a2beb460f22..ef746bf84148 100644 --- a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts @@ -35,7 +35,7 @@ integrationTest("Communication via Security S0 works", { // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ - ownNodeId: controller.host.ownNodeId, + ownNodeId: controller.ownNodeId, networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); @@ -46,11 +46,11 @@ integrationTest("Communication via Security S0 works", { handleCC(controller, self, receivedCC) { if (receivedCC instanceof SecurityCCNonceGet) { const nonce = sm0Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, 8, ); const cc = new SecurityCCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, nonce, }); return { action: "sendCC", cc }; @@ -68,7 +68,7 @@ integrationTest("Communication via Security S0 works", { instanceof SecurityCCCommandsSupportedGet ) { const nonceGet = new SecurityCCNonceGet(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, }); await self.sendToController( createMockZWaveRequestFrame(nonceGet, { @@ -91,13 +91,14 @@ integrationTest("Communication via Security S0 works", { const response = new SecurityCCCommandsSupportedReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedCCs: [CommandClasses.Basic], controlledCCs: [], }, ); const cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, response, ); @@ -124,7 +125,7 @@ integrationTest("Communication via Security S0 works", { && receivedCC.encapsulated instanceof BasicCCGet ) { const nonceGet = new SecurityCCNonceGet(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, }); await self.sendToController( createMockZWaveRequestFrame(nonceGet, { @@ -145,11 +146,12 @@ integrationTest("Communication via Security S0 works", { const receiverNonce = nonceReport.payload.nonce; const response = new BasicCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: ++queryCount, }); const cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, response, ); diff --git a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts index ee4c54b8d1a9..4a54fa3a7762 100644 --- a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts @@ -56,7 +56,7 @@ integrationTest( // Create a security manager for the controller const sm0Ctrlr = new SecurityManager({ - ownNodeId: controller.host.ownNodeId, + ownNodeId: controller.ownNodeId, networkKey: driver.options.securityKeys!.S0_Legacy!, nonceTimeout: 100000, }); @@ -67,11 +67,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof SecurityCCNonceGet) { const nonce = sm0Node.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, 8, ); const cc = new SecurityCCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, nonce, }); return { action: "sendCC", cc }; @@ -89,7 +89,7 @@ integrationTest( instanceof SecurityCCCommandsSupportedGet ) { const nonceGet = new SecurityCCNonceGet(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, }); await self.sendToController( createMockZWaveRequestFrame(nonceGet, { @@ -116,13 +116,14 @@ integrationTest( new SecurityCCCommandsSupportedReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, supportedCCs: [CommandClasses.Basic], controlledCCs: [], }, ); const cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, response, ); @@ -156,7 +157,7 @@ integrationTest( } const nonceGet = new SecurityCCNonceGet(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, }); await self.sendToController( createMockZWaveRequestFrame(nonceGet, { @@ -180,11 +181,12 @@ integrationTest( const receiverNonce = nonceReport.payload.nonce; const response = new BasicCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: queryCount, }); const cc = SecurityCC.encapsulate( self.host, + self.id, self.securityManagers.securityManager!, response, ); @@ -236,7 +238,7 @@ integrationTest( // Now send a Nonce Get from node 3, which must be answered immediately const nonceGet = new SecurityCCNonceGet(mockNode3.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, }); await mockNode3.sendToController( createMockZWaveRequestFrame(nonceGet, { diff --git a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts index ff95961456db..2dd4c0a3e4a4 100644 --- a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts @@ -85,10 +85,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -111,10 +112,11 @@ integrationTest( === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -139,7 +141,7 @@ integrationTest( let cc: CommandClass = new SupervisionCCReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.encapsulated.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, @@ -148,6 +150,7 @@ integrationTest( cc = Security2CC.encapsulate( self.host, cc, + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -171,9 +174,10 @@ integrationTest( const nodeToHost = Security2CC.encapsulate( mockNode.host, new BinarySwitchCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: true, }), + mockNode.id, mockNode.securityManagers, ); const p1 = mockNode.sendToController( @@ -258,10 +262,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -284,10 +289,11 @@ integrationTest( === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -315,9 +321,10 @@ integrationTest( const nodeToHost = Security2CC.encapsulate( mockNode.host, new BasicCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 99, }), + mockNode.id, mockNode.securityManagers, ); const p1 = mockNode.sendToController( @@ -395,10 +402,11 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof Security2CCNonceGet) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -421,10 +429,11 @@ integrationTest( === ZWaveErrorCodes.Security2CC_NoSPAN ) { const nonce = smNode.generateNonce( - controller.host.ownNodeId, + controller.ownNodeId, ); const cc = new Security2CCNonceReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, + ownNodeId: self.id, securityManagers: self.securityManagers, SOS: true, MOS: false, @@ -449,7 +458,7 @@ integrationTest( let cc: CommandClass = new SupervisionCCReport( self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.encapsulated.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, @@ -458,6 +467,7 @@ integrationTest( cc = Security2CC.encapsulate( self.host, cc, + self.id, self.securityManagers, ); return { action: "sendCC", cc }; @@ -486,7 +496,7 @@ integrationTest( let nodeToHost: CommandClass = new BinarySwitchCCReport( mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: true, }, ); @@ -494,13 +504,14 @@ integrationTest( mockNode.host, nodeToHost, driver.getNextSupervisionSessionId( - mockController.host.ownNodeId, + mockController.ownNodeId, ), false, ); nodeToHost = Security2CC.encapsulate( mockNode.host, nodeToHost, + mockNode.id, mockNode.securityManagers, ); @@ -530,7 +541,7 @@ integrationTest( // const nodeToHost = Security2CC.encapsulate( // mockNode.host, // new BasicCCReport(mockNode.host, { - // nodeId: mockController.host.ownNodeId, + // nodeId: mockController.ownNodeId, // currentValue: 99, // }), // ); diff --git a/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts b/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts index dcf1e2a39911..c42947f2cb4d 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts @@ -33,7 +33,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { const cc = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Fail, @@ -48,7 +48,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { const cc = new BinarySwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: false, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts b/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts index d58686b1606a..a61159b46ade 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts @@ -30,7 +30,7 @@ integrationTest("setValue without supervision: expect validation GET", { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { const cc = new BinarySwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: false, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts index b917f86bc453..5103ae634f6d 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts @@ -47,11 +47,11 @@ integrationTest( } let cc: CommandClass = new BasicCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: Math.round(Math.random() * 99), }); cc = new MultiChannelCCCommandEncapsulation(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, destination: receivedCC.endpointIndex, endpoint: receivedCC.destination as number, encapsulated: cc, diff --git a/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts index 8feb0bf5a816..b3abc96466ac 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts @@ -33,7 +33,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { const cc = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts index 576d25fe5c99..6c078727c23e 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts @@ -33,7 +33,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { const cc = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, @@ -55,7 +55,7 @@ integrationTest( ?.toMilliseconds() ) { const cc1 = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: true, status: SupervisionStatus.Working, @@ -63,7 +63,7 @@ integrationTest( }); const cc2 = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, @@ -119,7 +119,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultilevelSwitchCCGet) { const cc = new MultilevelSwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, targetValue: 88, currentValue: 88, }); diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts index 6dea3ea9684d..563d7da2cc0f 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts @@ -32,7 +32,7 @@ integrationTest( async handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { const cc = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: true, // <-- this is the important part status: SupervisionStatus.Success, diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts index 927a6d01ced7..1d433b7284de 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts @@ -44,7 +44,7 @@ integrationTest( async handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { let cc = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: true, status: SupervisionStatus.Working, @@ -59,7 +59,7 @@ integrationTest( await wait(2000); cc = new SupervisionCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, diff --git a/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts b/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts index fd296d90b871..82b7d41eacc6 100644 --- a/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts +++ b/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts @@ -38,7 +38,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { const cc = new BinarySwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: true, }); return { action: "sendCC", cc }; @@ -74,7 +74,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { const cc = new BinarySwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: true, }); return { action: "sendCC", cc }; diff --git a/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts b/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts index 4273ae3c9483..12847b6cedb2 100644 --- a/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts +++ b/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts @@ -45,7 +45,7 @@ integrationTest(`Basic Reports with the UNKNOWN state are correctly handled`, { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BasicCCGet) { const cc = new BasicCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, currentValue: 0, targetValue: 0, duration: new Duration(0, "seconds"), @@ -67,7 +67,7 @@ integrationTest(`Basic Reports with the UNKNOWN state are correctly handled`, { // Send an update with UNKNOWN state const cc = new BasicCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 254, targetValue: 254, duration: Duration.default(), @@ -114,7 +114,7 @@ integrationTest( // Send an initial state let cc = new MultilevelSwitchCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 0, targetValue: 0, }); @@ -132,7 +132,7 @@ integrationTest( // Send an update with UNKNOWN state cc = new MultilevelSwitchCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: 254, targetValue: 254, }); @@ -186,7 +186,7 @@ integrationTest( // Send an initial state let cc = new BinarySwitchCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: false, targetValue: false, duration: new Duration(0, "seconds"), @@ -205,7 +205,7 @@ integrationTest( // Send an update with UNKNOWN state cc = new BinarySwitchCCReport(mockNode.host, { - nodeId: mockController.host.ownNodeId, + nodeId: mockController.ownNodeId, currentValue: UNKNOWN_STATE, targetValue: UNKNOWN_STATE, duration: Duration.default(), diff --git a/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts b/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts index 340e6b19c18a..6bee1771cc01 100644 --- a/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts +++ b/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts @@ -50,7 +50,7 @@ integrationTest( { supportCheck: false }, ); - t.is(ids.ownNodeId, mockController.host.ownNodeId); + t.is(ids.ownNodeId, mockController.ownNodeId); }, }, ); diff --git a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts index ee69c1b4f7bc..967805cd7a4a 100644 --- a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts +++ b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts @@ -52,7 +52,7 @@ integrationTest( handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultilevelSwitchCCGet) { const cc = new MultilevelSwitchCCReport(self.host, { - nodeId: controller.host.ownNodeId, + nodeId: controller.ownNodeId, targetValue: 88, currentValue: 88, }); From c08f8dea2601ad554422fecd600bc3447d9fdfb8 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 14:09:42 +0200 Subject: [PATCH 32/60] refactor: move __internalIsMockNode to CCParsingContext --- packages/cc/src/cc/Security2CC.ts | 2 +- packages/host/src/ZWaveHost.ts | 3 +-- packages/host/src/mocks.ts | 5 +---- packages/testing/src/MockNode.ts | 1 - .../zwave-js/src/lib/controller/MockControllerBehaviors.ts | 1 + 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 1a7f1426d655..f66f6806e84c 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -1813,7 +1813,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { && prevSequenceNumber != undefined && this["_sequenceNumber"] === ((prevSequenceNumber + 1) & 0xff) // And in case of a mock-based test, do this only on the controller - && !this.host.__internalIsMockNode + && !ctx.__internalIsMockNode ) { const nonce = spanState.currentSPAN.nonce; spanState.currentSPAN = undefined; diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index c2bbf99d9f41..a525c9b7c596 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -44,6 +44,7 @@ export interface CCParsingContext extends Readonly, GetDeviceConfig, HostIDs { sourceNodeId: number; + __internalIsMockNode?: boolean; /** If known, the frame type of the containing message */ frameType?: FrameType; @@ -112,8 +113,6 @@ export interface ZWaveHost { nodeId: number, endpointIndex?: number, ): boolean; - - __internalIsMockNode?: boolean; } /** Host application abstractions that provide support for reading and writing values to a database */ diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 765c493a8a65..368c8a877c51 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -30,10 +30,7 @@ export type BaseTestNode = export type TestingHost< TNode extends BaseTestNode, > = - & Omit< - ZWaveApplicationHost, - "__internalIsMockNode" - > + & ZWaveApplicationHost & { setNode(nodeId: number, node: TNode): void; }; diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index d7bc77c83284..57d2d4cf0263 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -115,7 +115,6 @@ export class MockNode { // A node's host is a bit more specialized than the controller's host. this.host = { ...this.controller.host, - __internalIsMockNode: true, // // Mimic the behavior of ZWaveNode, but for arbitrary node IDs }; diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index ecd8219717be..5fea5577cd17 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -99,6 +99,7 @@ function createLazySendDataPayload( origin: MessageOrigin.Host, context: { sourceNodeId: node.id, + __internalIsMockNode: true, ...node.encodingContext, ...node.securityManagers, }, From 99cd2ba14e465fd6f7679d3c930a7ea063536970 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 14:36:44 +0200 Subject: [PATCH 33/60] refactor: get rid of CC.knownVersion --- packages/cc/src/lib/CommandClass.ts | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index cb57cebe9812..585a8ecf1b8f 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -218,12 +218,6 @@ export class CommandClass implements CCId { this.nodeId, this.endpointIndex, ); - // But remember which version the node supports - this._knownVersion = this.host.getSupportedCCVersion( - this.ccId, - this.nodeId, - this.endpointIndex, - ); } catch (e) { if ( isZWaveError(e) @@ -231,7 +225,6 @@ export class CommandClass implements CCId { ) { // Someone tried to create a CC that is not implemented. Just set all versions to 0. this.version = 0; - this._knownVersion = 0; } else { throw e; } @@ -250,7 +243,6 @@ export class CommandClass implements CCId { // For multicast and broadcast CCs, we just use the highest implemented version to serialize // Older nodes will ignore the additional fields this.version = getImplementedVersion(this.ccId); - this._knownVersion = this.version; } } @@ -273,9 +265,6 @@ export class CommandClass implements CCId { // Work around https://github.com/Microsoft/TypeScript/issues/27555 public version!: number; - /** The version of the CC the node has reported support for */ - private _knownVersion!: number; - /** Which endpoint of the node this CC belongs to. 0 for the root device. */ public endpointIndex: number; @@ -880,6 +869,20 @@ export class CommandClass implements CCId { ...valueDB.getAllMetadata(this.ccId), ]; + // To determine which value IDs to expose, we need to know the CC version + // that we're doing this for + const supportedVersion = typeof this.nodeId === "number" + && this.nodeId !== NODE_ID_BROADCAST + && this.nodeId !== NODE_ID_BROADCAST_LR + // On singlecast CCs, use the version the node reported support for, + ? applHost.getSupportedCCVersion( + this.ccId, + this.nodeId, + this.endpointIndex, + ) + // on multicast/broadcast, use the highest version we implement + : getImplementedVersion(this.ccId); + // ...or which are statically defined using @ccValues(...) for (const value of Object.values(getCCValues(this) ?? {})) { // Skip dynamic CC values - they need a specific subclass instance to be evaluated @@ -888,7 +891,7 @@ export class CommandClass implements CCId { // Skip those values that are only supported in higher versions of the CC if ( value.options.minVersion != undefined - && value.options.minVersion > this._knownVersion + && value.options.minVersion > supportedVersion ) { continue; } @@ -955,6 +958,15 @@ export class CommandClass implements CCId { return false; } + // To determine which value IDs to expose, we need to know the CC version + // that we're doing this for + const supportedVersion = applHost.getSupportedCCVersion( + this.ccId, + // Values are only persisted for singlecast, so we know nodeId is a number + this.nodeId as number, + this.endpointIndex, + ); + // Get all properties of this CC which are annotated with a @ccValue decorator and store them. for (const [prop, _value] of getCCValueProperties(this)) { // Evaluate dynamic CC values first @@ -963,7 +975,7 @@ export class CommandClass implements CCId { // Skip those values that are only supported in higher versions of the CC if ( value.options.minVersion != undefined - && value.options.minVersion > this.version + && value.options.minVersion > supportedVersion ) { continue; } @@ -977,7 +989,7 @@ export class CommandClass implements CCId { && (sourceValue != undefined // ... or if we know which CC version the node supports // and the value may be automatically created - || (this._knownVersion >= value.options.minVersion + || (supportedVersion >= value.options.minVersion && this.shouldAutoCreateValue(applHost, value))); if (createMetadata && !valueDB.hasMetadata(valueId)) { From d902546a5e301c7087b12f9cfe7cc7dc753e8f7a Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 14 Oct 2024 21:31:26 +0200 Subject: [PATCH 34/60] refactor: remove usages of this.version in CC constructors --- packages/cc/src/cc/AssociationCC.ts | 31 ++-- packages/cc/src/cc/CentralSceneCC.ts | 9 +- packages/cc/src/cc/ColorSwitchCC.ts | 2 +- packages/cc/src/cc/ConfigurationCC.ts | 38 +++-- packages/cc/src/cc/DoorLockCC.ts | 4 +- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 60 ++++---- packages/cc/src/cc/IndicatorCC.ts | 38 ++--- .../cc/src/cc/MultiChannelAssociationCC.ts | 21 +-- packages/cc/src/cc/MultiChannelCC.ts | 2 +- packages/cc/src/cc/MultilevelSwitchCC.ts | 2 +- packages/cc/src/cc/NotificationCC.ts | 58 +++----- packages/cc/src/cc/ThermostatFanModeCC.ts | 5 +- packages/cc/src/cc/ThermostatModeCC.ts | 16 +-- packages/cc/src/cc/ThermostatSetpointCC.ts | 132 +++--------------- packages/cc/src/cc/UserCodeCC.ts | 5 +- packages/cc/src/cc/VersionCC.ts | 3 +- packages/cc/src/cc/WakeUpCC.ts | 4 +- packages/cc/src/lib/_Types.ts | 1 + 18 files changed, 145 insertions(+), 286 deletions(-) diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 827c8c25e60f..b9b0f111f949 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -207,6 +207,21 @@ export class AssociationCCAPI extends PhysicalCCAPI { AssociationCommand.Remove, ); + // Validate options + if (!options.groupId) { + if (this.version === 1) { + throw new ZWaveError( + `Node ${this.endpoint.nodeId} only supports AssociationCC V1 which requires the group Id to be set`, + ZWaveErrorCodes.Argument_Invalid, + ); + } + } else if (options.groupId < 0) { + throw new ZWaveError( + "The group id must be positive!", + ZWaveErrorCodes.Argument_Invalid, + ); + } + const cc = new AssociationCCRemove(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, @@ -566,22 +581,6 @@ export class AssociationCCRemove extends AssociationCC { } this.nodeIds = [...this.payload.subarray(1)]; } else { - // Validate options - if (!options.groupId) { - if (this.version === 1) { - throw new ZWaveError( - `Node ${this - .nodeId as number} only supports AssociationCC V1 which requires the group Id to be set`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - } else if (options.groupId < 0) { - throw new ZWaveError( - "The group id must be positive!", - ZWaveErrorCodes.Argument_Invalid, - ); - } - // When removing associations, we allow invalid node IDs. // See GH#3606 - it is possible that those exist. this.groupId = options.groupId; diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 5bf263d50f5d..707a09bd6ee3 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -312,10 +312,7 @@ export class CentralSceneCCNotification extends CentralSceneCC { this.sequenceNumber = this.payload[0]; this.keyAttribute = this.payload[1] & 0b111; this.sceneNumber = this.payload[2]; - if ( - this.keyAttribute === CentralSceneKeys.KeyHeldDown - && this.version >= 3 - ) { + if (this.keyAttribute === CentralSceneKeys.KeyHeldDown) { // A receiving node MUST ignore this field if the command is not // carrying the Key Held Down key attribute. this.slowRefresh = !!(this.payload[1] & 0b1000_0000); @@ -370,9 +367,7 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC { validatePayload(this.payload.length >= 2); this.sceneCount = this.payload[0]; - if (this.version >= 3) { - this.supportsSlowRefresh = !!(this.payload[1] & 0b1000_0000); - } + this.supportsSlowRefresh = !!(this.payload[1] & 0b1000_0000); const bitMaskBytes = (this.payload[1] & 0b110) >>> 1; const identicalKeyAttributes = !!(this.payload[1] & 0b1); const numEntries = identicalKeyAttributes ? 1 : this.sceneCount; diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index a2da869525b0..03d83c1a0edf 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -760,7 +760,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { this.colorComponent = this.payload[0]; this.currentValue = this.payload[1]; - if (this.version >= 3 && this.payload.length >= 4) { + if (this.payload.length >= 4) { this.targetValue = this.payload[2]; this.duration = Duration.parseReport(this.payload[3]); } diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index e87db14c05bd..c34262e4dd81 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -816,6 +816,17 @@ export class ConfigurationCCAPI extends CCAPI { return this.resetBulk([parameter]); } + // According to SDS14223 this flag SHOULD NOT be set + // Because we don't want to test the behavior, we enforce that it MUST not be set + // on legacy nodes + if (this.version <= 3) { + throw new ZWaveError( + `Resetting configuration parameters to default MUST not be done on nodes implementing ConfigurationCC V3 or below!`, + ZWaveErrorCodes + .ConfigurationCC_NoResetToDefaultOnLegacyDevices, + ); + } + this.assertSupportsCommand( ConfigurationCommand, ConfigurationCommand.Set, @@ -1862,16 +1873,6 @@ export class ConfigurationCCSet extends ConfigurationCC { ); } else { this.parameter = options.parameter; - // According to SDS14223 this flag SHOULD NOT be set - // Because we don't want to test the behavior, we enforce that it MUST not be set - // on legacy nodes - if (options.resetToDefault && this.version <= 3) { - throw new ZWaveError( - `The resetToDefault flag MUST not be used on nodes implementing ConfigurationCC V3 or less!`, - ZWaveErrorCodes - .ConfigurationCC_NoResetToDefaultOnLegacyDevices, - ); - } this.resetToDefault = !!options.resetToDefault; if (!options.resetToDefault) { // TODO: Default to the stored value size @@ -2672,18 +2673,13 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { this.valueFormat, ); } - if (this.version < 4) { - // Read the last 2 bytes to work around nodes not omitting min/max value when their size is 0 - this.nextParameter = this.payload.readUInt16BE( - this.payload.length - 2, - ); - } else { - this.nextParameter = this.payload.readUInt16BE( - nextParameterOffset, - ); - // Ensure the payload contains a byte for the 2nd option flags - validatePayload(this.payload.length >= nextParameterOffset + 3); + this.nextParameter = this.payload.readUInt16BE( + nextParameterOffset, + ); + + if (this.payload.length >= nextParameterOffset + 3) { + // V4 adds an options byte after the next parameter and two bits in byte 2 const options1 = this.payload[2]; const options2 = this.payload[3 + 3 * this.valueSize + 2]; this.altersCapabilities = !!(options1 & 0b1000_0000); diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 2a9df7b994f5..35d58afc1c33 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -903,7 +903,7 @@ export class DoorLockCCOperationReport extends DoorLockCC { this.lockTimeout = lockTimeoutSeconds + lockTimeoutMinutes * 60; } - if (this.version >= 3 && this.payload.length >= 7) { + if (this.payload.length >= 7) { this.targetMode = this.payload[5]; this.duration = Duration.parseReport(this.payload[6]); } @@ -1042,7 +1042,7 @@ export class DoorLockCCConfigurationReport extends DoorLockCC { + lockTimeoutMinutes * 60; } } - if (this.version >= 4 && this.payload.length >= 5) { + if (this.payload.length >= 5) { this.autoRelockTime = this.payload.readUInt16BE(4); this.holdAndReleaseTime = this.payload.readUInt16BE(6); diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index c3fd2df7fc3c..33a8c498ca39 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -367,7 +367,8 @@ export class FirmwareUpdateMetaDataCCMetaDataReport this.firmwareUpgradable = this.payload[6] === 0xff || this.payload[6] == undefined; - if (this.version >= 3 && this.payload.length >= 10) { + if (this.payload.length >= 10) { + // V3+ this.maxFragmentSize = this.payload.readUInt16BE(8); // Read variable length list of additional firmwares const numAdditionalFirmwares = this.payload[7]; @@ -383,24 +384,22 @@ export class FirmwareUpdateMetaDataCCMetaDataReport this.additionalFirmwareIDs = additionalFirmwareIDs; // Read hardware version (if it exists) let offset = 10 + 2 * numAdditionalFirmwares; - if (this.version >= 5 && this.payload.length >= offset + 1) { + if (this.payload.length >= offset + 1) { + // V5+ this.hardwareVersion = this.payload[offset]; offset++; - if ( - this.version >= 6 && this.payload.length >= offset + 1 - ) { + if (this.payload.length >= offset + 1) { + // V6+ const capabilities = this.payload[offset]; offset++; this.continuesToFunction = !!(capabilities & 0b1); - if (this.version >= 7) { - this.supportsActivation = !!(capabilities & 0b10); - } - if (this.version >= 8) { - this.supportsResuming = !!(capabilities & 0b1000); - this.supportsNonSecureTransfer = - !!(capabilities & 0b100); - } + // V7+ + this.supportsActivation = !!(capabilities & 0b10); + // V8+ + this.supportsResuming = !!(capabilities & 0b1000); + this.supportsNonSecureTransfer = + !!(capabilities & 0b100); } } } @@ -612,31 +611,19 @@ export class FirmwareUpdateMetaDataCCRequestGet public nonSecureTransfer?: boolean; public serialize(ctx: CCEncodingContext): Buffer { - const isV3 = this.version >= 3 - && this.firmwareTarget != undefined - && this.fragmentSize != undefined; - const isV4 = isV3 && this.version >= 4; - const isV5 = isV4 - && this.version >= 5 - && this.hardwareVersion != undefined; - this.payload = Buffer.allocUnsafe( - 6 + (isV3 ? 3 : 0) + (isV4 ? 1 : 0) + (isV5 ? 1 : 0), - ); + this.payload = Buffer.alloc(11, 0); this.payload.writeUInt16BE(this.manufacturerId, 0); this.payload.writeUInt16BE(this.firmwareId, 2); this.payload.writeUInt16BE(this.checksum, 4); - if (isV3) { - this.payload[6] = this.firmwareTarget!; - this.payload.writeUInt16BE(this.fragmentSize!, 7); - } - if (isV4) { - this.payload[9] = (this.activation ? 0b1 : 0) - | (this.nonSecureTransfer ? 0b10 : 0) - | (this.resume ? 0b100 : 0); - } - if (isV5) { - this.payload[10] = this.hardwareVersion!; - } + this.payload[6] = this.firmwareTarget ?? 0; + // 32 seems like a reasonable default fragment size, + // but it should be specified anyways + this.payload.writeUInt16BE(this.fragmentSize ?? 32, 7); + this.payload[9] = (this.activation ? 0b1 : 0) + | (this.nonSecureTransfer ? 0b10 : 0) + | (this.resume ? 0b100 : 0); + this.payload[10] = this.hardwareVersion ?? 0x00; + return super.serialize(ctx); } @@ -821,7 +808,8 @@ export class FirmwareUpdateMetaDataCCActivationReport this.checksum = this.payload.readUInt16BE(4); this.firmwareTarget = this.payload[6]; this.activationStatus = this.payload[7]; - if (this.version >= 5 && this.payload.length >= 9) { + if (this.payload.length >= 9) { + // V5+ this.hardwareVersion = this.payload[8]; } } diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 20dbb235f188..09b045ffe24b 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -379,6 +379,23 @@ export class IndicatorCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(IndicatorCommand, IndicatorCommand.Set); + if (this.version === 1 && typeof value !== "number") { + throw new ZWaveError( + `Node ${this.endpoint + .nodeId as number} only supports IndicatorCC V1 which requires a single value to be set`, + ZWaveErrorCodes.Argument_Invalid, + ); + } else if ( + this.version >= 2 + && isArray(value) + && value.length > MAX_INDICATOR_OBJECTS + ) { + throw new ZWaveError( + `Only ${MAX_INDICATOR_OBJECTS} indicator values can be set at a time!`, + ZWaveErrorCodes.Argument_Invalid, + ); + } + const cc = new IndicatorCCSet(this.applHost, { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, @@ -913,27 +930,10 @@ export class IndicatorCCSet extends IndicatorCC { } } } else { - if (this.version === 1) { - if (!("value" in options)) { - throw new ZWaveError( - `Node ${this - .nodeId as number} only supports IndicatorCC V1 which requires a single value to be set`, - ZWaveErrorCodes.Argument_Invalid, - ); - } + if ("value" in options) { this.indicator0Value = options.value; } else { - if ("value" in options) { - this.indicator0Value = options.value; - } else { - if (options.values.length > MAX_INDICATOR_OBJECTS) { - throw new ZWaveError( - `Only ${MAX_INDICATOR_OBJECTS} indicator values can be set at a time!`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - this.values = options.values; - } + this.values = options.values; } } } diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index ca61eab9cb3e..87ece3f2d58e 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -339,6 +339,11 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { // TODO: evaluate intermediate supervision results await this.applHost.sendCommand(cc, this.commandOptions); } + } else if (options.groupId && options.groupId < 0) { + throw new ZWaveError( + "The group id must not be negative!", + ZWaveErrorCodes.Argument_Invalid, + ); } else { const cc = new MultiChannelAssociationCCRemove(this.applHost, { nodeId: this.endpoint.nodeId, @@ -717,22 +722,6 @@ export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { this.payload.subarray(1), )); } else { - // Validate options - if (!options.groupId) { - if (this.version === 1) { - throw new ZWaveError( - `Node ${this - .nodeId as number} only supports MultiChannelAssociationCC V1 which requires the group Id to be set`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - } else if (options.groupId < 0) { - throw new ZWaveError( - "The group id must be positive!", - ZWaveErrorCodes.Argument_Invalid, - ); - } - // When removing associations, we allow invalid node IDs. // See GH#3606 - it is possible that those exist. this.groupId = options.groupId; diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 06e1f295643a..539a63061020 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -835,7 +835,7 @@ export class MultiChannelCCEndPointReport extends MultiChannelCC { this.countIsDynamic = !!(this.payload[0] & 0b10000000); this.identicalCapabilities = !!(this.payload[0] & 0b01000000); this.individualCount = this.payload[1] & 0b01111111; - if (this.version >= 4 && this.payload.length >= 3) { + if (this.payload.length >= 3) { this.aggregatedCount = this.payload[2] & 0b01111111; } } else { diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index a1d7344a3648..f3de3512c383 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -705,7 +705,7 @@ export class MultilevelSwitchCCReport extends MultilevelSwitchCC { this.payload[0] === 0xff ? 99 : parseMaybeNumber(this.payload[0]); - if (this.version >= 4 && this.payload.length >= 3) { + if (this.payload.length >= 3) { this.targetValue = parseMaybeNumber(this.payload[1]); this.duration = Duration.parseReport(this.payload[2]); } diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index cef6211e8f46..f84ed4e4169d 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -329,7 +329,6 @@ export class NotificationCCAPI extends PhysicalCCAPI { "notificationStatus", "notificationEvent", "alarmLevel", - "zensorNetSourceNodeId", "eventParameters", "sequenceNumber", ]); @@ -980,13 +979,8 @@ export class NotificationCCReport extends NotificationCC { validatePayload(this.payload.length >= 2); this.alarmType = this.payload[0]; this.alarmLevel = this.payload[1]; - // V2..V3, reserved in V4+ - if ( - (this.version === 2 || this.version === 3) - && this.payload.length >= 3 - ) { - this.zensorNetSourceNodeId = this.payload[2]; - } + // Byte 2 used to be zensorNetSourceNodeId in V2 and V3, but we don't care about that + // V2+ requires the alarm bytes to be zero. Manufacturers don't care though, so we don't enforce that. // Don't use the version to decide because we might discard notifications // before the interview is complete @@ -1017,8 +1011,6 @@ export class NotificationCCReport extends NotificationCC { if ("alarmType" in options) { this.alarmType = options.alarmType; this.alarmLevel = options.alarmLevel; - // Send a V1 command - this.version = 1; } else { this.notificationType = options.notificationType; this.notificationStatus = true; @@ -1133,7 +1125,6 @@ export class NotificationCCReport extends NotificationCC { public notificationStatus: boolean | number | undefined; public notificationEvent: number | undefined; - public readonly zensorNetSourceNodeId: number | undefined; public eventParameters: | Buffer | Duration @@ -1187,9 +1178,6 @@ export class NotificationCCReport extends NotificationCC { }; } } - if (this.zensorNetSourceNodeId) { - message["zensor net source node id"] = this.zensorNetSourceNodeId; - } if (this.sequenceNumber != undefined) { message["sequence number"] = this.sequenceNumber; } @@ -1380,21 +1368,12 @@ export class NotificationCCReport extends NotificationCC { } public serialize(ctx: CCEncodingContext): Buffer { - if (this.version === 1) { - if (this.alarmLevel == undefined || this.alarmType == undefined) { - throw new ZWaveError( - `Notification CC V1 (Alarm CC) reports requires the alarm type and level to be set!`, - ZWaveErrorCodes.Argument_Invalid, - ); - } - this.payload = Buffer.from([this.alarmType, this.alarmLevel]); - } else { + if (this.notificationType != undefined) { if ( - this.notificationType == undefined - || this.notificationEvent == undefined + this.notificationEvent == undefined ) { throw new ZWaveError( - `Notification CC reports requires the notification type and event to be set!`, + `Notification CC reports requires the notification event to be set!`, ZWaveErrorCodes.Argument_Invalid, ); } else if ( @@ -1406,6 +1385,7 @@ export class NotificationCCReport extends NotificationCC { ZWaveErrorCodes.Argument_Invalid, ); } + const controlByte = (this.sequenceNumber != undefined ? 0b1000_0000 : 0) | ((this.eventParameters?.length ?? 0) & 0b11111); @@ -1430,7 +1410,13 @@ export class NotificationCCReport extends NotificationCC { Buffer.from([this.sequenceNumber]), ]); } + } else { + this.payload = Buffer.from([ + this.alarmType ?? 0x00, + this.alarmLevel ?? 0x00, + ]); } + return super.serialize(ctx); } } @@ -1482,18 +1468,14 @@ export class NotificationCCGet extends NotificationCC { public notificationEvent: number | undefined; public serialize(ctx: CCEncodingContext): Buffer { - const payload: number[] = [this.alarmType || 0]; - if (this.version >= 2 && this.notificationType != undefined) { - payload.push(this.notificationType); - if (this.version >= 3) { - payload.push( - this.notificationType === 0xff - ? 0x00 - : this.notificationEvent || 0, - ); - } - } - this.payload = Buffer.from(payload); + const notificationEvent = this.notificationEvent === 0xff + ? 0x00 + : this.notificationEvent; + this.payload = Buffer.from([ + this.alarmType ?? 0x00, + this.notificationType ?? 0xff, + notificationEvent ?? 0x00, + ]); return super.serialize(ctx); } diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index 2840aed7fce6..ddd4753aa17c 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -395,9 +395,8 @@ export class ThermostatFanModeCCReport extends ThermostatFanModeCC { validatePayload(this.payload.length >= 1); this.mode = this.payload[0] & 0b1111; - if (this.version >= 3) { - this.off = !!(this.payload[0] & 0b1000_0000); - } + // V3+ + this.off = !!(this.payload[0] & 0b1000_0000); } @ccValue(ThermostatFanModeCCValues.fanMode) diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index 129d24ff0d24..636d4f576122 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -418,18 +418,16 @@ export class ThermostatModeCCReport extends ThermostatModeCC { validatePayload(this.payload.length >= 1); this.mode = this.payload[0] & 0b11111; - if (this.version >= 3) { - const manufacturerDataLength = this.payload[0] >>> 5; - + // V3+ + const manufacturerDataLength = this.payload[0] >>> 5; + if (manufacturerDataLength > 0) { validatePayload( this.payload.length >= 1 + manufacturerDataLength, ); - if (manufacturerDataLength) { - this.manufacturerData = this.payload.subarray( - 1, - 1 + manufacturerDataLength, - ); - } + this.manufacturerData = this.payload.subarray( + 1, + 1 + manufacturerDataLength, + ); } } else { this.mode = options.mode; diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 732ccd95dbd3..1bca7409b813 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -88,10 +88,6 @@ export const ThermostatSetpointCCValues = Object.freeze({ ...V.staticProperty("supportedSetpointTypes", undefined, { internal: true, }), - - ...V.staticProperty("setpointTypesInterpretation", undefined, { - internal: true, - }), }), ...V.defineDynamicCCValues(CommandClasses["Thermostat Setpoint"], { @@ -365,62 +361,25 @@ export class ThermostatSetpointCC extends CommandClass { }); if (this.version <= 2) { - let setpointTypes: ThermostatSetpointType[]; - let interpretation: "A" | "B" | undefined; - // Whether our tests changed the assumed bitmask interpretation - let interpretationChanged = false; - - // Query the supported setpoint types - applHost.controllerLog.logNode(node.id, { - endpoint: this.endpointIndex, - message: "retrieving supported setpoint types...", - direction: "outbound", - }); - const resp = await api.getSupportedSetpointTypes(); - if (!resp) { - applHost.controllerLog.logNode(node.id, { - endpoint: this.endpointIndex, - message: - "Querying supported setpoint types timed out, skipping interview...", - level: "warn", - }); - return; - } - setpointTypes = [...resp]; - interpretation = undefined; // we don't know yet which interpretation the device uses - - // If necessary, test which interpretation the device follows - - // Assume interpretation B - // --> If setpoints 3,4,5 or 6 are supported, the assumption is wrong ==> A - function switchToInterpretationA(): void { - setpointTypes = setpointTypes.map( - (i) => thermostatSetpointTypeMap[i], - ); - interpretation = "A"; - interpretationChanged = true; - } - - if ([3, 4, 5, 6].some((type) => setpointTypes.includes(type))) { - applHost.controllerLog.logNode(node.id, { - endpoint: this.endpointIndex, - message: "uses Thermostat Setpoint bitmap interpretation A", - direction: "none", - }); - switchToInterpretationA(); - } else { - applHost.controllerLog.logNode(node.id, { - endpoint: this.endpointIndex, - message: - "Thermostat Setpoint bitmap interpretation is unknown, assuming B for now", - direction: "none", - }); - } + // It has been found that early implementations of this Command Class applied two non-interoperable + // interpretations of the bit mask advertising the support for specific Setpoint Types in the Thermostat + // Setpoint Supported Report Command. + // A controlling node SHOULD determine the supported Setpoint Types of a version 1 and version 2 + // supporting node by sending one Thermostat Setpoint Get Command at a time while incrementing + // the requested Setpoint Type. + // If the same Setpoint Type is advertised in the returned Thermostat Setpoint Report Command, the + // controlling node MUST conclude that the actual Setpoint Type is supported. + // If the Setpoint Type 0x00 (type N/A) is advertised in the returned Thermostat Setpoint Report + // Command, the controlling node MUST conclude that the actual Setpoint Type is not supported. // Now scan all endpoints. Each type we received a value for gets marked as supported const supportedSetpointTypes: ThermostatSetpointType[] = []; - for (let i = 0; i < setpointTypes.length; i++) { - const type = setpointTypes[i]; + for ( + let type: ThermostatSetpointType = + ThermostatSetpointType.Heating; + type <= ThermostatSetpointType["Full Power"]; + type++ + ) { const setpointName = getEnumMemberName( ThermostatSetpointType, type, @@ -444,21 +403,9 @@ export class ThermostatSetpointCC extends CommandClass { `received current value of setpoint ${setpointName}: ${setpoint.value} ${ setpoint.scale.unit ?? "" }`; - } else if (!interpretation) { - // The setpoint type is not supported, switch to interpretation A - applHost.controllerLog.logNode(node.id, { - endpoint: this.endpointIndex, - message: - `the setpoint type ${type} is unsupported, switching to interpretation A`, - direction: "none", - }); - switchToInterpretationA(); - // retry the current type and scan the remaining types as A - i--; - continue; } else { // We're sure about the interpretation - this should not happen - logMessage = `Setpoint ${setpointName} is not supported`; + logMessage = `setpoint ${setpointName} is not supported`; } applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, @@ -467,30 +414,12 @@ export class ThermostatSetpointCC extends CommandClass { }); } - // If we made an assumption and did not switch to interpretation A, - // the device adheres to interpretation B - if (!interpretation && !interpretationChanged) { - // our assumption about interpretation B was correct - interpretation = "B"; - interpretationChanged = true; - } - - // Remember which setpoint types are actually supported, so we don't - // need to do this guesswork again + // Remember which setpoint types are actually supported this.setValue( applHost, ThermostatSetpointCCValues.supportedSetpointTypes, supportedSetpointTypes, ); - - // Also save the bitmap interpretation if we know it now - if (interpretationChanged) { - this.setValue( - applHost, - ThermostatSetpointCCValues.setpointTypesInterpretation, - interpretation, - ); - } } else { // Versions >= 3 adhere to bitmap interpretation A, so we can rely on getSupportedSetpointTypes @@ -985,26 +914,11 @@ export class ThermostatSetpointCCSupportedReport extends ThermostatSetpointCC { bitMask, ThermostatSetpointType["N/A"], ); - if (this.version >= 3) { - // Interpretation A - this.supportedSetpointTypes = supported.map( - (i) => thermostatSetpointTypeMap[i], - ); - } else { - // It is unknown which interpretation the device complies to. - // This must be tested during the interview - this.supportedSetpointTypes = supported; - } - // TODO: - // Some devices skip the gaps in the ThermostatSetpointType (Interpretation A), some don't (Interpretation B) - // Devices with V3+ must comply with Interpretation A - // It is RECOMMENDED that a controlling node determines supported Setpoint Types - // by sending one Thermostat Setpoint Get Command at a time while incrementing - // the requested Setpoint Type. If the same Setpoint Type is advertised in the - // resulting Thermostat Setpoint Report Command, the controlling node MAY conclude - // that the actual Setpoint Type is supported. If the Setpoint Type 0x00 (type N/A) - // is advertised in the resulting Thermostat Setpoint Report Command, the controlling - // node MUST conclude that the actual Setpoint Type is not supported. + // We use this command only when we are sure that bitmask interpretation A is used + // FIXME: Figure out if we can do this without the CC version + this.supportedSetpointTypes = supported.map( + (i) => thermostatSetpointTypeMap[i], + ); } else { if (options.supportedSetpointTypes.length === 0) { throw new ZWaveError( diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 7a1302acbd7f..181777d4cdad 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -1354,10 +1354,7 @@ export class UserCodeCCReport extends UserCodeCC const userCodeString = userCodeBuffer.toString("utf8"); if (isPrintableASCII(userCodeString)) { this.userCode = userCodeString; - } else if ( - this.version === 1 - && isPrintableASCIIWithWhitespace(userCodeString) - ) { + } else if (isPrintableASCIIWithWhitespace(userCodeString)) { // Ignore leading and trailing whitespace in V1 reports if the rest is ASCII this.userCode = userCodeString.trim(); } else { diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index eed3499d5bbc..1930c0301c3c 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -678,7 +678,8 @@ export class VersionCCReport extends VersionCC { this.libraryType = this.payload[0]; this.protocolVersion = `${this.payload[1]}.${this.payload[2]}`; this.firmwareVersions = [`${this.payload[3]}.${this.payload[4]}`]; - if (this.version >= 2 && this.payload.length >= 7) { + if (this.payload.length >= 7) { + // V2+ this.hardwareVersion = this.payload[5]; const additionalFirmwares = this.payload[6]; validatePayload( diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 1b58e947b19e..a022b669dc1c 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -459,8 +459,8 @@ export class WakeUpCCIntervalCapabilitiesReport extends WakeUpCC { this.defaultWakeUpInterval = this.payload.readUIntBE(6, 3); this.wakeUpIntervalSteps = this.payload.readUIntBE(9, 3); - // Get 'Wake Up on Demand Support' if node supports V3 and sends 13th byte - if (this.version >= 3 && this.payload.length >= 13) { + if (this.payload.length >= 13) { + // V3+ this.wakeUpOnDemandSupported = !!(this.payload[12] & 0b1); } else { this.wakeUpOnDemandSupported = false; diff --git a/packages/cc/src/lib/_Types.ts b/packages/cc/src/lib/_Types.ts index 14a1e68e75eb..870ed6749a97 100644 --- a/packages/cc/src/lib/_Types.ts +++ b/packages/cc/src/lib/_Types.ts @@ -1512,6 +1512,7 @@ export enum ThermostatSetpointType { "Away Heating" = 0x0d, // CC v2 "Away Cooling" = 0x0e, // CC v3 "Full Power" = 0x0f, // CC v3 + // Update the interview procecure when adding new types } export interface ThermostatSetpointValue { From 2b920ef328d481da676ce1ba66a838696bf34913 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 15 Oct 2024 08:58:50 +0200 Subject: [PATCH 35/60] fix: tests --- packages/cc/src/lib/CommandClass.ts | 3 ++- .../lib/test/cc/ThermostatFanModeCC.test.ts | 25 +------------------ .../handleMultiCommandPayload/7e570001.jsonl | 1 + .../createCCValuesUsingKnownVersion.test.ts | 2 +- 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 585a8ecf1b8f..fcbabee6748a 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -965,7 +965,8 @@ export class CommandClass implements CCId { // Values are only persisted for singlecast, so we know nodeId is a number this.nodeId as number, this.endpointIndex, - ); + // If the version isn't known yet, limit the created values to V1 + ) || 1; // Get all properties of this CC which are annotated with a @ccValue decorator and store them. for (const [prop, _value] of getCCValueProperties(this)) { diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts index 8e30ed351239..f03eac134009 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts @@ -60,30 +60,7 @@ test("the Set command should serialize correctly (off = true)", (t) => { t.deepEqual(cc.serialize({} as any), expected); }); -test("the Report command (v1-v2) should be deserialized correctly", (t) => { - const ccData = buildCCBuffer( - Buffer.from([ - ThermostatFanModeCommand.Report, // CC Command - ThermostatFanMode["Auto low"], // current value - ]), - ); - const cc = new ThermostatFanModeCCReport( - { - ...host, - getSafeCCVersion: () => 1, - }, - { - nodeId: 1, - data: ccData, - context: {} as any, - }, - ); - - t.is(cc.mode, ThermostatFanMode["Auto low"]); - t.is(cc.off, undefined); -}); - -test("the Report command (v3-v5) should be deserialized correctly", (t) => { +test("the Report command should be deserialized correctly", (t) => { const ccData = buildCCBuffer( Buffer.from([ ThermostatFanModeCommand.Report, // CC Command diff --git a/packages/zwave-js/src/lib/test/compliance/fixtures/handleMultiCommandPayload/7e570001.jsonl b/packages/zwave-js/src/lib/test/compliance/fixtures/handleMultiCommandPayload/7e570001.jsonl index 4423f128d324..65ac64955c4e 100644 --- a/packages/zwave-js/src/lib/test/compliance/fixtures/handleMultiCommandPayload/7e570001.jsonl +++ b/packages/zwave-js/src/lib/test/compliance/fixtures/handleMultiCommandPayload/7e570001.jsonl @@ -17,3 +17,4 @@ // Define some base functionality for node 2 so we can skip the interview of these CCs {"k":"node.2.endpoint.0.commandClass.0x5e","v":{"isSupported":true,"isControlled":false,"secure":false,"version":2}} +{"k":"node.2.endpoint.0.commandClass.0x2b","v":{"isSupported":false,"isControlled":true,"secure":false,"version":1}} diff --git a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts index 4a5d62822cb4..195e2344e2b5 100644 --- a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts +++ b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts @@ -11,7 +11,7 @@ import { integrationTest } from "../integrationTestSuite"; // values, which includes some the device does not actually support integrationTest("CC values are created using the known CC version", { - // debug: true, + debug: true, provisioningDirectory: path.join( __dirname, From 83fddb7e08c328a2eaf5f2899bdb2dc6ca394873 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 15 Oct 2024 13:42:33 +0200 Subject: [PATCH 36/60] refactor: remove version property from CC instances --- packages/cc/src/cc/BasicCC.ts | 4 +- packages/cc/src/cc/BatteryCC.ts | 4 +- packages/cc/src/cc/BinarySensorCC.ts | 4 +- packages/cc/src/cc/BinarySwitchCC.ts | 4 +- packages/cc/src/cc/CentralSceneCC.ts | 2 +- packages/cc/src/cc/ColorSwitchCC.ts | 7 +- packages/cc/src/cc/ConfigurationCC.ts | 9 ++- packages/cc/src/cc/DoorLockCC.ts | 4 +- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 13 ++-- packages/cc/src/cc/IndicatorCC.ts | 6 +- packages/cc/src/cc/MeterCC.ts | 22 +++--- packages/cc/src/cc/MultiChannelCC.ts | 53 +++++++------- packages/cc/src/cc/MultilevelSensorCC.ts | 9 ++- packages/cc/src/cc/MultilevelSwitchCC.ts | 9 ++- packages/cc/src/cc/NotificationCC.ts | 11 +-- packages/cc/src/cc/ProtectionCC.ts | 6 +- packages/cc/src/cc/Security2CC.ts | 9 ++- packages/cc/src/cc/ThermostatSetpointCC.ts | 2 +- packages/cc/src/cc/UserCodeCC.ts | 9 ++- packages/cc/src/cc/VersionCC.ts | 19 +---- packages/cc/src/cc/WakeUpCC.ts | 2 +- packages/cc/src/lib/API.ts | 2 +- packages/cc/src/lib/CommandClass.ts | 51 ++++++-------- packages/host/src/ZWaveHost.ts | 22 +++++- packages/host/src/mocks.ts | 8 ++- packages/serial/src/message/Message.ts | 3 +- packages/testing/src/MockController.ts | 8 +++ packages/testing/src/MockNode.ts | 69 ++++++++++--------- packages/zwave-js/src/lib/driver/Driver.ts | 49 +++++++------ packages/zwave-js/src/lib/node/Node.ts | 7 +- .../src/lib/node/mixins/70_FirmwareUpdate.ts | 9 ++- .../src/lib/test/cc/MultiChannelCC.test.ts | 2 +- .../encapsulationAnswerAsAsked.test.ts | 11 ++- 33 files changed, 255 insertions(+), 194 deletions(-) diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 7a22c787d94d..6e9c7559103d 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -37,6 +37,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -493,8 +494,9 @@ export class BasicCCReport extends BasicCC { (this.duration ?? Duration.unknown()).serializeReport(), ]); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 2 && ctx.getDeviceConfig?.( + ccVersion < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 47659f5864c0..06b487a35172 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -321,7 +321,7 @@ export class BatteryCC extends CommandClass { level: ${batteryStatus.level}${ batteryStatus.isLow ? " (low)" : "" }`; - if (this.version >= 2) { + if (api.version >= 2) { logMessage += ` status: ${ BatteryChargingStatus[batteryStatus.chargingStatus!] @@ -343,7 +343,7 @@ is disconnected: ${batteryStatus.disconnected}`; }); } - if (this.version >= 2) { + if (api.version >= 2) { // always query the health applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 80880d78eeac..3e33164a101e 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -211,7 +211,7 @@ export class BinarySensorCC extends CommandClass { }); // Find out which sensor types this sensor supports - if (this.version >= 2) { + if (api.version >= 2) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported sensor types...", @@ -263,7 +263,7 @@ export class BinarySensorCC extends CommandClass { }); // Query (all of) the sensor's current value(s) - if (this.version === 1) { + if (api.version === 1) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current value...", diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 8c9d6417518d..76dad09e80d1 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -38,6 +38,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -339,8 +340,9 @@ export class BinarySwitchCCSet extends BinarySwitchCC { (this.duration ?? Duration.default()).serializeSet(), ]); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 2 && ctx.getDeviceConfig?.( + ccVersion < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 707a09bd6ee3..9c041550481a 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -286,7 +286,7 @@ supports slow refresh: ${ccSupported.supportsSlowRefresh}`; } // The slow refresh capability should be enabled whenever possible - if (this.version >= 3 && ccSupported?.supportsSlowRefresh) { + if (api.version >= 3 && ccSupported?.supportsSlowRefresh) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "Enabling slow refresh capability...", diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 03d83c1a0edf..b61a90234f68 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -48,6 +48,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -1023,8 +1024,9 @@ export class ColorSwitchCCSet extends ColorSwitchCC { this.duration ?? Duration.default() ).serializeSet(); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 2 && ctx.getDeviceConfig?.( + ccVersion < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { @@ -1122,8 +1124,9 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { (this.duration ?? Duration.default()).serializeSet(), ]); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 3 && ctx.getDeviceConfig?.( + ccVersion < 3 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index c34262e4dd81..fd5846dd4298 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -52,6 +52,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -1091,7 +1092,7 @@ export class ConfigurationCC extends CommandClass { Array.from(paramInfo?.keys() ?? []).map((k) => k.parameter), ); - if (this.version >= 3) { + if (api.version >= 3) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "finding first configuration parameter...", @@ -1226,7 +1227,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; priority: MessagePriority.NodeQuery, }); - if (this.version < 3) { + if (api.version < 3) { // V1/V2: Query all values defined in the config file const paramInfo = getParamInformationFromConfigFile( applHost, @@ -1654,6 +1655,8 @@ export class ConfigurationCCReport extends ConfigurationCC { public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; + const ccVersion = getEffectiveCCVersion(applHost, this); + // This parameter may be a partial param in the following cases: // * a config file defines it as such // * it was reported by the device as a bit field @@ -1681,7 +1684,7 @@ export class ConfigurationCCReport extends ConfigurationCC { valueSize: this.valueSize, }); if ( - this.version < 3 + ccVersion < 3 && !this.paramExistsInConfigFile(applHost, this.parameter) && oldParamInformation.min == undefined && oldParamInformation.max == undefined diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 35d58afc1c33..218842b9b29d 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -624,7 +624,7 @@ export class DoorLockCC extends CommandClass { let boltSupported = true; let latchSupported = true; - if (this.version >= 4) { + if (api.version >= 4) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting lock capabilities...", @@ -766,7 +766,7 @@ inside handles can open door: ${ .map(String) .join(", ") }`; - if (this.version >= 4) { + if (api.version >= 4) { logMessage += ` auto-relock time ${config.autoRelockTime ?? "-"} seconds hold-and-release time ${config.holdAndReleaseTime ?? "-"} seconds diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index 33a8c498ca39..b19fa5814eb2 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -28,6 +28,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -731,7 +732,10 @@ export class FirmwareUpdateMetaDataCCReport extends FirmwareUpdateMetaDataCC { 0, ); - if (this.version >= 2) { + // V1 devices would consider the checksum to be part of the firmware data + // so it must not be included for those + const ccVersion = getEffectiveCCVersion(ctx, this); + if (ccVersion >= 2) { // Compute and save the CRC16 in the payload // The CC header is included in the CRC computation let crc = CRC16_CCITT(Buffer.from([this.ccId, this.ccCommand])); @@ -886,15 +890,12 @@ export class FirmwareUpdateMetaDataCCActivationSet public hardwareVersion?: number; public serialize(ctx: CCEncodingContext): Buffer { - const isV5 = this.version >= 5 && this.hardwareVersion != undefined; - this.payload = Buffer.allocUnsafe(7 + (isV5 ? 1 : 0)); + this.payload = Buffer.allocUnsafe(8); this.payload.writeUInt16BE(this.manufacturerId, 0); this.payload.writeUInt16BE(this.firmwareId, 2); this.payload.writeUInt16BE(this.checksum, 4); this.payload[6] = this.firmwareTarget; - if (isV5) { - this.payload[7] = this.hardwareVersion!; - } + this.payload[7] = this.hardwareVersion ?? 0x00; return super.serialize(ctx); } diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 09b045ffe24b..53c33b3ab315 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -711,7 +711,7 @@ export class IndicatorCC extends CommandClass { direction: "none", }); - if (this.version > 1) { + if (api.version > 1) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "scanning supported indicator IDs...", @@ -755,7 +755,7 @@ export class IndicatorCC extends CommandClass { direction: "inbound", }); - if (this.version >= 4) { + if (api.version >= 4) { const manufacturerDefinedIndicatorIds = supportedIndicatorIds .filter((id) => isManufacturerDefinedIndicator(id)); if (manufacturerDefinedIndicatorIds.length > 0) { @@ -793,7 +793,7 @@ export class IndicatorCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - if (this.version === 1) { + if (api.version === 1) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current indicator value...", diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 063babca4488..a3cc0ae1d8dd 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -57,6 +57,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -649,7 +650,7 @@ export class MeterCC extends CommandClass { direction: "none", }); - if (this.version >= 2) { + if (api.version >= 2) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "querying meter support...", @@ -713,7 +714,7 @@ supports reset: ${suppResp.supportsReset}`; priority: MessagePriority.NodeQuery, }); - if (this.version === 1) { + if (api.version === 1) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: `querying default meter value...`, @@ -934,6 +935,8 @@ export class MeterCCReport extends MeterCC { public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; + const ccVersion = getEffectiveCCVersion(applHost, this); + const meter = getMeter(this.type); const scale = getMeterScale(this.type, this.scale) ?? getUnknownMeterScale(this.scale); @@ -952,7 +955,7 @@ export class MeterCCReport extends MeterCC { )(scale.label !== getUnknownMeterScale(this.scale).label); // Filter out unsupported meter types, scales and rate types if possible - if (this.version >= 2) { + if (ccVersion >= 2) { const expectedType = this.getValue( applHost, MeterCCValues.type, @@ -1130,16 +1133,17 @@ export class MeterCCGet extends MeterCC { let scale2: number | undefined; let bufferLength = 0; + const ccVersion = getEffectiveCCVersion(ctx, this); if (this.scale == undefined) { scale1 = 0; - } else if (this.version >= 4 && this.scale >= 7) { + } else if (ccVersion >= 4 && this.scale >= 7) { scale1 = 7; scale2 = this.scale >>> 3; bufferLength = 2; - } else if (this.version >= 3) { + } else if (ccVersion >= 3) { scale1 = this.scale & 0b111; bufferLength = 1; - } else if (this.version >= 2) { + } else if (ccVersion >= 2) { scale1 = this.scale & 0b11; bufferLength = 1; } else { @@ -1147,7 +1151,7 @@ export class MeterCCGet extends MeterCC { } let rateTypeFlags = 0; - if (this.version >= 4 && this.rateType != undefined) { + if (ccVersion >= 4 && this.rateType != undefined) { rateTypeFlags = this.rateType & 0b11; bufferLength = Math.max(bufferLength, 1); } @@ -1256,8 +1260,10 @@ export class MeterCCSupportedReport extends MeterCC { if (!super.persistValues(applHost)) return false; if (!this.supportsReset) return true; + const ccVersion = getEffectiveCCVersion(applHost, this); + // Create reset values - if (this.version < 6) { + if (ccVersion < 6) { this.ensureMetadata(applHost, MeterCCValues.resetAll); } else { for (const scale of this.supportedScales) { diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 539a63061020..6e63b990dd97 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -33,6 +33,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -405,33 +406,32 @@ export class MultiChannelCC extends CommandClass { ); } - /** Encapsulates a command that targets a specific endpoint */ + /** Encapsulates a command that targets a specific endpoint, with version 2+ of the Multi Channel CC */ public static encapsulate( host: ZWaveHost, cc: CommandClass, - ): - | MultiChannelCCCommandEncapsulation - | MultiChannelCCV1CommandEncapsulation - { - const ccVersion = host.getSafeCCVersion( - CommandClasses["Multi Channel"], - cc.nodeId as number, - ); - let ret: - | MultiChannelCCCommandEncapsulation - | MultiChannelCCV1CommandEncapsulation; - if (ccVersion === 1) { - ret = new MultiChannelCCV1CommandEncapsulation(host, { - nodeId: cc.nodeId, - encapsulated: cc, - }); - } else { - ret = new MultiChannelCCCommandEncapsulation(host, { - nodeId: cc.nodeId, - encapsulated: cc, - destination: cc.endpointIndex, - }); - } + ): MultiChannelCCCommandEncapsulation { + const ret = new MultiChannelCCCommandEncapsulation(host, { + nodeId: cc.nodeId, + encapsulated: cc, + destination: cc.endpointIndex, + }); + + // Copy the encapsulation flags from the encapsulated command + ret.encapsulationFlags = cc.encapsulationFlags; + + return ret; + } + + /** Encapsulates a command that targets a specific endpoint, with version 1 of the Multi Channel CC */ + public static encapsulateV1( + host: ZWaveHost, + cc: CommandClass, + ): MultiChannelCCV1CommandEncapsulation { + const ret = new MultiChannelCCV1CommandEncapsulation(host, { + nodeId: cc.nodeId, + encapsulated: cc, + }); // Copy the encapsulation flags from the encapsulated command ret.encapsulationFlags = cc.encapsulationFlags; @@ -468,7 +468,8 @@ export class MultiChannelCC extends CommandClass { }); // Special interview procedure for legacy nodes - if (this.version === 1) return this.interviewV1(applHost); + const ccVersion = getEffectiveCCVersion(applHost, this); + if (ccVersion === 1) return this.interviewV1(applHost); const endpoint = node.getEndpoint(this.endpointIndex)!; const api = CCAPI.create( @@ -586,7 +587,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; for (const endpoint of allEndpoints) { if ( endpoint > multiResponse.individualEndpointCount - && this.version >= 4 + && ccVersion >= 4 ) { // Find members of aggregated end point applHost.controllerLog.logNode(node.id, { diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 264811baad24..8f639f30c2f2 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -46,6 +46,7 @@ import { type CCResponsePredicate, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -403,7 +404,7 @@ export class MultilevelSensorCC extends CommandClass { direction: "none", }); - if (this.version >= 5) { + if (api.version >= 5) { // Query the supported sensor types applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, @@ -490,7 +491,7 @@ export class MultilevelSensorCC extends CommandClass { }); const valueDB = this.getValueDB(applHost); - if (this.version <= 4) { + if (api.version <= 4) { // Sensors up to V4 only support a single value applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, @@ -667,9 +668,11 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { this.nodeId as number, )?.compat?.disableStrictMeasurementValidation; + const ccVersion = getEffectiveCCVersion(applHost, this); + if (measurementValidation) { // Filter out unsupported sensor types and scales if possible - if (this.version >= 5) { + if (ccVersion >= 5) { const supportedSensorTypes = this.getValue( applHost, MultilevelSensorCCValues.supportedSensorTypes, diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index f3de3512c383..04477b5015be 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -37,6 +37,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -539,7 +540,7 @@ export class MultilevelSwitchCC extends CommandClass { direction: "none", }); - if (this.version >= 3) { + if (api.version >= 3) { // Find out which kind of switch this is applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, @@ -655,8 +656,9 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { (this.duration ?? Duration.default()).serializeSet(), ]); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 2 && ctx.getDeviceConfig?.( + ccVersion < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { @@ -817,8 +819,9 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { (this.duration ?? Duration.default()).serializeSet(), ]); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 2 && ctx.getDeviceConfig?.( + ccVersion < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index f84ed4e4169d..014de413650a 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -53,6 +53,7 @@ import { CommandClass, type CommandClassDeserializationOptions, InvalidCC, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -601,7 +602,7 @@ export class NotificationCC extends CommandClass { } let supportsV1Alarm = false; - if (this.version >= 2) { + if (api.version >= 2) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported notification types...", @@ -640,7 +641,7 @@ export class NotificationCC extends CommandClass { direction: "inbound", }); - if (this.version >= 3) { + if (api.version >= 3) { // Query each notification for its supported events for (let i = 0; i < supportedNotificationTypes.length; i++) { const type = supportedNotificationTypes[i]; @@ -746,7 +747,7 @@ export class NotificationCC extends CommandClass { } // Only create metadata for V1 values if necessary - if (this.version === 1 || supportsV1Alarm) { + if (api.version === 1 || supportsV1Alarm) { this.ensureMetadata(applHost, NotificationCCValues.alarmType); this.ensureMetadata(applHost, NotificationCCValues.alarmLevel); } @@ -1024,13 +1025,15 @@ export class NotificationCCReport extends NotificationCC { public persistValues(applHost: ZWaveApplicationHost): boolean { if (!super.persistValues(applHost)) return false; + const ccVersion = getEffectiveCCVersion(applHost, this); + // Check if we need to re-interpret the alarm values somehow if ( this.alarmType != undefined && this.alarmLevel != undefined && this.alarmType !== 0 ) { - if (this.version >= 2) { + if (ccVersion >= 2) { // Check if the device actually supports Notification CC, but chooses // to send Alarm frames instead (GH#1034) const supportedNotificationTypes = this.getValue< diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index a9f7b510fbc0..01863a570e92 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -37,6 +37,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -381,7 +382,7 @@ export class ProtectionCC extends CommandClass { let hadCriticalTimeout = false; // First find out what the device supports - if (this.version >= 2) { + if (api.version >= 2) { applHost.controllerLog.logNode(node.id, { message: "querying protection capabilities...", direction: "outbound", @@ -532,8 +533,9 @@ export class ProtectionCCSet extends ProtectionCC { (this.rf ?? RFProtectionState.Unprotected) & 0b1111, ]); + const ccVersion = getEffectiveCCVersion(ctx, this); if ( - this.version < 2 && ctx.getDeviceConfig?.( + ccVersion < 2 && ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.encodeCCsUsingTargetVersion ) { diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index f66f6806e84c..24fad7d6021a 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -366,7 +366,14 @@ export class Security2CCAPI extends CCAPI { // encapsulation because it would use a different security class. Therefore the entire possible stack // of encapsulation needs to be done here if (MultiChannelCC.requiresEncapsulation(cc)) { - cc = MultiChannelCC.encapsulate(this.applHost, cc); + const multiChannelCCVersion = this.applHost.getSupportedCCVersion( + CommandClasses["Multi Channel"], + this.endpoint.nodeId as number, + ); + + cc = multiChannelCCVersion === 1 + ? MultiChannelCC.encapsulateV1(this.applHost, cc) + : MultiChannelCC.encapsulate(this.applHost, cc); } cc = Security2CC.encapsulate( this.applHost, diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 1bca7409b813..951a0399372c 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -360,7 +360,7 @@ export class ThermostatSetpointCC extends CommandClass { direction: "none", }); - if (this.version <= 2) { + if (api.version <= 2) { // It has been found that early implementations of this Command Class applied two non-interoperable // interpretations of the bit mask advertising the support for specific Setpoint Types in the Thermostat // Setpoint Supported Report Command. diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 181777d4cdad..82aba905eb59 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -46,6 +46,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -193,9 +194,11 @@ function setUserCodeMetadata( const statusValue = UserCodeCCValues.userIdStatus(userId); const codeValue = UserCodeCCValues.userCode(userId); + const ccVersion = getEffectiveCCVersion(applHost, this); + const supportedUserIDStatuses: UserIDStatus[] = this.getValue(applHost, UserCodeCCValues.supportedUserIDStatuses) - ?? (this.version === 1 + ?? (ccVersion === 1 ? [ UserIDStatus.Available, UserIDStatus.Enabled, @@ -903,7 +906,7 @@ export class UserCodeCC extends CommandClass { }); // Query capabilities first to determine what needs to be done when refreshing - if (this.version >= 2) { + if (api.version >= 2) { applHost.controllerLog.logNode(node.id, { message: "querying capabilities...", direction: "outbound", @@ -980,7 +983,7 @@ export class UserCodeCC extends CommandClass { ); // Check for changed values and codes - if (this.version >= 2) { + if (api.version >= 2) { if (supportsAdminCode) { applHost.controllerLog.logNode(node.id, { message: "querying admin code...", diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 1930c0301c3c..4ca70f989fa6 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -228,15 +228,8 @@ export class VersionCCAPI extends PhysicalCCAPI { case VersionCommand.CapabilitiesGet: case VersionCommand.CapabilitiesReport: case VersionCommand.ZWaveSoftwareReport: - // The API might have been created before the versions were determined, - // so `this.version` may contains a wrong value - return ( - this.applHost.getSafeCCVersion( - this.ccId, - this.endpoint.nodeId, - this.endpoint.index, - ) >= 3 - ); + return this.version >= 3; + case VersionCommand.ZWaveSoftwareGet: { return this.getValueDB().getValue( VersionCCValues.supportsZWaveSoftwareGet.endpoint( @@ -557,12 +550,6 @@ export class VersionCC extends CommandClass { if (this.endpointIndex === 0) { // Step 1: Query Version CC version await queryCCVersion(CommandClasses.Version); - // The CC instance was created before the versions were determined, so `this.version` contains a wrong value - this.version = applHost.getSafeCCVersion( - CommandClasses.Version, - node.id, - this.endpointIndex, - ); // Step 2: Query node versions applHost.controllerLog.logNode(node.id, { @@ -615,7 +602,7 @@ export class VersionCC extends CommandClass { } // Step 4: Query VersionCC capabilities (root device only) - if (this.endpointIndex === 0 && this.version >= 3) { + if (this.endpointIndex === 0 && api.version >= 3) { // Step 4a: Support for SoftwareGet applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index a022b669dc1c..76c70a0eba5b 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -260,7 +260,7 @@ export class WakeUpCC extends CommandClass { let maxInterval: number | undefined; // Retrieve the allowed wake up intervals and wake on demand support if possible - if (this.version >= 2) { + if (api.version >= 2) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index 1ccdd26f630b..ea230d6e2557 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -396,7 +396,7 @@ export class CCAPI { this.ccId, this.endpoint.nodeId, this.endpoint.index, - ); + ) ?? 0; } else { return getImplementedVersion(this.ccId); } diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index fcbabee6748a..9286cbf648c8 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -36,6 +36,7 @@ import { import type { CCEncodingContext, CCParsingContext, + GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, ZWaveHost, @@ -141,6 +142,21 @@ export type CCNode = & ListenBehavior & QueryNodeStatus; +export function getEffectiveCCVersion( + ctx: GetSupportedCCVersion, + cc: CommandClass, + defaultVersion?: number, +): number { + // For multicast and broadcast CCs, just use the highest implemented version to serialize + // Older nodes will ignore the additional fields + if (!cc.isSinglecast()) { + return getImplementedVersion(cc.ccId); + } + // For singlecast CCs, set the CC version as high as possible + return ctx.getSupportedCCVersion(cc.ccId, cc.nodeId, cc.endpointIndex) + || (defaultVersion ?? getImplementedVersion(cc.ccId)); +} + // @publicAPI export class CommandClass implements CCId { // empty constructor to parse messages @@ -150,8 +166,10 @@ export class CommandClass implements CCId { this.endpointIndex = ("endpoint" in options ? options.endpoint : undefined) ?? 0; - // We cannot use @ccValue for non-derived classes, so register interviewComplete as an internal value here - // this.registerValue("interviewComplete", { internal: true }); + this.origin = options.origin + ?? (gotDeserializationOptions(options) + ? MessageOrigin.Controller + : MessageOrigin.Host); if (gotDeserializationOptions(options)) { // For deserialized commands, try to invoke the correct subclass constructor @@ -211,25 +229,6 @@ export class CommandClass implements CCId { if (this instanceof InvalidCC) return; if (options.origin !== MessageOrigin.Host && this.isSinglecast()) { - try { - // For singlecast CCs, set the CC version as high as possible - this.version = this.host.getSafeCCVersion( - this.ccId, - this.nodeId, - this.endpointIndex, - ); - } catch (e) { - if ( - isZWaveError(e) - && e.code === ZWaveErrorCodes.CC_NotImplemented - ) { - // Someone tried to create a CC that is not implemented. Just set all versions to 0. - this.version = 0; - } else { - throw e; - } - } - // Send secure commands if necessary this.toggleEncapsulationFlag( EncapsulationFlags.Security, @@ -239,10 +238,6 @@ export class CommandClass implements CCId { this.endpointIndex, ), ); - } else { - // For multicast and broadcast CCs, we just use the highest implemented version to serialize - // Older nodes will ignore the additional fields - this.version = getImplementedVersion(this.ccId); } } @@ -261,13 +256,11 @@ export class CommandClass implements CCId { // Work around https://github.com/Microsoft/TypeScript/issues/27555 public payload!: Buffer; - /** The version of the command class used */ - // Work around https://github.com/Microsoft/TypeScript/issues/27555 - public version!: number; - /** Which endpoint of the node this CC belongs to. 0 for the root device. */ public endpointIndex: number; + public origin: MessageOrigin; + /** * Which encapsulation CCs this CC is/was/should be encapsulated with. * diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index a525c9b7c596..3b4aad64d57f 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -39,6 +39,18 @@ export interface GetDeviceConfig { getDeviceConfig?: (nodeId: number) => DeviceConfig | undefined; } +export interface GetSupportedCCVersion { + /** + * Retrieves the maximum version of a command class the given node/endpoint has reported support for. + * Returns 0 when the CC is not supported or that information is not known yet. + */ + getSupportedCCVersion( + cc: CommandClasses, + nodeId: number, + endpointIndex?: number, + ): number; +} + /** Additional context needed for deserializing CCs */ export interface CCParsingContext extends Readonly, GetDeviceConfig, HostIDs @@ -66,7 +78,11 @@ export interface CCParsingContext /** Additional context needed for serializing CCs */ // FIXME: Lot of duplication between the CC and message contexts export interface CCEncodingContext - extends Readonly, GetDeviceConfig, HostIDs + extends + Readonly, + GetDeviceConfig, + HostIDs, + GetSupportedCCVersion { getHighestSecurityClass(nodeId: number): MaybeNotKnown; @@ -87,13 +103,13 @@ export interface ZWaveHost { /** * Retrieves the maximum version of a command class that can be used to communicate with a node. * Returns 1 if the node claims that it does not support a CC. - * Throws if the CC is not implemented in this library yet. + * Returns `undefined` for CCs that are not implemented in this library yet. */ getSafeCCVersion( cc: CommandClasses, nodeId: number, endpointIndex?: number, - ): number; + ): number | undefined; /** * Retrieves the maximum version of a command class the given node/endpoint has reported support for. diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 368c8a877c51..33732b065740 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -93,9 +93,11 @@ export function createTestingHost< nodes.set(nodeId, node); }, getSafeCCVersion: options.getSafeCCVersion ?? (() => 100), - getSupportedCCVersion: options.getSupportedCCVersion - ?? options.getSafeCCVersion - ?? (() => 100), + getSupportedCCVersion: (cc, nodeId, endpoint) => { + return options.getSupportedCCVersion?.(cc, nodeId, endpoint) + ?? options.getSafeCCVersion?.(cc, nodeId, endpoint) + ?? 100; + }, getValueDB: (nodeId) => { if (!valueDBCache.has(nodeId)) { valueDBCache.set( diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 79025b579c8b..40a0bc326d56 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -14,6 +14,7 @@ import { } from "@zwave-js/core"; import type { GetDeviceConfig, + GetSupportedCCVersion, HostIDs, ZWaveApplicationHost, ZWaveHost, @@ -97,7 +98,7 @@ export type MessageOptions = | MessageDeserializationOptions; export interface MessageEncodingContext - extends Readonly, HostIDs + extends Readonly, HostIDs, GetSupportedCCVersion { /** How many bytes a node ID occupies in serial API commands */ nodeIdType: NodeIDType; diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 13e0d4e439b6..5ead88e4f3e3 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -121,6 +121,14 @@ export class MockController { // If we don't have the info for every security class, we don't know the highest one yet return missingSome ? undefined : SecurityClass.None; }, + getSupportedCCVersion: (cc, nodeId, endpointIndex = 0) => { + if (!this.nodes.has(nodeId)) { + return 0; + } + const node = this.nodes.get(nodeId)!; + const endpoint = node.endpoints.get(endpointIndex); + return (endpoint ?? node).implementedCCs.get(cc)?.version ?? 0; + }, }; this.parsingContext = { ...this.encodingContext, diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 57d2d4cf0263..c1f3dcc92db8 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -120,6 +120,38 @@ export class MockNode { const securityClasses = new Map>(); + const { + commandClasses = [], + endpoints = [], + ...capabilities + } = options.capabilities ?? {}; + this.capabilities = { + ...getDefaultMockNodeCapabilities(), + ...capabilities, + }; + + for (const cc of commandClasses) { + if (typeof cc === "number") { + this.addCC(cc, {}); + } else { + const { ccId, ...ccInfo } = cc; + this.addCC(ccId, ccInfo); + } + } + + let index = 0; + for (const endpoint of endpoints) { + index++; + this.endpoints.set( + index, + new MockEndpoint({ + index, + node: this, + capabilities: endpoint, + }), + ); + } + this.encodingContext = { homeId: this.controller.homeId, ownNodeId: this.id, @@ -156,39 +188,12 @@ export class MockNode { // If we don't have the info for every security class, we don't know the highest one yet return missingSome ? undefined : SecurityClass.None; }, + getSupportedCCVersion: (cc, nodeId, endpointIndex = 0) => { + // Mock endpoints only care about the version they implement + const endpoint = this.endpoints.get(endpointIndex); + return (endpoint ?? this).implementedCCs.get(cc)?.version ?? 0; + }, }; - - const { - commandClasses = [], - endpoints = [], - ...capabilities - } = options.capabilities ?? {}; - this.capabilities = { - ...getDefaultMockNodeCapabilities(), - ...capabilities, - }; - - for (const cc of commandClasses) { - if (typeof cc === "number") { - this.addCC(cc, {}); - } else { - const { ccId, ...ccInfo } = cc; - this.addCC(ccId, ccInfo); - } - } - - let index = 0; - for (const endpoint of endpoints) { - index++; - this.endpoints.set( - index, - new MockEndpoint({ - index, - node: this, - capabilities: endpoint, - }), - ); - } } public readonly host: ZWaveHost; diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 8ba3052a4841..e5c929167040 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -109,6 +109,7 @@ import { wasControllerReset, } from "@zwave-js/core"; import type { + CCEncodingContext, HostIDs, NodeSchedulePollOptions, ZWaveApplicationHost, @@ -671,6 +672,8 @@ export class Driver extends TypedEventEmitter this.hasSecurityClass(nodeId, securityClass), setSecurityClass: (nodeId, securityClass, granted) => this.setSecurityClass(nodeId, securityClass, granted), + getSupportedCCVersion: (cc, nodeId, endpointIndex) => + this.getSupportedCCVersion(cc, nodeId, endpointIndex), }; this.immediateQueue = new TransactionQueue({ @@ -716,7 +719,7 @@ export class Driver extends TypedEventEmitter keyof HostIDs | "nodeIdType" >; - private getCCEncodingContext() { + private getCCEncodingContext(): MessageEncodingContext & CCEncodingContext { // FIXME: The type system isn't helping here. We need the security managers to encode CCs // but not for messages, yet those implicitly encode CCs return { @@ -2806,7 +2809,7 @@ export class Driver extends TypedEventEmitter /** * Retrieves the maximum version of a command class that can be used to communicate with a node. * Returns the highest implemented version if the node's CC version is unknown. - * Throws if the CC is not implemented in this library yet. + * Returns `undefined` for CCs that are not implemented in this library yet. * * @param cc The command class whose version should be retrieved * @param nodeId The node for which the CC version should be retrieved @@ -2816,7 +2819,14 @@ export class Driver extends TypedEventEmitter cc: CommandClasses, nodeId: number, endpointIndex: number = 0, - ): number { + ): number | undefined { + const implementedVersion = getImplementedVersion(cc); + if ( + implementedVersion === 0 + || implementedVersion === Number.POSITIVE_INFINITY + ) { + return undefined; + } const supportedVersion = this.getSupportedCCVersion( cc, nodeId, @@ -2824,28 +2834,10 @@ export class Driver extends TypedEventEmitter ); if (supportedVersion === 0) { // Unknown, use the highest implemented version - const implementedVersion = getImplementedVersion(cc); - if ( - implementedVersion !== 0 - && implementedVersion !== Number.POSITIVE_INFINITY - ) { - return implementedVersion; - } - } else { - // For supported versions find the maximum version supported by both the - // node and this library - const implementedVersion = getImplementedVersion(cc); - if ( - implementedVersion !== 0 - && implementedVersion !== Number.POSITIVE_INFINITY - ) { - return Math.min(supportedVersion, implementedVersion); - } + return implementedVersion; } - throw new ZWaveError( - "Cannot retrieve the version of a CC that is not implemented", - ZWaveErrorCodes.CC_NotImplemented, - ); + + return Math.min(supportedVersion, implementedVersion); } /** @@ -5256,7 +5248,14 @@ ${handlers.length} left`, // 4. if (MultiChannelCC.requiresEncapsulation(cmd)) { - cmd = MultiChannelCC.encapsulate(this, cmd); + const multiChannelCCVersion = this.getSupportedCCVersion( + CommandClasses["Multi Channel"], + cmd.nodeId as number, + ); + + cmd = multiChannelCCVersion === 1 + ? MultiChannelCC.encapsulateV1(this, cmd) + : MultiChannelCC.encapsulate(this, cmd); } // 5. diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index cd5720dc7921..be8f30e2e661 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -37,6 +37,7 @@ import { ZWavePlusNodeType, ZWavePlusRoleType, entryControlEventTypeLabels, + getEffectiveCCVersion, getImplementedVersion, isCommandClassContainer, utils as ccUtils, @@ -4334,6 +4335,8 @@ protocol version: ${this.protocolVersion}`; return; } + const ccVersion = getEffectiveCCVersion(this.driver, command); + // Look up the received notification in the config const notification = getNotification(command.notificationType); @@ -4486,7 +4489,7 @@ protocol version: ${this.protocolVersion}`; ); valueId = unknownValue.endpoint(command.endpointIndex); - if (command.version >= 2) { + if (ccVersion >= 2) { if (!this.valueDB.hasMetadata(valueId)) { this.valueDB.setMetadata(valueId, unknownValue.meta); } @@ -4539,7 +4542,7 @@ protocol version: ${this.protocolVersion}`; const valueId = unknownValue.endpoint(command.endpointIndex); // Make sure the metdata exists - if (command.version >= 2) { + if (ccVersion >= 2) { if (!this.valueDB.hasMetadata(valueId)) { this.valueDB.setMetadata(valueId, unknownValue.meta); } diff --git a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts index 25ebcdd48f2d..4c6745096c76 100644 --- a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts +++ b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts @@ -11,6 +11,7 @@ import { FirmwareUpdateRequestStatus, type FirmwareUpdateResult, FirmwareUpdateStatus, + getEffectiveCCVersion, isCommandClassContainer, } from "@zwave-js/cc"; import { @@ -564,12 +565,13 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin const maxGrossPayloadSizeNonSecure = this.driver .computeNetCCPayloadSize(fcc, true); + const ccVersion = getEffectiveCCVersion(this.driver, fcc); const maxNetPayloadSizeSecure = maxGrossPayloadSizeSecure - 2 // report number - - (fcc.version >= 2 ? 2 : 0); // checksum + - (ccVersion >= 2 ? 2 : 0); // checksum const maxNetPayloadSizeNonSecure = maxGrossPayloadSizeNonSecure - 2 // report number - - (fcc.version >= 2 ? 2 : 0); // checksum + - (ccVersion >= 2 ? 2 : 0); // checksum // Use the smallest allowed payload const fragmentSizeSecure = Math.min( @@ -614,9 +616,10 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin const fcc = new FirmwareUpdateMetaDataCC(this.driver, { nodeId: this.id, }); + const ccVersion = getEffectiveCCVersion(this.driver, fcc); const fragmentSize = this.driver.computeNetCCPayloadSize(fcc) - 2 // report number - - (fcc.version >= 2 ? 2 : 0); // checksum + - (ccVersion >= 2 ? 2 : 0); // checksum const fragment = randomBytes(fragmentSize); try { await this.sendCorruptedFirmwareUpdateReport( diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts index ab793e0f5bbc..078204441cfa 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts @@ -205,7 +205,7 @@ test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => { nodeId: 2, endpoint: 2, }), - ) as MultiChannelCCCommandEncapsulation; + ); // A multicast request never expects a response ccRequest.destination = [1, 2, 3]; t.false(ccRequest.expectsCCResponse()); diff --git a/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts b/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts index 113c2b26faf0..e8261ce512e5 100644 --- a/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts @@ -92,7 +92,7 @@ integrationTest( nodeId: mockController.ownNodeId, }); const cc = MultiChannelCC.encapsulate(mockNode.host, zwpRequest); - (cc as MultiChannelCCCommandEncapsulation).endpointIndex = 2; + cc.endpointIndex = 2; await mockNode.sendToController(createMockZWaveRequestFrame(cc)); @@ -142,7 +142,11 @@ integrationTest( nodeId: mockController.ownNodeId, currentValue: 0, }); - const cc = SupervisionCC.encapsulate(mockNode.host, basicReport); + const cc = SupervisionCC.encapsulate( + mockNode.host, + basicReport, + driver.getNextSupervisionSessionId(mockNode.id), + ); await mockNode.sendToController(createMockZWaveRequestFrame(cc)); @@ -196,9 +200,10 @@ integrationTest( const supervised = SupervisionCC.encapsulate( mockNode.host, basicReport, + driver.getNextSupervisionSessionId(mockNode.id), ); const cc = MultiChannelCC.encapsulate(mockNode.host, supervised); - (cc as MultiChannelCCCommandEncapsulation).endpointIndex = 2; + cc.endpointIndex = 2; await mockNode.sendToController(createMockZWaveRequestFrame(cc)); From a317a25c17bc6a8740e7f9bbbafb765bf5c7a36e Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 15 Oct 2024 13:53:59 +0200 Subject: [PATCH 37/60] fix: broken tests --- .../src/lib/test/cc/BinarySwitchCC.test.ts | 20 ++++++++--- .../src/lib/test/cc/ColorSwitchCC.test.ts | 29 ++++++++++++---- .../zwave-js/src/lib/test/cc/MeterCC.test.ts | 34 ++++++++++++++++--- .../lib/test/cc/MultilevelSwitchCC.test.ts | 29 ++++++++++++---- 4 files changed, 89 insertions(+), 23 deletions(-) diff --git a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts index 2f31b08bd569..77bae2a99407 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts @@ -6,7 +6,7 @@ import { BinarySwitchCommand, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; import test from "ava"; const host = createTestingHost(); @@ -35,7 +35,6 @@ test("the Set command should serialize correctly (no duration)", (t) => { nodeId: 2, targetValue: false, }); - cc.version = 1; const expected = buildCCBuffer( Buffer.from([ BinarySwitchCommand.Set, // CC Command @@ -43,7 +42,13 @@ test("the Set command should serialize correctly (no duration)", (t) => { 0xff, // default duration ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 1; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Set command should serialize correctly", (t) => { @@ -53,7 +58,6 @@ test("the Set command should serialize correctly", (t) => { targetValue: true, duration, }); - cc.version = 2; const expected = buildCCBuffer( Buffer.from([ BinarySwitchCommand.Set, // CC Command @@ -61,7 +65,13 @@ test("the Set command should serialize correctly", (t) => { duration.serializeSet(), ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 2; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Report command (v1) should be deserialized correctly", (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts index e16845b17130..8381339036f5 100644 --- a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts @@ -16,7 +16,7 @@ import { ZWaveErrorCodes, assertZWaveError, } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; import test from "ava"; const host = createTestingHost(); @@ -147,7 +147,14 @@ test("the Set command should serialize correctly (without duration)", (t) => { 0xff, // duration: default ]), ); - t.deepEqual(cc.serialize({} as any), expected); + + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 0; // Default to implemented version + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Set command should serialize correctly (version 2)", (t) => { @@ -170,7 +177,13 @@ test("the Set command should serialize correctly (version 2)", (t) => { 0b0000_0001, // duration: 1 ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 2; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the StartLevelChange command should serialize correctly", (t) => { @@ -182,8 +195,6 @@ test("the StartLevelChange command should serialize correctly", (t) => { colorComponent: ColorComponent.Red, duration: new Duration(1, "seconds"), }); - cc.version = 3; - const expected = buildCCBuffer( Buffer.from([ ColorSwitchCommand.StartLevelChange, @@ -193,7 +204,13 @@ test("the StartLevelChange command should serialize correctly", (t) => { 0b0000_0001, // duration: 1 ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 3; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the StopLevelChange command should serialize correctly", (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts index 90f745908440..4d4e960ebdac 100644 --- a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts @@ -13,7 +13,7 @@ import { ZWaveErrorCodes, assertZWaveError, } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; import test from "ava"; import * as nodeUtils from "../../node/utils"; import { createTestNode } from "../mocks"; @@ -37,7 +37,13 @@ test("the Get command (V1) should serialize correctly", (t) => { MeterCommand.Get, // CC Command ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 1; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Get command (V2) should serialize correctly", (t) => { @@ -48,7 +54,13 @@ test("the Get command (V2) should serialize correctly", (t) => { 0b11_000, // Scale ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 2; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Get command (V3) should serialize correctly", (t) => { @@ -59,7 +71,13 @@ test("the Get command (V3) should serialize correctly", (t) => { 0b110_000, // Scale ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 3; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Get command (V4) should serialize correctly", (t) => { @@ -71,7 +89,13 @@ test("the Get command (V4) should serialize correctly", (t) => { 0x1, // Scale 2 ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 4; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the SupportedGet command should serialize correctly", (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts index 196bf26ea02c..9d2a54aafe15 100644 --- a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts @@ -9,7 +9,7 @@ import { MultilevelSwitchCommand, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; import test from "ava"; const host = createTestingHost(); @@ -38,7 +38,6 @@ test("the Set command should serialize correctly (no duration)", (t) => { nodeId: 2, targetValue: 55, }); - cc.version = 1; const expected = buildCCBuffer( Buffer.from([ MultilevelSwitchCommand.Set, // CC Command @@ -46,7 +45,13 @@ test("the Set command should serialize correctly (no duration)", (t) => { 0xff, // default duration ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 1; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Set command (V2) should serialize correctly", (t) => { @@ -55,7 +60,6 @@ test("the Set command (V2) should serialize correctly", (t) => { targetValue: 55, duration: new Duration(2, "minutes"), }); - cc.version = 2; const expected = buildCCBuffer( Buffer.from([ MultilevelSwitchCommand.Set, // CC Command @@ -63,7 +67,13 @@ test("the Set command (V2) should serialize correctly", (t) => { 0x81, // 2 minutes ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 2; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the Report command (V1) should be deserialized correctly", (t) => { @@ -125,7 +135,6 @@ test("the StartLevelChange command (V2) should serialize correctly (down, ignore startLevel: 50, duration: new Duration(3, "seconds"), }); - cc.version = 2; const expected = buildCCBuffer( Buffer.from([ MultilevelSwitchCommand.StartLevelChange, // CC Command @@ -134,7 +143,13 @@ test("the StartLevelChange command (V2) should serialize correctly (down, ignore 3, // 3 sec ]), ); - t.deepEqual(cc.serialize({} as any), expected); + const ctx = { + getSupportedCCVersion(cc, nodeId, endpointIndex) { + return 2; + }, + } satisfies GetSupportedCCVersion as any; + + t.deepEqual(cc.serialize(ctx), expected); }); test("the SupportedGet command should serialize correctly", (t) => { From 3671f11bc87f46cc798e646d5bbd8dfa56ef2a86 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 15 Oct 2024 13:57:08 +0200 Subject: [PATCH 38/60] fix: lint --- .../src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts index 195e2344e2b5..4a5d62822cb4 100644 --- a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts +++ b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts @@ -11,7 +11,7 @@ import { integrationTest } from "../integrationTestSuite"; // values, which includes some the device does not actually support integrationTest("CC values are created using the known CC version", { - debug: true, + // debug: true, provisioningDirectory: path.join( __dirname, From 6437856cdc791e503118ad1a8823e8af01205502 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 15 Oct 2024 23:09:39 +0200 Subject: [PATCH 39/60] refactor: remove host instance from CCs --- packages/cc/src/cc/AlarmSensorCC.ts | 14 +- packages/cc/src/cc/AssociationCC.ts | 35 ++- packages/cc/src/cc/AssociationGroupInfoCC.ts | 31 +-- packages/cc/src/cc/BarrierOperatorCC.ts | 38 ++-- packages/cc/src/cc/BasicCC.ts | 11 +- packages/cc/src/cc/BatteryCC.ts | 11 +- packages/cc/src/cc/BinarySensorCC.ts | 18 +- packages/cc/src/cc/BinarySwitchCC.ts | 11 +- packages/cc/src/cc/CRC16CC.ts | 16 +- packages/cc/src/cc/CentralSceneCC.ts | 19 +- .../cc/src/cc/ClimateControlScheduleCC.ts | 34 +-- packages/cc/src/cc/ClockCC.ts | 11 +- packages/cc/src/cc/ColorSwitchCC.ts | 29 +-- packages/cc/src/cc/ConfigurationCC.ts | 94 +++----- packages/cc/src/cc/DeviceResetLocallyCC.ts | 7 +- packages/cc/src/cc/DoorLockCC.ts | 26 +-- packages/cc/src/cc/DoorLockLoggingCC.ts | 14 +- packages/cc/src/cc/EnergyProductionCC.ts | 9 +- packages/cc/src/cc/EntryControlCC.ts | 24 +- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 41 ++-- packages/cc/src/cc/HumidityControlModeCC.ts | 16 +- .../src/cc/HumidityControlOperatingStateCC.ts | 11 +- .../cc/src/cc/HumidityControlSetpointCC.ts | 46 ++-- packages/cc/src/cc/InclusionControllerCC.ts | 12 +- packages/cc/src/cc/IndicatorCC.ts | 36 ++- packages/cc/src/cc/IrrigationCC.ts | 70 +++--- packages/cc/src/cc/LanguageCC.ts | 11 +- packages/cc/src/cc/LockCC.ts | 11 +- .../cc/src/cc/ManufacturerProprietaryCC.ts | 14 +- packages/cc/src/cc/ManufacturerSpecificCC.ts | 16 +- packages/cc/src/cc/MeterCC.ts | 23 +- .../cc/src/cc/MultiChannelAssociationCC.ts | 50 ++-- packages/cc/src/cc/MultiChannelCC.ts | 59 ++--- packages/cc/src/cc/MultiCommandCC.ts | 16 +- packages/cc/src/cc/MultilevelSensorCC.ts | 24 +- packages/cc/src/cc/MultilevelSwitchCC.ts | 23 +- packages/cc/src/cc/NoOperationCC.ts | 2 +- packages/cc/src/cc/NodeNamingCC.ts | 21 +- packages/cc/src/cc/NotificationCC.ts | 31 +-- packages/cc/src/cc/PowerlevelCC.ts | 32 +-- packages/cc/src/cc/ProtectionCC.ts | 36 ++- packages/cc/src/cc/SceneActivationCC.ts | 11 +- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 16 +- .../src/cc/SceneControllerConfigurationCC.ts | 16 +- packages/cc/src/cc/ScheduleEntryLockCC.ts | 103 ++++----- packages/cc/src/cc/Security2CC.ts | 87 +++---- packages/cc/src/cc/SecurityCC.ts | 51 ++--- packages/cc/src/cc/SoundSwitchCC.ts | 36 ++- packages/cc/src/cc/SupervisionCC.ts | 14 +- packages/cc/src/cc/ThermostatFanModeCC.ts | 16 +- packages/cc/src/cc/ThermostatFanStateCC.ts | 11 +- packages/cc/src/cc/ThermostatModeCC.ts | 16 +- .../cc/src/cc/ThermostatOperatingStateCC.ts | 11 +- packages/cc/src/cc/ThermostatSetbackCC.ts | 11 +- packages/cc/src/cc/ThermostatSetpointCC.ts | 27 +-- packages/cc/src/cc/TimeCC.ts | 27 +-- packages/cc/src/cc/TimeParametersCC.ts | 11 +- packages/cc/src/cc/TransportServiceCC.ts | 23 +- packages/cc/src/cc/UserCodeCC.ts | 64 ++---- packages/cc/src/cc/VersionCC.ts | 30 +-- packages/cc/src/cc/WakeUpCC.ts | 18 +- packages/cc/src/cc/WindowCoveringCC.ts | 29 +-- packages/cc/src/cc/ZWavePlusCC.ts | 8 +- packages/cc/src/cc/ZWaveProtocolCC.ts | 83 +++---- .../cc/manufacturerProprietary/FibaroCC.ts | 36 ++- packages/cc/src/lib/CommandClass.ts | 36 +-- packages/host/src/ZWaveHost.ts | 65 +++--- packages/host/src/mocks.ts | 6 +- packages/serial/src/message/Message.test.ts | 24 +- packages/serial/src/message/Message.ts | 9 +- .../serial/src/message/ZnifferMessages.ts | 1 - packages/testing/src/MockController.ts | 24 +- packages/testing/src/MockNode.ts | 9 +- .../zwave-js/src/lib/controller/Controller.ts | 215 ++++++++---------- .../lib/controller/MockControllerBehaviors.ts | 96 ++++---- packages/zwave-js/src/lib/driver/Driver.ts | 49 ++-- .../src/lib/driver/MessageGenerators.ts | 23 +- .../src/lib/driver/Transaction.test.ts | 4 +- packages/zwave-js/src/lib/node/Endpoint.ts | 4 +- .../src/lib/node/MockNodeBehaviors.ts | 12 +- packages/zwave-js/src/lib/node/Node.ts | 6 +- .../zwave-js/src/lib/node/mixins/40_Values.ts | 1 - .../src/lib/node/mixins/70_FirmwareUpdate.ts | 16 +- .../src/lib/node/mockCCBehaviors/Basic.ts | 2 +- .../lib/node/mockCCBehaviors/BinarySensor.ts | 4 +- .../lib/node/mockCCBehaviors/BinarySwitch.ts | 2 +- .../lib/node/mockCCBehaviors/ColorSwitch.ts | 4 +- .../lib/node/mockCCBehaviors/Configuration.ts | 10 +- .../node/mockCCBehaviors/EnergyProduction.ts | 2 +- .../mockCCBehaviors/ManufacturerSpecific.ts | 2 +- .../src/lib/node/mockCCBehaviors/Meter.ts | 4 +- .../lib/node/mockCCBehaviors/MultiChannel.ts | 8 +- .../node/mockCCBehaviors/MultilevelSensor.ts | 6 +- .../node/mockCCBehaviors/MultilevelSwitch.ts | 4 +- .../lib/node/mockCCBehaviors/Notification.ts | 4 +- .../node/mockCCBehaviors/ScheduleEntryLock.ts | 23 +- .../lib/node/mockCCBehaviors/SoundSwitch.ts | 32 ++- .../node/mockCCBehaviors/ThermostatMode.ts | 4 +- .../node/mockCCBehaviors/ThermostatSetback.ts | 2 +- .../mockCCBehaviors/ThermostatSetpoint.ts | 10 +- .../src/lib/node/mockCCBehaviors/UserCode.ts | 14 +- .../node/mockCCBehaviors/WindowCovering.ts | 2 +- packages/zwave-js/src/lib/node/utils.ts | 2 - .../application/ApplicationCommandRequest.ts | 6 +- .../application/ApplicationUpdateRequest.ts | 19 +- .../BridgeApplicationCommandRequest.ts | 6 +- .../application/SerialAPIStartedRequest.ts | 4 +- .../serialapi/application/ShutdownMessages.ts | 4 +- .../GetControllerCapabilitiesMessages.ts | 4 +- .../GetControllerVersionMessages.ts | 4 +- .../capability/GetLongRangeNodesMessages.ts | 7 +- .../capability/GetProtocolVersionMessages.ts | 4 +- .../GetSerialApiCapabilitiesMessages.ts | 4 +- .../GetSerialApiInitDataMessages.ts | 4 +- .../serialapi/capability/HardResetRequest.ts | 12 +- .../capability/LongRangeChannelMessages.ts | 10 +- .../capability/SerialAPISetupMessages.ts | 111 ++++----- .../SetApplicationNodeInformationRequest.ts | 4 +- .../SetLongRangeShadowNodeIDsRequest.ts | 4 +- .../memory/GetControllerIdMessages.ts | 4 +- .../misc/GetBackgroundRSSIMessages.ts | 4 +- .../misc/SetRFReceiveModeMessages.ts | 7 +- .../misc/SetSerialApiTimeoutsMessages.ts | 7 +- .../network-mgmt/AddNodeToNetworkRequest.ts | 17 +- .../AssignPriorityReturnRouteMessages.ts | 19 +- .../AssignPrioritySUCReturnRouteMessages.ts | 15 +- .../network-mgmt/AssignReturnRouteMessages.ts | 16 +- .../AssignSUCReturnRouteMessages.ts | 21 +- .../network-mgmt/DeleteReturnRouteMessages.ts | 16 +- .../DeleteSUCReturnRouteMessages.ts | 21 +- .../GetNodeProtocolInfoMessages.ts | 7 +- .../network-mgmt/GetPriorityRouteMessages.ts | 7 +- .../network-mgmt/GetRoutingInfoMessages.ts | 8 +- .../network-mgmt/GetSUCNodeIdMessages.ts | 4 +- .../network-mgmt/IsFailedNodeMessages.ts | 8 +- .../network-mgmt/RemoveFailedNodeMessages.ts | 16 +- .../RemoveNodeFromNetworkRequest.ts | 13 +- .../network-mgmt/ReplaceFailedNodeRequest.ts | 16 +- .../network-mgmt/RequestNodeInfoMessages.ts | 7 +- .../RequestNodeNeighborUpdateMessages.ts | 13 +- .../network-mgmt/SetLearnModeMessages.ts | 16 +- .../network-mgmt/SetPriorityRouteMessages.ts | 7 +- .../network-mgmt/SetSUCNodeIDMessages.ts | 16 +- .../nvm/ExtNVMReadLongBufferMessages.ts | 7 +- .../nvm/ExtNVMReadLongByteMessages.ts | 7 +- .../nvm/ExtNVMWriteLongBufferMessages.ts | 7 +- .../nvm/ExtNVMWriteLongByteMessages.ts | 7 +- .../nvm/ExtendedNVMOperationsMessages.ts | 18 +- .../nvm/FirmwareUpdateNVMMessages.ts | 37 ++- .../src/lib/serialapi/nvm/GetNVMIdMessages.ts | 4 +- .../serialapi/nvm/NVMOperationsMessages.ts | 18 +- .../transport/SendDataBridgeMessages.ts | 35 ++- .../serialapi/transport/SendDataMessages.ts | 43 ++-- .../transport/SendTestFrameMessages.ts | 16 +- .../discardUnsupportedReports.test.ts | 12 +- .../mapNotificationDoorLock.test.ts | 4 +- .../cc-specific/notificationEnums.test.ts | 42 ++-- .../notificationIdleManually.test.ts | 8 +- .../notificationIdleRelated.test.ts | 4 +- .../cc-specific/undefinedTargetValue.test.ts | 2 +- .../cc-specific/unknownNotifications.test.ts | 2 +- packages/zwave-js/src/lib/test/cc/API.test.ts | 2 +- .../src/lib/test/cc/AssociationCC.test.ts | 16 +- .../test/cc/AssociationGroupInfoCC.test.ts | 18 +- .../zwave-js/src/lib/test/cc/BasicCC.test.ts | 32 +-- .../src/lib/test/cc/BatteryCC.test.ts | 14 +- .../src/lib/test/cc/BinarySensorCC.test.ts | 14 +- .../src/lib/test/cc/BinarySwitchCC.test.ts | 12 +- .../zwave-js/src/lib/test/cc/CRC16CC.test.ts | 12 +- .../src/lib/test/cc/CentralSceneCC.test.ts | 18 +- .../src/lib/test/cc/ColorSwitchCC.test.ts | 18 +- .../cc/CommandClass.persistValues.test.ts | 4 +- .../src/lib/test/cc/CommandClass.test.ts | 16 +- .../src/lib/test/cc/DoorLockCC.test.ts | 30 +-- .../src/lib/test/cc/DoorLockLoggingCC.test.ts | 8 +- .../src/lib/test/cc/EntryControlCC.test.ts | 16 +- .../zwave-js/src/lib/test/cc/FibaroCC.test.ts | 16 +- .../lib/test/cc/HumidityControlModeCC.test.ts | 16 +- .../HumidityControlOperatingStateCC.test.ts | 4 +- .../test/cc/HumidityControlSetpointCC.test.ts | 26 +-- .../src/lib/test/cc/IndicatorCC.test.ts | 15 +- .../src/lib/test/cc/LanguageCC.test.ts | 12 +- .../test/cc/ManufacturerSpecificCC.test.ts | 4 +- .../zwave-js/src/lib/test/cc/MeterCC.test.ts | 36 +-- .../test/cc/MultiChannelAssociationCC.test.ts | 28 +-- .../src/lib/test/cc/MultiChannelCC.test.ts | 42 ++-- .../src/lib/test/cc/MultiCommandCC.test.ts | 2 +- .../lib/test/cc/MultilevelSwitchCC.test.ts | 18 +- .../src/lib/test/cc/NoOperationCC.test.ts | 4 +- .../src/lib/test/cc/PowerlevelCC.test.ts | 14 +- .../src/lib/test/cc/SceneActivationCC.test.ts | 8 +- .../cc/SceneActuatorConfigurationCC.test.ts | 10 +- .../cc/SceneControllerConfigurationCC.test.ts | 14 +- .../src/lib/test/cc/SupervisionCC.test.ts | 10 +- .../lib/test/cc/ThermostatFanModeCC.test.ts | 8 +- .../lib/test/cc/ThermostatFanStateCC.test.ts | 6 +- .../zwave-js/src/lib/test/cc/TimeCC.test.ts | 10 +- .../zwave-js/src/lib/test/cc/WakeUpCC.test.ts | 6 +- .../src/lib/test/cc/ZWavePlusCC.test.ts | 2 +- ...rySensorReportAnyUseFirstSupported.test.ts | 2 +- .../invalidCallbackFunctionTypes.test.ts | 40 ++-- .../compat/notificationAlarmMapping.test.ts | 2 +- .../test/compat/reInterviewWakeUpNIF.test.ts | 2 +- .../test/compliance/decodeLowerS2Keys.test.ts | 10 +- .../discardInsecureCommands.test.ts | 9 +- .../encapsulationAnswerAsAsked.test.ts | 16 +- .../handleMultiCommandPayload.test.ts | 6 +- .../secureNodeSecureEndpoint.test.ts | 16 +- .../test/driver/assemblePartialCCs.test.ts | 32 +-- .../driver/computeNetCCPayloadSize.test.ts | 8 +- .../lib/test/driver/controllerJammed.test.ts | 18 +- .../createCCValuesUsingKnownVersion.test.ts | 2 +- .../driver/handleNonImplementedCCs.test.ts | 2 +- ...noreCCVersion0ForKnownSupportedCCs.test.ts | 79 +++---- .../multiStageResponseNoTimeout.test.ts | 55 ++--- .../driver/nodeAsleepBlockNonceReport.test.ts | 6 +- .../test/driver/nodeAsleepNoReject.test.ts | 4 +- .../lib/test/driver/nodeDeadReject.test.ts | 8 +- .../test/driver/notificationPushNoAGI.test.ts | 2 +- .../driver/reInterviewAssumeAwake.test.ts | 4 +- .../lib/test/driver/receiveMessages.test.ts | 2 +- .../test/driver/s0AndS2Encapsulation.test.ts | 9 +- .../lib/test/driver/s0Encapsulation.test.ts | 21 +- .../driver/s0EncapsulationTwoNodes.test.ts | 21 +- .../src/lib/test/driver/s2Collisions.test.ts | 66 ++---- .../driver/sendDataAbortAfterTimeout.test.ts | 22 +- .../lib/test/driver/sendDataFailThrow.test.ts | 4 +- .../sendDataMissingCallbackAbort.test.ts | 36 +-- .../driver/sendDataMissingResponse.test.ts | 20 +- .../setValueFailedSupervisionGet.test.ts | 4 +- .../test/driver/setValueNoSupervision.test.ts | 2 +- .../setValueSucceedAfterFailure.test.ts | 4 +- ...setValueSuccessfulSupervisionNoGet.test.ts | 2 +- .../driver/setValueSupervision255Get.test.ts | 8 +- ...ValueSupervisionSuccessMoreUpdates.test.ts | 2 +- .../driver/setValueSupervisionWorking.test.ts | 4 +- .../driver/targetValueVersionUnknown.test.ts | 4 +- .../src/lib/test/driver/unknownValues.test.ts | 12 +- .../lib/test/driver/unresponsiveStick.test.ts | 6 +- .../legacyRefreshActuatorSensorCCs.test.ts | 2 +- .../src/lib/zniffer/CCParsingContext.ts | 96 -------- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 43 +++- 242 files changed, 1840 insertions(+), 2728 deletions(-) delete mode 100644 packages/zwave-js/src/lib/zniffer/CCParsingContext.ts diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 0b5af1dfe06c..848b61fbf3fd 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -15,7 +15,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -131,7 +130,7 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI { public async get(sensorType?: AlarmSensorType) { this.assertSupportsCommand(AlarmSensorCommand, AlarmSensorCommand.Get); - const cc = new AlarmSensorCCGet(this.applHost, { + const cc = new AlarmSensorCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sensorType, @@ -150,7 +149,7 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI { AlarmSensorCommand.SupportedGet, ); - const cc = new AlarmSensorCCSupportedGet(this.applHost, { + const cc = new AlarmSensorCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -324,10 +323,9 @@ duration: ${currentValue.duration}`; @CCCommand(AlarmSensorCommand.Report) export class AlarmSensorCCReport extends AlarmSensorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 5, this.payload[1] !== 0xff); // Alarm Sensor reports may be forwarded by a different node, in this case // (and only then!) the payload contains the original node ID @@ -405,10 +403,9 @@ export interface AlarmSensorCCGetOptions extends CCCommandOptions { @expectedCCResponse(AlarmSensorCCReport, testResponseForAlarmSensorGet) export class AlarmSensorCCGet extends AlarmSensorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | AlarmSensorCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -443,10 +440,9 @@ export class AlarmSensorCCGet extends AlarmSensorCC { @CCCommand(AlarmSensorCommand.SupportedReport) export class AlarmSensorCCSupportedReport extends AlarmSensorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); const bitMaskLength = this.payload[0]; validatePayload(this.payload.length >= 1 + bitMaskLength); diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index b9b0f111f949..c7ae11f24924 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -18,7 +18,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { distinct } from "alcalzone-shared/arrays"; @@ -106,7 +105,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { AssociationCommand.SupportedGroupingsGet, ); - const cc = new AssociationCCSupportedGroupingsGet(this.applHost, { + const cc = new AssociationCCSupportedGroupingsGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -126,7 +125,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { AssociationCommand.SupportedGroupingsReport, ); - const cc = new AssociationCCSupportedGroupingsReport(this.applHost, { + const cc = new AssociationCCSupportedGroupingsReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupCount, @@ -142,7 +141,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { public async getGroup(groupId: number) { this.assertSupportsCommand(AssociationCommand, AssociationCommand.Get); - const cc = new AssociationCCGet(this.applHost, { + const cc = new AssociationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -168,7 +167,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { AssociationCommand.Report, ); - const cc = new AssociationCCReport(this.applHost, { + const cc = new AssociationCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -186,7 +185,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(AssociationCommand, AssociationCommand.Set); - const cc = new AssociationCCSet(this.applHost, { + const cc = new AssociationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -222,7 +221,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { ); } - const cc = new AssociationCCRemove(this.applHost, { + const cc = new AssociationCCRemove({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -269,7 +268,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { AssociationCommand.SpecificGroupGet, ); - const cc = new AssociationCCSpecificGroupGet(this.applHost, { + const cc = new AssociationCCSpecificGroupGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -294,7 +293,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { AssociationCommand.SpecificGroupReport, ); - const cc = new AssociationCCSpecificGroupReport(this.applHost, { + const cc = new AssociationCCSpecificGroupReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, group, @@ -508,10 +507,9 @@ export interface AssociationCCSetOptions extends CCCommandOptions { @useSupervision() export class AssociationCCSet extends AssociationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | AssociationCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.groupId = this.payload[0]; @@ -568,12 +566,11 @@ export interface AssociationCCRemoveOptions { @useSupervision() export class AssociationCCRemove extends AssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (AssociationCCRemoveOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); if (this.payload[0] !== 0) { @@ -624,12 +621,11 @@ export interface AssociationCCReportSpecificOptions { @CCCommand(AssociationCommand.Report) export class AssociationCCReport extends AssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (AssociationCCReportSpecificOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -713,10 +709,9 @@ export interface AssociationCCGetOptions extends CCCommandOptions { @expectedCCResponse(AssociationCCReport) export class AssociationCCGet extends AssociationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | AssociationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.groupId = this.payload[0]; @@ -756,12 +751,11 @@ export interface AssociationCCSupportedGroupingsReportOptions @CCCommand(AssociationCommand.SupportedGroupingsReport) export class AssociationCCSupportedGroupingsReport extends AssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | AssociationCCSupportedGroupingsReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -799,12 +793,11 @@ export interface AssociationCCSpecificGroupReportOptions { @CCCommand(AssociationCommand.SpecificGroupReport) export class AssociationCCSpecificGroupReport extends AssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (AssociationCCSpecificGroupReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index ba2189336a84..cff849ff794f 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -15,7 +15,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { cpp2js, getEnumMemberName, num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -112,7 +111,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { AssociationGroupInfoCommand.NameGet, ); - const cc = new AssociationGroupInfoCCNameGet(this.applHost, { + const cc = new AssociationGroupInfoCCNameGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -133,7 +132,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { AssociationGroupInfoCommand.NameReport, ); - const cc = new AssociationGroupInfoCCNameReport(this.applHost, { + const cc = new AssociationGroupInfoCCNameReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -151,7 +150,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { AssociationGroupInfoCommand.InfoGet, ); - const cc = new AssociationGroupInfoCCInfoGet(this.applHost, { + const cc = new AssociationGroupInfoCCInfoGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -184,7 +183,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { AssociationGroupInfoCommand.InfoReport, ); - const cc = new AssociationGroupInfoCCInfoReport(this.applHost, { + const cc = new AssociationGroupInfoCCInfoReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -205,7 +204,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { AssociationGroupInfoCommand.CommandListGet, ); - const cc = new AssociationGroupInfoCCCommandListGet(this.applHost, { + const cc = new AssociationGroupInfoCCCommandListGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -230,7 +229,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { AssociationGroupInfoCommand.CommandListReport, ); - const cc = new AssociationGroupInfoCCCommandListReport(this.applHost, { + const cc = new AssociationGroupInfoCCCommandListReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -474,12 +473,11 @@ export interface AssociationGroupInfoCCNameReportOptions @CCCommand(AssociationGroupInfoCommand.NameReport) export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | AssociationGroupInfoCCNameReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -542,12 +540,11 @@ export interface AssociationGroupInfoCCNameGetOptions extends CCCommandOptions { @expectedCCResponse(AssociationGroupInfoCCNameReport) export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | AssociationGroupInfoCCNameGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.groupId = this.payload[0]; @@ -588,7 +585,6 @@ export interface AssociationGroupInfoCCInfoReportSpecificOptions { @CCCommand(AssociationGroupInfoCommand.InfoReport) export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ( @@ -596,7 +592,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { & CCCommandOptions ), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -708,12 +704,11 @@ export type AssociationGroupInfoCCInfoGetOptions = @expectedCCResponse(AssociationGroupInfoCCInfoReport) export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | AssociationGroupInfoCCInfoGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); const optionByte = this.payload[0]; @@ -773,12 +768,11 @@ export class AssociationGroupInfoCCCommandListReport extends AssociationGroupInfoCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | AssociationGroupInfoCCCommandListReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -866,12 +860,11 @@ export class AssociationGroupInfoCCCommandListGet extends AssociationGroupInfoCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | AssociationGroupInfoCCCommandListGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.allowCache = !!(this.payload[0] & 0b1000_0000); diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 0277aa7b0598..2ae3ace6b665 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -18,7 +18,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, @@ -148,7 +147,7 @@ export class BarrierOperatorCCAPI extends CCAPI { BarrierOperatorCommand.Get, ); - const cc = new BarrierOperatorCCGet(this.applHost, { + const cc = new BarrierOperatorCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -172,7 +171,7 @@ export class BarrierOperatorCCAPI extends CCAPI { BarrierOperatorCommand.Set, ); - const cc = new BarrierOperatorCCSet(this.applHost, { + const cc = new BarrierOperatorCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, targetState, @@ -189,13 +188,10 @@ export class BarrierOperatorCCAPI extends CCAPI { BarrierOperatorCommand.SignalingCapabilitiesGet, ); - const cc = new BarrierOperatorCCSignalingCapabilitiesGet( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - }, - ); + const cc = new BarrierOperatorCCSignalingCapabilitiesGet({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + }); const response = await this.applHost.sendCommand< BarrierOperatorCCSignalingCapabilitiesReport >( @@ -214,7 +210,7 @@ export class BarrierOperatorCCAPI extends CCAPI { BarrierOperatorCommand.EventSignalingGet, ); - const cc = new BarrierOperatorCCEventSignalingGet(this.applHost, { + const cc = new BarrierOperatorCCEventSignalingGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, subsystemType, @@ -238,7 +234,7 @@ export class BarrierOperatorCCAPI extends CCAPI { BarrierOperatorCommand.EventSignalingSet, ); - const cc = new BarrierOperatorCCEventSignalingSet(this.applHost, { + const cc = new BarrierOperatorCCEventSignalingSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, subsystemType, @@ -552,12 +548,11 @@ export interface BarrierOperatorCCSetOptions extends CCCommandOptions { @useSupervision() export class BarrierOperatorCCSet extends BarrierOperatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | BarrierOperatorCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -586,10 +581,9 @@ export class BarrierOperatorCCSet extends BarrierOperatorCC { @CCCommand(BarrierOperatorCommand.Report) export class BarrierOperatorCCReport extends BarrierOperatorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); @@ -649,10 +643,9 @@ export class BarrierOperatorCCSignalingCapabilitiesReport extends BarrierOperatorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); this.supportedSubsystemTypes = parseBitMask( this.payload, @@ -693,12 +686,11 @@ export interface BarrierOperatorCCEventSignalingSetOptions @useSupervision() export class BarrierOperatorCCEventSignalingSet extends BarrierOperatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | BarrierOperatorCCEventSignalingSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -738,10 +730,9 @@ export class BarrierOperatorCCEventSignalingSet extends BarrierOperatorCC { @CCCommand(BarrierOperatorCommand.EventSignalingReport) export class BarrierOperatorCCEventSignalingReport extends BarrierOperatorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.subsystemType = this.payload[0]; @@ -792,12 +783,11 @@ export interface BarrierOperatorCCEventSignalingGetOptions @expectedCCResponse(BarrierOperatorCCEventSignalingReport) export class BarrierOperatorCCEventSignalingGet extends BarrierOperatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | BarrierOperatorCCEventSignalingGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 6e9c7559103d..6832cd5755da 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { type AllOrNone, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -216,7 +215,7 @@ export class BasicCCAPI extends CCAPI { public async get() { this.assertSupportsCommand(BasicCommand, BasicCommand.Get); - const cc = new BasicCCGet(this.applHost, { + const cc = new BasicCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -239,7 +238,7 @@ export class BasicCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(BasicCommand, BasicCommand.Set); - const cc = new BasicCCSet(this.applHost, { + const cc = new BasicCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, targetValue, @@ -364,10 +363,9 @@ export interface BasicCCSetOptions extends CCCommandOptions { @useSupervision() export class BasicCCSet extends BasicCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | BasicCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.targetValue = this.payload[0]; @@ -406,10 +404,9 @@ export type BasicCCReportOptions = export class BasicCCReport extends BasicCC { // @noCCValues See comment in the constructor public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | BasicCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 06b487a35172..1858b978b92b 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { type AllOrNone, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { @@ -230,7 +229,7 @@ export class BatteryCCAPI extends PhysicalCCAPI { public async get() { this.assertSupportsCommand(BatteryCommand, BatteryCommand.Get); - const cc = new BatteryCCGet(this.applHost, { + const cc = new BatteryCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -258,7 +257,7 @@ export class BatteryCCAPI extends PhysicalCCAPI { public async getHealth() { this.assertSupportsCommand(BatteryCommand, BatteryCommand.HealthGet); - const cc = new BatteryCCHealthGet(this.applHost, { + const cc = new BatteryCCHealthGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -416,10 +415,9 @@ export type BatteryCCReportOptions = @CCCommand(BatteryCommand.Report) export class BatteryCCReport extends BatteryCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | BatteryCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -602,10 +600,9 @@ export class BatteryCCGet extends BatteryCC {} @CCCommand(BatteryCommand.HealthReport) export class BatteryCCHealthReport extends BatteryCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 3e33164a101e..c3d4d02bc77b 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -14,7 +14,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -113,7 +112,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { BinarySensorCommand.Get, ); - const cc = new BinarySensorCCGet(this.applHost, { + const cc = new BinarySensorCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sensorType, @@ -136,7 +135,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { BinarySensorCommand.Report, ); - const cc = new BinarySensorCCReport(this.applHost, { + const cc = new BinarySensorCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, value, @@ -153,7 +152,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { BinarySensorCommand.SupportedGet, ); - const cc = new BinarySensorCCSupportedGet(this.applHost, { + const cc = new BinarySensorCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -176,7 +175,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { BinarySensorCommand.SupportedReport, ); - const cc = new BinarySensorCCSupportedReport(this.applHost, { + const cc = new BinarySensorCCSupportedReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, supportedSensorTypes: supported, @@ -347,12 +346,11 @@ export interface BinarySensorCCReportOptions extends CCCommandOptions { @CCCommand(BinarySensorCommand.Report) export class BinarySensorCCReport extends BinarySensorCC { public constructor( - host: ZWaveHost, options: | BinarySensorCCReportOptions | CommandClassDeserializationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -431,10 +429,9 @@ export interface BinarySensorCCGetOptions extends CCCommandOptions { @expectedCCResponse(BinarySensorCCReport, testResponseForBinarySensorGet) export class BinarySensorCCGet extends BinarySensorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | BinarySensorCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { if (this.payload.length >= 1) { this.sensorType = this.payload[0]; @@ -472,12 +469,11 @@ export interface BinarySensorCCSupportedReportOptions { @CCCommand(BinarySensorCommand.SupportedReport) export class BinarySensorCCSupportedReport extends BinarySensorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (BinarySensorCCSupportedReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 76dad09e80d1..9c2a132b8169 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -18,7 +18,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import type { AllOrNone } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -103,7 +102,7 @@ export class BinarySwitchCCAPI extends CCAPI { BinarySwitchCommand.Get, ); - const cc = new BinarySwitchCCGet(this.applHost, { + const cc = new BinarySwitchCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -136,7 +135,7 @@ export class BinarySwitchCCAPI extends CCAPI { BinarySwitchCommand.Set, ); - const cc = new BinarySwitchCCSet(this.applHost, { + const cc = new BinarySwitchCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, targetValue, @@ -315,10 +314,9 @@ export interface BinarySwitchCCSetOptions extends CCCommandOptions { @useSupervision() export class BinarySwitchCCSet extends BinarySwitchCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | BinarySwitchCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.targetValue = !!this.payload[0]; @@ -381,12 +379,11 @@ export type BinarySwitchCCReportOptions = @CCCommand(BinarySwitchCommand.Report) export class BinarySwitchCCReport extends BinarySwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | BinarySwitchCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index e14ebd90b301..0fe5349e4066 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -6,11 +6,7 @@ import { type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, @@ -50,7 +46,7 @@ export class CRC16CCAPI extends CCAPI { CRC16Command.CommandEncapsulation, ); - const cc = new CRC16CCCommandEncapsulation(this.applHost, { + const cc = new CRC16CCCommandEncapsulation({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, encapsulated: encapsulatedCC, @@ -74,10 +70,9 @@ export class CRC16CC extends CommandClass { /** Encapsulates a command in a CRC-16 CC */ public static encapsulate( - host: ZWaveHost, cc: CommandClass, ): CRC16CCCommandEncapsulation { - const ret = new CRC16CCCommandEncapsulation(host, { + const ret = new CRC16CCCommandEncapsulation({ nodeId: cc.nodeId, encapsulated: cc, }); @@ -111,12 +106,11 @@ function getCCResponseForCommandEncapsulation( ) export class CRC16CCCommandEncapsulation extends CRC16CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | CRC16CCCommandEncapsulationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -130,7 +124,7 @@ export class CRC16CCCommandEncapsulation extends CRC16CC { ); validatePayload(expectedCRC === actualCRC); - this.encapsulated = CommandClass.from(this.host, { + this.encapsulated = CommandClass.from({ data: ccBuffer, fromEncapsulation: true, encapCC: this, diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 9c041550481a..d5ba86452aa8 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -18,7 +18,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -115,7 +114,7 @@ export class CentralSceneCCAPI extends CCAPI { CentralSceneCommand.SupportedGet, ); - const cc = new CentralSceneCCSupportedGet(this.applHost, { + const cc = new CentralSceneCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -141,7 +140,7 @@ export class CentralSceneCCAPI extends CCAPI { CentralSceneCommand.ConfigurationGet, ); - const cc = new CentralSceneCCConfigurationGet(this.applHost, { + const cc = new CentralSceneCCConfigurationGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -165,7 +164,7 @@ export class CentralSceneCCAPI extends CCAPI { CentralSceneCommand.ConfigurationSet, ); - const cc = new CentralSceneCCConfigurationSet(this.applHost, { + const cc = new CentralSceneCCConfigurationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, slowRefresh, @@ -303,10 +302,9 @@ supports slow refresh: ${ccSupported.supportsSlowRefresh}`; @CCCommand(CentralSceneCommand.Notification) export class CentralSceneCCNotification extends CentralSceneCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 3); this.sequenceNumber = this.payload[0]; @@ -360,10 +358,9 @@ export class CentralSceneCCNotification extends CentralSceneCC { @CCCommand(CentralSceneCommand.SupportedReport) export class CentralSceneCCSupportedReport extends CentralSceneCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.sceneCount = this.payload[0]; @@ -458,10 +455,9 @@ export class CentralSceneCCSupportedGet extends CentralSceneCC {} @CCCommand(CentralSceneCommand.ConfigurationReport) export class CentralSceneCCConfigurationReport extends CentralSceneCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.slowRefresh = !!(this.payload[0] & 0b1000_0000); @@ -493,12 +489,11 @@ export interface CentralSceneCCConfigurationSetOptions @useSupervision() export class CentralSceneCCConfigurationSet extends CentralSceneCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | CentralSceneCCConfigurationSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index 85d3acb77fdf..3a94ac2a7b83 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -9,11 +9,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; @@ -114,7 +110,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { ClimateControlScheduleCommand.Set, ); - const cc = new ClimateControlScheduleCCSet(this.applHost, { + const cc = new ClimateControlScheduleCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, weekday, @@ -132,7 +128,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { ClimateControlScheduleCommand.Get, ); - const cc = new ClimateControlScheduleCCGet(this.applHost, { + const cc = new ClimateControlScheduleCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, weekday, @@ -152,7 +148,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { ClimateControlScheduleCommand.ChangedGet, ); - const cc = new ClimateControlScheduleCCChangedGet(this.applHost, { + const cc = new ClimateControlScheduleCCChangedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -172,7 +168,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { ClimateControlScheduleCommand.OverrideGet, ); - const cc = new ClimateControlScheduleCCOverrideGet(this.applHost, { + const cc = new ClimateControlScheduleCCOverrideGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -200,7 +196,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { ClimateControlScheduleCommand.OverrideSet, ); - const cc = new ClimateControlScheduleCCOverrideSet(this.applHost, { + const cc = new ClimateControlScheduleCCOverrideSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, overrideType: type, @@ -227,12 +223,11 @@ export interface ClimateControlScheduleCCSetOptions extends CCCommandOptions { @useSupervision() export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ClimateControlScheduleCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -291,10 +286,9 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { @CCCommand(ClimateControlScheduleCommand.Report) export class ClimateControlScheduleCCReport extends ClimateControlScheduleCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 28); // 1 + 9 * 3 this.weekday = this.payload[0] & 0b111; @@ -348,12 +342,11 @@ export interface ClimateControlScheduleCCGetOptions extends CCCommandOptions { @expectedCCResponse(ClimateControlScheduleCCReport) export class ClimateControlScheduleCCGet extends ClimateControlScheduleCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ClimateControlScheduleCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -384,10 +377,9 @@ export class ClimateControlScheduleCCChangedReport extends ClimateControlScheduleCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.changeCounter = this.payload[0]; @@ -414,10 +406,9 @@ export class ClimateControlScheduleCCOverrideReport extends ClimateControlScheduleCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.overrideType = this.payload[0] & 0b11; @@ -465,12 +456,11 @@ export class ClimateControlScheduleCCOverrideSet extends ClimateControlScheduleCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ClimateControlScheduleCCOverrideSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 7357ce02538f..c7993bb071b9 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -14,7 +14,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -55,7 +54,7 @@ export class ClockCCAPI extends CCAPI { public async get() { this.assertSupportsCommand(ClockCommand, ClockCommand.Get); - const cc = new ClockCCGet(this.applHost, { + const cc = new ClockCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -76,7 +75,7 @@ export class ClockCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(ClockCommand, ClockCommand.Set); - const cc = new ClockCCSet(this.applHost, { + const cc = new ClockCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, hour, @@ -154,10 +153,9 @@ export interface ClockCCSetOptions extends CCCommandOptions { @useSupervision() export class ClockCCSet extends ClockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ClockCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -207,10 +205,9 @@ export class ClockCCSet extends ClockCC { @CCCommand(ClockCommand.Report) export class ClockCCReport extends ClockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.weekday = this.payload[0] >>> 5; diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index b61a90234f68..302060033a75 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -20,7 +20,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -210,7 +209,7 @@ export class ColorSwitchCCAPI extends CCAPI { ColorSwitchCommand.SupportedGet, ); - const cc = new ColorSwitchCCSupportedGet(this.applHost, { + const cc = new ColorSwitchCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -228,7 +227,7 @@ export class ColorSwitchCCAPI extends CCAPI { public async get(component: ColorComponent) { this.assertSupportsCommand(ColorSwitchCommand, ColorSwitchCommand.Get); - const cc = new ColorSwitchCCGet(this.applHost, { + const cc = new ColorSwitchCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, colorComponent: component, @@ -248,7 +247,7 @@ export class ColorSwitchCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(ColorSwitchCommand, ColorSwitchCommand.Set); - const cc = new ColorSwitchCCSet(this.applHost, { + const cc = new ColorSwitchCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -366,7 +365,7 @@ export class ColorSwitchCCAPI extends CCAPI { ColorSwitchCommand.StartLevelChange, ); - const cc = new ColorSwitchCCStartLevelChange(this.applHost, { + const cc = new ColorSwitchCCStartLevelChange({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -384,7 +383,7 @@ export class ColorSwitchCCAPI extends CCAPI { ColorSwitchCommand.StopLevelChange, ); - const cc = new ColorSwitchCCStopLevelChange(this.applHost, { + const cc = new ColorSwitchCCStopLevelChange({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, colorComponent, @@ -687,12 +686,11 @@ export interface ColorSwitchCCSupportedReportOptions { @CCCommand(ColorSwitchCommand.SupportedReport) export class ColorSwitchCCSupportedReport extends ColorSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (ColorSwitchCCSupportedReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // Docs say 'variable length', but the table shows 2 bytes. @@ -749,12 +747,11 @@ export type ColorSwitchCCReportOptions = @CCCommand(ColorSwitchCommand.Report) export class ColorSwitchCCReport extends ColorSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (ColorSwitchCCReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -905,10 +902,9 @@ function testResponseForColorSwitchGet( @expectedCCResponse(ColorSwitchCCReport, testResponseForColorSwitchGet) export class ColorSwitchCCGet extends ColorSwitchCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ColorSwitchCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this._colorComponent = this.payload[0]; @@ -958,12 +954,11 @@ export type ColorSwitchCCSetOptions = (ColorTable | { hexColor: string }) & { @useSupervision() export class ColorSwitchCCSet extends ColorSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & ColorSwitchCCSetOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const populatedColorCount = this.payload[0] & 0b11111; @@ -1080,12 +1075,11 @@ export type ColorSwitchCCStartLevelChangeOptions = @useSupervision() export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & ColorSwitchCCStartLevelChangeOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); const ignoreStartLevel = (this.payload[0] & 0b0_0_1_00000) >>> 5; @@ -1167,12 +1161,11 @@ export interface ColorSwitchCCStopLevelChangeOptions extends CCCommandOptions { @useSupervision() export class ColorSwitchCCStopLevelChange extends ColorSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ColorSwitchCCStopLevelChangeOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.colorComponent = this.payload[0]; diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index fd5846dd4298..95f3099630f4 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -29,7 +29,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -147,11 +146,9 @@ type NormalizedConfigurationCCAPISetOptions = ); function createConfigurationCCInstance( - applHost: ZWaveApplicationHost, endpoint: CCAPIEndpoint, ): ConfigurationCC { return CommandClass.createInstanceUnchecked( - applHost, endpoint.virtual ? endpoint.node.physicalNodes[0] : endpoint, ConfigurationCC, )!; @@ -164,7 +161,7 @@ function normalizeConfigurationCCAPISetOptions( ): NormalizedConfigurationCCAPISetOptions { if ("bitMask" in options && options.bitMask) { // Variant 3: Partial param, look it up in the device config - const ccc = createConfigurationCCInstance(applHost, endpoint); + const ccc = createConfigurationCCInstance(endpoint); const paramInfo = ccc.getParamInformation( applHost, options.parameter, @@ -193,7 +190,7 @@ function normalizeConfigurationCCAPISetOptions( ]); } else { // Variant 1: Normal parameter, defined in a config file - const ccc = createConfigurationCCInstance(applHost, endpoint); + const ccc = createConfigurationCCInstance(endpoint); const paramInfo = ccc.getParamInformation( applHost, options.parameter, @@ -234,7 +231,7 @@ function bulkMergePartialParamValues( } // and push the merged result into the array we'll be working with if (unmergedPartials.size) { - const ccc = createConfigurationCCInstance(applHost, endpoint); + const ccc = createConfigurationCCInstance(endpoint); for (const [parameter, partials] of unmergedPartials) { allParams.push({ parameter, @@ -344,10 +341,7 @@ export class ConfigurationCCAPI extends CCAPI { const applHost = this.applHost; if (this.isSinglecast()) { - ccInstance = createConfigurationCCInstance( - this.applHost, - this.endpoint, - ); + ccInstance = createConfigurationCCInstance(this.endpoint); } else if (this.isMulticast()) { // Multicast is only possible if the parameter definition is the same on all target nodes const nodes = this.endpoint.node.physicalNodes; @@ -367,7 +361,6 @@ export class ConfigurationCCAPI extends CCAPI { const paramInfos = this.endpoint.node.physicalNodes.map( (node) => createConfigurationCCInstance( - this.applHost, node.getEndpoint(this.endpoint.index)!, ).getParamInformation( this.applHost, @@ -391,10 +384,7 @@ export class ConfigurationCCAPI extends CCAPI { ); } // If it is, just use the first node to create the CC instance - ccInstance = createConfigurationCCInstance( - this.applHost, - this.endpoint, - ); + ccInstance = createConfigurationCCInstance(this.endpoint); } else { throw new ZWaveError( `The setValue API for Configuration CC is not supported via broadcast!`, @@ -533,7 +523,7 @@ export class ConfigurationCCAPI extends CCAPI { const { valueBitMask, allowUnexpectedResponse } = options ?? {}; - const cc = new ConfigurationCCGet(this.applHost, { + const cc = new ConfigurationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -602,7 +592,7 @@ export class ConfigurationCCAPI extends CCAPI { this.supportsCommand(ConfigurationCommand.BulkGet) && isConsecutiveArray(distinctParameters) ) { - const cc = new ConfigurationCCBulkGet(this.applHost, { + const cc = new ConfigurationCCBulkGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameters: distinctParameters, @@ -622,7 +612,7 @@ export class ConfigurationCCAPI extends CCAPI { const _values = new Map(); for (const parameter of distinctParameters) { - const cc = new ConfigurationCCGet(this.applHost, { + const cc = new ConfigurationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -641,7 +631,7 @@ export class ConfigurationCCAPI extends CCAPI { } // Combine the returned values with the requested ones - const cc = createConfigurationCCInstance(this.applHost, this.endpoint); + const cc = createConfigurationCCInstance(this.endpoint); return options.map((o) => { let value = values?.get(o.parameter); if (typeof value === "number" && o.bitMask) { @@ -684,10 +674,7 @@ export class ConfigurationCCAPI extends CCAPI { ); let value = normalized.value; if (normalized.bitMask) { - const ccc = createConfigurationCCInstance( - this.applHost, - this.endpoint, - ); + const ccc = createConfigurationCCInstance(this.endpoint); value = ccc.composePartialParamValue( this.applHost, normalized.parameter, @@ -695,7 +682,7 @@ export class ConfigurationCCAPI extends CCAPI { normalized.value, ); } - const cc = new ConfigurationCCSet(this.applHost, { + const cc = new ConfigurationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, resetToDefault: false, @@ -739,7 +726,7 @@ export class ConfigurationCCAPI extends CCAPI { && new Set(allParams.map((v) => v.valueSize)).size === 1; if (canUseBulkSet) { - const cc = new ConfigurationCCBulkSet(this.applHost, { + const cc = new ConfigurationCCBulkSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameters: allParams.map((v) => v.parameter), @@ -787,7 +774,7 @@ export class ConfigurationCCAPI extends CCAPI { valueFormat, } of allParams ) { - const cc = new ConfigurationCCSet(this.applHost, { + const cc = new ConfigurationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -833,7 +820,7 @@ export class ConfigurationCCAPI extends CCAPI { ConfigurationCommand.Set, ); - const cc = new ConfigurationCCSet(this.applHost, { + const cc = new ConfigurationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -855,7 +842,7 @@ export class ConfigurationCCAPI extends CCAPI { isConsecutiveArray(parameters) && this.supportsCommand(ConfigurationCommand.BulkSet) ) { - const cc = new ConfigurationCCBulkSet(this.applHost, { + const cc = new ConfigurationCCBulkSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameters, @@ -869,7 +856,7 @@ export class ConfigurationCCAPI extends CCAPI { ); const CCs = distinct(parameters).map( (parameter) => - new ConfigurationCCSet(this.applHost, { + new ConfigurationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -892,7 +879,7 @@ export class ConfigurationCCAPI extends CCAPI { ConfigurationCommand.DefaultReset, ); - const cc = new ConfigurationCCDefaultReset(this.applHost, { + const cc = new ConfigurationCCDefaultReset({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -905,7 +892,7 @@ export class ConfigurationCCAPI extends CCAPI { // Get-type commands are only possible in singlecast this.assertPhysicalEndpoint(this.endpoint); - const cc = new ConfigurationCCPropertiesGet(this.applHost, { + const cc = new ConfigurationCCPropertiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -938,7 +925,7 @@ export class ConfigurationCCAPI extends CCAPI { // Get-type commands are only possible in singlecast this.assertPhysicalEndpoint(this.endpoint); - const cc = new ConfigurationCCNameGet(this.applHost, { + const cc = new ConfigurationCCNameGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -958,7 +945,7 @@ export class ConfigurationCCAPI extends CCAPI { // Get-type commands are only possible in singlecast this.assertPhysicalEndpoint(this.endpoint); - const cc = new ConfigurationCCInfoGet(this.applHost, { + const cc = new ConfigurationCCInfoGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -999,10 +986,7 @@ export class ConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, message: `Scanning available parameters...`, }); - const ccInstance = createConfigurationCCInstance( - this.applHost, - this.endpoint, - ); + const ccInstance = createConfigurationCCInstance(this.endpoint); for (let param = 1; param <= 255; param++) { // Check if the parameter is readable let originalValue: ConfigValue | undefined; @@ -1614,12 +1598,11 @@ export interface ConfigurationCCReportOptions extends CCCommandOptions { @CCCommand(ConfigurationCommand.Report) export class ConfigurationCCReport extends ConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ConfigurationCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // All fields must be present @@ -1799,10 +1782,9 @@ export interface ConfigurationCCGetOptions extends CCCommandOptions { @expectedCCResponse(ConfigurationCCReport, testResponseForConfigurationGet) export class ConfigurationCCGet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ConfigurationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.parameter = this.payload[0]; @@ -1852,10 +1834,9 @@ export type ConfigurationCCSetOptions = @useSupervision() export class ConfigurationCCSet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ConfigurationCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.parameter = this.payload[0]; @@ -1988,12 +1969,11 @@ function getResponseForBulkSet(cc: ConfigurationCCBulkSet) { @useSupervision() export class ConfigurationCCBulkSet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ConfigurationCCBulkSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2128,10 +2108,9 @@ export class ConfigurationCCBulkSet extends ConfigurationCC { @CCCommand(ConfigurationCommand.BulkReport) export class ConfigurationCCBulkReport extends ConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); // Ensure we received enough bytes for the preamble validatePayload(this.payload.length >= 5); @@ -2259,12 +2238,11 @@ export interface ConfigurationCCBulkGetOptions extends CCCommandOptions { @expectedCCResponse(ConfigurationCCBulkReport) export class ConfigurationCCBulkGet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ConfigurationCCBulkGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2312,12 +2290,11 @@ export interface ConfigurationCCNameReportOptions extends CCCommandOptions { @CCCommand(ConfigurationCommand.NameReport) export class ConfigurationCCNameReport extends ConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ConfigurationCCNameReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // Parameter and # of reports must be present @@ -2422,10 +2399,9 @@ export class ConfigurationCCNameReport extends ConfigurationCC { @expectedCCResponse(ConfigurationCCNameReport) export class ConfigurationCCNameGet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ConfigurationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.parameter = this.payload.readUInt16BE(0); @@ -2460,12 +2436,11 @@ export interface ConfigurationCCInfoReportOptions extends CCCommandOptions { @CCCommand(ConfigurationCommand.InfoReport) export class ConfigurationCCInfoReport extends ConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ConfigurationCCInfoReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // Parameter and # of reports must be present @@ -2583,10 +2558,9 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { @expectedCCResponse(ConfigurationCCInfoReport) export class ConfigurationCCInfoGet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ConfigurationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.parameter = this.payload.readUInt16BE(0); @@ -2631,12 +2605,11 @@ export interface ConfigurationCCPropertiesReportOptions @CCCommand(ConfigurationCommand.PropertiesReport) export class ConfigurationCCPropertiesReport extends ConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ConfigurationCCPropertiesReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -2907,10 +2880,9 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { @expectedCCResponse(ConfigurationCCPropertiesReport) export class ConfigurationCCPropertiesGet extends ConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ConfigurationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.parameter = this.payload.readUInt16BE(0); diff --git a/packages/cc/src/cc/DeviceResetLocallyCC.ts b/packages/cc/src/cc/DeviceResetLocallyCC.ts index 8a028fa9e3c7..9927ddff1922 100644 --- a/packages/cc/src/cc/DeviceResetLocallyCC.ts +++ b/packages/cc/src/cc/DeviceResetLocallyCC.ts @@ -4,7 +4,6 @@ import { TransmitOptions, validatePayload, } from "@zwave-js/core/safe"; -import type { ZWaveHost } from "@zwave-js/host/safe"; import { CCAPI } from "../lib/API"; import { CommandClass, @@ -39,7 +38,7 @@ export class DeviceResetLocallyCCAPI extends CCAPI { DeviceResetLocallyCommand.Notification, ); - const cc = new DeviceResetLocallyCCNotification(this.applHost, { + const cc = new DeviceResetLocallyCCNotification({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -73,8 +72,8 @@ export class DeviceResetLocallyCC extends CommandClass { @CCCommand(DeviceResetLocallyCommand.Notification) export class DeviceResetLocallyCCNotification extends DeviceResetLocallyCC { - public constructor(host: ZWaveHost, options: CommandClassOptions) { - super(host, options); + public constructor(options: CommandClassOptions) { + super(options); if (gotDeserializationOptions(options)) { // We need to make sure this doesn't get parsed accidentally, e.g. because of a bit flip diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 218842b9b29d..90d1728687eb 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -465,7 +464,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { DoorLockCommand.CapabilitiesGet, ); - const cc = new DoorLockCCCapabilitiesGet(this.applHost, { + const cc = new DoorLockCCCapabilitiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -499,7 +498,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { DoorLockCommand.OperationGet, ); - const cc = new DoorLockCCOperationGet(this.applHost, { + const cc = new DoorLockCCOperationGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -533,7 +532,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { DoorLockCommand.OperationSet, ); - const cc = new DoorLockCCOperationSet(this.applHost, { + const cc = new DoorLockCCOperationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, mode, @@ -550,7 +549,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { DoorLockCommand.ConfigurationSet, ); - const cc = new DoorLockCCConfigurationSet(this.applHost, { + const cc = new DoorLockCCConfigurationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...configuration, @@ -565,7 +564,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { DoorLockCommand.ConfigurationGet, ); - const cc = new DoorLockCCConfigurationGet(this.applHost, { + const cc = new DoorLockCCConfigurationGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -829,12 +828,11 @@ export interface DoorLockCCOperationSetOptions extends CCCommandOptions { @useSupervision() export class DoorLockCCOperationSet extends DoorLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | DoorLockCCOperationSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -872,10 +870,9 @@ export class DoorLockCCOperationSet extends DoorLockCC { @CCCommand(DoorLockCommand.OperationReport) export class DoorLockCCOperationReport extends DoorLockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 5); this.currentMode = this.payload[0]; @@ -1015,10 +1012,9 @@ export class DoorLockCCOperationGet extends DoorLockCC {} @CCCommand(DoorLockCommand.ConfigurationReport) export class DoorLockCCConfigurationReport extends DoorLockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); this.operationType = this.payload[0]; @@ -1190,12 +1186,11 @@ export type DoorLockCCConfigurationSetOptions = @useSupervision() export class DoorLockCCConfigurationSet extends DoorLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & DoorLockCCConfigurationSetOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -1326,10 +1321,9 @@ export class DoorLockCCConfigurationSet extends DoorLockCC { @CCCommand(DoorLockCommand.CapabilitiesReport) export class DoorLockCCCapabilitiesReport extends DoorLockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); // parse variable length operation type bit mask validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index 9272a10eca27..543bf87dc997 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -12,7 +12,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { isPrintableASCII, num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -128,7 +127,7 @@ export class DoorLockLoggingCCAPI extends PhysicalCCAPI { DoorLockLoggingCommand.RecordsSupportedGet, ); - const cc = new DoorLockLoggingCCRecordsSupportedGet(this.applHost, { + const cc = new DoorLockLoggingCCRecordsSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -151,7 +150,7 @@ export class DoorLockLoggingCCAPI extends PhysicalCCAPI { DoorLockLoggingCommand.RecordGet, ); - const cc = new DoorLockLoggingCCRecordGet(this.applHost, { + const cc = new DoorLockLoggingCCRecordGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, recordNumber, @@ -233,10 +232,9 @@ export class DoorLockLoggingCC extends CommandClass { @CCCommand(DoorLockLoggingCommand.RecordsSupportedReport) export class DoorLockLoggingCCRecordsSupportedReport extends DoorLockLoggingCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.recordsCount = this.payload[0]; @@ -269,10 +267,9 @@ export class DoorLockLoggingCCRecordsSupportedGet extends DoorLockLoggingCC {} @CCCommand(DoorLockLoggingCommand.RecordReport) export class DoorLockLoggingCCRecordReport extends DoorLockLoggingCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 11); this.recordNumber = this.payload[0]; @@ -372,12 +369,11 @@ function testResponseForDoorLockLoggingRecordGet( ) export class DoorLockLoggingCCRecordGet extends DoorLockLoggingCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | DoorLockLoggingCCRecordGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index 6a1195c1fb57..15cd08892ed0 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -12,7 +12,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host"; import { getEnumMemberName, pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -111,7 +110,7 @@ export class EnergyProductionCCAPI extends CCAPI { EnergyProductionCommand.Get, ); - const cc = new EnergyProductionCCGet(this.applHost, { + const cc = new EnergyProductionCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -199,12 +198,11 @@ export interface EnergyProductionCCReportOptions extends CCCommandOptions { @CCCommand(EnergyProductionCommand.Report) export class EnergyProductionCCReport extends EnergyProductionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | EnergyProductionCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.parameter = this.payload[0]; @@ -283,12 +281,11 @@ function testResponseForEnergyProductionGet( ) export class EnergyProductionCCGet extends EnergyProductionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | EnergyProductionCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.parameter = this.payload[0]; diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index cf90c6e35908..5449503ade1e 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { buffer2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -115,7 +114,7 @@ export class EntryControlCCAPI extends CCAPI { EntryControlCommand.KeySupportedGet, ); - const cc = new EntryControlCCKeySupportedGet(this.applHost, { + const cc = new EntryControlCCKeySupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -135,7 +134,7 @@ export class EntryControlCCAPI extends CCAPI { EntryControlCommand.EventSupportedGet, ); - const cc = new EntryControlCCEventSupportedGet(this.applHost, { + const cc = new EntryControlCCEventSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -164,7 +163,7 @@ export class EntryControlCCAPI extends CCAPI { EntryControlCommand.ConfigurationGet, ); - const cc = new EntryControlCCConfigurationGet(this.applHost, { + const cc = new EntryControlCCConfigurationGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -189,7 +188,7 @@ export class EntryControlCCAPI extends CCAPI { EntryControlCommand.ConfigurationGet, ); - const cc = new EntryControlCCConfigurationSet(this.applHost, { + const cc = new EntryControlCCConfigurationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, keyCacheSize, @@ -397,10 +396,9 @@ key cache timeout: ${conf.keyCacheTimeout} seconds`, @CCCommand(EntryControlCommand.Notification) export class EntryControlCCNotification extends EntryControlCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); this.sequenceNumber = this.payload[0]; @@ -499,10 +497,9 @@ export class EntryControlCCNotification extends EntryControlCC { @CCCommand(EntryControlCommand.KeySupportedReport) export class EntryControlCCKeySupportedReport extends EntryControlCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); const length = this.payload[0]; @@ -531,10 +528,9 @@ export class EntryControlCCKeySupportedGet extends EntryControlCC {} @CCCommand(EntryControlCommand.EventSupportedReport) export class EntryControlCCEventSupportedReport extends EntryControlCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); const dataTypeLength = this.payload[0] & 0b11; @@ -630,10 +626,9 @@ export class EntryControlCCEventSupportedGet extends EntryControlCC {} @CCCommand(EntryControlCommand.ConfigurationReport) export class EntryControlCCConfigurationReport extends EntryControlCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); @@ -675,12 +670,11 @@ export interface EntryControlCCConfigurationSetOptions @useSupervision() export class EntryControlCCConfigurationSet extends EntryControlCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | EntryControlCCConfigurationSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index b19fa5814eb2..b5dbdf38ead9 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -13,7 +13,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -116,7 +115,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { FirmwareUpdateMetaDataCommand.MetaDataGet, ); - const cc = new FirmwareUpdateMetaDataCCMetaDataGet(this.applHost, { + const cc = new FirmwareUpdateMetaDataCCMetaDataGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -152,7 +151,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { FirmwareUpdateMetaDataCommand.Report, ); - const cc = new FirmwareUpdateMetaDataCCMetaDataReport(this.applHost, { + const cc = new FirmwareUpdateMetaDataCCMetaDataReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -173,7 +172,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { FirmwareUpdateMetaDataCommand.RequestGet, ); - const cc = new FirmwareUpdateMetaDataCCRequestGet(this.applHost, { + const cc = new FirmwareUpdateMetaDataCCRequestGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -217,7 +216,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { FirmwareUpdateMetaDataCommand.Report, ); - const cc = new FirmwareUpdateMetaDataCCReport(this.applHost, { + const cc = new FirmwareUpdateMetaDataCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, reportNumber: fragmentNumber, @@ -241,7 +240,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { FirmwareUpdateMetaDataCommand.ActivationSet, ); - const cc = new FirmwareUpdateMetaDataCCActivationSet(this.applHost, { + const cc = new FirmwareUpdateMetaDataCCActivationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -349,7 +348,6 @@ export class FirmwareUpdateMetaDataCCMetaDataReport implements FirmwareUpdateMetaData { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ( @@ -357,7 +355,7 @@ export class FirmwareUpdateMetaDataCCMetaDataReport & CCCommandOptions ), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 6); @@ -511,10 +509,9 @@ export class FirmwareUpdateMetaDataCCRequestReport extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.status = this.payload[0]; if (this.payload.length >= 2) { @@ -574,12 +571,11 @@ export class FirmwareUpdateMetaDataCCRequestGet extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (FirmwareUpdateMetaDataCCRequestGetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -663,10 +659,9 @@ export class FirmwareUpdateMetaDataCCRequestGet // This is sent to us from the node, so we expect no response export class FirmwareUpdateMetaDataCCGet extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 3); this.numReports = this.payload[0]; this.reportNumber = this.payload.readUInt16BE(1) & 0x7fff; @@ -699,12 +694,11 @@ export interface FirmwareUpdateMetaDataCCReportOptions // We send this in reply to the Get command and expect no response export class FirmwareUpdateMetaDataCCReport extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | FirmwareUpdateMetaDataCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -768,10 +762,9 @@ export class FirmwareUpdateMetaDataCCStatusReport extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.status = this.payload[0]; if (this.payload.length >= 3) { @@ -802,10 +795,9 @@ export class FirmwareUpdateMetaDataCCActivationReport extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 8); this.manufacturerId = this.payload.readUInt16BE(0); this.firmwareId = this.payload.readUInt16BE(2); @@ -862,12 +854,11 @@ export class FirmwareUpdateMetaDataCCActivationSet extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (FirmwareUpdateMetaDataCCActivationSetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -921,10 +912,9 @@ export class FirmwareUpdateMetaDataCCPrepareReport extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 3); this.status = this.payload[0]; this.checksum = this.payload.readUInt16BE(1); @@ -961,12 +951,11 @@ export class FirmwareUpdateMetaDataCCPrepareGet extends FirmwareUpdateMetaDataCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | FirmwareUpdateMetaDataCCPrepareGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index 754ef6ee0fb2..420952c27566 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -16,7 +16,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -127,7 +126,7 @@ export class HumidityControlModeCCAPI extends CCAPI { HumidityControlModeCommand.Get, ); - const cc = new HumidityControlModeCCGet(this.applHost, { + const cc = new HumidityControlModeCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -151,7 +150,7 @@ export class HumidityControlModeCCAPI extends CCAPI { HumidityControlModeCommand.Set, ); - const cc = new HumidityControlModeCCSet(this.applHost, { + const cc = new HumidityControlModeCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, mode, @@ -167,7 +166,7 @@ export class HumidityControlModeCCAPI extends CCAPI { HumidityControlModeCommand.SupportedGet, ); - const cc = new HumidityControlModeCCSupportedGet(this.applHost, { + const cc = new HumidityControlModeCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -286,12 +285,11 @@ export interface HumidityControlModeCCSetOptions extends CCCommandOptions { @useSupervision() export class HumidityControlModeCCSet extends HumidityControlModeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | HumidityControlModeCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -323,10 +321,9 @@ export class HumidityControlModeCCSet extends HumidityControlModeCC { @CCCommand(HumidityControlModeCommand.Report) export class HumidityControlModeCCReport extends HumidityControlModeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.mode = this.payload[0] & 0b1111; @@ -354,10 +351,9 @@ export class HumidityControlModeCCSupportedReport extends HumidityControlModeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this._supportedModes = parseBitMask( diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index 9d6b9d8a26c8..c82b18931e67 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -7,11 +7,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { - GetValueDB, - ZWaveApplicationHost, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { GetValueDB, ZWaveApplicationHost } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { CCAPI, @@ -90,7 +86,7 @@ export class HumidityControlOperatingStateCCAPI extends CCAPI { HumidityControlOperatingStateCommand.Get, ); - const cc = new HumidityControlOperatingStateCCGet(this.applHost, { + const cc = new HumidityControlOperatingStateCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -168,10 +164,9 @@ export class HumidityControlOperatingStateCCReport extends HumidityControlOperatingStateCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.state = this.payload[0] & 0b1111; diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 2fa2eb871178..87c5a9f13adc 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -21,7 +21,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -208,7 +207,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { HumidityControlSetpointCommand.Get, ); - const cc = new HumidityControlSetpointCCGet(this.applHost, { + const cc = new HumidityControlSetpointCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setpointType, @@ -241,7 +240,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { HumidityControlSetpointCommand.Set, ); - const cc = new HumidityControlSetpointCCSet(this.applHost, { + const cc = new HumidityControlSetpointCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setpointType, @@ -260,7 +259,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { HumidityControlSetpointCommand.CapabilitiesGet, ); - const cc = new HumidityControlSetpointCCCapabilitiesGet(this.applHost, { + const cc = new HumidityControlSetpointCCCapabilitiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setpointType, @@ -289,7 +288,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { HumidityControlSetpointCommand.SupportedGet, ); - const cc = new HumidityControlSetpointCCSupportedGet(this.applHost, { + const cc = new HumidityControlSetpointCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -311,14 +310,11 @@ export class HumidityControlSetpointCCAPI extends CCAPI { HumidityControlSetpointCommand.SupportedGet, ); - const cc = new HumidityControlSetpointCCScaleSupportedGet( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - setpointType, - }, - ); + const cc = new HumidityControlSetpointCCScaleSupportedGet({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + setpointType, + }); const response = await this.applHost.sendCommand< HumidityControlSetpointCCScaleSupportedReport >( @@ -527,12 +523,11 @@ export interface HumidityControlSetpointCCSetOptions extends CCCommandOptions { @useSupervision() export class HumidityControlSetpointCCSet extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | HumidityControlSetpointCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -576,10 +571,9 @@ export class HumidityControlSetpointCCSet extends HumidityControlSetpointCC { @CCCommand(HumidityControlSetpointCommand.Report) export class HumidityControlSetpointCCReport extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this._type = this.payload[0] & 0b1111; @@ -675,12 +669,11 @@ export interface HumidityControlSetpointCCGetOptions extends CCCommandOptions { ) export class HumidityControlSetpointCCGet extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | HumidityControlSetpointCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -717,10 +710,9 @@ export class HumidityControlSetpointCCSupportedReport extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.supportedSetpointTypes = parseBitMask( @@ -764,10 +756,9 @@ export class HumidityControlSetpointCCScaleSupportedReport extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); @@ -807,12 +798,11 @@ export class HumidityControlSetpointCCScaleSupportedGet extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | HumidityControlSetpointCCScaleSupportedGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -849,10 +839,9 @@ export class HumidityControlSetpointCCCapabilitiesReport extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this._type = this.payload[0] & 0b1111; @@ -940,12 +929,11 @@ export class HumidityControlSetpointCCCapabilitiesGet extends HumidityControlSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | HumidityControlSetpointCCCapabilitiesGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index 2902bdb40f55..515b6d04fb53 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -4,7 +4,7 @@ import { validatePayload, } from "@zwave-js/core"; import { type MaybeNotKnown } from "@zwave-js/core/safe"; -import type { CCEncodingContext, GetValueDB, ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host"; import { getEnumMemberName } from "@zwave-js/shared"; import { CCAPI } from "../lib/API"; import { @@ -57,7 +57,7 @@ export class InclusionControllerCCAPI extends CCAPI { InclusionControllerCommand.Initiate, ); - const cc = new InclusionControllerCCInitiate(this.applHost, { + const cc = new InclusionControllerCCInitiate({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, includedNodeId: nodeId, @@ -76,7 +76,7 @@ export class InclusionControllerCCAPI extends CCAPI { InclusionControllerCommand.Complete, ); - const cc = new InclusionControllerCCComplete(this.applHost, { + const cc = new InclusionControllerCCComplete({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, step, @@ -95,12 +95,11 @@ export interface InclusionControllerCCCompleteOptions extends CCCommandOptions { @CCCommand(InclusionControllerCommand.Complete) export class InclusionControllerCCComplete extends InclusionControllerCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | InclusionControllerCCCompleteOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.step = this.payload[0]; @@ -145,12 +144,11 @@ export interface InclusionControllerCCInitiateOptions extends CCCommandOptions { @CCCommand(InclusionControllerCommand.Initiate) export class InclusionControllerCCInitiate extends InclusionControllerCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | InclusionControllerCCInitiateOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.includedNodeId = this.payload[0]; diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 53c33b3ab315..9f0c2a7322d1 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -359,7 +358,7 @@ export class IndicatorCCAPI extends CCAPI { ): Promise> { this.assertSupportsCommand(IndicatorCommand, IndicatorCommand.Get); - const cc = new IndicatorCCGet(this.applHost, { + const cc = new IndicatorCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, indicatorId, @@ -396,7 +395,7 @@ export class IndicatorCCAPI extends CCAPI { ); } - const cc = new IndicatorCCSet(this.applHost, { + const cc = new IndicatorCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...(typeof value === "number" ? { value } : { values: value }), @@ -413,7 +412,7 @@ export class IndicatorCCAPI extends CCAPI { IndicatorCommand.Report, ); - const cc = new IndicatorCCReport(this.applHost, { + const cc = new IndicatorCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -436,7 +435,7 @@ export class IndicatorCCAPI extends CCAPI { IndicatorCommand.SupportedGet, ); - const cc = new IndicatorCCSupportedGet(this.applHost, { + const cc = new IndicatorCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, indicatorId, @@ -470,7 +469,7 @@ export class IndicatorCCAPI extends CCAPI { IndicatorCommand.SupportedReport, ); - const cc = new IndicatorCCSupportedReport(this.applHost, { + const cc = new IndicatorCCSupportedReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, indicatorId, @@ -491,7 +490,7 @@ export class IndicatorCCAPI extends CCAPI { IndicatorCommand.DescriptionReport, ); - const cc = new IndicatorCCDescriptionReport(this.applHost, { + const cc = new IndicatorCCDescriptionReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, indicatorId, @@ -671,7 +670,7 @@ export class IndicatorCCAPI extends CCAPI { IndicatorCommand.DescriptionGet, ); - const cc = new IndicatorCCDescriptionGet(this.applHost, { + const cc = new IndicatorCCDescriptionGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, indicatorId, @@ -902,12 +901,11 @@ export type IndicatorCCSetOptions = @useSupervision() export class IndicatorCCSet extends IndicatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (IndicatorCCSetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -1002,12 +1000,11 @@ export type IndicatorCCReportSpecificOptions = @CCCommand(IndicatorCommand.Report) export class IndicatorCCReport extends IndicatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (IndicatorCCReportSpecificOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -1212,10 +1209,9 @@ export interface IndicatorCCGetOptions extends CCCommandOptions { @expectedCCResponse(IndicatorCCReport) export class IndicatorCCGet extends IndicatorCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | IndicatorCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { if (this.payload.length > 0) { this.indicatorId = this.payload[0]; @@ -1254,12 +1250,11 @@ export interface IndicatorCCSupportedReportOptions extends CCCommandOptions { @CCCommand(IndicatorCommand.SupportedReport) export class IndicatorCCSupportedReport extends IndicatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IndicatorCCSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -1356,12 +1351,11 @@ function testResponseForIndicatorSupportedGet( ) export class IndicatorCCSupportedGet extends IndicatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IndicatorCCSupportedGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.indicatorId = this.payload[0]; @@ -1396,12 +1390,11 @@ export interface IndicatorCCDescriptionReportOptions { @CCCommand(IndicatorCommand.DescriptionReport) export class IndicatorCCDescriptionReport extends IndicatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (IndicatorCCDescriptionReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -1473,12 +1466,11 @@ function testResponseForIndicatorDescriptionGet( ) export class IndicatorCCDescriptionGet extends IndicatorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IndicatorCCDescriptionGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.indicatorId = this.payload[0]; diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index ec06da849953..c2b09fbda68c 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -604,7 +603,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.SystemInfoGet, ); - const cc = new IrrigationCCSystemInfoGet(this.applHost, { + const cc = new IrrigationCCSystemInfoGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -631,7 +630,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.SystemStatusGet, ); - const cc = new IrrigationCCSystemStatusGet(this.applHost, { + const cc = new IrrigationCCSystemStatusGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -669,7 +668,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.SystemConfigGet, ); - const cc = new IrrigationCCSystemConfigGet(this.applHost, { + const cc = new IrrigationCCSystemConfigGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -699,7 +698,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.SystemConfigSet, ); - const cc = new IrrigationCCSystemConfigSet(this.applHost, { + const cc = new IrrigationCCSystemConfigSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...config, @@ -716,7 +715,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.ValveInfoGet, ); - const cc = new IrrigationCCValveInfoGet(this.applHost, { + const cc = new IrrigationCCValveInfoGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, valveId, @@ -750,7 +749,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.ValveConfigSet, ); - const cc = new IrrigationCCValveConfigSet(this.applHost, { + const cc = new IrrigationCCValveConfigSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -767,7 +766,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.ValveConfigGet, ); - const cc = new IrrigationCCValveConfigGet(this.applHost, { + const cc = new IrrigationCCValveConfigGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, valveId, @@ -801,7 +800,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.ValveRun, ); - const cc = new IrrigationCCValveRun(this.applHost, { + const cc = new IrrigationCCValveRun({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, valveId, @@ -844,7 +843,7 @@ export class IrrigationCCAPI extends CCAPI { } } - const cc = new IrrigationCCValveTableSet(this.applHost, { + const cc = new IrrigationCCValveTableSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, tableId, @@ -863,7 +862,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.ValveTableGet, ); - const cc = new IrrigationCCValveTableGet(this.applHost, { + const cc = new IrrigationCCValveTableGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, tableId, @@ -888,7 +887,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.ValveTableRun, ); - const cc = new IrrigationCCValveTableRun(this.applHost, { + const cc = new IrrigationCCValveTableRun({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, tableIDs, @@ -910,7 +909,7 @@ export class IrrigationCCAPI extends CCAPI { IrrigationCommand.SystemShutoff, ); - const cc = new IrrigationCCSystemShutoff(this.applHost, { + const cc = new IrrigationCCSystemShutoff({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, duration, @@ -1350,10 +1349,9 @@ moisture sensor polarity: ${ @CCCommand(IrrigationCommand.SystemInfoReport) export class IrrigationCCSystemInfoReport extends IrrigationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); this.supportsMasterValve = !!(this.payload[0] & 0x01); this.numValves = this.payload[1]; @@ -1393,10 +1391,9 @@ export class IrrigationCCSystemInfoGet extends IrrigationCC {} @CCCommand(IrrigationCommand.SystemStatusReport) export class IrrigationCCSystemStatusReport extends IrrigationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.systemVoltage = this.payload[0]; this.flowSensorActive = !!(this.payload[1] & 0x01); @@ -1544,12 +1541,11 @@ export type IrrigationCCSystemConfigSetOptions = { @useSupervision() export class IrrigationCCSystemConfigSet extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (IrrigationCCSystemConfigSetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -1619,10 +1615,9 @@ export class IrrigationCCSystemConfigSet extends IrrigationCC { @CCCommand(IrrigationCommand.SystemConfigReport) export class IrrigationCCSystemConfigReport extends IrrigationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.masterValveDelay = this.payload[0]; let offset = 1; @@ -1698,10 +1693,9 @@ export class IrrigationCCSystemConfigGet extends IrrigationCC {} @CCCommand(IrrigationCommand.ValveInfoReport) export class IrrigationCCValveInfoReport extends IrrigationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); if ((this.payload[0] & 0b1) === ValveType.MasterValve) { this.valveId = "master"; @@ -1848,12 +1842,11 @@ function testResponseForIrrigationCommandWithValveId( ) export class IrrigationCCValveInfoGet extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCValveInfoGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -1901,12 +1894,11 @@ export type IrrigationCCValveConfigSetOptions = { @useSupervision() export class IrrigationCCValveConfigSet extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (IrrigationCCValveConfigSetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -1977,10 +1969,9 @@ export class IrrigationCCValveConfigSet extends IrrigationCC { @CCCommand(IrrigationCommand.ValveConfigReport) export class IrrigationCCValveConfigReport extends IrrigationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); if ((this.payload[0] & 0b1) === ValveType.MasterValve) { this.valveId = "master"; @@ -2119,12 +2110,11 @@ export interface IrrigationCCValveConfigGetOptions extends CCCommandOptions { ) export class IrrigationCCValveConfigGet extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCValveConfigGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2166,12 +2156,11 @@ export interface IrrigationCCValveRunOptions extends CCCommandOptions { @useSupervision() export class IrrigationCCValveRun extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCValveRunOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2224,12 +2213,11 @@ export interface IrrigationCCValveTableSetOptions extends CCCommandOptions { @useSupervision() export class IrrigationCCValveTableSet extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCValveTableSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2280,10 +2268,9 @@ export class IrrigationCCValveTableSet extends IrrigationCC { @CCCommand(IrrigationCommand.ValveTableReport) export class IrrigationCCValveTableReport extends IrrigationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload((this.payload.length - 1) % 3 === 0); this.tableId = this.payload[0]; this.entries = []; @@ -2337,12 +2324,11 @@ function testResponseForIrrigationValveTableGet( ) export class IrrigationCCValveTableGet extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCValveTableGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2380,12 +2366,11 @@ export interface IrrigationCCValveTableRunOptions extends CCCommandOptions { @useSupervision() export class IrrigationCCValveTableRun extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCValveTableRunOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2435,12 +2420,11 @@ export interface IrrigationCCSystemShutoffOptions extends CCCommandOptions { @useSupervision() export class IrrigationCCSystemShutoff extends IrrigationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | IrrigationCCSystemShutoffOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 47d84199c323..7cc894aacb8c 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -16,7 +16,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -79,7 +78,7 @@ export class LanguageCCAPI extends CCAPI { public async get() { this.assertSupportsCommand(LanguageCommand, LanguageCommand.Get); - const cc = new LanguageCCGet(this.applHost, { + const cc = new LanguageCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -99,7 +98,7 @@ export class LanguageCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(LanguageCommand, LanguageCommand.Set); - const cc = new LanguageCCSet(this.applHost, { + const cc = new LanguageCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, language, @@ -173,10 +172,9 @@ export interface LanguageCCSetOptions extends CCCommandOptions { @useSupervision() export class LanguageCCSet extends LanguageCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | LanguageCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -243,10 +241,9 @@ export class LanguageCCSet extends LanguageCC { @CCCommand(LanguageCommand.Report) export class LanguageCCReport extends LanguageCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); // if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.language = this.payload.toString("ascii", 0, 3); diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 2850e303c2ed..97aa071a5338 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -14,7 +14,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -74,7 +73,7 @@ export class LockCCAPI extends PhysicalCCAPI { public async get(): Promise> { this.assertSupportsCommand(LockCommand, LockCommand.Get); - const cc = new LockCCGet(this.applHost, { + const cc = new LockCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -93,7 +92,7 @@ export class LockCCAPI extends PhysicalCCAPI { public async set(locked: boolean): Promise { this.assertSupportsCommand(LockCommand, LockCommand.Set); - const cc = new LockCCSet(this.applHost, { + const cc = new LockCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, locked, @@ -191,10 +190,9 @@ export interface LockCCSetOptions extends CCCommandOptions { @useSupervision() export class LockCCSet extends LockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | LockCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -224,10 +222,9 @@ export class LockCCSet extends LockCC { @CCCommand(LockCommand.Report) export class LockCCReport extends LockCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.locked = this.payload[0] === 1; } diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index b9530afba754..a6a8b80e9357 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -7,7 +7,6 @@ import { import type { CCEncodingContext, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { staticExtends } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -37,7 +36,7 @@ export type ManufacturerProprietaryCCConstructor< typeof ManufacturerProprietaryCC, > = T & { // I don't like the any, but we need it to support half-implemented CCs (e.g. report classes) - new (host: ZWaveHost, options: any): InstanceType; + new (options: any): InstanceType; }; @API(CommandClasses["Manufacturer Proprietary"]) @@ -71,7 +70,7 @@ export class ManufacturerProprietaryCCAPI extends CCAPI { manufacturerId: number, data?: Buffer, ): Promise { - const cc = new ManufacturerProprietaryCC(this.applHost, { + const cc = new ManufacturerProprietaryCC({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, manufacturerId, @@ -84,7 +83,7 @@ export class ManufacturerProprietaryCCAPI extends CCAPI { @validateArgs() // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types public async sendAndReceiveData(manufacturerId: number, data?: Buffer) { - const cc = new ManufacturerProprietaryCC(this.applHost, { + const cc = new ManufacturerProprietaryCC({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, manufacturerId, @@ -137,12 +136,11 @@ export class ManufacturerProprietaryCC extends CommandClass { declare ccCommand: undefined; public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ManufacturerProprietaryCCOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -159,7 +157,7 @@ export class ManufacturerProprietaryCC extends CommandClass { && new.target !== PCConstructor && !staticExtends(new.target, PCConstructor) ) { - return new PCConstructor(host, options); + return new PCConstructor(options); } // If the constructor is correct, update the payload for subclass deserialization @@ -218,7 +216,7 @@ export class ManufacturerProprietaryCC extends CommandClass { this.manufacturerId, ); if (PCConstructor) { - return new PCConstructor(this.host, { + return new PCConstructor({ nodeId: this.nodeId, endpoint: this.endpointIndex, }); diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 2aafb863272d..5bf1db1f1c35 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -12,7 +12,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -109,7 +108,7 @@ export class ManufacturerSpecificCCAPI extends PhysicalCCAPI { ManufacturerSpecificCommand.Get, ); - const cc = new ManufacturerSpecificCCGet(this.applHost, { + const cc = new ManufacturerSpecificCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -137,7 +136,7 @@ export class ManufacturerSpecificCCAPI extends PhysicalCCAPI { ManufacturerSpecificCommand.DeviceSpecificGet, ); - const cc = new ManufacturerSpecificCCDeviceSpecificGet(this.applHost, { + const cc = new ManufacturerSpecificCCDeviceSpecificGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, deviceIdType, @@ -160,7 +159,7 @@ export class ManufacturerSpecificCCAPI extends PhysicalCCAPI { ManufacturerSpecificCommand.Report, ); - const cc = new ManufacturerSpecificCCReport(this.applHost, { + const cc = new ManufacturerSpecificCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -238,12 +237,11 @@ export interface ManufacturerSpecificCCReportOptions { @CCCommand(ManufacturerSpecificCommand.Report) export class ManufacturerSpecificCCReport extends ManufacturerSpecificCC { public constructor( - host: ZWaveHost, options: | (ManufacturerSpecificCCReportOptions & CCCommandOptions) | CommandClassDeserializationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 6); @@ -295,10 +293,9 @@ export class ManufacturerSpecificCCDeviceSpecificReport extends ManufacturerSpecificCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.type = this.payload[0] & 0b111; @@ -345,12 +342,11 @@ export class ManufacturerSpecificCCDeviceSpecificGet extends ManufacturerSpecificCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ManufacturerSpecificCCDeviceSpecificGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index a3cc0ae1d8dd..23493e0de167 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -29,7 +29,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -356,7 +355,7 @@ export class MeterCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(MeterCommand, MeterCommand.Get); - const cc = new MeterCCGet(this.applHost, { + const cc = new MeterCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -386,7 +385,7 @@ export class MeterCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(MeterCommand, MeterCommand.Report); - const cc = new MeterCCReport(this.applHost, { + const cc = new MeterCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -447,7 +446,7 @@ export class MeterCCAPI extends PhysicalCCAPI { public async getSupported() { this.assertSupportsCommand(MeterCommand, MeterCommand.SupportedGet); - const cc = new MeterCCSupportedGet(this.applHost, { + const cc = new MeterCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -473,7 +472,7 @@ export class MeterCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(MeterCommand, MeterCommand.SupportedReport); - const cc = new MeterCCSupportedReport(this.applHost, { + const cc = new MeterCCSupportedReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -487,7 +486,7 @@ export class MeterCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(MeterCommand, MeterCommand.Reset); - const cc = new MeterCCReset(this.applHost, { + const cc = new MeterCCReset({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -879,12 +878,11 @@ export interface MeterCCReportOptions { @CCCommand(MeterCommand.Report) export class MeterCCReport extends MeterCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MeterCCReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const { type, rateType, scale1, value, bytesRead } = @@ -1104,12 +1102,11 @@ export interface MeterCCGetOptions { @expectedCCResponse(MeterCCReport, testResponseForMeterGet) export class MeterCCGet extends MeterCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MeterCCGetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { if (this.payload.length >= 1) { this.rateType = (this.payload[0] & 0b11_000_000) >>> 6; @@ -1198,12 +1195,11 @@ export interface MeterCCSupportedReportOptions { @CCCommand(MeterCommand.SupportedReport) export class MeterCCSupportedReport extends MeterCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MeterCCSupportedReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -1366,12 +1362,11 @@ export type MeterCCResetOptions = AllOrNone<{ @useSupervision() export class MeterCCReset extends MeterCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MeterCCResetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { if (this.payload.length > 0) { const { diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 87ece3f2d58e..fc8b61bc9e21 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -20,7 +20,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -205,13 +204,10 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { MultiChannelAssociationCommand.SupportedGroupingsGet, ); - const cc = new MultiChannelAssociationCCSupportedGroupingsGet( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - }, - ); + const cc = new MultiChannelAssociationCCSupportedGroupingsGet({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + }); const response = await this.applHost.sendCommand< MultiChannelAssociationCCSupportedGroupingsReport >( @@ -228,14 +224,11 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { MultiChannelAssociationCommand.SupportedGroupingsReport, ); - const cc = new MultiChannelAssociationCCSupportedGroupingsReport( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - groupCount, - }, - ); + const cc = new MultiChannelAssociationCCSupportedGroupingsReport({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + groupCount, + }); await this.applHost.sendCommand(cc, this.commandOptions); } @@ -250,7 +243,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { MultiChannelAssociationCommand.Get, ); - const cc = new MultiChannelAssociationCCGet(this.applHost, { + const cc = new MultiChannelAssociationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -275,7 +268,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { MultiChannelAssociationCommand.Report, ); - const cc = new MultiChannelAssociationCCReport(this.applHost, { + const cc = new MultiChannelAssociationCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -295,7 +288,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { MultiChannelAssociationCommand.Set, ); - const cc = new MultiChannelAssociationCCSet(this.applHost, { + const cc = new MultiChannelAssociationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -324,7 +317,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { this.endpoint, ); for (const [group, destinations] of currentDestinations) { - const cc = new MultiChannelAssociationCCRemove(this.applHost, { + const cc = new MultiChannelAssociationCCRemove({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId: group, @@ -345,7 +338,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { ZWaveErrorCodes.Argument_Invalid, ); } else { - const cc = new MultiChannelAssociationCCRemove(this.applHost, { + const cc = new MultiChannelAssociationCCRemove({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -634,12 +627,11 @@ export type MultiChannelAssociationCCSetOptions = @useSupervision() export class MultiChannelAssociationCCSet extends MultiChannelAssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MultiChannelAssociationCCSetOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.groupId = this.payload[0]; @@ -708,12 +700,11 @@ export interface MultiChannelAssociationCCRemoveOptions { @useSupervision() export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MultiChannelAssociationCCRemoveOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.groupId = this.payload[0]; @@ -774,12 +765,11 @@ export interface MultiChannelAssociationCCReportOptions { @CCCommand(MultiChannelAssociationCommand.Report) export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (MultiChannelAssociationCCReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -883,12 +873,11 @@ export interface MultiChannelAssociationCCGetOptions extends CCCommandOptions { @expectedCCResponse(MultiChannelAssociationCCReport) export class MultiChannelAssociationCCGet extends MultiChannelAssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelAssociationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.groupId = this.payload[0]; @@ -930,12 +919,11 @@ export class MultiChannelAssociationCCSupportedGroupingsReport extends MultiChannelAssociationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelAssociationCCSupportedGroupingsReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 6e63b990dd97..3c58ca9d4f3d 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -23,7 +23,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { distinct } from "alcalzone-shared/arrays"; @@ -217,7 +216,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.EndPointGet, ); - const cc = new MultiChannelCCEndPointGet(this.applHost, { + const cc = new MultiChannelCCEndPointGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -246,7 +245,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.CapabilityGet, ); - const cc = new MultiChannelCCCapabilityGet(this.applHost, { + const cc = new MultiChannelCCCapabilityGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, requestedEndpoint: endpoint, @@ -285,7 +284,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.EndPointFind, ); - const cc = new MultiChannelCCEndPointFind(this.applHost, { + const cc = new MultiChannelCCEndPointFind({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, genericClass, @@ -309,7 +308,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.AggregatedMembersGet, ); - const cc = new MultiChannelCCAggregatedMembersGet(this.applHost, { + const cc = new MultiChannelCCAggregatedMembersGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, requestedEndpoint: endpoint, @@ -337,7 +336,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.CommandEncapsulation, ); - const cc = new MultiChannelCCCommandEncapsulation(this.applHost, { + const cc = new MultiChannelCCCommandEncapsulation({ nodeId: this.endpoint.nodeId, ...options, }); @@ -353,7 +352,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.GetV1, ); - const cc = new MultiChannelCCV1Get(this.applHost, { + const cc = new MultiChannelCCV1Get({ nodeId: this.endpoint.nodeId, requestedCC: ccId, }); @@ -375,7 +374,7 @@ export class MultiChannelCCAPI extends CCAPI { MultiChannelCommand.CommandEncapsulationV1, ); - const cc = new MultiChannelCCV1CommandEncapsulation(this.applHost, { + const cc = new MultiChannelCCV1CommandEncapsulation({ nodeId: this.endpoint.nodeId, encapsulated, }); @@ -408,10 +407,9 @@ export class MultiChannelCC extends CommandClass { /** Encapsulates a command that targets a specific endpoint, with version 2+ of the Multi Channel CC */ public static encapsulate( - host: ZWaveHost, cc: CommandClass, ): MultiChannelCCCommandEncapsulation { - const ret = new MultiChannelCCCommandEncapsulation(host, { + const ret = new MultiChannelCCCommandEncapsulation({ nodeId: cc.nodeId, encapsulated: cc, destination: cc.endpointIndex, @@ -425,10 +423,9 @@ export class MultiChannelCC extends CommandClass { /** Encapsulates a command that targets a specific endpoint, with version 1 of the Multi Channel CC */ public static encapsulateV1( - host: ZWaveHost, cc: CommandClass, ): MultiChannelCCV1CommandEncapsulation { - const ret = new MultiChannelCCV1CommandEncapsulation(host, { + const ret = new MultiChannelCCV1CommandEncapsulation({ nodeId: cc.nodeId, encapsulated: cc, }); @@ -740,7 +737,6 @@ supported CCs:`; .filter( (cc) => !CommandClass.createInstanceUnchecked( - applHost, node, cc, )?.skipEndpointInterview(), @@ -824,12 +820,11 @@ export interface MultiChannelCCEndPointReportOptions extends CCCommandOptions { @CCCommand(MultiChannelCommand.EndPointReport) export class MultiChannelCCEndPointReport extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCEndPointReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -907,12 +902,11 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC implements ApplicationNodeInformation { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCCapabilityReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // Only validate the bytes we expect to see here @@ -1019,12 +1013,11 @@ function testResponseForMultiChannelCapabilityGet( ) export class MultiChannelCCCapabilityGet extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCCapabilityGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.requestedEndpoint = this.payload[0] & 0b01111111; @@ -1061,12 +1054,11 @@ export interface MultiChannelCCEndPointFindReportOptions @CCCommand(MultiChannelCommand.EndPointFindReport) export class MultiChannelCCEndPointFindReport extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCEndPointFindReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -1155,12 +1147,11 @@ export interface MultiChannelCCEndPointFindOptions extends CCCommandOptions { @expectedCCResponse(MultiChannelCCEndPointFindReport) export class MultiChannelCCEndPointFind extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCEndPointFindOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.genericClass = this.payload[0]; @@ -1197,10 +1188,9 @@ export class MultiChannelCCEndPointFind extends MultiChannelCC { @CCCommand(MultiChannelCommand.AggregatedMembersReport) export class MultiChannelCCAggregatedMembersReport extends MultiChannelCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.aggregatedEndpointIndex = this.payload[0] & 0b0111_1111; @@ -1241,12 +1231,11 @@ export interface MultiChannelCCAggregatedMembersGetOptions @expectedCCResponse(MultiChannelCCAggregatedMembersReport) export class MultiChannelCCAggregatedMembersGet extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCAggregatedMembersGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -1327,12 +1316,11 @@ function testResponseForCommandEncapsulation( ) export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCCommandEncapsulationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); if ( @@ -1356,7 +1344,7 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { } } // No need to validate further, each CC does it for itself - this.encapsulated = CommandClass.from(this.host, { + this.encapsulated = CommandClass.from({ data: this.payload.subarray(2), fromEncapsulation: true, encapCC: this, @@ -1418,10 +1406,9 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { @CCCommand(MultiChannelCommand.ReportV1) export class MultiChannelCCV1Report extends MultiChannelCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); // V1 won't be extended in the future, so do an exact check validatePayload(this.payload.length === 2); this.requestedCC = this.payload[0]; @@ -1458,12 +1445,11 @@ export interface MultiChannelCCV1GetOptions extends CCCommandOptions { @expectedCCResponse(MultiChannelCCV1Report, testResponseForMultiChannelV1Get) export class MultiChannelCCV1Get extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCV1GetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -1522,12 +1508,11 @@ export interface MultiChannelCCV1CommandEncapsulationOptions ) export class MultiChannelCCV1CommandEncapsulation extends MultiChannelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiChannelCCV1CommandEncapsulationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.endpointIndex = this.payload[0]; @@ -1538,7 +1523,7 @@ export class MultiChannelCCV1CommandEncapsulation extends MultiChannelCC { && this.payload[1] === 0x00; // No need to validate further, each CC does it for itself - this.encapsulated = CommandClass.from(this.host, { + this.encapsulated = CommandClass.from({ data: this.payload.subarray(isV2withV1Header ? 2 : 1), fromEncapsulation: true, encapCC: this, diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index 0d4b29297848..da005011abc1 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -5,11 +5,7 @@ import { type MessageOrCCLogEntry, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { @@ -49,7 +45,7 @@ export class MultiCommandCCAPI extends CCAPI { ); // FIXME: This should not be on the API but rather on the applHost level - const cc = new MultiCommandCCCommandEncapsulation(this.applHost, { + const cc = new MultiCommandCCCommandEncapsulation({ nodeId: this.endpoint.nodeId, encapsulated: commands, }); @@ -72,10 +68,9 @@ export class MultiCommandCC extends CommandClass { } public static encapsulate( - host: ZWaveHost, CCs: CommandClass[], ): MultiCommandCCCommandEncapsulation { - const ret = new MultiCommandCCCommandEncapsulation(host, { + const ret = new MultiCommandCCCommandEncapsulation({ nodeId: CCs[0].nodeId, encapsulated: CCs, }); @@ -109,12 +104,11 @@ export interface MultiCommandCCCommandEncapsulationOptions // When sending commands encapsulated in this CC, responses to GET-type commands likely won't be encapsulated export class MultiCommandCCCommandEncapsulation extends MultiCommandCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultiCommandCCCommandEncapsulationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const numCommands = this.payload[0]; @@ -125,7 +119,7 @@ export class MultiCommandCCCommandEncapsulation extends MultiCommandCC { const cmdLength = this.payload[offset]; validatePayload(this.payload.length >= offset + 1 + cmdLength); this.encapsulated.push( - CommandClass.from(this.host, { + CommandClass.from({ data: this.payload.subarray( offset + 1, offset + 1 + cmdLength, diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 8f639f30c2f2..95be6d1b8431 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -29,7 +29,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -278,7 +277,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { ); } - const cc = new MultilevelSensorCCGet(this.applHost, { + const cc = new MultilevelSensorCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sensorType, @@ -321,7 +320,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { MultilevelSensorCommand.GetSupportedSensor, ); - const cc = new MultilevelSensorCCGetSupportedSensor(this.applHost, { + const cc = new MultilevelSensorCCGetSupportedSensor({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -343,7 +342,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { MultilevelSensorCommand.GetSupportedScale, ); - const cc = new MultilevelSensorCCGetSupportedScale(this.applHost, { + const cc = new MultilevelSensorCCGetSupportedScale({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sensorType, @@ -368,7 +367,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { MultilevelSensorCommand.Report, ); - const cc = new MultilevelSensorCCReport(this.applHost, { + const cc = new MultilevelSensorCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, type: sensorType, @@ -629,12 +628,11 @@ export interface MultilevelSensorCCReportOptions extends CCCommandOptions { @useSupervision() export class MultilevelSensorCCReport extends MultilevelSensorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSensorCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -776,12 +774,11 @@ export type MultilevelSensorCCGetOptions = ) export class MultilevelSensorCCGet extends MultilevelSensorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSensorCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { if (this.payload.length >= 2) { this.sensorType = this.payload[0]; @@ -846,12 +843,11 @@ export class MultilevelSensorCCSupportedSensorReport extends MultilevelSensorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSensorCCSupportedSensorReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -897,12 +893,11 @@ export interface MultilevelSensorCCSupportedScaleReportOptions @CCCommand(MultilevelSensorCommand.SupportedScaleReport) export class MultilevelSensorCCSupportedScaleReport extends MultilevelSensorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSensorCCSupportedScaleReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -964,12 +959,11 @@ export interface MultilevelSensorCCGetSupportedScaleOptions @expectedCCResponse(MultilevelSensorCCSupportedScaleReport) export class MultilevelSensorCCGetSupportedScale extends MultilevelSensorCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSensorCCGetSupportedScaleOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.sensorType = this.payload[0]; diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 04477b5015be..7e9d996b7142 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -231,7 +230,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { MultilevelSwitchCommand.Get, ); - const cc = new MultilevelSwitchCCGet(this.applHost, { + const cc = new MultilevelSwitchCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -262,7 +261,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { MultilevelSwitchCommand.Set, ); - const cc = new MultilevelSwitchCCSet(this.applHost, { + const cc = new MultilevelSwitchCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, targetValue, @@ -280,7 +279,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { MultilevelSwitchCommand.StartLevelChange, ); - const cc = new MultilevelSwitchCCStartLevelChange(this.applHost, { + const cc = new MultilevelSwitchCCStartLevelChange({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -295,7 +294,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { MultilevelSwitchCommand.StopLevelChange, ); - const cc = new MultilevelSwitchCCStopLevelChange(this.applHost, { + const cc = new MultilevelSwitchCCStopLevelChange({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -309,7 +308,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { MultilevelSwitchCommand.SupportedGet, ); - const cc = new MultilevelSwitchCCSupportedGet(this.applHost, { + const cc = new MultilevelSwitchCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -628,12 +627,11 @@ export interface MultilevelSwitchCCSetOptions extends CCCommandOptions { @useSupervision() export class MultilevelSwitchCCSet extends MultilevelSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSwitchCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.targetValue = this.payload[0]; @@ -693,12 +691,11 @@ export interface MultilevelSwitchCCReportOptions extends CCCommandOptions { @CCCommand(MultilevelSwitchCommand.Report) export class MultilevelSwitchCCReport extends MultilevelSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | MultilevelSwitchCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -779,12 +776,11 @@ export type MultilevelSwitchCCStartLevelChangeOptions = @useSupervision() export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & MultilevelSwitchCCStartLevelChangeOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); const ignoreStartLevel = (this.payload[0] & 0b0_0_1_00000) >>> 5; @@ -861,12 +857,11 @@ export interface MultilevelSwitchCCSupportedReportOptions { @CCCommand(MultilevelSwitchCommand.SupportedReport) export class MultilevelSwitchCCSupportedReport extends MultilevelSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & MultilevelSwitchCCSupportedReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/NoOperationCC.ts b/packages/cc/src/cc/NoOperationCC.ts index a83bb194e56e..79ae57ff5e9c 100644 --- a/packages/cc/src/cc/NoOperationCC.ts +++ b/packages/cc/src/cc/NoOperationCC.ts @@ -16,7 +16,7 @@ import { isCommandClassContainer } from "../lib/ICommandClassContainer"; export class NoOperationCCAPI extends PhysicalCCAPI { public async send(): Promise { await this.applHost.sendCommand( - new NoOperationCC(this.applHost, { + new NoOperationCC({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }), diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 1f866d3fcdd0..6381e23a266c 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -13,7 +13,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -135,7 +134,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { NodeNamingAndLocationCommand.NameGet, ); - const cc = new NodeNamingAndLocationCCNameGet(this.applHost, { + const cc = new NodeNamingAndLocationCCNameGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -155,7 +154,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { NodeNamingAndLocationCommand.NameSet, ); - const cc = new NodeNamingAndLocationCCNameSet(this.applHost, { + const cc = new NodeNamingAndLocationCCNameSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, name, @@ -169,7 +168,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { NodeNamingAndLocationCommand.LocationGet, ); - const cc = new NodeNamingAndLocationCCLocationGet(this.applHost, { + const cc = new NodeNamingAndLocationCCLocationGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -191,7 +190,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { NodeNamingAndLocationCommand.LocationSet, ); - const cc = new NodeNamingAndLocationCCLocationSet(this.applHost, { + const cc = new NodeNamingAndLocationCCLocationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, location, @@ -278,12 +277,11 @@ export interface NodeNamingAndLocationCCNameSetOptions @useSupervision() export class NodeNamingAndLocationCCNameSet extends NodeNamingAndLocationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | NodeNamingAndLocationCCNameSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -329,10 +327,9 @@ export class NodeNamingAndLocationCCNameSet extends NodeNamingAndLocationCC { @CCCommand(NodeNamingAndLocationCommand.NameReport) export class NodeNamingAndLocationCCNameReport extends NodeNamingAndLocationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); const encoding = this.payload[0] === 2 ? "utf16le" : "ascii"; let nameBuffer = this.payload.subarray(1); if (encoding === "utf16le") { @@ -371,12 +368,11 @@ export class NodeNamingAndLocationCCLocationSet extends NodeNamingAndLocationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | NodeNamingAndLocationCCLocationSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -424,10 +420,9 @@ export class NodeNamingAndLocationCCLocationReport extends NodeNamingAndLocationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); const encoding = this.payload[0] === 2 ? "utf16le" : "ascii"; let locationBuffer = this.payload.subarray(1); if (encoding === "utf16le") { diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index 014de413650a..cf7d49e947c8 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -35,7 +35,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -293,7 +292,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { NotificationCommand.Get, ); - const cc = new NotificationCCGet(this.applHost, { + const cc = new NotificationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -313,7 +312,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { NotificationCommand.Report, ); - const cc = new NotificationCCReport(this.applHost, { + const cc = new NotificationCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -346,7 +345,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { NotificationCommand.Set, ); - const cc = new NotificationCCSet(this.applHost, { + const cc = new NotificationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, notificationType, @@ -362,7 +361,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { NotificationCommand.SupportedGet, ); - const cc = new NotificationCCSupportedGet(this.applHost, { + const cc = new NotificationCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -389,7 +388,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { NotificationCommand.EventSupportedGet, ); - const cc = new NotificationCCEventSupportedGet(this.applHost, { + const cc = new NotificationCCEventSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, notificationType, @@ -917,10 +916,9 @@ export interface NotificationCCSetOptions extends CCCommandOptions { @useSupervision() export class NotificationCCSet extends NotificationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | NotificationCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.notificationType = this.payload[0]; @@ -969,12 +967,11 @@ export type NotificationCCReportOptions = @useSupervision() export class NotificationCCReport extends NotificationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (NotificationCCReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -1278,7 +1275,7 @@ export class NotificationCCReport extends NotificationCC { // Try to parse the event parameters - if this fails, we should still handle the notification report try { // Convert CommandClass instances to a standardized object representation - const cc = CommandClass.from(this.host, { + const cc = CommandClass.from({ data: this.eventParameters, fromEncapsulation: true, encapCC: this, @@ -1441,10 +1438,9 @@ export type NotificationCCGetOptions = @expectedCCResponse(NotificationCCReport) export class NotificationCCGet extends NotificationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | NotificationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.alarmType = this.payload[0] || undefined; @@ -1514,12 +1510,11 @@ export interface NotificationCCSupportedReportOptions extends CCCommandOptions { @CCCommand(NotificationCommand.SupportedReport) export class NotificationCCSupportedReport extends NotificationCC { public constructor( - host: ZWaveHost, options: | NotificationCCSupportedReportOptions | CommandClassDeserializationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -1596,12 +1591,11 @@ export interface NotificationCCEventSupportedReportOptions @CCCommand(NotificationCommand.EventSupportedReport) export class NotificationCCEventSupportedReport extends NotificationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | NotificationCCEventSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -1731,12 +1725,11 @@ export interface NotificationCCEventSupportedGetOptions @expectedCCResponse(NotificationCCEventSupportedReport) export class NotificationCCEventSupportedGet extends NotificationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | NotificationCCEventSupportedGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.notificationType = this.payload[0]; diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index 891e4064f66c..ab8c30824532 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -9,11 +9,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { PhysicalCCAPI } from "../lib/API"; @@ -57,7 +53,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { public async setNormalPowerlevel(): Promise { this.assertSupportsCommand(PowerlevelCommand, PowerlevelCommand.Set); - const cc = new PowerlevelCCSet(this.applHost, { + const cc = new PowerlevelCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, powerlevel: Powerlevel["Normal Power"], @@ -72,7 +68,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(PowerlevelCommand, PowerlevelCommand.Set); - const cc = new PowerlevelCCSet(this.applHost, { + const cc = new PowerlevelCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, powerlevel, @@ -86,7 +82,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { > { this.assertSupportsCommand(PowerlevelCommand, PowerlevelCommand.Get); - const cc = new PowerlevelCCGet(this.applHost, { + const cc = new PowerlevelCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -105,7 +101,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { ): Promise { this.assertSupportsCommand(PowerlevelCommand, PowerlevelCommand.Report); - const cc = new PowerlevelCCReport(this.applHost, { + const cc = new PowerlevelCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -144,7 +140,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { ); } - const cc = new PowerlevelCCTestNodeSet(this.applHost, { + const cc = new PowerlevelCCTestNodeSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, testNodeId, @@ -167,7 +163,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { PowerlevelCommand.TestNodeGet, ); - const cc = new PowerlevelCCTestNodeGet(this.applHost, { + const cc = new PowerlevelCCTestNodeGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -195,7 +191,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { PowerlevelCommand.TestNodeReport, ); - const cc = new PowerlevelCCTestNodeReport(this.applHost, { + const cc = new PowerlevelCCTestNodeReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -228,10 +224,9 @@ export type PowerlevelCCSetOptions = @useSupervision() export class PowerlevelCCSet extends PowerlevelCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | PowerlevelCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.powerlevel = this.payload[0]; @@ -286,12 +281,11 @@ export type PowerlevelCCReportOptions = { @CCCommand(PowerlevelCommand.Report) export class PowerlevelCCReport extends PowerlevelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (PowerlevelCCReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.powerlevel = this.payload[0]; @@ -341,12 +335,11 @@ export interface PowerlevelCCTestNodeSetOptions extends CCCommandOptions { @useSupervision() export class PowerlevelCCTestNodeSet extends PowerlevelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | PowerlevelCCTestNodeSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this.testNodeId = this.payload[0]; @@ -391,12 +384,11 @@ export interface PowerlevelCCTestNodeReportOptions { @CCCommand(PowerlevelCommand.TestNodeReport) export class PowerlevelCCTestNodeReport extends PowerlevelCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (PowerlevelCCTestNodeReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 01863a570e92..9942c4a67fe9 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -18,7 +18,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -223,7 +222,7 @@ export class ProtectionCCAPI extends CCAPI { public async get() { this.assertSupportsCommand(ProtectionCommand, ProtectionCommand.Get); - const cc = new ProtectionCCGet(this.applHost, { + const cc = new ProtectionCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -243,7 +242,7 @@ export class ProtectionCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(ProtectionCommand, ProtectionCommand.Set); - const cc = new ProtectionCCSet(this.applHost, { + const cc = new ProtectionCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, local, @@ -259,7 +258,7 @@ export class ProtectionCCAPI extends CCAPI { ProtectionCommand.SupportedGet, ); - const cc = new ProtectionCCSupportedGet(this.applHost, { + const cc = new ProtectionCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -285,7 +284,7 @@ export class ProtectionCCAPI extends CCAPI { ProtectionCommand.ExclusiveControlGet, ); - const cc = new ProtectionCCExclusiveControlGet(this.applHost, { + const cc = new ProtectionCCExclusiveControlGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -307,7 +306,7 @@ export class ProtectionCCAPI extends CCAPI { ProtectionCommand.ExclusiveControlSet, ); - const cc = new ProtectionCCExclusiveControlSet(this.applHost, { + const cc = new ProtectionCCExclusiveControlSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, exclusiveControlNodeId: nodeId, @@ -321,7 +320,7 @@ export class ProtectionCCAPI extends CCAPI { ProtectionCommand.TimeoutGet, ); - const cc = new ProtectionCCTimeoutGet(this.applHost, { + const cc = new ProtectionCCTimeoutGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -343,7 +342,7 @@ export class ProtectionCCAPI extends CCAPI { ProtectionCommand.TimeoutSet, ); - const cc = new ProtectionCCTimeoutSet(this.applHost, { + const cc = new ProtectionCCTimeoutSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, timeout, @@ -508,10 +507,9 @@ export interface ProtectionCCSetOptions extends CCCommandOptions { @useSupervision() export class ProtectionCCSet extends ProtectionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | ProtectionCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -563,10 +561,9 @@ export class ProtectionCCSet extends ProtectionCC { @CCCommand(ProtectionCommand.Report) export class ProtectionCCReport extends ProtectionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.local = this.payload[0] & 0b1111; if (this.payload.length >= 2) { @@ -601,10 +598,9 @@ export class ProtectionCCGet extends ProtectionCC {} @CCCommand(ProtectionCommand.SupportedReport) export class ProtectionCCSupportedReport extends ProtectionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 5); this.supportsTimeout = !!(this.payload[0] & 0b1); this.supportsExclusiveControl = !!(this.payload[0] & 0b10); @@ -683,10 +679,9 @@ export class ProtectionCCSupportedGet extends ProtectionCC {} @CCCommand(ProtectionCommand.ExclusiveControlReport) export class ProtectionCCExclusiveControlReport extends ProtectionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.exclusiveControlNodeId = this.payload[0]; } @@ -720,12 +715,11 @@ export interface ProtectionCCExclusiveControlSetOptions @useSupervision() export class ProtectionCCExclusiveControlSet extends ProtectionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ProtectionCCExclusiveControlSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -757,10 +751,9 @@ export class ProtectionCCExclusiveControlSet extends ProtectionCC { @CCCommand(ProtectionCommand.TimeoutReport) export class ProtectionCCTimeoutReport extends ProtectionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.timeout = Timeout.parse(this.payload[0]); } @@ -790,12 +783,11 @@ export interface ProtectionCCTimeoutSetOptions extends CCCommandOptions { @useSupervision() export class ProtectionCCTimeoutSet extends ProtectionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ProtectionCCTimeoutSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index 7529d2f610cf..469069b312cf 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -10,11 +10,7 @@ import { ValueMetadata, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, @@ -112,7 +108,7 @@ export class SceneActivationCCAPI extends CCAPI { SceneActivationCommand.Set, ); - const cc = new SceneActivationCCSet(this.applHost, { + const cc = new SceneActivationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sceneId, @@ -139,12 +135,11 @@ export interface SceneActivationCCSetOptions extends CCCommandOptions { @useSupervision() export class SceneActivationCCSet extends SceneActivationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SceneActivationCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.sceneId = this.payload[0]; diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 995eef75d8b3..ede5b7bb0db3 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -15,7 +15,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -209,7 +208,7 @@ export class SceneActuatorConfigurationCCAPI extends CCAPI { // Undefined `dimmingDuration` defaults to 0 seconds to simplify the call // for actuators that don't support non-instant `dimmingDuration` // Undefined `level` uses the actuator's current value (override = 0). - const cc = new SceneActuatorConfigurationCCSet(this.applHost, { + const cc = new SceneActuatorConfigurationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sceneId, @@ -234,7 +233,7 @@ export class SceneActuatorConfigurationCCAPI extends CCAPI { SceneActuatorConfigurationCommand.Get, ); - const cc = new SceneActuatorConfigurationCCGet(this.applHost, { + const cc = new SceneActuatorConfigurationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sceneId: 0, @@ -274,7 +273,7 @@ export class SceneActuatorConfigurationCCAPI extends CCAPI { ); } - const cc = new SceneActuatorConfigurationCCGet(this.applHost, { + const cc = new SceneActuatorConfigurationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, sceneId: sceneId, @@ -360,12 +359,11 @@ export class SceneActuatorConfigurationCCSet extends SceneActuatorConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SceneActuatorConfigurationCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -420,10 +418,9 @@ export class SceneActuatorConfigurationCCReport extends SceneActuatorConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 3); this.sceneId = this.payload[0]; @@ -508,12 +505,11 @@ export class SceneActuatorConfigurationCCGet extends SceneActuatorConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SceneActuatorConfigurationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index f929a99bbe7c..9e9e176bb310 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -16,7 +16,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -267,7 +266,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { ); } - const cc = new SceneControllerConfigurationCCSet(this.applHost, { + const cc = new SceneControllerConfigurationCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -291,7 +290,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { SceneControllerConfigurationCommand.Get, ); - const cc = new SceneControllerConfigurationCCGet(this.applHost, { + const cc = new SceneControllerConfigurationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId: 0, @@ -339,7 +338,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { ); } - const cc = new SceneControllerConfigurationCCGet(this.applHost, { + const cc = new SceneControllerConfigurationCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, groupId, @@ -497,12 +496,11 @@ export class SceneControllerConfigurationCCSet extends SceneControllerConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SceneControllerConfigurationCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -548,10 +546,9 @@ export class SceneControllerConfigurationCCReport extends SceneControllerConfigurationCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 3); this.groupId = this.payload[0]; this.sceneId = this.payload[1]; @@ -620,12 +617,11 @@ export class SceneControllerConfigurationCCGet extends SceneControllerConfigurationCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SceneControllerConfigurationCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index aa97ef95d9ea..836317694bac 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host"; import { type AllOrNone, @@ -232,7 +231,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.EnableSet, ); - const cc = new ScheduleEntryLockCCEnableSet(this.applHost, { + const cc = new ScheduleEntryLockCCEnableSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, userId, @@ -246,7 +245,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.EnableAllSet, ); - const cc = new ScheduleEntryLockCCEnableAllSet(this.applHost, { + const cc = new ScheduleEntryLockCCEnableAllSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, enabled, @@ -275,7 +274,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.SupportedGet, ); - const cc = new ScheduleEntryLockCCSupportedGet(this.applHost, { + const cc = new ScheduleEntryLockCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -333,7 +332,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { } } - const cc = new ScheduleEntryLockCCWeekDayScheduleSet(this.applHost, { + const cc = new ScheduleEntryLockCCWeekDayScheduleSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...slot, @@ -390,7 +389,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.WeekDayScheduleSet, ); - const cc = new ScheduleEntryLockCCWeekDayScheduleGet(this.applHost, { + const cc = new ScheduleEntryLockCCWeekDayScheduleGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...slot, @@ -460,7 +459,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { } } - const cc = new ScheduleEntryLockCCYearDayScheduleSet(this.applHost, { + const cc = new ScheduleEntryLockCCYearDayScheduleSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...slot, @@ -517,7 +516,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.YearDayScheduleSet, ); - const cc = new ScheduleEntryLockCCYearDayScheduleGet(this.applHost, { + const cc = new ScheduleEntryLockCCYearDayScheduleGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...slot, @@ -570,22 +569,19 @@ export class ScheduleEntryLockCCAPI extends CCAPI { } } - const cc = new ScheduleEntryLockCCDailyRepeatingScheduleSet( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - ...slot, - ...(schedule - ? { - action: ScheduleEntryLockSetAction.Set, - ...schedule, - } - : { - action: ScheduleEntryLockSetAction.Erase, - }), - }, - ); + const cc = new ScheduleEntryLockCCDailyRepeatingScheduleSet({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + ...slot, + ...(schedule + ? { + action: ScheduleEntryLockSetAction.Set, + ...schedule, + } + : { + action: ScheduleEntryLockSetAction.Erase, + }), + }); const result = await this.applHost.sendCommand(cc, this.commandOptions); @@ -630,14 +626,11 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.DailyRepeatingScheduleSet, ); - const cc = new ScheduleEntryLockCCDailyRepeatingScheduleGet( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - ...slot, - }, - ); + const cc = new ScheduleEntryLockCCDailyRepeatingScheduleGet({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + ...slot, + }); const result = await this.applHost.sendCommand< ScheduleEntryLockCCDailyRepeatingScheduleReport >( @@ -662,7 +655,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.TimeOffsetGet, ); - const cc = new ScheduleEntryLockCCTimeOffsetGet(this.applHost, { + const cc = new ScheduleEntryLockCCTimeOffsetGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -687,7 +680,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ScheduleEntryLockCommand.TimeOffsetSet, ); - const cc = new ScheduleEntryLockCCTimeOffsetSet(this.applHost, { + const cc = new ScheduleEntryLockCCTimeOffsetSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...timezone, @@ -944,12 +937,11 @@ export interface ScheduleEntryLockCCEnableSetOptions extends CCCommandOptions { @useSupervision() export class ScheduleEntryLockCCEnableSet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCEnableSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -990,12 +982,11 @@ export interface ScheduleEntryLockCCEnableAllSetOptions @useSupervision() export class ScheduleEntryLockCCEnableAllSet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCEnableAllSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.enabled = this.payload[0] === 0x01; @@ -1033,12 +1024,11 @@ export interface ScheduleEntryLockCCSupportedReportOptions @CCCommand(ScheduleEntryLockCommand.SupportedReport) export class ScheduleEntryLockCCSupportedReport extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.numWeekDaySlots = this.payload[0]; @@ -1106,12 +1096,11 @@ export type ScheduleEntryLockCCWeekDayScheduleSetOptions = @useSupervision() export class ScheduleEntryLockCCWeekDayScheduleSet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCWeekDayScheduleSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.action = this.payload[0]; @@ -1216,12 +1205,11 @@ export class ScheduleEntryLockCCWeekDayScheduleReport extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCWeekDayScheduleReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -1340,12 +1328,11 @@ export type ScheduleEntryLockCCWeekDayScheduleGetOptions = @expectedCCResponse(ScheduleEntryLockCCWeekDayScheduleReport) export class ScheduleEntryLockCCWeekDayScheduleGet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCWeekDayScheduleGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -1392,12 +1379,11 @@ export type ScheduleEntryLockCCYearDayScheduleSetOptions = @useSupervision() export class ScheduleEntryLockCCYearDayScheduleSet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCYearDayScheduleSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.action = this.payload[0]; @@ -1524,12 +1510,11 @@ export class ScheduleEntryLockCCYearDayScheduleReport extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCYearDayScheduleReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -1686,12 +1671,11 @@ export type ScheduleEntryLockCCYearDayScheduleGetOptions = @expectedCCResponse(ScheduleEntryLockCCYearDayScheduleReport) export class ScheduleEntryLockCCYearDayScheduleGet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCYearDayScheduleGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -1733,12 +1717,11 @@ export interface ScheduleEntryLockCCTimeOffsetSetOptions @useSupervision() export class ScheduleEntryLockCCTimeOffsetSet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCTimeOffsetSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const { standardOffset, dstOffset } = parseTimezone(this.payload); this.standardOffset = standardOffset; @@ -1782,12 +1765,11 @@ export interface ScheduleEntryLockCCTimeOffsetReportOptions @CCCommand(ScheduleEntryLockCommand.TimeOffsetReport) export class ScheduleEntryLockCCTimeOffsetReport extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCTimeOffsetReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const { standardOffset, dstOffset } = parseTimezone(this.payload); this.standardOffset = standardOffset; @@ -1843,12 +1825,11 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleSet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCDailyRepeatingScheduleSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.action = this.payload[0]; @@ -1962,7 +1943,6 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ( @@ -1970,7 +1950,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport & ScheduleEntryLockCCDailyRepeatingScheduleReportOptions ), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -2098,12 +2078,11 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleGet extends ScheduleEntryLockCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ScheduleEntryLockCCDailyRepeatingScheduleGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 24fad7d6021a..4a6dfd290219 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -41,7 +41,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; @@ -210,7 +209,7 @@ export class Security2CCAPI extends CCAPI { this.endpoint.nodeId, ); - const cc = new Security2CCNonceReport(this.applHost, { + const cc = new Security2CCNonceReport({ nodeId: this.endpoint.nodeId, ownNodeId: this.applHost.ownNodeId, endpoint: this.endpoint.index, @@ -258,7 +257,7 @@ export class Security2CCAPI extends CCAPI { this.assertPhysicalEndpoint(this.endpoint); - const cc = new Security2CCNonceReport(this.applHost, { + const cc = new Security2CCNonceReport({ nodeId: this.endpoint.nodeId, ownNodeId: this.applHost.ownNodeId, endpoint: this.endpoint.index, @@ -303,7 +302,7 @@ export class Security2CCAPI extends CCAPI { this.assertPhysicalEndpoint(this.endpoint); - const cc = new Security2CCMessageEncapsulation(this.applHost, { + const cc = new Security2CCMessageEncapsulation({ nodeId: this.endpoint.nodeId, ownNodeId: this.applHost.ownNodeId, endpoint: this.endpoint.index, @@ -355,13 +354,10 @@ export class Security2CCAPI extends CCAPI { Security2Command.CommandsSupportedGet, ); - let cc: CommandClass = new Security2CCCommandsSupportedGet( - this.applHost, - { - nodeId: this.endpoint.nodeId, - endpoint: this.endpoint.index, - }, - ); + let cc: CommandClass = new Security2CCCommandsSupportedGet({ + nodeId: this.endpoint.nodeId, + endpoint: this.endpoint.index, + }); // Security2CCCommandsSupportedGet is special because we cannot reply on the applHost to do the automatic // encapsulation because it would use a different security class. Therefore the entire possible stack // of encapsulation needs to be done here @@ -372,11 +368,10 @@ export class Security2CCAPI extends CCAPI { ); cc = multiChannelCCVersion === 1 - ? MultiChannelCC.encapsulateV1(this.applHost, cc) - : MultiChannelCC.encapsulate(this.applHost, cc); + ? MultiChannelCC.encapsulateV1(cc) + : MultiChannelCC.encapsulate(cc); } cc = Security2CC.encapsulate( - this.applHost, cc, this.applHost.ownNodeId, this.applHost, @@ -403,7 +398,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.CommandsSupportedReport, ); - const cc = new Security2CCCommandsSupportedReport(this.applHost, { + const cc = new Security2CCCommandsSupportedReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, supportedCCs, @@ -415,7 +410,7 @@ export class Security2CCAPI extends CCAPI { public async getKeyExchangeParameters() { this.assertSupportsCommand(Security2Command, Security2Command.KEXGet); - const cc = new Security2CCKEXGet(this.applHost, { + const cc = new Security2CCKEXGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -444,7 +439,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.KEXReport, ); - const cc = new Security2CCKEXReport(this.applHost, { + const cc = new Security2CCKEXReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...params, @@ -459,7 +454,7 @@ export class Security2CCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(Security2Command, Security2Command.KEXSet); - const cc = new Security2CCKEXSet(this.applHost, { + const cc = new Security2CCKEXSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...params, @@ -477,7 +472,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.KEXReport, ); - const cc = new Security2CCKEXReport(this.applHost, { + const cc = new Security2CCKEXReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...params, @@ -495,7 +490,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.KEXSet, ); - const cc = new Security2CCKEXSet(this.applHost, { + const cc = new Security2CCKEXSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...params, @@ -508,7 +503,7 @@ export class Security2CCAPI extends CCAPI { public async abortKeyExchange(failType: KEXFailType): Promise { this.assertSupportsCommand(Security2Command, Security2Command.KEXFail); - const cc = new Security2CCKEXFail(this.applHost, { + const cc = new Security2CCKEXFail({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, failType, @@ -525,7 +520,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.PublicKeyReport, ); - const cc = new Security2CCPublicKeyReport(this.applHost, { + const cc = new Security2CCPublicKeyReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, includingNode, @@ -542,7 +537,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.NetworkKeyGet, ); - const cc = new Security2CCNetworkKeyGet(this.applHost, { + const cc = new Security2CCNetworkKeyGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, requestedKey: securityClass, @@ -559,7 +554,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.NetworkKeyReport, ); - const cc = new Security2CCNetworkKeyReport(this.applHost, { + const cc = new Security2CCNetworkKeyReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, grantedKey: securityClass, @@ -574,7 +569,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.NetworkKeyVerify, ); - const cc = new Security2CCNetworkKeyVerify(this.applHost, { + const cc = new Security2CCNetworkKeyVerify({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -587,7 +582,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.TransferEnd, ); - const cc = new Security2CCTransferEnd(this.applHost, { + const cc = new Security2CCTransferEnd({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, keyVerified: true, @@ -606,7 +601,7 @@ export class Security2CCAPI extends CCAPI { Security2Command.TransferEnd, ); - const cc = new Security2CCTransferEnd(this.applHost, { + const cc = new Security2CCTransferEnd({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, keyVerified: false, @@ -957,7 +952,6 @@ export class Security2CC extends CommandClass { /** Encapsulates a command that should be sent encrypted */ public static encapsulate( - host: ZWaveHost, cc: CommandClass, ownNodeId: number, securityManagers: SecurityManagers, @@ -992,7 +986,7 @@ export class Security2CC extends CommandClass { nodeId = cc.nodeId as number; } - const ret = new Security2CCMessageEncapsulation(host, { + const ret = new Security2CCMessageEncapsulation({ nodeId, ownNodeId, encapsulated: cc, @@ -1090,12 +1084,11 @@ export type MulticastContext = ) export class Security2CCMessageEncapsulation extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | Security2CCMessageEncapsulationOptions, ) { - super(host, options); + super(options); // Make sure that we can send/receive secure commands this.securityManager = this.assertSecurity(options); @@ -1408,7 +1401,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { // make sure this contains a complete CC command that's worth splitting validatePayload(decryptedCCBytes.length >= 2); // and deserialize the CC - this.encapsulated = CommandClass.from(this.host, { + this.encapsulated = CommandClass.from({ data: decryptedCCBytes, fromEncapsulation: true, encapCC: this, @@ -1993,12 +1986,11 @@ export type Security2CCNonceReportOptions = @CCCommand(Security2Command.NonceReport) export class Security2CCNonceReport extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & Security2CCNonceReportOptions), ) { - super(host, options); + super(options); // Make sure that we can send/receive secure commands this.securityManager = this.assertSecurity(options); @@ -2098,12 +2090,11 @@ export class Security2CCNonceGet extends Security2CC { // 250 ms before receiving the Security 2 Nonce Report Command. public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & Security2CCNonceGetOptions), ) { - super(host, options); + super(options); // Make sure that we can send/receive secure commands this.securityManager = this.assertSecurity(options); @@ -2166,12 +2157,11 @@ export interface Security2CCKEXReportOptions { @CCCommand(Security2Command.KEXReport) export class Security2CCKEXReport extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & Security2CCKEXReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this.requestCSA = !!(this.payload[0] & 0b10); @@ -2291,12 +2281,11 @@ function testExpectedResponseForKEXSet( @expectedCCResponse(getExpectedResponseForKEXSet, testExpectedResponseForKEXSet) export class Security2CCKEXSet extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & Security2CCKEXSetOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this._reserved = this.payload[0] & 0b1111_1100; @@ -2391,10 +2380,9 @@ export interface Security2CCKEXFailOptions extends CCCommandOptions { @CCCommand(Security2Command.KEXFail) export class Security2CCKEXFail extends Security2CC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | Security2CCKEXFailOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.failType = this.payload[0]; @@ -2427,12 +2415,11 @@ export interface Security2CCPublicKeyReportOptions extends CCCommandOptions { @CCCommand(Security2Command.PublicKeyReport) export class Security2CCPublicKeyReport extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | Security2CCPublicKeyReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 17); this.includingNode = !!(this.payload[0] & 0b1); @@ -2474,12 +2461,11 @@ export interface Security2CCNetworkKeyReportOptions extends CCCommandOptions { @CCCommand(Security2Command.NetworkKeyReport) export class Security2CCNetworkKeyReport extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | Security2CCNetworkKeyReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 17); this.grantedKey = bitMaskToSecurityClass(this.payload, 0); @@ -2526,12 +2512,11 @@ export interface Security2CCNetworkKeyGetOptions extends CCCommandOptions { // FIXME: maybe use the dynamic @expectedCCResponse instead? export class Security2CCNetworkKeyGet extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | Security2CCNetworkKeyGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.requestedKey = bitMaskToSecurityClass(this.payload, 0); @@ -2572,12 +2557,11 @@ export interface Security2CCTransferEndOptions extends CCCommandOptions { @CCCommand(Security2Command.TransferEnd) export class Security2CCTransferEnd extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | Security2CCTransferEndOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.keyVerified = !!(this.payload[0] & 0b10); @@ -2619,12 +2603,11 @@ export interface Security2CCCommandsSupportedReportOptions @CCCommand(Security2Command.CommandsSupportedReport) export class Security2CCCommandsSupportedReport extends Security2CC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | Security2CCCommandsSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const CCs = parseCCList(this.payload); // SDS13783: A sending node MAY terminate the list of supported command classes with the diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 2b1d2eac4ed2..23bb7289336d 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -26,7 +26,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; @@ -115,7 +114,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { requestNextNonce ? SecurityCCCommandEncapsulationNonceGet : SecurityCCCommandEncapsulation - )(this.applHost, { + )({ nodeId: this.endpoint.nodeId, ownNodeId: this.applHost.ownNodeId, securityManager: this.applHost.securityManager!, @@ -130,7 +129,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { public async getNonce(): Promise { this.assertSupportsCommand(SecurityCommand, SecurityCommand.NonceGet); - const cc = new SecurityCCNonceGet(this.applHost, { + const cc = new SecurityCCNonceGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -180,7 +179,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { ); const nonceId = this.applHost.securityManager.getNonceId(nonce); - const cc = new SecurityCCNonceReport(this.applHost, { + const cc = new SecurityCCNonceReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, nonce, @@ -215,7 +214,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { public async getSecurityScheme(): Promise<[0]> { this.assertSupportsCommand(SecurityCommand, SecurityCommand.SchemeGet); - const cc = new SecurityCCSchemeGet(this.applHost, { + const cc = new SecurityCCSchemeGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -230,12 +229,12 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.SchemeReport, ); - let cc: CommandClass = new SecurityCCSchemeReport(this.applHost, { + let cc: CommandClass = new SecurityCCSchemeReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); if (encapsulated) { - cc = new SecurityCCCommandEncapsulation(this.applHost, { + cc = new SecurityCCCommandEncapsulation({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ownNodeId: this.applHost.ownNodeId, @@ -252,7 +251,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.SchemeInherit, ); - const cc = new SecurityCCSchemeInherit(this.applHost, { + const cc = new SecurityCCSchemeInherit({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -266,12 +265,12 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.NetworkKeySet, ); - const keySet = new SecurityCCNetworkKeySet(this.applHost, { + const keySet = new SecurityCCNetworkKeySet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, networkKey, }); - const cc = new SecurityCCCommandEncapsulation(this.applHost, { + const cc = new SecurityCCCommandEncapsulation({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ownNodeId: this.applHost.ownNodeId, @@ -288,7 +287,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.NetworkKeyVerify, ); - const cc = new SecurityCCNetworkKeyVerify(this.applHost, { + const cc = new SecurityCCNetworkKeyVerify({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -302,7 +301,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.CommandsSupportedGet, ); - const cc = new SecurityCCCommandsSupportedGet(this.applHost, { + const cc = new SecurityCCCommandsSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -326,7 +325,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.CommandsSupportedReport, ); - const cc = new SecurityCCCommandsSupportedReport(this.applHost, { + const cc = new SecurityCCCommandsSupportedReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, supportedCCs, @@ -537,13 +536,12 @@ export class SecurityCC extends CommandClass { /** Encapsulates a command that should be sent encrypted */ public static encapsulate( - host: ZWaveHost, ownNodeId: number, securityManager: SecurityManager, cc: CommandClass, ): SecurityCCCommandEncapsulation { // TODO: When to return a SecurityCCCommandEncapsulationNonceGet? - const ret = new SecurityCCCommandEncapsulation(host, { + const ret = new SecurityCCCommandEncapsulation({ nodeId: cc.nodeId, ownNodeId, securityManager, @@ -566,12 +564,11 @@ interface SecurityCCNonceReportOptions extends CCCommandOptions { @CCCommand(SecurityCommand.NonceReport) export class SecurityCCNonceReport extends SecurityCC { constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SecurityCCNonceReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload.withReason("Invalid nonce length")( this.payload.length === HALF_NONCE_SIZE, @@ -632,12 +629,11 @@ function getCCResponseForCommandEncapsulation( ) export class SecurityCCCommandEncapsulation extends SecurityCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SecurityCCCommandEncapsulationOptions, ) { - super(host, options); + super(options); this.securityManager = this.assertSecurity(options); @@ -769,7 +765,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { // make sure this contains a complete CC command that's worth splitting validatePayload(this.decryptedCCBytes.length >= 2); // and deserialize the CC - this.encapsulated = CommandClass.from(this.host, { + this.encapsulated = CommandClass.from({ data: this.decryptedCCBytes, fromEncapsulation: true, encapCC: this, @@ -875,10 +871,9 @@ export class SecurityCCCommandEncapsulationNonceGet @CCCommand(SecurityCommand.SchemeReport) export class SecurityCCSchemeReport extends SecurityCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); // The including controller MUST NOT perform any validation of the Supported Security Schemes byte @@ -904,10 +899,9 @@ export class SecurityCCSchemeReport extends SecurityCC { @expectedCCResponse(SecurityCCSchemeReport) export class SecurityCCSchemeGet extends SecurityCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); // Don't care, we won't get sent this and we have no options } @@ -930,10 +924,9 @@ export class SecurityCCSchemeGet extends SecurityCC { @expectedCCResponse(SecurityCCSchemeReport) export class SecurityCCSchemeInherit extends SecurityCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); // Don't care, we won't get sent this and we have no options } @@ -964,12 +957,11 @@ export interface SecurityCCNetworkKeySetOptions extends CCCommandOptions { @expectedCCResponse(SecurityCCNetworkKeyVerify) export class SecurityCCNetworkKeySet extends SecurityCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SecurityCCNetworkKeySetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 16); this.networkKey = this.payload.subarray(0, 16); @@ -1009,12 +1001,11 @@ export interface SecurityCCCommandsSupportedReportOptions @CCCommand(SecurityCommand.CommandsSupportedReport) export class SecurityCCCommandsSupportedReport extends SecurityCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SecurityCCCommandsSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index 316f2fae7b23..dd54f54dbf79 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -15,7 +15,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -121,7 +120,7 @@ export class SoundSwitchCCAPI extends CCAPI { SoundSwitchCommand.TonesNumberGet, ); - const cc = new SoundSwitchCCTonesNumberGet(this.applHost, { + const cc = new SoundSwitchCCTonesNumberGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -142,7 +141,7 @@ export class SoundSwitchCCAPI extends CCAPI { SoundSwitchCommand.ToneInfoGet, ); - const cc = new SoundSwitchCCToneInfoGet(this.applHost, { + const cc = new SoundSwitchCCToneInfoGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, toneId, @@ -166,7 +165,7 @@ export class SoundSwitchCCAPI extends CCAPI { SoundSwitchCommand.ConfigurationSet, ); - const cc = new SoundSwitchCCConfigurationSet(this.applHost, { + const cc = new SoundSwitchCCConfigurationSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, defaultToneId, @@ -182,7 +181,7 @@ export class SoundSwitchCCAPI extends CCAPI { SoundSwitchCommand.ConfigurationGet, ); - const cc = new SoundSwitchCCConfigurationGet(this.applHost, { + const cc = new SoundSwitchCCConfigurationGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -214,7 +213,7 @@ export class SoundSwitchCCAPI extends CCAPI { ); } - const cc = new SoundSwitchCCTonePlaySet(this.applHost, { + const cc = new SoundSwitchCCTonePlaySet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, toneId, @@ -229,7 +228,7 @@ export class SoundSwitchCCAPI extends CCAPI { SoundSwitchCommand.TonePlaySet, ); - const cc = new SoundSwitchCCTonePlaySet(this.applHost, { + const cc = new SoundSwitchCCTonePlaySet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, toneId: 0x00, @@ -245,7 +244,7 @@ export class SoundSwitchCCAPI extends CCAPI { SoundSwitchCommand.TonePlayGet, ); - const cc = new SoundSwitchCCTonePlayGet(this.applHost, { + const cc = new SoundSwitchCCTonePlayGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -481,12 +480,11 @@ export interface SoundSwitchCCTonesNumberReportOptions @CCCommand(SoundSwitchCommand.TonesNumberReport) export class SoundSwitchCCTonesNumberReport extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SoundSwitchCCTonesNumberReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.toneCount = this.payload[0]; @@ -524,12 +522,11 @@ export interface SoundSwitchCCToneInfoReportOptions extends CCCommandOptions { @CCCommand(SoundSwitchCommand.ToneInfoReport) export class SoundSwitchCCToneInfoReport extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SoundSwitchCCToneInfoReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this.toneId = this.payload[0]; @@ -590,12 +587,11 @@ export interface SoundSwitchCCToneInfoGetOptions extends CCCommandOptions { ) export class SoundSwitchCCToneInfoGet extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SoundSwitchCCToneInfoGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.toneId = this.payload[0]; @@ -629,12 +625,11 @@ export interface SoundSwitchCCConfigurationSetOptions extends CCCommandOptions { @useSupervision() export class SoundSwitchCCConfigurationSet extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | SoundSwitchCCConfigurationSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.defaultVolume = this.payload[0]; @@ -673,12 +668,11 @@ export interface SoundSwitchCCConfigurationReportOptions { @CCCommand(SoundSwitchCommand.ConfigurationReport) export class SoundSwitchCCConfigurationReport extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & SoundSwitchCCConfigurationReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.defaultVolume = clamp(this.payload[0], 0, 100); @@ -726,12 +720,11 @@ export interface SoundSwitchCCTonePlaySetOptions { @useSupervision() export class SoundSwitchCCTonePlaySet extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & SoundSwitchCCTonePlaySetOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.toneId = this.payload[0]; @@ -776,12 +769,11 @@ export interface SoundSwitchCCTonePlayReportOptions { @CCCommand(SoundSwitchCommand.TonePlayReport) export class SoundSwitchCCTonePlayReport extends SoundSwitchCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & SoundSwitchCCTonePlayReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.toneId = this.payload[0]; diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 04eea4b65b64..42753c9364fa 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -23,7 +23,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { PhysicalCCAPI } from "../lib/API"; @@ -92,7 +91,7 @@ export class SupervisionCCAPI extends PhysicalCCAPI { lowPriority = false, ...cmdOptions } = options; - const cc = new SupervisionCCReport(this.applHost, { + const cc = new SupervisionCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...cmdOptions, @@ -144,7 +143,6 @@ export class SupervisionCC extends CommandClass { /** Encapsulates a command that targets a specific endpoint */ public static encapsulate( - host: ZWaveHost, cc: CommandClass, sessionId: number, requestStatusUpdates: boolean = true, @@ -156,7 +154,7 @@ export class SupervisionCC extends CommandClass { ); } - const ret = new SupervisionCCGet(host, { + const ret = new SupervisionCCGet({ nodeId: cc.nodeId, // Supervision CC is wrapped inside MultiChannel CCs, so the endpoint must be copied endpoint: cc.endpointIndex, @@ -291,12 +289,11 @@ export type SupervisionCCReportOptions = @CCCommand(SupervisionCommand.Report) export class SupervisionCCReport extends SupervisionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & SupervisionCCReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); @@ -390,16 +387,15 @@ function testResponseForSupervisionCCGet( @expectedCCResponse(SupervisionCCReport, testResponseForSupervisionCCGet) export class SupervisionCCGet extends SupervisionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | SupervisionCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.requestStatusUpdates = !!(this.payload[0] & 0b1_0_000000); this.sessionId = this.payload[0] & 0b111111; - this.encapsulated = CommandClass.from(this.host, { + this.encapsulated = CommandClass.from({ data: this.payload.subarray(2), fromEncapsulation: true, encapCC: this, diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index ddd4753aa17c..bdb2cb881950 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -177,7 +176,7 @@ export class ThermostatFanModeCCAPI extends CCAPI { ThermostatFanModeCommand.Get, ); - const cc = new ThermostatFanModeCCGet(this.applHost, { + const cc = new ThermostatFanModeCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -202,7 +201,7 @@ export class ThermostatFanModeCCAPI extends CCAPI { ThermostatFanModeCommand.Set, ); - const cc = new ThermostatFanModeCCSet(this.applHost, { + const cc = new ThermostatFanModeCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, mode, @@ -219,7 +218,7 @@ export class ThermostatFanModeCCAPI extends CCAPI { ThermostatFanModeCommand.SupportedGet, ); - const cc = new ThermostatFanModeCCSupportedGet(this.applHost, { + const cc = new ThermostatFanModeCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -344,12 +343,11 @@ export type ThermostatFanModeCCSetOptions = CCCommandOptions & { @useSupervision() export class ThermostatFanModeCCSet extends ThermostatFanModeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatFanModeCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -387,10 +385,9 @@ export class ThermostatFanModeCCSet extends ThermostatFanModeCC { @CCCommand(ThermostatFanModeCommand.Report) export class ThermostatFanModeCCReport extends ThermostatFanModeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.mode = this.payload[0] & 0b1111; @@ -426,10 +423,9 @@ export class ThermostatFanModeCCGet extends ThermostatFanModeCC {} @CCCommand(ThermostatFanModeCommand.SupportedReport) export class ThermostatFanModeCCSupportedReport extends ThermostatFanModeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); this.supportedModes = parseBitMask( this.payload, ThermostatFanMode["Auto low"], diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index afb1ecd94ca3..e64d52b1386d 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -8,11 +8,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { - GetValueDB, - ZWaveApplicationHost, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { GetValueDB, ZWaveApplicationHost } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { CCAPI, @@ -82,7 +78,7 @@ export class ThermostatFanStateCCAPI extends CCAPI { ThermostatFanStateCommand.Get, ); - const cc = new ThermostatFanStateCCGet(this.applHost, { + const cc = new ThermostatFanStateCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -155,10 +151,9 @@ export class ThermostatFanStateCC extends CommandClass { @CCCommand(ThermostatFanStateCommand.Report) export class ThermostatFanStateCCReport extends ThermostatFanStateCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length == 1); this.state = this.payload[0] & 0b1111; diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index 636d4f576122..0a3f5ac74e7d 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -18,7 +18,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -133,7 +132,7 @@ export class ThermostatModeCCAPI extends CCAPI { ThermostatModeCommand.Get, ); - const cc = new ThermostatModeCCGet(this.applHost, { + const cc = new ThermostatModeCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -183,7 +182,7 @@ export class ThermostatModeCCAPI extends CCAPI { manufacturerData = Buffer.from(manufacturerData, "hex"); } - const cc = new ThermostatModeCCSet(this.applHost, { + const cc = new ThermostatModeCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, mode, @@ -200,7 +199,7 @@ export class ThermostatModeCCAPI extends CCAPI { ThermostatModeCommand.SupportedGet, ); - const cc = new ThermostatModeCCSupportedGet(this.applHost, { + const cc = new ThermostatModeCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -327,12 +326,11 @@ export type ThermostatModeCCSetOptions = @useSupervision() export class ThermostatModeCCSet extends ThermostatModeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatModeCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const manufacturerDataLength = (this.payload[0] >>> 5) & 0b111; @@ -407,12 +405,11 @@ export type ThermostatModeCCReportOptions = @CCCommand(ThermostatModeCommand.Report) export class ThermostatModeCCReport extends ThermostatModeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatModeCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -521,12 +518,11 @@ export interface ThermostatModeCCSupportedReportOptions @CCCommand(ThermostatModeCommand.SupportedReport) export class ThermostatModeCCSupportedReport extends ThermostatModeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatModeCCSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.supportedModes = parseBitMask( this.payload, diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index 3f27ca9a072b..df3aaf543391 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -7,11 +7,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { - GetValueDB, - ZWaveApplicationHost, - ZWaveHost, -} from "@zwave-js/host/safe"; +import type { GetValueDB, ZWaveApplicationHost } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { CCAPI, @@ -88,7 +84,7 @@ export class ThermostatOperatingStateCCAPI extends PhysicalCCAPI { ThermostatOperatingStateCommand.Get, ); - const cc = new ThermostatOperatingStateCCGet(this.applHost, { + const cc = new ThermostatOperatingStateCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -166,10 +162,9 @@ export class ThermostatOperatingStateCCReport extends ThermostatOperatingStateCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); this.state = this.payload[0]; diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 83aacaa08136..eb9c6251ad9f 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -10,7 +10,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -79,7 +78,7 @@ export class ThermostatSetbackCCAPI extends CCAPI { ThermostatSetbackCommand.Get, ); - const cc = new ThermostatSetbackCCGet(this.applHost, { + const cc = new ThermostatSetbackCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -104,7 +103,7 @@ export class ThermostatSetbackCCAPI extends CCAPI { ThermostatSetbackCommand.Get, ); - const cc = new ThermostatSetbackCCSet(this.applHost, { + const cc = new ThermostatSetbackCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setbackType, @@ -179,12 +178,11 @@ export interface ThermostatSetbackCCSetOptions extends CCCommandOptions { @useSupervision() export class ThermostatSetbackCCSet extends ThermostatSetbackCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetbackCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.setbackType = this.payload[0] & 0b11; @@ -235,12 +233,11 @@ export interface ThermostatSetbackCCReportOptions { @CCCommand(ThermostatSetbackCommand.Report) export class ThermostatSetbackCCReport extends ThermostatSetbackCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & ThermostatSetbackCCReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 951a0399372c..025ed981942a 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -22,7 +22,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -221,7 +220,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { ThermostatSetpointCommand.Get, ); - const cc = new ThermostatSetpointCCGet(this.applHost, { + const cc = new ThermostatSetpointCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setpointType, @@ -254,7 +253,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { ThermostatSetpointCommand.Set, ); - const cc = new ThermostatSetpointCCSet(this.applHost, { + const cc = new ThermostatSetpointCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setpointType, @@ -272,7 +271,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { ThermostatSetpointCommand.CapabilitiesGet, ); - const cc = new ThermostatSetpointCCCapabilitiesGet(this.applHost, { + const cc = new ThermostatSetpointCCCapabilitiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, setpointType, @@ -306,7 +305,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { ThermostatSetpointCommand.SupportedGet, ); - const cc = new ThermostatSetpointCCSupportedGet(this.applHost, { + const cc = new ThermostatSetpointCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -553,12 +552,11 @@ export interface ThermostatSetpointCCSetOptions extends CCCommandOptions { @useSupervision() export class ThermostatSetpointCCSet extends ThermostatSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetpointCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.setpointType = this.payload[0] & 0b1111; @@ -615,12 +613,11 @@ export interface ThermostatSetpointCCReportOptions extends CCCommandOptions { @CCCommand(ThermostatSetpointCommand.Report) export class ThermostatSetpointCCReport extends ThermostatSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetpointCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -721,12 +718,11 @@ export interface ThermostatSetpointCCGetOptions extends CCCommandOptions { ) export class ThermostatSetpointCCGet extends ThermostatSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetpointCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.setpointType = this.payload[0] & 0b1111; @@ -771,12 +767,11 @@ export class ThermostatSetpointCCCapabilitiesReport extends ThermostatSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetpointCCCapabilitiesReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -856,12 +851,11 @@ export interface ThermostatSetpointCCCapabilitiesGetOptions @expectedCCResponse(ThermostatSetpointCCCapabilitiesReport) export class ThermostatSetpointCCCapabilitiesGet extends ThermostatSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetpointCCCapabilitiesGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.setpointType = this.payload[0] & 0b1111; @@ -900,12 +894,11 @@ export interface ThermostatSetpointCCSupportedReportOptions @CCCommand(ThermostatSetpointCommand.SupportedReport) export class ThermostatSetpointCCSupportedReport extends ThermostatSetpointCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ThermostatSetpointCCSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 61e7e6b375eb..7ab9834abaa8 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -15,7 +15,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -64,7 +63,7 @@ export class TimeCCAPI extends CCAPI { public async getTime() { this.assertSupportsCommand(TimeCommand, TimeCommand.TimeGet); - const cc = new TimeCCTimeGet(this.applHost, { + const cc = new TimeCCTimeGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -85,7 +84,7 @@ export class TimeCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(TimeCommand, TimeCommand.TimeReport); - const cc = new TimeCCTimeReport(this.applHost, { + const cc = new TimeCCTimeReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, hour, @@ -99,7 +98,7 @@ export class TimeCCAPI extends CCAPI { public async getDate() { this.assertSupportsCommand(TimeCommand, TimeCommand.DateGet); - const cc = new TimeCCDateGet(this.applHost, { + const cc = new TimeCCDateGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -120,7 +119,7 @@ export class TimeCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(TimeCommand, TimeCommand.DateReport); - const cc = new TimeCCDateReport(this.applHost, { + const cc = new TimeCCDateReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, year, @@ -136,7 +135,7 @@ export class TimeCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(TimeCommand, TimeCommand.TimeOffsetSet); - const cc = new TimeCCTimeOffsetSet(this.applHost, { + const cc = new TimeCCTimeOffsetSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, standardOffset: timezone.standardOffset, @@ -150,7 +149,7 @@ export class TimeCCAPI extends CCAPI { public async getTimezone(): Promise> { this.assertSupportsCommand(TimeCommand, TimeCommand.TimeOffsetGet); - const cc = new TimeCCTimeOffsetGet(this.applHost, { + const cc = new TimeCCTimeOffsetGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -176,7 +175,7 @@ export class TimeCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(TimeCommand, TimeCommand.TimeOffsetReport); - const cc = new TimeCCTimeOffsetReport(this.applHost, { + const cc = new TimeCCTimeOffsetReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, standardOffset: timezone.standardOffset, @@ -239,10 +238,9 @@ export interface TimeCCTimeReportOptions extends CCCommandOptions { @CCCommand(TimeCommand.TimeReport) export class TimeCCTimeReport extends TimeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | TimeCCTimeReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.hour = this.payload[0] & 0b11111; @@ -301,10 +299,9 @@ export interface TimeCCDateReportOptions extends CCCommandOptions { @CCCommand(TimeCommand.DateReport) export class TimeCCDateReport extends TimeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | TimeCCDateReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this.year = this.payload.readUInt16BE(0); @@ -365,12 +362,11 @@ export interface TimeCCTimeOffsetSetOptions extends CCCommandOptions { @useSupervision() export class TimeCCTimeOffsetSet extends TimeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TimeCCTimeOffsetSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -432,12 +428,11 @@ export interface TimeCCTimeOffsetReportOptions extends CCCommandOptions { @CCCommand(TimeCommand.TimeOffsetReport) export class TimeCCTimeOffsetReport extends TimeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TimeCCTimeOffsetReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 9); const { standardOffset, dstOffset } = parseTimezone(this.payload); diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 7b68467375c8..dbfcbe6d683f 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -177,7 +176,7 @@ export class TimeParametersCCAPI extends CCAPI { TimeParametersCommand.Get, ); - const cc = new TimeParametersCCGet(this.applHost, { + const cc = new TimeParametersCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -207,7 +206,7 @@ export class TimeParametersCCAPI extends CCAPI { const useLocalTime = shouldUseLocalTime(this.applHost, endpointToCheck); - const cc = new TimeParametersCCSet(this.applHost, { + const cc = new TimeParametersCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, dateAndTime, @@ -258,10 +257,9 @@ export class TimeParametersCC extends CommandClass { @CCCommand(TimeParametersCommand.Report) export class TimeParametersCCReport extends TimeParametersCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 7); const dateSegments = { year: this.payload.readUInt16BE(0), @@ -323,12 +321,11 @@ export interface TimeParametersCCSetOptions extends CCCommandOptions { @useSupervision() export class TimeParametersCCSet extends TimeParametersCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TimeParametersCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 7); const dateSegments = { diff --git a/packages/cc/src/cc/TransportServiceCC.ts b/packages/cc/src/cc/TransportServiceCC.ts index 8c6302c47efa..ad951c0678c1 100644 --- a/packages/cc/src/cc/TransportServiceCC.ts +++ b/packages/cc/src/cc/TransportServiceCC.ts @@ -12,7 +12,6 @@ import type { CCParsingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { buffer2hex } from "@zwave-js/shared/safe"; import { @@ -82,10 +81,7 @@ export class TransportServiceCC extends CommandClass } /** Encapsulates a command that should be sent in multiple segments */ - public static encapsulate( - _host: ZWaveHost, - _cc: CommandClass, - ): TransportServiceCC { + public static encapsulate(_cc: CommandClass): TransportServiceCC { throw new Error("not implemented"); } } @@ -118,12 +114,11 @@ export function isTransportServiceEncapsulation( // @expectedCCResponse(TransportServiceCCReport) export class TransportServiceCCFirstSegment extends TransportServiceCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TransportServiceCCFirstSegmentOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // Deserialization has already split the datagram size from the ccCommand. // Therefore we have one more payload byte @@ -251,12 +246,11 @@ export interface TransportServiceCCSubsequentSegmentOptions // @expectedCCResponse(TransportServiceCCReport) export class TransportServiceCCSubsequentSegment extends TransportServiceCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TransportServiceCCSubsequentSegmentOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // Deserialization has already split the datagram size from the ccCommand. // Therefore we have one more payload byte @@ -373,7 +367,7 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { } // and deserialize the CC - this._encapsulated = CommandClass.from(this.host, { + this._encapsulated = CommandClass.from({ data: datagram, fromEncapsulation: true, encapCC: this, @@ -471,12 +465,11 @@ function testResponseForSegmentRequest( @expectedCCResponse(TransportServiceCC, testResponseForSegmentRequest) export class TransportServiceCCSegmentRequest extends TransportServiceCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TransportServiceCCSegmentRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.sessionId = this.payload[1] >>> 4; @@ -521,12 +514,11 @@ export interface TransportServiceCCSegmentCompleteOptions @CCCommand(TransportServiceCommand.SegmentComplete) export class TransportServiceCCSegmentComplete extends TransportServiceCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TransportServiceCCSegmentCompleteOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.sessionId = this.payload[1] >>> 4; @@ -558,12 +550,11 @@ export interface TransportServiceCCSegmentWaitOptions extends CCCommandOptions { @CCCommand(TransportServiceCommand.SegmentWait) export class TransportServiceCCSegmentWait extends TransportServiceCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | TransportServiceCCSegmentWaitOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.pendingSegments = this.payload[1]; diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 82aba905eb59..22474bd99e38 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, @@ -449,7 +448,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { UserCodeCommand.UsersNumberGet, ); - const cc = new UserCodeCCUsersNumberGet(this.applHost, { + const cc = new UserCodeCCUsersNumberGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -482,7 +481,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { UserCodeCommand.ExtendedUserCodeGet, ); - const cc = new UserCodeCCExtendedUserCodeGet(this.applHost, { + const cc = new UserCodeCCExtendedUserCodeGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, userId, @@ -507,7 +506,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { } else { this.assertSupportsCommand(UserCodeCommand, UserCodeCommand.Get); - const cc = new UserCodeCCGet(this.applHost, { + const cc = new UserCodeCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, userId, @@ -547,7 +546,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); } - const cc = new UserCodeCCSet(this.applHost, { + const cc = new UserCodeCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, userId, @@ -658,7 +657,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { } } } - const cc = new UserCodeCCExtendedUserCodeSet(this.applHost, { + const cc = new UserCodeCCExtendedUserCodeSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, userCodes: codes, @@ -692,7 +691,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); } - const cc = new UserCodeCCSet(this.applHost, { + const cc = new UserCodeCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, userId, @@ -709,7 +708,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { UserCodeCommand.CapabilitiesGet, ); - const cc = new UserCodeCCCapabilitiesGet(this.applHost, { + const cc = new UserCodeCCCapabilitiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -739,7 +738,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { UserCodeCommand.KeypadModeGet, ); - const cc = new UserCodeCCKeypadModeGet(this.applHost, { + const cc = new UserCodeCCKeypadModeGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -783,7 +782,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); } - const cc = new UserCodeCCKeypadModeSet(this.applHost, { + const cc = new UserCodeCCKeypadModeSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, keypadMode, @@ -798,7 +797,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { UserCodeCommand.AdminCodeGet, ); - const cc = new UserCodeCCAdminCodeGet(this.applHost, { + const cc = new UserCodeCCAdminCodeGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -851,7 +850,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); } - const cc = new UserCodeCCAdminCodeSet(this.applHost, { + const cc = new UserCodeCCAdminCodeSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, adminCode, @@ -866,7 +865,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { UserCodeCommand.UserCodeChecksumGet, ); - const cc = new UserCodeCCUserCodeChecksumGet(this.applHost, { + const cc = new UserCodeCCUserCodeChecksumGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -1233,12 +1232,11 @@ export type UserCodeCCSetOptions = @useSupervision() export class UserCodeCCSet extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & UserCodeCCSetOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userId = this.payload[0]; @@ -1326,10 +1324,9 @@ export class UserCodeCCReport extends UserCodeCC implements NotificationEventPayload { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | UserCodeCCReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); @@ -1429,10 +1426,9 @@ export interface UserCodeCCGetOptions extends CCCommandOptions { @expectedCCResponse(UserCodeCCReport) export class UserCodeCCGet extends UserCodeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | UserCodeCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.userId = this.payload[0]; @@ -1464,12 +1460,11 @@ export interface UserCodeCCUsersNumberReportOptions extends CCCommandOptions { @CCCommand(UserCodeCommand.UsersNumberReport) export class UserCodeCCUsersNumberReport extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCUsersNumberReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -1523,12 +1518,11 @@ export interface UserCodeCCCapabilitiesReportOptions extends CCCommandOptions { @CCCommand(UserCodeCommand.CapabilitiesReport) export class UserCodeCCCapabilitiesReport extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCCapabilitiesReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { let offset = 0; @@ -1700,12 +1694,11 @@ export interface UserCodeCCKeypadModeSetOptions extends CCCommandOptions { @useSupervision() export class UserCodeCCKeypadModeSet extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCKeypadModeSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.keypadMode = this.payload[0]; @@ -1737,12 +1730,11 @@ export interface UserCodeCCKeypadModeReportOptions extends CCCommandOptions { @CCCommand(UserCodeCommand.KeypadModeReport) export class UserCodeCCKeypadModeReport extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCKeypadModeReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.keypadMode = this.payload[0]; @@ -1803,12 +1795,11 @@ export interface UserCodeCCAdminCodeSetOptions extends CCCommandOptions { @useSupervision() export class UserCodeCCAdminCodeSet extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCAdminCodeSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const codeLength = this.payload[0] & 0b1111; @@ -1847,12 +1838,11 @@ export interface UserCodeCCAdminCodeReportOptions extends CCCommandOptions { @CCCommand(UserCodeCommand.AdminCodeReport) export class UserCodeCCAdminCodeReport extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCAdminCodeReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const codeLength = this.payload[0] & 0b1111; @@ -1898,12 +1888,11 @@ export interface UserCodeCCUserCodeChecksumReportOptions @CCCommand(UserCodeCommand.UserCodeChecksumReport) export class UserCodeCCUserCodeChecksumReport extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCUserCodeChecksumReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.userCodeChecksum = this.payload.readUInt16BE(0); @@ -1948,12 +1937,11 @@ export interface UserCode { @useSupervision() export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCExtendedUserCodeSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( @@ -2009,10 +1997,9 @@ export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { @CCCommand(UserCodeCommand.ExtendedUserCodeReport) export class UserCodeCCExtendedUserCodeReport extends UserCodeCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); const numCodes = this.payload[0]; let offset = 1; @@ -2076,12 +2063,11 @@ export interface UserCodeCCExtendedUserCodeGetOptions extends CCCommandOptions { @expectedCCResponse(UserCodeCCExtendedUserCodeReport) export class UserCodeCCExtendedUserCodeGet extends UserCodeCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | UserCodeCCExtendedUserCodeGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // TODO: Deserialize payload throw new ZWaveError( diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 4ca70f989fa6..ad756b7cd467 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -245,7 +244,7 @@ export class VersionCCAPI extends PhysicalCCAPI { public async get() { this.assertSupportsCommand(VersionCommand, VersionCommand.Get); - const cc = new VersionCCGet(this.applHost, { + const cc = new VersionCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -267,7 +266,7 @@ export class VersionCCAPI extends PhysicalCCAPI { public async sendReport(options: VersionCCReportOptions): Promise { this.assertSupportsCommand(VersionCommand, VersionCommand.Report); - const cc = new VersionCCReport(this.applHost, { + const cc = new VersionCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -284,7 +283,7 @@ export class VersionCCAPI extends PhysicalCCAPI { VersionCommand.CommandClassGet, ); - const cc = new VersionCCCommandClassGet(this.applHost, { + const cc = new VersionCCCommandClassGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, requestedCC, @@ -325,7 +324,7 @@ export class VersionCCAPI extends PhysicalCCAPI { break; } - const cc = new VersionCCCommandClassReport(this.applHost, { + const cc = new VersionCCCommandClassReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, requestedCC, @@ -341,7 +340,7 @@ export class VersionCCAPI extends PhysicalCCAPI { VersionCommand.CapabilitiesGet, ); - const cc = new VersionCCCapabilitiesGet(this.applHost, { + const cc = new VersionCCCapabilitiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -362,7 +361,7 @@ export class VersionCCAPI extends PhysicalCCAPI { VersionCommand.CapabilitiesReport, ); - const cc = new VersionCCCapabilitiesReport(this.applHost, { + const cc = new VersionCCCapabilitiesReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, // At this time, we do not support responding to Z-Wave Software Get @@ -378,7 +377,7 @@ export class VersionCCAPI extends PhysicalCCAPI { VersionCommand.ZWaveSoftwareGet, ); - const cc = new VersionCCZWaveSoftwareGet(this.applHost, { + const cc = new VersionCCZWaveSoftwareGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -653,12 +652,11 @@ export interface VersionCCReportOptions { @CCCommand(VersionCommand.Report) export class VersionCCReport extends VersionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (VersionCCReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 5); @@ -783,12 +781,11 @@ export interface VersionCCCommandClassReportOptions extends CCCommandOptions { @CCCommand(VersionCommand.CommandClassReport) export class VersionCCCommandClassReport extends VersionCC { public constructor( - host: ZWaveHost, options: | VersionCCCommandClassReportOptions | CommandClassDeserializationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.requestedCC = this.payload[0]; @@ -838,12 +835,11 @@ function testResponseForVersionCommandClassGet( ) export class VersionCCCommandClassGet extends VersionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | VersionCCCommandClassGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.requestedCC = this.payload[0]; @@ -875,12 +871,11 @@ export interface VersionCCCapabilitiesReportOptions { @CCCommand(VersionCommand.CapabilitiesReport) export class VersionCCCapabilitiesReport extends VersionCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (VersionCCCapabilitiesReportOptions & CCCommandOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -919,10 +914,9 @@ export class VersionCCCapabilitiesGet extends VersionCC {} @CCCommand(VersionCommand.ZWaveSoftwareReport) export class VersionCCZWaveSoftwareReport extends VersionCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 23); this.sdkVersion = parseVersion(this.payload); diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 76c70a0eba5b..b17942fc252a 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -13,7 +13,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -136,7 +135,7 @@ export class WakeUpCCAPI extends CCAPI { public async getInterval() { this.assertSupportsCommand(WakeUpCommand, WakeUpCommand.IntervalGet); - const cc = new WakeUpCCIntervalGet(this.applHost, { + const cc = new WakeUpCCIntervalGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -158,7 +157,7 @@ export class WakeUpCCAPI extends CCAPI { WakeUpCommand.IntervalCapabilitiesGet, ); - const cc = new WakeUpCCIntervalCapabilitiesGet(this.applHost, { + const cc = new WakeUpCCIntervalCapabilitiesGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -186,7 +185,7 @@ export class WakeUpCCAPI extends CCAPI { ): Promise { this.assertSupportsCommand(WakeUpCommand, WakeUpCommand.IntervalSet); - const cc = new WakeUpCCIntervalSet(this.applHost, { + const cc = new WakeUpCCIntervalSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, wakeUpInterval, @@ -201,7 +200,7 @@ export class WakeUpCCAPI extends CCAPI { WakeUpCommand.NoMoreInformation, ); - const cc = new WakeUpCCNoMoreInformation(this.applHost, { + const cc = new WakeUpCCNoMoreInformation({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -364,12 +363,11 @@ export interface WakeUpCCIntervalSetOptions extends CCCommandOptions { @useSupervision() export class WakeUpCCIntervalSet extends WakeUpCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | WakeUpCCIntervalSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this.wakeUpInterval = this.payload.readUIntBE(0, 3); @@ -408,10 +406,9 @@ export class WakeUpCCIntervalSet extends WakeUpCC { @CCCommand(WakeUpCommand.IntervalReport) export class WakeUpCCIntervalReport extends WakeUpCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); this.wakeUpInterval = this.payload.readUIntBE(0, 3); @@ -448,10 +445,9 @@ export class WakeUpCCNoMoreInformation extends WakeUpCC {} @CCCommand(WakeUpCommand.IntervalCapabilitiesReport) export class WakeUpCCIntervalCapabilitiesReport extends WakeUpCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 12); this.minWakeUpInterval = this.payload.readUIntBE(0, 3); diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 57737fb7e5fb..25a8d7c6b734 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -15,7 +15,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -475,7 +474,7 @@ export class WindowCoveringCCAPI extends CCAPI { WindowCoveringCommand.SupportedGet, ); - const cc = new WindowCoveringCCSupportedGet(this.applHost, { + const cc = new WindowCoveringCCSupportedGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -496,7 +495,7 @@ export class WindowCoveringCCAPI extends CCAPI { WindowCoveringCommand.Get, ); - const cc = new WindowCoveringCCGet(this.applHost, { + const cc = new WindowCoveringCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -525,7 +524,7 @@ export class WindowCoveringCCAPI extends CCAPI { WindowCoveringCommand.StartLevelChange, ); - const cc = new WindowCoveringCCSet(this.applHost, { + const cc = new WindowCoveringCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, targetValues, @@ -546,7 +545,7 @@ export class WindowCoveringCCAPI extends CCAPI { WindowCoveringCommand.StartLevelChange, ); - const cc = new WindowCoveringCCStartLevelChange(this.applHost, { + const cc = new WindowCoveringCCStartLevelChange({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -566,7 +565,7 @@ export class WindowCoveringCCAPI extends CCAPI { WindowCoveringCommand.StopLevelChange, ); - const cc = new WindowCoveringCCStopLevelChange(this.applHost, { + const cc = new WindowCoveringCCStopLevelChange({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, parameter, @@ -691,12 +690,11 @@ export interface WindowCoveringCCSupportedReportOptions @CCCommand(WindowCoveringCommand.SupportedReport) export class WindowCoveringCCSupportedReport extends WindowCoveringCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | WindowCoveringCCSupportedReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); @@ -759,10 +757,9 @@ export class WindowCoveringCCSupportedGet extends WindowCoveringCC {} @CCCommand(WindowCoveringCommand.Report) export class WindowCoveringCCReport extends WindowCoveringCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); this.parameter = this.payload[0]; this.currentValue = this.payload[1]; @@ -821,12 +818,11 @@ function testResponseForWindowCoveringGet( @expectedCCResponse(WindowCoveringCCReport, testResponseForWindowCoveringGet) export class WindowCoveringCCGet extends WindowCoveringCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | WindowCoveringCCGetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.parameter = this.payload[0]; @@ -868,12 +864,11 @@ export interface WindowCoveringCCSetOptions extends CCCommandOptions { @useSupervision() export class WindowCoveringCCSet extends WindowCoveringCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | WindowCoveringCCSetOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const numEntries = this.payload[0] & 0b11111; @@ -951,12 +946,11 @@ export interface WindowCoveringCCStartLevelChangeOptions @useSupervision() export class WindowCoveringCCStartLevelChange extends WindowCoveringCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | WindowCoveringCCStartLevelChangeOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.direction = !!(this.payload[0] & 0b0100_0000) ? "down" : "up"; @@ -1013,12 +1007,11 @@ export interface WindowCoveringCCStopLevelChangeOptions @useSupervision() export class WindowCoveringCCStopLevelChange extends WindowCoveringCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | WindowCoveringCCStopLevelChangeOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.parameter = this.payload[0]; diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index 941c746d8460..4c6d7284ed3c 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -9,7 +9,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -85,7 +84,7 @@ export class ZWavePlusCCAPI extends PhysicalCCAPI { public async get() { this.assertSupportsCommand(ZWavePlusCommand, ZWavePlusCommand.Get); - const cc = new ZWavePlusCCGet(this.applHost, { + const cc = new ZWavePlusCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -108,7 +107,7 @@ export class ZWavePlusCCAPI extends PhysicalCCAPI { public async sendReport(options: ZWavePlusCCReportOptions): Promise { this.assertSupportsCommand(ZWavePlusCommand, ZWavePlusCommand.Report); - const cc = new ZWavePlusCCReport(this.applHost, { + const cc = new ZWavePlusCCReport({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, ...options, @@ -180,12 +179,11 @@ export interface ZWavePlusCCReportOptions { @CCCommand(ZWavePlusCommand.Report) export class ZWavePlusCCReport extends ZWavePlusCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | (CCCommandOptions & ZWavePlusCCReportOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 7); this.zwavePlusVersion = this.payload[0]; diff --git a/packages/cc/src/cc/ZWaveProtocolCC.ts b/packages/cc/src/cc/ZWaveProtocolCC.ts index fd67ea05be4e..cd45e039a9ae 100644 --- a/packages/cc/src/cc/ZWaveProtocolCC.ts +++ b/packages/cc/src/cc/ZWaveProtocolCC.ts @@ -20,7 +20,7 @@ import { parseNodeProtocolInfoAndDeviceClass, validatePayload, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext } from "@zwave-js/host"; import { type CCCommandOptions, CommandClass, @@ -78,12 +78,11 @@ export class ZWaveProtocolCCNodeInformationFrame extends ZWaveProtocolCC implements NodeInformationFrame { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCNodeInformationFrameOptions, ) { - super(host, options); + super(options); let nif: NodeInformationFrame; if (gotDeserializationOptions(options)) { @@ -142,12 +141,11 @@ export interface ZWaveProtocolCCAssignIDsOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.AssignIDs) export class ZWaveProtocolCCAssignIDs extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCAssignIDsOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 5); this.assignedNodeId = this.payload[0]; @@ -181,12 +179,11 @@ export interface ZWaveProtocolCCFindNodesInRangeOptions @CCCommand(ZWaveProtocolCommand.FindNodesInRange) export class ZWaveProtocolCCFindNodesInRange extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCFindNodesInRangeOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const speedPresent = this.payload[0] & 0b1000_0000; @@ -248,12 +245,11 @@ export interface ZWaveProtocolCCRangeInfoOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.RangeInfo) export class ZWaveProtocolCCRangeInfo extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCRangeInfoOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const bitmaskLength = this.payload[0] & 0b0001_1111; @@ -303,12 +299,11 @@ export interface ZWaveProtocolCCCommandCompleteOptions @CCCommand(ZWaveProtocolCommand.CommandComplete) export class ZWaveProtocolCCCommandComplete extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCCommandCompleteOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.sequenceNumber = this.payload[0]; @@ -337,12 +332,11 @@ export interface ZWaveProtocolCCTransferPresentationOptions @CCCommand(ZWaveProtocolCommand.TransferPresentation) export class ZWaveProtocolCCTransferPresentation extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCTransferPresentationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const option = this.payload[0]; @@ -389,12 +383,11 @@ export class ZWaveProtocolCCTransferNodeInformation extends ZWaveProtocolCC implements NodeProtocolInfoAndDeviceClass { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCTransferNodeInformationOptions, ) { - super(host, options); + super(options); let info: NodeProtocolInfoAndDeviceClass; if (gotDeserializationOptions(options)) { @@ -460,12 +453,11 @@ export interface ZWaveProtocolCCTransferRangeInformationOptions @CCCommand(ZWaveProtocolCommand.TransferRangeInformation) export class ZWaveProtocolCCTransferRangeInformation extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCTransferRangeInformationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 3); this.sequenceNumber = this.payload[0]; @@ -508,12 +500,11 @@ export interface ZWaveProtocolCCTransferEndOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.TransferEnd) export class ZWaveProtocolCCTransferEnd extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCTransferEndOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.status = this.payload[0]; @@ -544,12 +535,11 @@ export interface ZWaveProtocolCCAssignReturnRouteOptions @CCCommand(ZWaveProtocolCommand.AssignReturnRoute) export class ZWaveProtocolCCAssignReturnRoute extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCAssignReturnRouteOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 7); this.destinationNodeId = this.payload[0]; @@ -609,12 +599,11 @@ export class ZWaveProtocolCCNewNodeRegistered extends ZWaveProtocolCC implements NodeInformationFrame { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCNewNodeRegisteredOptions, ) { - super(host, options); + super(options); let nif: NodeInformationFrame; if (gotDeserializationOptions(options)) { @@ -676,12 +665,11 @@ export interface ZWaveProtocolCCNewRangeRegisteredOptions @CCCommand(ZWaveProtocolCommand.NewRangeRegistered) export class ZWaveProtocolCCNewRangeRegistered extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCNewRangeRegisteredOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.testedNodeId = this.payload[0]; @@ -720,12 +708,11 @@ export class ZWaveProtocolCCTransferNewPrimaryControllerComplete extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCTransferNewPrimaryControllerCompleteOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.genericDeviceClass = this.payload[0]; @@ -756,12 +743,11 @@ export interface ZWaveProtocolCCSUCNodeIDOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.SUCNodeID) export class ZWaveProtocolCCSUCNodeID extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCSUCNodeIDOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.sucNodeId = this.payload[0]; @@ -790,12 +776,11 @@ export interface ZWaveProtocolCCSetSUCOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.SetSUC) export class ZWaveProtocolCCSetSUC extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCSetSUCOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); // Byte 0 must be 0x01 or ignored @@ -823,12 +808,11 @@ export interface ZWaveProtocolCCSetSUCAckOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.SetSUCAck) export class ZWaveProtocolCCSetSUCAck extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCSetSUCAckOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.accepted = this.payload[0] === 0x01; @@ -867,12 +851,11 @@ export interface ZWaveProtocolCCStaticRouteRequestOptions @CCCommand(ZWaveProtocolCommand.StaticRouteRequest) export class ZWaveProtocolCCStaticRouteRequest extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCStaticRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 5); this.nodeIds = [...this.payload.subarray(0, 5)].filter( @@ -908,12 +891,11 @@ export interface ZWaveProtocolCCLostOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.Lost) export class ZWaveProtocolCCLost extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCLostOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.lostNodeId = this.payload[0]; @@ -938,12 +920,11 @@ export interface ZWaveProtocolCCAcceptLostOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.AcceptLost) export class ZWaveProtocolCCAcceptLost extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCAcceptLostOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); validatePayload( @@ -971,12 +952,11 @@ export interface ZWaveProtocolCCNOPPowerOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.NOPPower) export class ZWaveProtocolCCNOPPower extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCNOPPowerOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { if (this.payload.length >= 2) { // Ignore byte 0 @@ -1031,12 +1011,11 @@ export interface ZWaveProtocolCCReservedIDsOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.ReservedIDs) export class ZWaveProtocolCCReservedIDs extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCReservedIDsOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); const numNodeIDs = this.payload[0]; @@ -1069,12 +1048,11 @@ export interface ZWaveProtocolCCReserveNodeIDsOptions extends CCCommandOptions { @expectedCCResponse(ZWaveProtocolCCReservedIDs) export class ZWaveProtocolCCReserveNodeIDs extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCReserveNodeIDsOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 1); this.numNodeIDs = this.payload[0]; @@ -1102,12 +1080,11 @@ export interface ZWaveProtocolCCNodesExistReplyOptions @CCCommand(ZWaveProtocolCommand.NodesExistReply) export class ZWaveProtocolCCNodesExistReply extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCNodesExistReplyOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.nodeMaskType = this.payload[0]; @@ -1150,12 +1127,11 @@ export interface ZWaveProtocolCCNodesExistOptions extends CCCommandOptions { ) export class ZWaveProtocolCCNodesExist extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCNodesExistOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.nodeMaskType = this.payload[0]; @@ -1190,12 +1166,11 @@ export interface ZWaveProtocolCCSetNWIModeOptions extends CCCommandOptions { @CCCommand(ZWaveProtocolCommand.SetNWIMode) export class ZWaveProtocolCCSetNWIMode extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCSetNWIModeOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.enabled = this.payload[0] === 0x01; @@ -1234,12 +1209,11 @@ export interface ZWaveProtocolCCAssignReturnRoutePriorityOptions @CCCommand(ZWaveProtocolCommand.AssignReturnRoutePriority) export class ZWaveProtocolCCAssignReturnRoutePriority extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCAssignReturnRoutePriorityOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.targetNodeId = this.payload[0]; @@ -1276,12 +1250,11 @@ export class ZWaveProtocolCCSmartStartIncludedNodeInformation extends ZWaveProtocolCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | ZWaveProtocolCCSmartStartIncludedNodeInformationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 4); this.nwiHomeId = this.payload.subarray(0, 4); diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index e8cbf2cf788e..bf17cf524e8f 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -14,7 +14,6 @@ import type { CCEncodingContext, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -113,7 +112,7 @@ export enum FibaroCCIDs { export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types public async fibaroVenetianBlindsGet() { - const cc = new FibaroVenetianBlindCCGet(this.applHost, { + const cc = new FibaroVenetianBlindCCGet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); @@ -130,7 +129,7 @@ export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { @validateArgs() public async fibaroVenetianBlindsSetPosition(value: number): Promise { - const cc = new FibaroVenetianBlindCCSet(this.applHost, { + const cc = new FibaroVenetianBlindCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, position: value, @@ -140,7 +139,7 @@ export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { @validateArgs() public async fibaroVenetianBlindsSetTilt(value: number): Promise { - const cc = new FibaroVenetianBlindCCSet(this.applHost, { + const cc = new FibaroVenetianBlindCCSet({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, tilt: value, @@ -217,10 +216,9 @@ export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { @manufacturerId(MANUFACTURERID_FIBARO) export class FibaroCC extends ManufacturerProprietaryCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { validatePayload(this.payload.length >= 2); this.fibaroCCId = this.payload[0]; @@ -234,7 +232,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { FibaroConstructor && (new.target as any) !== FibaroConstructor ) { - return new FibaroConstructor(host, options); + return new FibaroConstructor(options); } this.payload = this.payload.subarray(2); @@ -257,9 +255,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { - const instance = new SubConstructor(applHost, { - nodeId: node.id, - }); + const instance = new SubConstructor({ nodeId: node.id }); await instance.interview(applHost); } } @@ -275,9 +271,7 @@ export class FibaroCC extends ManufacturerProprietaryCC { for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { - const instance = new SubConstructor(applHost, { - nodeId: node.id, - }); + const instance = new SubConstructor({ nodeId: node.id }); await instance.refreshValues(applHost); } } @@ -315,10 +309,9 @@ export class FibaroVenetianBlindCC extends FibaroCC { declare fibaroCCCommand: FibaroVenetianBlindCCCommand; public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); this.fibaroCCId = FibaroCCIDs.VenetianBlind; if (gotDeserializationOptions(options)) { @@ -326,7 +319,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { this.fibaroCCCommand === FibaroVenetianBlindCCCommand.Report && (new.target as any) !== FibaroVenetianBlindCCReport ) { - return new FibaroVenetianBlindCCReport(host, options); + return new FibaroVenetianBlindCCReport(options); } } } @@ -356,7 +349,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { direction: "outbound", }); const resp = await applHost.sendCommand( - new FibaroVenetianBlindCCGet(applHost, { + new FibaroVenetianBlindCCGet({ nodeId: this.nodeId, endpoint: this.endpointIndex, }), @@ -392,12 +385,11 @@ export type FibaroVenetianBlindCCSetOptions = @fibaroCCCommand(FibaroVenetianBlindCCCommand.Set) export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { public constructor( - host: ZWaveHost, options: | CommandClassDeserializationOptions | FibaroVenetianBlindCCSetOptions, ) { - super(host, options); + super(options); this.fibaroCCCommand = FibaroVenetianBlindCCCommand.Set; if (Buffer.isBuffer(options)) { @@ -444,10 +436,9 @@ export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { @fibaroCCCommand(FibaroVenetianBlindCCCommand.Report) export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions, ) { - super(host, options); + super(options); this.fibaroCCCommand = FibaroVenetianBlindCCCommand.Report; validatePayload(this.payload.length >= 3); @@ -519,10 +510,9 @@ export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { @expectedCCResponse(FibaroVenetianBlindCCReport) export class FibaroVenetianBlindCCGet extends FibaroVenetianBlindCC { public constructor( - host: ZWaveHost, options: CommandClassDeserializationOptions | CCCommandOptions, ) { - super(host, options); + super(options); this.fibaroCCCommand = FibaroVenetianBlindCCCommand.Get; } } diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 9286cbf648c8..b027147469f3 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -39,7 +39,6 @@ import type { GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host"; import { MessageOrigin } from "@zwave-js/serial"; import { @@ -160,8 +159,7 @@ export function getEffectiveCCVersion( // @publicAPI export class CommandClass implements CCId { // empty constructor to parse messages - public constructor(host: ZWaveHost, options: CommandClassOptions) { - this.host = host; + public constructor(options: CommandClassOptions) { // Default to the root endpoint - Inherited classes may override this behavior this.endpointIndex = ("endpoint" in options ? options.endpoint : undefined) ?? 0; @@ -187,7 +185,7 @@ export class CommandClass implements CCId { CommandConstructor && (new.target as any) !== CommandConstructor ) { - return new CommandConstructor(host, options); + return new CommandConstructor(options); } } @@ -225,24 +223,8 @@ export class CommandClass implements CCId { this.ccCommand = ccCommand; this.payload = payload; } - - if (this instanceof InvalidCC) return; - - if (options.origin !== MessageOrigin.Host && this.isSinglecast()) { - // Send secure commands if necessary - this.toggleEncapsulationFlag( - EncapsulationFlags.Security, - this.host.isCCSecure( - this.ccId, - this.nodeId, - this.endpointIndex, - ), - ); - } } - protected host: ZWaveHost; - /** This CC's identifier */ public ccId!: CommandClasses; public ccCommand?: number; @@ -401,7 +383,6 @@ export class CommandClass implements CCId { * Creates an instance of the CC that is serialized in the given buffer */ public static from( - host: ZWaveHost, options: CommandClassDeserializationOptions, ): CommandClass { // Fall back to unspecified command class in case we receive one that is not implemented @@ -409,7 +390,7 @@ export class CommandClass implements CCId { const Constructor = getCCConstructor(ccId) ?? CommandClass; try { - return new Constructor(host, options); + return new Constructor(options); } catch (e) { // Indicate invalid payloads with a special CC type if ( @@ -439,7 +420,7 @@ export class CommandClass implements CCId { reason = e.context; } - const ret = new InvalidCC(host, { + const ret = new InvalidCC({ nodeId, ccId, ccName, @@ -463,13 +444,12 @@ export class CommandClass implements CCId { * **INTERNAL:** Applications should not use this directly. */ public static createInstanceUnchecked( - host: ZWaveHost, endpoint: EndpointId, cc: CommandClasses | CCConstructor, ): T | undefined { const Constructor = typeof cc === "number" ? getCCConstructor(cc) : cc; if (Constructor) { - return new Constructor(host, { + return new Constructor({ nodeId: endpoint.nodeId, endpoint: endpoint.index, }) as T; @@ -1213,8 +1193,8 @@ export interface InvalidCCCreationOptions extends CommandClassCreationOptions { } export class InvalidCC extends CommandClass { - public constructor(host: ZWaveHost, options: InvalidCCCreationOptions) { - super(host, options); + public constructor(options: InvalidCCCreationOptions) { + super(options); this._ccName = options.ccName; // Numeric reasons are used internally to communicate problems with a CC // without ignoring them entirely @@ -1266,7 +1246,7 @@ export function assertValidCCs(container: ICommandClassContainer): void { export type CCConstructor = typeof CommandClass & { // I don't like the any, but we need it to support half-implemented CCs (e.g. report classes) - new (host: ZWaveHost, options: any): T; + new (options: any): T; }; /** diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 3b4aad64d57f..17b4d78fc076 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -98,39 +98,6 @@ export interface CCEncodingContext ): void; } -/** Host application abstractions to be used in Serial API and CC implementations */ -export interface ZWaveHost { - /** - * Retrieves the maximum version of a command class that can be used to communicate with a node. - * Returns 1 if the node claims that it does not support a CC. - * Returns `undefined` for CCs that are not implemented in this library yet. - */ - getSafeCCVersion( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): number | undefined; - - /** - * Retrieves the maximum version of a command class the given node/endpoint has reported support for. - * Returns 0 when the CC is not supported or that information is not known yet. - */ - getSupportedCCVersion( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): number; - - /** - * Determines whether a CC must be secure for a given node and endpoint. - */ - isCCSecure( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): boolean; -} - /** Host application abstractions that provide support for reading and writing values to a database */ export interface GetValueDB { /** Returns the value DB which belongs to the node with the given ID, or throws if the Value DB cannot be accessed */ @@ -151,12 +118,10 @@ export interface GetAllNodes { getAllNodes(): T[]; } -/** A more featureful version of the ZWaveHost interface, which is meant to be used on the controller application side. */ export interface ZWaveApplicationHost extends GetValueDB, HostIDs, - ZWaveHost, GetNode, GetAllNodes, SecurityManagers, @@ -190,6 +155,36 @@ export interface ZWaveApplicationHost valueId: ValueID, options: NodeSchedulePollOptions, ): boolean; + + /** + * Retrieves the maximum version of a command class that can be used to communicate with a node. + * Returns 1 if the node claims that it does not support a CC. + * Returns `undefined` for CCs that are not implemented in this library yet. + */ + getSafeCCVersion( + cc: CommandClasses, + nodeId: number, + endpointIndex?: number, + ): number | undefined; + + /** + * Retrieves the maximum version of a command class the given node/endpoint has reported support for. + * Returns 0 when the CC is not supported or that information is not known yet. + */ + getSupportedCCVersion( + cc: CommandClasses, + nodeId: number, + endpointIndex?: number, + ): number; + + /** + * Determines whether a CC must be secure for a given node and endpoint. + */ + isCCSecure( + cc: CommandClasses, + nodeId: number, + endpointIndex?: number, + ): boolean; } export interface NodeSchedulePollOptions { diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 33732b065740..babd0e065c2e 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -13,11 +13,11 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { createThrowingMap } from "@zwave-js/shared"; -import type { HostIDs, ZWaveApplicationHost, ZWaveHost } from "./ZWaveHost"; +import type { HostIDs, ZWaveApplicationHost } from "./ZWaveHost"; export interface CreateTestingHostOptions extends HostIDs { - getSafeCCVersion: ZWaveHost["getSafeCCVersion"]; - getSupportedCCVersion?: ZWaveHost["getSupportedCCVersion"]; + getSafeCCVersion: ZWaveApplicationHost["getSafeCCVersion"]; + getSupportedCCVersion?: ZWaveApplicationHost["getSupportedCCVersion"]; } export type BaseTestNode = diff --git a/packages/serial/src/message/Message.test.ts b/packages/serial/src/message/Message.test.ts index 181e91f86d3a..664245187419 100644 --- a/packages/serial/src/message/Message.test.ts +++ b/packages/serial/src/message/Message.test.ts @@ -40,7 +40,7 @@ test("should deserialize and serialize correctly", (t) => { ]), ]; for (const original of okayMessages) { - const parsed = new Message(host, { data: original }); + const parsed = new Message({ data: original }); t.deepEqual(parsed.serialize(), original); } }); @@ -49,7 +49,7 @@ test("should serialize correctly when the payload is null", (t) => { const host = createTestingHost(); // synthetic message const expected = Buffer.from([0x01, 0x03, 0x00, 0xff, 0x03]); - const message = new Message(host, { + const message = new Message({ type: MessageType.Request, functionType: 0xff as any, }); @@ -92,7 +92,7 @@ test("should throw the correct error when parsing a faulty message", (t) => { ], ]; for (const [message, msg, code] of brokenMessages) { - assertZWaveError(t, () => new Message(host, { data: message }), { + assertZWaveError(t, () => new Message({ data: message }), { messageMatches: msg, errorCode: code, }); @@ -249,7 +249,7 @@ test("isComplete() should work correctly", (t) => { test("toJSON() should return a semi-readable JSON representation", (t) => { const host = createTestingHost(); - const msg1 = new Message(host, { + const msg1 = new Message({ type: MessageType.Request, functionType: FunctionType.GetControllerVersion, }); @@ -259,7 +259,7 @@ test("toJSON() should return a semi-readable JSON representation", (t) => { functionType: "GetControllerVersion", payload: "", }; - const msg2 = new Message(host, { + const msg2 = new Message({ type: MessageType.Request, functionType: FunctionType.GetControllerVersion, payload: Buffer.from("aabbcc", "hex"), @@ -270,7 +270,7 @@ test("toJSON() should return a semi-readable JSON representation", (t) => { functionType: "GetControllerVersion", payload: "aabbcc", }; - const msg3 = new Message(host, { + const msg3 = new Message({ type: MessageType.Response, functionType: FunctionType.GetControllerVersion, expectedResponse: FunctionType.GetControllerVersion, @@ -282,7 +282,7 @@ test("toJSON() should return a semi-readable JSON representation", (t) => { expectedResponse: "GetControllerVersion", payload: "", }; - const msg4 = new Message(host, { + const msg4 = new Message({ type: MessageType.Request, functionType: FunctionType.GetControllerVersion, expectedResponse: FunctionType.GetControllerVersion, @@ -311,7 +311,7 @@ test(`the constructor should throw when no message type is specified`, (t) => { const host = createTestingHost(); assertZWaveError( t, - () => new Message(host, { functionType: 0xff as any }), + () => new Message({ functionType: 0xff as any }), { errorCode: ZWaveErrorCodes.Argument_Invalid, messageMatches: /message type/i, @@ -331,7 +331,7 @@ test(`the constructor should throw when no function type is specified`, (t) => { const host = createTestingHost(); assertZWaveError( t, - () => new Message(host, { type: MessageType.Request }), + () => new Message({ type: MessageType.Request }), { errorCode: ZWaveErrorCodes.Argument_Invalid, messageMatches: /function type/i, @@ -349,7 +349,7 @@ test(`the constructor should throw when no function type is specified`, (t) => { test("getNodeUnsafe() returns undefined when the controller is not initialized yet", (t) => { const host = createTestingHost(); - const msg = new Message(host, { + const msg = new Message({ type: MessageType.Request, functionType: 0xff as any, }); @@ -358,7 +358,7 @@ test("getNodeUnsafe() returns undefined when the controller is not initialized y test("getNodeUnsafe() returns undefined when the message is no node query", (t) => { const host = createTestingHost(); - const msg = new Message(host, { + const msg = new Message({ type: MessageType.Request, functionType: 0xff as any, }); @@ -369,7 +369,7 @@ test("getNodeUnsafe() returns the associated node otherwise", (t) => { const host = createTestingHost(); host.setNode(1, {} as any); - const msg = new Message(host, { + const msg = new Message({ type: MessageType.Request, functionType: 0xff as any, }); diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 40a0bc326d56..41d3f1304e18 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -17,7 +17,6 @@ import type { GetSupportedCCVersion, HostIDs, ZWaveApplicationHost, - ZWaveHost, } from "@zwave-js/host"; import type { JSONObject, TypedClassDecorator } from "@zwave-js/shared/safe"; import { num2hex, staticExtends } from "@zwave-js/shared/safe"; @@ -26,12 +25,10 @@ import { FunctionType, MessageType } from "./Constants"; import { isNodeQuery } from "./INodeQuery"; export type MessageConstructor = new ( - host: ZWaveHost, options?: MessageOptions, ) => T; export type DeserializingMessageConstructor = new ( - host: ZWaveHost, options: MessageDeserializationOptions, ) => T; @@ -122,8 +119,7 @@ export interface MessageEncodingContext */ export class Message { public constructor( - public readonly host: ZWaveHost, - options: MessageOptions = {}, + public readonly options: MessageOptions = {}, ) { // decide which implementation we follow if (gotDeserializationOptions(options)) { @@ -297,7 +293,6 @@ export class Message { /** Creates an instance of the message that is serialized in the given buffer */ public static from( - host: ZWaveHost, options: MessageDeserializationOptions, contextStore?: Map>, ): Message { @@ -312,7 +307,7 @@ export class Message { } } - const ret = new Constructor(host, options); + const ret = new Constructor(options); return ret; } diff --git a/packages/serial/src/message/ZnifferMessages.ts b/packages/serial/src/message/ZnifferMessages.ts index dddd22e70d9d..de4cc9ed5b49 100644 --- a/packages/serial/src/message/ZnifferMessages.ts +++ b/packages/serial/src/message/ZnifferMessages.ts @@ -59,7 +59,6 @@ export type ZnifferMessageOptions = */ export class ZnifferMessage { public constructor( - // public readonly host: ZWaveHost, options: ZnifferMessageOptions, ) { // decide which implementation we follow diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 5ead88e4f3e3..030558af5013 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -7,7 +7,6 @@ import { type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { Message, type MessageEncodingContext, @@ -64,19 +63,6 @@ export class MockController { this.ownNodeId = options.ownNodeId ?? 1; this.homeId = options.homeId ?? 0x7e571000; - this.host = { - getSafeCCVersion: () => 100, - getSupportedCCVersion: (cc, nodeId, endpointIndex = 0) => { - if (!this.nodes.has(nodeId)) { - return 0; - } - const node = this.nodes.get(nodeId)!; - const endpoint = node.endpoints.get(endpointIndex); - return (endpoint ?? node).implementedCCs.get(cc)?.version ?? 0; - }, - isCCSecure: () => false, - }; - this.capabilities = { ...getDefaultMockControllerCapabilities(), ...options.capabilities, @@ -184,8 +170,6 @@ export class MockController { this._nodes.delete(node.id); } - public readonly host: ZWaveHost; - public readonly capabilities: MockControllerCapabilities; /** Can be used by behaviors to store controller related state */ @@ -228,7 +212,7 @@ export class MockController { let msg: Message; try { - msg = Message.from(this.host, { + msg = Message.from({ data, origin: MessageOrigin.Host, parseCCs: false, @@ -253,7 +237,7 @@ export class MockController { handler.resolve(msg); } else { for (const behavior of this.behaviors) { - if (await behavior.onHostMessage?.(this.host, this, msg)) { + if (await behavior.onHostMessage?.(this, msg)) { return; } } @@ -443,7 +427,7 @@ export class MockController { // Then apply generic predefined behavior for (const behavior of this.behaviors) { if ( - await behavior.onNodeFrame?.(this.host, this, node, frame) + await behavior.onNodeFrame?.(this, node, frame) ) { return; } @@ -549,13 +533,11 @@ export class MockController { export interface MockControllerBehavior { /** Gets called when a message from the host is received. Return `true` to indicate that the message has been handled. */ onHostMessage?: ( - host: ZWaveHost, controller: MockController, msg: Message, ) => Promise | boolean | undefined; /** Gets called when a message from a node is received. Return `true` to indicate that the message has been handled. */ onNodeFrame?: ( - host: ZWaveHost, controller: MockController, node: MockNode, frame: MockZWaveFrame, diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index c1f3dcc92db8..8e9874ec50a5 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -8,7 +8,7 @@ import { type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext } from "@zwave-js/host"; import { TimedExpectation } from "@zwave-js/shared"; import { isDeepStrictEqual } from "node:util"; import type { CCIdToCapabilities } from "./CCSpecificCapabilities"; @@ -112,12 +112,6 @@ export class MockNode { this.id = options.id; this.controller = options.controller; - // A node's host is a bit more specialized than the controller's host. - this.host = { - ...this.controller.host, - // // Mimic the behavior of ZWaveNode, but for arbitrary node IDs - }; - const securityClasses = new Map>(); const { @@ -196,7 +190,6 @@ export class MockNode { }; } - public readonly host: ZWaveHost; public readonly id: number; public readonly controller: MockController; public readonly capabilities: MockNodeCapabilities; diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index 3b12c50f38bd..0730dc4ea047 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -1144,7 +1144,7 @@ export class ZWaveController const apiCaps = await this.driver.sendMessage< GetSerialApiCapabilitiesResponse >( - new GetSerialApiCapabilitiesRequest(this.driver), + new GetSerialApiCapabilitiesRequest(), { supportCheck: false, }, @@ -1175,7 +1175,7 @@ export class ZWaveController const version = await this.driver.sendMessage< GetControllerVersionResponse >( - new GetControllerVersionRequest(this.driver), + new GetControllerVersionRequest(), { supportCheck: false, }, @@ -1196,7 +1196,7 @@ export class ZWaveController const protocol = await this.driver.sendMessage< GetProtocolVersionResponse >( - new GetProtocolVersionRequest(this.driver), + new GetProtocolVersionRequest(), ); this._protocolVersion = protocol.protocolVersion; @@ -1236,7 +1236,7 @@ export class ZWaveController const setupCaps = await this.driver.sendMessage< SerialAPISetup_GetSupportedCommandsResponse >( - new SerialAPISetup_GetSupportedCommandsRequest(this.driver), + new SerialAPISetup_GetSupportedCommandsRequest(), ); this._supportedSerialAPISetupCommands = setupCaps.supportedCommands; this.driver.controllerLog.print( @@ -1689,7 +1689,7 @@ export class ZWaveController public async identify(): Promise { this.driver.controllerLog.print(`querying controller IDs...`); const ids = await this.driver.sendMessage( - new GetControllerIdRequest(this.driver), + new GetControllerIdRequest(), { supportCheck: false }, ); this._homeId = ids.homeId; @@ -1716,7 +1716,7 @@ export class ZWaveController const resp = await this.driver.sendMessage< SerialAPISetup_SetTXStatusReportResponse >( - new SerialAPISetup_SetTXStatusReportRequest(this.driver, { + new SerialAPISetup_SetTXStatusReportRequest({ enabled: true, }), ); @@ -1730,7 +1730,7 @@ export class ZWaveController // find the SUC this.driver.controllerLog.print(`finding SUC...`); const suc = await this.driver.sendMessage( - new GetSUCNodeIdRequest(this.driver), + new GetSUCNodeIdRequest(), { supportCheck: false }, ); this._sucNodeId = suc.sucNodeId; @@ -1792,7 +1792,7 @@ export class ZWaveController const resp = await this.driver.sendMessage< SetSerialApiTimeoutsResponse >( - new SetSerialApiTimeoutsRequest(this.driver, { + new SetSerialApiTimeoutsRequest({ ackTimeout: ack, byteTimeout: byte, }), @@ -1926,7 +1926,7 @@ export class ZWaveController const nodesResponse = await this.driver.sendMessage< GetLongRangeNodesResponse >( - new GetLongRangeNodesRequest(this.driver, { + new GetLongRangeNodesRequest({ segmentNumber: segment, }), ); @@ -1946,7 +1946,7 @@ export class ZWaveController public async setControllerNIF(): Promise { this.driver.controllerLog.print("Updating the controller NIF..."); await this.driver.sendMessage( - new SetApplicationNodeInformationRequest(this.driver, { + new SetApplicationNodeInformationRequest({ isListening: true, ...determineNIF(), }), @@ -1978,7 +1978,7 @@ export class ZWaveController } this.driver.controllerLog.print("performing hard reset..."); - await this.driver.sendMessage(new HardResetRequest(this.driver), { + await this.driver.sendMessage(new HardResetRequest(), { supportCheck: false, }); @@ -2003,7 +2003,7 @@ export class ZWaveController try { this.driver.controllerLog.print("Shutting down the Z-Wave API..."); const response = await this.driver.sendMessage( - new ShutdownRequest(this.driver), + new ShutdownRequest(), ); if (response.success) { this.driver.controllerLog.print("Z-Wave API was shut down"); @@ -2036,7 +2036,7 @@ export class ZWaveController "Starting hardware watchdog...", ); await this.driver.sendMessage( - new StartWatchdogRequest(this.driver), + new StartWatchdogRequest(), ); return true; @@ -2063,7 +2063,7 @@ export class ZWaveController "Stopping hardware watchdog...", ); await this.driver.sendMessage( - new StopWatchdogRequest(this.driver), + new StopWatchdogRequest(), ); return true; @@ -2159,7 +2159,7 @@ export class ZWaveController // kick off the inclusion process await this.driver.sendMessage( - new AddNodeToNetworkRequest(this.driver, { + new AddNodeToNetworkRequest({ addNodeType: AddNodeType.Any, highPower: true, networkWide: true, @@ -2230,7 +2230,7 @@ export class ZWaveController ); await this.driver.sendMessage( - new AddNodeDSKToNetworkRequest(this.driver, { + new AddNodeDSKToNetworkRequest({ nwiHomeId: nwiHomeIdFromDSK(dskBuffer), authHomeId: authHomeIdFromDSK(dskBuffer), protocol, @@ -2255,7 +2255,7 @@ export class ZWaveController */ public async stopInclusionNoCallback(): Promise { await this.driver.sendMessage( - new AddNodeToNetworkRequest(this.driver, { + new AddNodeToNetworkRequest({ callbackId: 0, // disable callbacks addNodeType: AddNodeType.Stop, highPower: true, @@ -2276,7 +2276,7 @@ export class ZWaveController const response = await this.driver.sendMessage< AddNodeToNetworkRequestStatusReport >( - new AddNodeToNetworkRequest(this.driver, { + new AddNodeToNetworkRequest({ addNodeType: AddNodeType.Stop, highPower: true, networkWide: true, @@ -2310,7 +2310,7 @@ export class ZWaveController try { // stop the inclusion process await this.driver.sendMessage( - new AddNodeToNetworkRequest(this.driver, { + new AddNodeToNetworkRequest({ addNodeType: AddNodeType.Stop, highPower: true, networkWide: true, @@ -2364,7 +2364,7 @@ export class ZWaveController ); try { await this.driver.sendMessage( - new EnableSmartStartListenRequest(this.driver, {}), + new EnableSmartStartListenRequest({}), ); this.driver.controllerLog.print( `Smart Start listening mode enabled`, @@ -2408,7 +2408,7 @@ export class ZWaveController ); try { await this.driver.sendMessage( - new AddNodeToNetworkRequest(this.driver, { + new AddNodeToNetworkRequest({ callbackId: 0, // disable callbacks addNodeType: AddNodeType.Stop, highPower: true, @@ -2450,7 +2450,7 @@ export class ZWaveController ); try { await this.driver.sendMessage( - new AddNodeToNetworkRequest(this.driver, { + new AddNodeToNetworkRequest({ callbackId: 0, // disable callbacks addNodeType: AddNodeType.Stop, highPower: true, @@ -2505,7 +2505,7 @@ export class ZWaveController try { // kick off the inclusion process await this.driver.sendMessage( - new RemoveNodeFromNetworkRequest(this.driver, { + new RemoveNodeFromNetworkRequest({ removeNodeType: RemoveNodeType.Any, highPower: true, networkWide: true, @@ -2542,7 +2542,7 @@ export class ZWaveController */ public async stopExclusionNoCallback(): Promise { await this.driver.sendMessage( - new RemoveNodeFromNetworkRequest(this.driver, { + new RemoveNodeFromNetworkRequest({ callbackId: 0, // disable callbacks removeNodeType: RemoveNodeType.Stop, highPower: true, @@ -2567,7 +2567,7 @@ export class ZWaveController try { // kick off the inclusion process await this.driver.sendMessage( - new RemoveNodeFromNetworkRequest(this.driver, { + new RemoveNodeFromNetworkRequest({ removeNodeType: RemoveNodeType.Stop, highPower: true, networkWide: true, @@ -5111,7 +5111,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetSUCNodeIdRequest(this.driver, { + new SetSUCNodeIdRequest({ ownNodeId: this.ownNodeId!, sucNodeId: nodeId, enableSUC, @@ -5175,7 +5175,7 @@ export class ZWaveController ?.disableCallbackFunctionTypeCheck ?.includes(FunctionType.AssignSUCReturnRoute); const result = await this.driver.sendMessage( - new AssignSUCReturnRouteRequest(this.driver, { + new AssignSUCReturnRouteRequest({ nodeId, disableCallbackFunctionTypeCheck, }), @@ -5289,7 +5289,7 @@ export class ZWaveController // We are always listening const targetWakeup = false; - const cc = new ZWaveProtocolCCAssignSUCReturnRoute(this.driver, { + const cc = new ZWaveProtocolCCAssignSUCReturnRoute({ nodeId, // Empty routes are marked with a nodeId of 0 destinationNodeId: isEmpty ? 0 : this.ownNodeId ?? 1, @@ -5317,14 +5317,11 @@ export class ZWaveController // If a priority route was passed, tell the node to use it if (priorityRouteIndex >= 0) { - const cc = new ZWaveProtocolCCAssignSUCReturnRoutePriority( - this.driver, - { - nodeId, - targetNodeId: this.ownNodeId ?? 1, - routeNumber: priorityRouteIndex, - }, - ); + const cc = new ZWaveProtocolCCAssignSUCReturnRoutePriority({ + nodeId, + targetNodeId: this.ownNodeId ?? 1, + routeNumber: priorityRouteIndex, + }); try { await this.driver.sendZWaveProtocolCC(cc); } catch { @@ -5383,7 +5380,7 @@ export class ZWaveController ?.disableCallbackFunctionTypeCheck ?.includes(FunctionType.DeleteSUCReturnRoute); const result = await this.driver.sendMessage( - new DeleteSUCReturnRouteRequest(this.driver, { + new DeleteSUCReturnRouteRequest({ nodeId, disableCallbackFunctionTypeCheck, }), @@ -5496,7 +5493,7 @@ export class ZWaveController const result = await this.driver.sendMessage< AssignReturnRouteRequestTransmitReport >( - new AssignReturnRouteRequest(this.driver, { + new AssignReturnRouteRequest({ nodeId, destinationNodeId, }), @@ -5602,7 +5599,7 @@ export class ZWaveController ? this.nodes.get(destinationNodeId)?.isFrequentListening : undefined; - const cc = new ZWaveProtocolCCAssignReturnRoute(this.driver, { + const cc = new ZWaveProtocolCCAssignReturnRoute({ nodeId, // Empty routes are marked with a nodeId of 0 destinationNodeId: isEmpty ? 0 : destinationNodeId, @@ -5630,14 +5627,11 @@ export class ZWaveController // If a priority route was passed, tell the node to use it if (priorityRouteIndex >= 0) { - const cc = new ZWaveProtocolCCAssignReturnRoutePriority( - this.driver, - { - nodeId, - targetNodeId: destinationNodeId, - routeNumber: priorityRouteIndex, - }, - ); + const cc = new ZWaveProtocolCCAssignReturnRoutePriority({ + nodeId, + targetNodeId: destinationNodeId, + routeNumber: priorityRouteIndex, + }); try { await this.driver.sendZWaveProtocolCC(cc); } catch { @@ -5709,7 +5703,7 @@ export class ZWaveController const result = await this.driver.sendMessage< DeleteReturnRouteRequestTransmitReport >( - new DeleteReturnRouteRequest(this.driver, { + new DeleteReturnRouteRequest({ nodeId, }), ); @@ -5765,7 +5759,7 @@ export class ZWaveController const result = await this.driver.sendMessage< AssignReturnRouteRequestTransmitReport >( - new AssignPriorityReturnRouteRequest(this.driver, { + new AssignPriorityReturnRouteRequest({ nodeId, destinationNodeId, repeaters, @@ -5882,7 +5876,7 @@ export class ZWaveController const result = await this.driver.sendMessage< AssignPrioritySUCReturnRouteRequestTransmitReport >( - new AssignPrioritySUCReturnRouteRequest(this.driver, { + new AssignPrioritySUCReturnRouteRequest({ nodeId, repeaters, routeSpeed, @@ -5987,7 +5981,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetPriorityRouteRequest(this.driver, { + new SetPriorityRouteRequest({ destinationNodeId, repeaters, routeSpeed, @@ -6024,7 +6018,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetPriorityRouteRequest(this.driver, { + new SetPriorityRouteRequest({ destinationNodeId, // no repeaters = remove }), @@ -6066,7 +6060,7 @@ export class ZWaveController const result = await this.driver.sendMessage< GetPriorityRouteResponse >( - new GetPriorityRouteRequest(this.driver, { + new GetPriorityRouteRequest({ destinationNodeId, }), ); @@ -6318,7 +6312,7 @@ export class ZWaveController */ public async isFailedNode(nodeId: number): Promise { const result = await this.driver.sendMessage( - new IsFailedNodeRequest(this.driver, { failedNodeId: nodeId }), + new IsFailedNodeRequest({ failedNodeId: nodeId }), ); return result.result; } @@ -6363,7 +6357,7 @@ export class ZWaveController const result = await this.driver.sendMessage< RemoveFailedNodeRequestStatusReport | RemoveFailedNodeResponse - >(new RemoveFailedNodeRequest(this.driver, { failedNodeId: nodeId })); + >(new RemoveFailedNodeRequest({ failedNodeId: nodeId })); if (result instanceof RemoveFailedNodeResponse) { // This implicates that the process was unsuccessful. @@ -6472,7 +6466,7 @@ export class ZWaveController this._inclusionOptions = options; const result = await this.driver.sendMessage( - new ReplaceFailedNodeRequest(this.driver, { + new ReplaceFailedNodeRequest({ failedNodeId: nodeId, }), ); @@ -6545,7 +6539,7 @@ export class ZWaveController const result = await this.driver.sendMessage< | SerialAPISetup_SetRFRegionResponse | SerialAPISetup_CommandUnsupportedResponse - >(new SerialAPISetup_SetRFRegionRequest(this.driver, { region })); + >(new SerialAPISetup_SetRFRegionRequest({ region })); if (result instanceof SerialAPISetup_CommandUnsupportedResponse) { throw new ZWaveError( `Your hardware does not support setting the RF region!`, @@ -6563,7 +6557,7 @@ export class ZWaveController const result = await this.driver.sendMessage< | SerialAPISetup_GetRFRegionResponse | SerialAPISetup_CommandUnsupportedResponse - >(new SerialAPISetup_GetRFRegionRequest(this.driver)); + >(new SerialAPISetup_GetRFRegionRequest()); if (result instanceof SerialAPISetup_CommandUnsupportedResponse) { throw new ZWaveError( `Your hardware does not support getting the RF region!`, @@ -6583,7 +6577,7 @@ export class ZWaveController const result = await this.driver.sendMessage< | SerialAPISetup_GetSupportedRegionsResponse | SerialAPISetup_CommandUnsupportedResponse - >(new SerialAPISetup_GetSupportedRegionsRequest(this.driver)); + >(new SerialAPISetup_GetSupportedRegionsRequest()); if (result instanceof SerialAPISetup_CommandUnsupportedResponse) { throw new ZWaveError( `Your hardware does not support getting the supported RF regions!`, @@ -6609,7 +6603,7 @@ export class ZWaveController const result = await this.driver.sendMessage< | SerialAPISetup_GetRegionInfoResponse | SerialAPISetup_CommandUnsupportedResponse - >(new SerialAPISetup_GetRegionInfoRequest(this.driver, { region })); + >(new SerialAPISetup_GetRegionInfoRequest({ region })); if (result instanceof SerialAPISetup_CommandUnsupportedResponse) { throw new ZWaveError( `Your hardware does not support getting the RF region info!`, @@ -6699,15 +6693,12 @@ export class ZWaveController SerialAPISetupCommand.SetPowerlevel16Bit, ) ) { - request = new SerialAPISetup_SetPowerlevel16BitRequest( - this.driver, - { - powerlevel, - measured0dBm, - }, - ); + request = new SerialAPISetup_SetPowerlevel16BitRequest({ + powerlevel, + measured0dBm, + }); } else { - request = new SerialAPISetup_SetPowerlevelRequest(this.driver, { + request = new SerialAPISetup_SetPowerlevelRequest({ powerlevel, measured0dBm, }); @@ -6741,9 +6732,9 @@ export class ZWaveController SerialAPISetupCommand.GetPowerlevel16Bit, ) ) { - request = new SerialAPISetup_GetPowerlevel16BitRequest(this.driver); + request = new SerialAPISetup_GetPowerlevel16BitRequest(); } else { - request = new SerialAPISetup_GetPowerlevelRequest(this.driver); + request = new SerialAPISetup_GetPowerlevelRequest(); } const result = await this.driver.sendMessage< | SerialAPISetup_GetPowerlevelResponse @@ -6764,10 +6755,9 @@ export class ZWaveController public async setMaxLongRangePowerlevel( limit: number, ): Promise { - const request = new SerialAPISetup_SetLongRangeMaximumTxPowerRequest( - this.driver, - { limit }, - ); + const request = new SerialAPISetup_SetLongRangeMaximumTxPowerRequest({ + limit, + }); const result = await this.driver.sendMessage< | SerialAPISetup_SetLongRangeMaximumTxPowerResponse @@ -6789,9 +6779,7 @@ export class ZWaveController /** Request the maximum TX powerlevel setting for Z-Wave Long Range */ public async getMaxLongRangePowerlevel(): Promise { - const request = new SerialAPISetup_GetLongRangeMaximumTxPowerRequest( - this.driver, - ); + const request = new SerialAPISetup_GetLongRangeMaximumTxPowerRequest(); const result = await this.driver.sendMessage< | SerialAPISetup_GetLongRangeMaximumTxPowerResponse | SerialAPISetup_CommandUnsupportedResponse @@ -6830,10 +6818,7 @@ export class ZWaveController const result = await this.driver.sendMessage< SetLongRangeChannelResponse >( - new SetLongRangeChannelRequest( - this.driver, - { channel }, - ), + new SetLongRangeChannelRequest({ channel }), ); if (result.success) { @@ -6849,7 +6834,7 @@ export class ZWaveController const result = await this.driver.sendMessage< GetLongRangeChannelResponse >( - new GetLongRangeChannelRequest(this.driver), + new GetLongRangeChannelRequest(), ); const channel = result.autoChannelSelectionActive @@ -6882,7 +6867,7 @@ export class ZWaveController | SerialAPISetup_SetNodeIDTypeResponse | SerialAPISetup_CommandUnsupportedResponse >( - new SerialAPISetup_SetNodeIDTypeRequest(this.driver, { + new SerialAPISetup_SetNodeIDTypeRequest({ nodeIdType, }), ); @@ -6928,7 +6913,7 @@ export class ZWaveController const result = await this.driver.sendMessage< | SerialAPISetup_GetMaximumPayloadSizeResponse | SerialAPISetup_CommandUnsupportedResponse - >(new SerialAPISetup_GetMaximumPayloadSizeRequest(this.driver), { + >(new SerialAPISetup_GetMaximumPayloadSizeRequest(), { supportCheck: false, }); if (result instanceof SerialAPISetup_CommandUnsupportedResponse) { @@ -6949,9 +6934,7 @@ export class ZWaveController | SerialAPISetup_GetLongRangeMaximumPayloadSizeResponse | SerialAPISetup_CommandUnsupportedResponse >( - new SerialAPISetup_GetLongRangeMaximumPayloadSizeRequest( - this.driver, - ), + new SerialAPISetup_GetLongRangeMaximumPayloadSizeRequest(), ); if (result instanceof SerialAPISetup_CommandUnsupportedResponse) { throw new ZWaveError( @@ -6994,7 +6977,7 @@ export class ZWaveController const resp = await this.driver.sendMessage< RequestNodeNeighborUpdateReport >( - new RequestNodeNeighborUpdateRequest(this.driver, { + new RequestNodeNeighborUpdateRequest({ nodeId, discoveryTimeout, }), @@ -7033,7 +7016,7 @@ export class ZWaveController }); try { const resp = await this.driver.sendMessage( - new GetRoutingInfoRequest(this.driver, { + new GetRoutingInfoRequest({ nodeId, removeBadLinks: false, removeNonRepeaters: onlyRepeaters, @@ -7082,7 +7065,7 @@ export class ZWaveController const initData = await this.driver.sendMessage< GetSerialApiInitDataResponse >( - new GetSerialApiInitDataRequest(this.driver), + new GetSerialApiInitDataRequest(), ); this.driver.controllerLog.print( @@ -7138,7 +7121,7 @@ export class ZWaveController const result = await this.driver.sendMessage< GetControllerCapabilitiesResponse >( - new GetControllerCapabilitiesRequest(this.driver), + new GetControllerCapabilitiesRequest(), { supportCheck: false }, ); @@ -7200,7 +7183,7 @@ export class ZWaveController `Turning RF ${enabled ? "on" : "off"}...`, ); const ret = await this.driver.sendMessage( - new SetRFReceiveModeRequest(this.driver, { enabled }), + new SetRFReceiveModeRequest({ enabled }), ); return ret.isOK(); } catch (e) { @@ -7243,7 +7226,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< FirmwareUpdateNVM_InitResponse >( - new FirmwareUpdateNVM_InitRequest(this.driver), + new FirmwareUpdateNVM_InitRequest(), ); return ret.supported; } @@ -7257,7 +7240,7 @@ export class ZWaveController value: boolean = true, ): Promise { await this.driver.sendMessage( - new FirmwareUpdateNVM_SetNewImageRequest(this.driver, { + new FirmwareUpdateNVM_SetNewImageRequest({ newImage: value, }), ); @@ -7272,7 +7255,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< FirmwareUpdateNVM_GetNewImageResponse >( - new FirmwareUpdateNVM_GetNewImageRequest(this.driver), + new FirmwareUpdateNVM_GetNewImageRequest(), ); return ret.newImage; } @@ -7290,7 +7273,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< FirmwareUpdateNVM_UpdateCRC16Response >( - new FirmwareUpdateNVM_UpdateCRC16Request(this.driver, { + new FirmwareUpdateNVM_UpdateCRC16Request({ offset, blockLength, crcSeed, @@ -7309,7 +7292,7 @@ export class ZWaveController buffer: Buffer, ): Promise { await this.driver.sendMessage( - new FirmwareUpdateNVM_WriteRequest(this.driver, { + new FirmwareUpdateNVM_WriteRequest({ offset, buffer, }), @@ -7325,7 +7308,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< FirmwareUpdateNVM_IsValidCRC16Response >( - new FirmwareUpdateNVM_IsValidCRC16Request(this.driver), + new FirmwareUpdateNVM_IsValidCRC16Request(), ); return ret.isValid; } @@ -7337,7 +7320,7 @@ export class ZWaveController */ public async getNVMId(): Promise { const ret = await this.driver.sendMessage( - new GetNVMIdRequest(this.driver), + new GetNVMIdRequest(), ); return pick(ret, ["nvmManufacturerId", "memoryType", "memorySize"]); } @@ -7349,7 +7332,7 @@ export class ZWaveController */ public async externalNVMReadByte(offset: number): Promise { const ret = await this.driver.sendMessage( - new ExtNVMReadLongByteRequest(this.driver, { offset }), + new ExtNVMReadLongByteRequest({ offset }), ); return ret.byte; } @@ -7368,7 +7351,7 @@ export class ZWaveController data: number, ): Promise { const ret = await this.driver.sendMessage( - new ExtNVMWriteLongByteRequest(this.driver, { offset, byte: data }), + new ExtNVMWriteLongByteRequest({ offset, byte: data }), ); return ret.success; } @@ -7383,7 +7366,7 @@ export class ZWaveController length: number, ): Promise { const ret = await this.driver.sendMessage( - new ExtNVMReadLongBufferRequest(this.driver, { + new ExtNVMReadLongBufferRequest({ offset, length, }), @@ -7403,7 +7386,7 @@ export class ZWaveController length: number, ): Promise<{ buffer: Buffer; endOfFile: boolean }> { const ret = await this.driver.sendMessage( - new NVMOperationsReadRequest(this.driver, { + new NVMOperationsReadRequest({ offset, length, }), @@ -7443,7 +7426,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< ExtendedNVMOperationsResponse >( - new ExtendedNVMOperationsReadRequest(this.driver, { + new ExtendedNVMOperationsReadRequest({ offset, length, }), @@ -7489,7 +7472,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< ExtNVMWriteLongBufferResponse >( - new ExtNVMWriteLongBufferRequest(this.driver, { + new ExtNVMWriteLongBufferRequest({ offset, buffer, }), @@ -7512,7 +7495,7 @@ export class ZWaveController buffer: Buffer, ): Promise<{ endOfFile: boolean }> { const ret = await this.driver.sendMessage( - new NVMOperationsWriteRequest(this.driver, { + new NVMOperationsWriteRequest({ offset, buffer, }), @@ -7555,7 +7538,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< ExtendedNVMOperationsResponse >( - new ExtendedNVMOperationsWriteRequest(this.driver, { + new ExtendedNVMOperationsWriteRequest({ offset, buffer, }), @@ -7599,7 +7582,7 @@ export class ZWaveController */ public async externalNVMOpen(): Promise { const ret = await this.driver.sendMessage( - new NVMOperationsOpenRequest(this.driver), + new NVMOperationsOpenRequest(), ); if (!ret.isOK()) { throw new ZWaveError( @@ -7624,7 +7607,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< ExtendedNVMOperationsResponse >( - new ExtendedNVMOperationsOpenRequest(this.driver), + new ExtendedNVMOperationsOpenRequest(), ); if (!ret.isOK()) { throw new ZWaveError( @@ -7652,7 +7635,7 @@ export class ZWaveController */ public async externalNVMClose(): Promise { const ret = await this.driver.sendMessage( - new NVMOperationsCloseRequest(this.driver), + new NVMOperationsCloseRequest(), ); if (!ret.isOK()) { throw new ZWaveError( @@ -7673,7 +7656,7 @@ export class ZWaveController const ret = await this.driver.sendMessage< ExtendedNVMOperationsResponse >( - new ExtendedNVMOperationsCloseRequest(this.driver), + new ExtendedNVMOperationsCloseRequest(), ); if (!ret.isOK()) { throw new ZWaveError( @@ -8107,7 +8090,7 @@ export class ZWaveController rssiChannel3?: RSSI; }> { const ret = await this.driver.sendMessage( - new GetBackgroundRSSIRequest(this.driver), + new GetBackgroundRSSIRequest(), ); const rssi = pick(ret, [ "rssiChannel0", @@ -8827,7 +8810,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetLearnModeRequest(this.driver, { + new SetLearnModeRequest({ intent: LearnModeIntent.Inclusion, }), ); @@ -8861,7 +8844,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetLearnModeRequest(this.driver, { + new SetLearnModeRequest({ // TODO: We should be using .Stop here for the non-legacy // inclusion/exclusion, but that command results in a // negative response on current firmwares, even though it works. @@ -8897,7 +8880,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetLearnModeRequest(this.driver, { + new SetLearnModeRequest({ intent: LearnModeIntent.NetworkWideExclusion, }), ); @@ -8933,7 +8916,7 @@ export class ZWaveController const result = await this.driver.sendMessage< Message & SuccessIndicator >( - new SetLearnModeRequest(this.driver, { + new SetLearnModeRequest({ // TODO: We should be using .Stop here for the non-legacy // inclusion/exclusion, but that command results in a // negative response on current firmwares, even though it works. diff --git a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts index 5fea5577cd17..81c42e810498 100644 --- a/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts +++ b/packages/zwave-js/src/lib/controller/MockControllerBehaviors.ts @@ -13,7 +13,6 @@ import { ZWaveErrorCodes, isZWaveError, } from "@zwave-js/core"; -import { type ZWaveHost } from "@zwave-js/host"; import { MessageOrigin } from "@zwave-js/serial"; import { MOCK_FRAME_ACK_TIMEOUT, @@ -86,14 +85,13 @@ import { import { determineNIF } from "./NodeInformationFrame"; function createLazySendDataPayload( - host: ZWaveHost, controller: MockController, node: MockNode, msg: SendDataRequest | SendDataMulticastRequest, ): () => CommandClass { return () => { try { - const cmd = CommandClass.from(node.host, { + const cmd = CommandClass.from({ nodeId: controller.ownNodeId, data: msg.payload, origin: MessageOrigin.Host, @@ -113,7 +111,7 @@ function createLazySendDataPayload( if (e.code === ZWaveErrorCodes.CC_NotImplemented) { // The whole CC is not implemented yet. If this happens in tests, it is because we sent a raw CC. try { - const cmd = new CommandClass(host, { + const cmd = new CommandClass({ nodeId: controller.ownNodeId, ccId: msg.payload[0], ccCommand: msg.payload[1], @@ -143,9 +141,9 @@ function createLazySendDataPayload( } const respondToGetControllerId: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetControllerIdRequest) { - const ret = new GetControllerIdResponse(host, { + const ret = new GetControllerIdResponse({ homeId: controller.homeId, ownNodeId: controller.ownNodeId, }); @@ -156,9 +154,9 @@ const respondToGetControllerId: MockControllerBehavior = { }; const respondToGetSerialApiCapabilities: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetSerialApiCapabilitiesRequest) { - const ret = new GetSerialApiCapabilitiesResponse(host, { + const ret = new GetSerialApiCapabilitiesResponse({ ...controller.capabilities, }); await controller.sendMessageToHost(ret); @@ -168,9 +166,9 @@ const respondToGetSerialApiCapabilities: MockControllerBehavior = { }; const respondToGetControllerVersion: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetControllerVersionRequest) { - const ret = new GetControllerVersionResponse(host, { + const ret = new GetControllerVersionResponse({ ...controller.capabilities, }); await controller.sendMessageToHost(ret); @@ -180,9 +178,9 @@ const respondToGetControllerVersion: MockControllerBehavior = { }; const respondToGetControllerCapabilities: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetControllerCapabilitiesRequest) { - const ret = new GetControllerCapabilitiesResponse(host, { + const ret = new GetControllerCapabilitiesResponse({ ...controller.capabilities, }); await controller.sendMessageToHost(ret); @@ -192,12 +190,12 @@ const respondToGetControllerCapabilities: MockControllerBehavior = { }; const respondToGetSUCNodeId: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetSUCNodeIdRequest) { const sucNodeId = controller.capabilities.isStaticUpdateController ? controller.ownNodeId : controller.capabilities.sucNodeId; - const ret = new GetSUCNodeIdResponse(host, { + const ret = new GetSUCNodeIdResponse({ sucNodeId, }); await controller.sendMessageToHost(ret); @@ -207,12 +205,12 @@ const respondToGetSUCNodeId: MockControllerBehavior = { }; const respondToGetSerialApiInitData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetSerialApiInitDataRequest) { const nodeIds = new Set(controller.nodes.keys()); nodeIds.add(controller.ownNodeId); - const ret = new GetSerialApiInitDataResponse(host, { + const ret = new GetSerialApiInitDataResponse({ zwaveApiVersion: controller.capabilities.zwaveApiVersion, isPrimary: !controller.capabilities.isSecondary, nodeType: NodeType.Controller, @@ -229,9 +227,9 @@ const respondToGetSerialApiInitData: MockControllerBehavior = { }; const respondToSoftReset: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { if (msg instanceof SoftResetRequest) { - const ret = new SerialAPIStartedRequest(host, { + const ret = new SerialAPIStartedRequest({ wakeUpReason: SerialAPIWakeUpReason.SoftwareReset, watchdogEnabled: controller.capabilities.watchdogEnabled, isListening: true, @@ -247,10 +245,10 @@ const respondToSoftReset: MockControllerBehavior = { }; const respondToGetNodeProtocolInfo: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof GetNodeProtocolInfoRequest) { if (msg.requestedNodeId === controller.ownNodeId) { - const ret = new GetNodeProtocolInfoResponse(host, { + const ret = new GetNodeProtocolInfoResponse({ ...determineNIF(), nodeType: NodeType.Controller, isListening: true, @@ -268,7 +266,7 @@ const respondToGetNodeProtocolInfo: MockControllerBehavior = { const nodeCaps = controller.nodes.get( msg.requestedNodeId, )!.capabilities; - const ret = new GetNodeProtocolInfoResponse(host, { + const ret = new GetNodeProtocolInfoResponse({ ...nodeCaps, }); await controller.sendMessageToHost(ret); @@ -279,7 +277,7 @@ const respondToGetNodeProtocolInfo: MockControllerBehavior = { }; const handleSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof SendDataRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -299,7 +297,7 @@ const handleSendData: MockControllerBehavior = { ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -310,7 +308,6 @@ const handleSendData: MockControllerBehavior = { const node = controller.nodes.get(msg.getNodeId()!)!; // Create a lazy frame, so it can be deserialized on the node after a short delay to simulate radio transmission const lazyPayload = createLazySendDataPayload( - host, controller, node, msg, @@ -350,7 +347,7 @@ const handleSendData: MockControllerBehavior = { MockControllerCommunicationState.Idle, ); - const cb = new SendDataRequestTransmitReport(host, { + const cb = new SendDataRequestTransmitReport({ callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK @@ -371,7 +368,7 @@ const handleSendData: MockControllerBehavior = { }; const handleSendDataMulticast: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof SendDataMulticastRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -393,7 +390,7 @@ const handleSendDataMulticast: MockControllerBehavior = { ); // Notify the host that the message was sent - const res = new SendDataMulticastResponse(host, { + const res = new SendDataMulticastResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -407,7 +404,6 @@ const handleSendDataMulticast: MockControllerBehavior = { const node = controller.nodes.get(nodeId)!; // Create a lazy frame, so it can be deserialized on the node after a short delay to simulate radio transmission const lazyPayload = createLazySendDataPayload( - host, controller, node, msg, @@ -449,7 +445,7 @@ const handleSendDataMulticast: MockControllerBehavior = { MockControllerCommunicationState.Idle, ); - const cb = new SendDataMulticastRequestTransmitReport(host, { + const cb = new SendDataMulticastRequestTransmitReport({ callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK @@ -470,7 +466,7 @@ const handleSendDataMulticast: MockControllerBehavior = { }; const handleRequestNodeInfo: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof RequestNodeInfoRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -493,10 +489,9 @@ const handleRequestNodeInfo: MockControllerBehavior = { // Send the data to the node const node = controller.nodes.get(msg.getNodeId()!)!; - const command = new ZWaveProtocolCCRequestNodeInformationFrame( - node.host, - { nodeId: controller.ownNodeId }, - ); + const command = new ZWaveProtocolCCRequestNodeInformationFrame({ + nodeId: controller.ownNodeId, + }); const frame = createMockZWaveRequestFrame(command, { ackRequested: false, }); @@ -508,7 +503,7 @@ const handleRequestNodeInfo: MockControllerBehavior = { ); // Notify the host that the message was sent - const res = new RequestNodeInfoResponse(host, { + const res = new RequestNodeInfoResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -523,14 +518,14 @@ const handleRequestNodeInfo: MockControllerBehavior = { let cb: ApplicationUpdateRequest; try { const nodeInfo = await nodeInfoPromise; - cb = new ApplicationUpdateRequestNodeInfoReceived(host, { + cb = new ApplicationUpdateRequestNodeInfoReceived({ nodeInformation: { ...nodeInfo, nodeId: nodeInfo.nodeId as number, }, }); } catch { - cb = new ApplicationUpdateRequestNodeInfoRequestFailed(host); + cb = new ApplicationUpdateRequestNodeInfoRequestFailed(); } controller.state.set( MockControllerStateKeys.CommunicationState, @@ -544,7 +539,7 @@ const handleRequestNodeInfo: MockControllerBehavior = { }; const handleAssignSUCReturnRoute: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof AssignSUCReturnRouteRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -569,7 +564,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { // Send the command to the node const node = controller.nodes.get(msg.getNodeId()!)!; - const command = new ZWaveProtocolCCAssignSUCReturnRoute(host, { + const command = new ZWaveProtocolCCAssignSUCReturnRoute({ nodeId: node.id, destinationNodeId: controller.ownNodeId, repeaters: [], // don't care @@ -583,7 +578,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { const ackPromise = controller.sendToNode(node, frame); // Notify the host that the message was sent - const res = new AssignSUCReturnRouteResponse(host, { + const res = new AssignSUCReturnRouteResponse({ wasExecuted: true, }); await controller.sendMessageToHost(res); @@ -610,7 +605,7 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { ); if (expectCallback) { - const cb = new AssignSUCReturnRouteRequestTransmitReport(host, { + const cb = new AssignSUCReturnRouteRequestTransmitReport({ callbackId: msg.callbackId!, transmitStatus: ack ? TransmitStatus.OK @@ -625,14 +620,14 @@ const handleAssignSUCReturnRoute: MockControllerBehavior = { }; const forwardCommandClassesToHost: MockControllerBehavior = { - async onNodeFrame(host, controller, node, frame) { + async onNodeFrame(controller, node, frame) { if ( frame.type === MockZWaveFrameType.Request && frame.payload instanceof CommandClass && !(frame.payload instanceof ZWaveProtocolCC) ) { // This is a CC that is meant for the host application - const msg = new ApplicationCommandRequest(host, { + const msg = new ApplicationCommandRequest({ command: frame.payload, }); // Nodes send commands TO the controller, so we need to fix the node ID before forwarding @@ -645,20 +640,17 @@ const forwardCommandClassesToHost: MockControllerBehavior = { }; const forwardUnsolicitedNIF: MockControllerBehavior = { - async onNodeFrame(host, controller, node, frame) { + async onNodeFrame(controller, node, frame) { if ( frame.type === MockZWaveFrameType.Request && frame.payload instanceof ZWaveProtocolCCNodeInformationFrame ) { - const updateRequest = new ApplicationUpdateRequestNodeInfoReceived( - host, - { - nodeInformation: { - ...frame.payload, - nodeId: frame.payload.nodeId as number, - }, + const updateRequest = new ApplicationUpdateRequestNodeInfoReceived({ + nodeInformation: { + ...frame.payload, + nodeId: frame.payload.nodeId as number, }, - ); + }); // Simulate a serialized frame being transmitted via radio before receiving it await controller.sendMessageToHost( updateRequest, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index e5c929167040..1477004adc88 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -3007,7 +3007,7 @@ export class Driver extends TypedEventEmitter try { this.isSoftResetting = true; - await this.sendMessage(new SoftResetRequest(this), { + await this.sendMessage(new SoftResetRequest(), { supportCheck: false, pauseSendThread: true, }); @@ -3067,7 +3067,7 @@ export class Driver extends TypedEventEmitter try { this.isSoftResetting = true; - await this.sendMessage(new SoftResetRequest(this), { + await this.sendMessage(new SoftResetRequest(), { supportCheck: false, pauseSendThread: true, }); @@ -3159,7 +3159,7 @@ export class Driver extends TypedEventEmitter try { // And resume sending - this requires us to unpause the send thread this.unpauseSendQueue(); - await this.sendMessage(new GetControllerVersionRequest(this), { + await this.sendMessage(new GetControllerVersionRequest(), { supportCheck: false, priority: MessagePriority.ControllerImmediate, }); @@ -3468,7 +3468,7 @@ export class Driver extends TypedEventEmitter try { // Parse the message while remembering potential decoding errors in embedded CCs // This way we can log the invalid CC contents - msg = Message.from(this, { + msg = Message.from({ data, sdkVersion: this._controller?.sdkVersion, ctx: this.getCCParsingContext(), @@ -4526,7 +4526,7 @@ export class Driver extends TypedEventEmitter level: "debug", direction: "outbound", }); - const cc = new TransportServiceCCSegmentRequest(this, { + const cc = new TransportServiceCCSegmentRequest({ nodeId: command.nodeId, sessionId: command.sessionId, datagramOffset: offset, @@ -4543,7 +4543,7 @@ export class Driver extends TypedEventEmitter level: "debug", direction: "outbound", }); - const cc = new TransportServiceCCSegmentComplete(this, { + const cc = new TransportServiceCCSegmentComplete({ nodeId: command.nodeId, sessionId: command.sessionId, }); @@ -4591,7 +4591,7 @@ export class Driver extends TypedEventEmitter }); } else { // This belongs to a session we don't know... tell the sending node to try again - const cc = new TransportServiceCCSegmentWait(this, { + const cc = new TransportServiceCCSegmentWait({ nodeId: command.nodeId, pendingSegments: 0, }); @@ -5240,7 +5240,6 @@ ${handlers.length} left`, // 3. if (SupervisionCC.requiresEncapsulation(cmd)) { cmd = SupervisionCC.encapsulate( - this, cmd, this.getNextSupervisionSessionId(cmd.nodeId as number), ); @@ -5254,13 +5253,13 @@ ${handlers.length} left`, ); cmd = multiChannelCCVersion === 1 - ? MultiChannelCC.encapsulateV1(this, cmd) - : MultiChannelCC.encapsulate(this, cmd); + ? MultiChannelCC.encapsulateV1(cmd) + : MultiChannelCC.encapsulate(cmd); } // 5. if (CRC16CC.requiresEncapsulation(cmd)) { - cmd = CRC16CC.encapsulate(this, cmd); + cmd = CRC16CC.encapsulate(cmd); } else { // The command must be S2-encapsulated, if ... let maybeS2 = false; @@ -5277,7 +5276,6 @@ ${handlers.length} left`, } if (maybeS2 && Security2CC.requiresEncapsulation(cmd)) { cmd = Security2CC.encapsulate( - this, cmd, this.ownNodeId, this, @@ -5293,7 +5291,6 @@ ${handlers.length} left`, // This check will return false for S2-encapsulated commands if (SecurityCC.requiresEncapsulation(cmd)) { cmd = SecurityCC.encapsulate( - this, this.ownNodeId, this.securityManager!, cmd, @@ -6119,13 +6116,13 @@ ${handlers.length} left`, this.controller.isFunctionSupported(FunctionType.SendDataBridge) ) { // Prioritize Bridge commands when they are supported - msg = new SendDataBridgeRequest(this, { + msg = new SendDataBridgeRequest({ sourceNodeId: this.ownNodeId, command, maxSendAttempts: this._options.attempts.sendData, }); } else { - msg = new SendDataRequest(this, { + msg = new SendDataRequest({ command, maxSendAttempts: this._options.attempts.sendData, }); @@ -6137,13 +6134,13 @@ ${handlers.length} left`, ) ) { // Prioritize Bridge commands when they are supported - msg = new SendDataMulticastBridgeRequest(this, { + msg = new SendDataMulticastBridgeRequest({ sourceNodeId: this.ownNodeId, command, maxSendAttempts: this._options.attempts.sendData, }); } else { - msg = new SendDataMulticastRequest(this, { + msg = new SendDataMulticastRequest({ command, maxSendAttempts: this._options.attempts.sendData, }); @@ -6233,7 +6230,6 @@ ${handlers.length} left`, // Create the encapsulating CC so we have a session ID const sessionId = this.getNextSupervisionSessionId(command.nodeId); command = SupervisionCC.encapsulate( - this, command, sessionId, options.requestStatusUpdates, @@ -6275,8 +6271,15 @@ ${handlers.length} left`, command.encapsulationFlags = options.encapsulationFlags; } - // For S2 multicast, the Security encapsulation flag does not get set automatically by the CC constructor - if (options?.s2MulticastGroupId != undefined) { + // Use security encapsulation for CCs that are only supported securely, and multicast commands + if ( + this.isCCSecure( + command.ccId, + command.nodeId as number, + command.endpointIndex, + ) + || options?.s2MulticastGroupId != undefined + ) { command.toggleEncapsulationFlag(EncapsulationFlags.Security, true); } @@ -6344,7 +6347,7 @@ ${handlers.length} left`, private async abortSendData(): Promise { try { - const abort = new SendDataAbort(this); + const abort = new SendDataAbort(); await this.writeSerial( abort.serialize(this.getCCEncodingContext()), ); @@ -6981,7 +6984,7 @@ ${handlers.length} left`, msg = commandOrMsg; } else { const SendDataConstructor = this.getSendDataSinglecastConstructor(); - msg = new SendDataConstructor(this, { + msg = new SendDataConstructor({ sourceNodeId: this.ownNodeId, command: commandOrMsg, }); @@ -7456,7 +7459,7 @@ ${handlers.length} left`, const result = await this.sendMessage< Message & SuccessIndicator >( - new SendTestFrameRequest(this, { + new SendTestFrameRequest({ testNodeId: nodeId, powerlevel, }), diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index 26c6c3762ad9..15b8ee124bde 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -340,14 +340,14 @@ export const maybeTransportServiceGenerator: MessageGeneratorImplementation = ); let cc: TransportServiceCC; if (segment === 0) { - cc = new TransportServiceCCFirstSegment(driver, { + cc = new TransportServiceCCFirstSegment({ nodeId, sessionId, datagramSize: payload.length, partialDatagram: chunk, }); } else { - cc = new TransportServiceCCSubsequentSegment(driver, { + cc = new TransportServiceCCSubsequentSegment({ nodeId, sessionId, datagramSize: payload.length, @@ -524,7 +524,7 @@ export const secureMessageGeneratorS0: MessageGeneratorImplementation = let nonce: Buffer | undefined = secMan.getFreeNonce(nodeId); if (!nonce) { // No free nonce, request a new one - const cc = new SecurityCCNonceGet(driver, { + const cc = new SecurityCCNonceGet({ nodeId: nodeId, endpoint: msg.command.endpointIndex, }); @@ -603,7 +603,7 @@ export const secureMessageGeneratorS2: MessageGeneratorImplementation = // Request a new nonce // No free nonce, request a new one - const cc = new Security2CCNonceGet(driver, { + const cc = new Security2CCNonceGet({ nodeId: nodeId, ownNodeId: driver.ownNodeId, endpoint: msg.command.endpointIndex, @@ -834,7 +834,7 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = const innerMPANState = secMan.getInnerMPANState(groupId); // This should always be defined, but better not throw unnecessarily here if (innerMPANState) { - const cc = new Security2CCMessageEncapsulation(driver, { + const cc = new Security2CCMessageEncapsulation({ nodeId, ownNodeId: driver.ownNodeId, securityManagers: driver, @@ -896,19 +896,16 @@ export const secureMessageGeneratorS2Multicast: MessageGeneratorImplementation = if (finalSupervisionResult) { // We can return return information about the success of this multicast - so we should // TODO: Not sure if we need to "wrap" the response for something. For now, try faking it - const cc = new SupervisionCCReport(driver, { + const cc = new SupervisionCCReport({ nodeId: NODE_ID_BROADCAST, sessionId: 0, // fake moreUpdatesFollow: false, // fake ...(finalSupervisionResult as any), }); - const ret = new (driver.getSendDataSinglecastConstructor())( - driver, - { - sourceNodeId: driver.ownNodeId, - command: cc, - }, - ); + const ret = new (driver.getSendDataSinglecastConstructor())({ + sourceNodeId: driver.ownNodeId, + command: cc, + }); return ret; } else { return response; diff --git a/packages/zwave-js/src/lib/driver/Transaction.test.ts b/packages/zwave-js/src/lib/driver/Transaction.test.ts index b564e5ad7a8d..fa2081225a7e 100644 --- a/packages/zwave-js/src/lib/driver/Transaction.test.ts +++ b/packages/zwave-js/src/lib/driver/Transaction.test.ts @@ -165,7 +165,7 @@ test("NodeQuery comparisons should prioritize listening nodes", (t) => { const driver = driverMock as any as Driver; const msg = nodeId != undefined ? new SendDataRequest(driver, { - command: new NoOperationCC(driver, { + command: new NoOperationCC({ nodeId, }), }) @@ -274,7 +274,7 @@ test("Messages in the wakeup queue should be preferred over lesser priorities on function createTransaction(nodeId: number, priority: MessagePriority) { const driver = driverMock as any as Driver; const msg = new SendDataRequest(driver, { - command: new NoOperationCC(driver, { nodeId }), + command: new NoOperationCC({ nodeId }), }); const ret = createDummyTransaction(driverMock, { priority, diff --git a/packages/zwave-js/src/lib/node/Endpoint.ts b/packages/zwave-js/src/lib/node/Endpoint.ts index 2e84cff4d0d4..c9a052c7eb25 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.ts @@ -271,7 +271,7 @@ export class Endpoint ZWaveErrorCodes.CC_NotSupported, ); } - return CommandClass.createInstanceUnchecked(this.driver, this, cc); + return CommandClass.createInstanceUnchecked(this, cc); } /** @@ -283,7 +283,7 @@ export class Endpoint ): T | undefined { const ccId = typeof cc === "number" ? cc : getCommandClassStatic(cc); if (this.supportsCC(ccId) || this.controlsCC(ccId)) { - return CommandClass.createInstanceUnchecked(this.driver, this, cc); + return CommandClass.createInstanceUnchecked(this, cc); } } diff --git a/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts b/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts index 42e73826a39b..3639dd80f3f0 100644 --- a/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts +++ b/packages/zwave-js/src/lib/node/MockNodeBehaviors.ts @@ -46,7 +46,7 @@ const respondToRequestNodeInfo: MockNodeBehavior = { receivedCC instanceof ZWaveProtocolCCRequestNodeInformationFrame ) { - const cc = new ZWaveProtocolCCNodeInformationFrame(self.host, { + const cc = new ZWaveProtocolCCNodeInformationFrame({ nodeId: self.id, ...self.capabilities, supportedCCs: [...self.implementedCCs] @@ -85,7 +85,7 @@ const respondToVersionCCCommandClassGet: MockNodeBehavior = { version = 1; } - const cc = new VersionCCCommandClassReport(self.host, { + const cc = new VersionCCCommandClassReport({ nodeId: self.id, endpoint: "index" in endpoint ? endpoint.index : undefined, requestedCC: receivedCC.requestedCC, @@ -99,7 +99,7 @@ const respondToVersionCCCommandClassGet: MockNodeBehavior = { const respondToZWavePlusCCGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof ZWavePlusCCGet) { - const cc = new ZWavePlusCCReport(self.host, { + const cc = new ZWavePlusCCReport({ nodeId: controller.ownNodeId, zwavePlusVersion: 2, nodeType: ZWavePlusNodeType.Node, @@ -123,7 +123,7 @@ const respondToS0ZWavePlusCCGet: MockNodeBehavior = { receivedCC instanceof SecurityCCCommandEncapsulation && receivedCC.encapsulated instanceof ZWavePlusCCGet ) { - let cc: CommandClass = new ZWavePlusCCReport(self.host, { + let cc: CommandClass = new ZWavePlusCCReport({ nodeId: controller.ownNodeId, zwavePlusVersion: 2, nodeType: ZWavePlusNodeType.Node, @@ -136,7 +136,6 @@ const respondToS0ZWavePlusCCGet: MockNodeBehavior = { userIcon: 0x0000, }); cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, cc, @@ -152,7 +151,7 @@ const respondToS2ZWavePlusCCGet: MockNodeBehavior = { receivedCC instanceof Security2CCMessageEncapsulation && receivedCC.encapsulated instanceof ZWavePlusCCGet ) { - let cc: CommandClass = new ZWavePlusCCReport(self.host, { + let cc: CommandClass = new ZWavePlusCCReport({ nodeId: controller.ownNodeId, zwavePlusVersion: 2, nodeType: ZWavePlusNodeType.Node, @@ -165,7 +164,6 @@ const respondToS2ZWavePlusCCGet: MockNodeBehavior = { userIcon: 0x0000, }); cc = Security2CC.encapsulate( - self.host, cc, self.id, self.securityManagers, diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index be8f30e2e661..c57a36aa8609 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -1140,7 +1140,7 @@ export class ZWaveNode extends ZWaveNodeMixins nodeId: this.id, }); const resp = await this.driver.sendMessage( - new GetNodeProtocolInfoRequest(this.driver, { + new GetNodeProtocolInfoRequest({ requestedNodeId: this.id, }), ); @@ -1300,7 +1300,7 @@ protocol version: ${this.protocolVersion}`; public async requestNodeInfo(): Promise { const resp = await this.driver.sendMessage< RequestNodeInfoResponse | ApplicationUpdateRequest - >(new RequestNodeInfoRequest(this.driver, { nodeId: this.id })); + >(new RequestNodeInfoRequest({ nodeId: this.id })); if (resp instanceof RequestNodeInfoResponse && !resp.wasSent) { // TODO: handle this in SendThreadMachine throw new ZWaveError( @@ -1393,7 +1393,6 @@ protocol version: ${this.protocolVersion}`; try { if (force) { instance = CommandClass.createInstanceUnchecked( - this.driver, endpoint, cc, )!; @@ -6368,7 +6367,6 @@ ${formatRouteHealthCheckSummary(this.id, otherNode.id, summary)}`, : undefined; const ccInstance = CommandClass.createInstanceUnchecked( - this.driver, this, valueId.commandClass, ); diff --git a/packages/zwave-js/src/lib/node/mixins/40_Values.ts b/packages/zwave-js/src/lib/node/mixins/40_Values.ts index d6737aa484df..0171d8525aca 100644 --- a/packages/zwave-js/src/lib/node/mixins/40_Values.ts +++ b/packages/zwave-js/src/lib/node/mixins/40_Values.ts @@ -139,7 +139,6 @@ export abstract class NodeValuesMixin extends NodeWakeupMixin } const ccInstance = CommandClass.createInstanceUnchecked( - this.driver, this, arg.commandClass, ); diff --git a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts index 4c6745096c76..7a049b6ffd8f 100644 --- a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts +++ b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts @@ -555,9 +555,11 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin // ================================ // STEP 2: // Determine the fragment size - const fcc = new FirmwareUpdateMetaDataCC(this.driver, { - nodeId: this.id, - }); + const fcc = new FirmwareUpdateMetaDataCC({ nodeId: this.id }); + fcc.toggleEncapsulationFlag( + EncapsulationFlags.Security, + this.driver.isCCSecure(fcc.ccId, this.id), + ); const maxGrossPayloadSizeSecure = this.driver .computeNetCCPayloadSize( fcc, @@ -613,9 +615,11 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin }); // Since no update is in progress, we need to determine the fragment size again - const fcc = new FirmwareUpdateMetaDataCC(this.driver, { - nodeId: this.id, - }); + const fcc = new FirmwareUpdateMetaDataCC({ nodeId: this.id }); + fcc.toggleEncapsulationFlag( + EncapsulationFlags.Security, + !!(command.encapsulationFlags & EncapsulationFlags.Security), + ); const ccVersion = getEffectiveCCVersion(this.driver, fcc); const fragmentSize = this.driver.computeNetCCPayloadSize(fcc) - 2 // report number diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts index 0f5ab952e176..4a4dc48c3467 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Basic.ts @@ -15,7 +15,7 @@ const respondToBasicGet: MockNodeBehavior = { return; } - const cc = new BasicCCReport(self.host, { + const cc = new BasicCCReport({ nodeId: controller.ownNodeId, currentValue: (self.state.get(StateKeys.currentValue) ?? 0) as number, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts index 751d08b98a87..9fb8c0d4a1b0 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySensor.ts @@ -23,7 +23,7 @@ const respondToBinarySensorSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new BinarySensorCCSupportedReport(self.host, { + const cc = new BinarySensorCCSupportedReport({ nodeId: controller.ownNodeId, supportedSensorTypes: capabilities.supportedSensorTypes, }); @@ -56,7 +56,7 @@ const respondToBinarySensorGet: MockNodeBehavior = { if (sensorType != undefined) { const value = capabilities.getValue?.(sensorType) ?? false; - const cc = new BinarySensorCCReport(self.host, { + const cc = new BinarySensorCCReport({ nodeId: controller.ownNodeId, type: sensorType, value, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts index a431d87ceab1..49b649f8f937 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/BinarySwitch.ts @@ -32,7 +32,7 @@ const respondToBinarySwitchGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new BinarySwitchCCReport(self.host, { + const cc = new BinarySwitchCCReport({ nodeId: controller.ownNodeId, currentValue: ( self.state.get(StateKeys.currentValue) diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts index 04ab347da8d2..ec0f63565677 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts @@ -35,7 +35,7 @@ const respondToColorSwitchSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new ColorSwitchCCSupportedReport(self.host, { + const cc = new ColorSwitchCCSupportedReport({ nodeId: controller.ownNodeId, supportedColorComponents: Object.keys( capabilities.colorComponents, @@ -74,7 +74,7 @@ const respondToColorSwitchGet: MockNodeBehavior = { }; const component = receivedCC.colorComponent; if (component in capabilities.colorComponents) { - const cc = new ColorSwitchCCReport(self.host, { + const cc = new ColorSwitchCCReport({ nodeId: controller.ownNodeId, colorComponent: component, currentValue: diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts index 4a5f0a2665a1..7eb5ce3ede84 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Configuration.ts @@ -50,7 +50,7 @@ const respondToConfigurationGet: MockNodeBehavior = { ?? paramInfo.defaultValue ?? 0; - const cc = new ConfigurationCCReport(self.host, { + const cc = new ConfigurationCCReport({ nodeId: controller.ownNodeId, parameter, value, @@ -137,7 +137,7 @@ const respondToConfigurationNameGet: MockNodeBehavior = { // Do nothing if the parameter is not supported if (!paramInfo) return { action: "fail" }; - const cc = new ConfigurationCCNameReport(self.host, { + const cc = new ConfigurationCCNameReport({ nodeId: controller.ownNodeId, parameter, name: paramInfo.name ?? "", @@ -165,7 +165,7 @@ const respondToConfigurationInfoGet: MockNodeBehavior = { // Do nothing if the parameter is not supported if (!paramInfo) return { action: "fail" }; - const cc = new ConfigurationCCInfoReport(self.host, { + const cc = new ConfigurationCCInfoReport({ nodeId: controller.ownNodeId, parameter, info: paramInfo.info ?? "", @@ -197,7 +197,7 @@ const respondToConfigurationPropertiesGet: MockNodeBehavior = { // If the parameter is not supported, respond with the first supported parameter if (!paramInfo) { - cc = new ConfigurationCCPropertiesReport(self.host, { + cc = new ConfigurationCCPropertiesReport({ nodeId: controller.ownNodeId, parameter, valueFormat: 0, @@ -205,7 +205,7 @@ const respondToConfigurationPropertiesGet: MockNodeBehavior = { nextParameter: nextParameter?.["#"] ?? 0, }); } else { - cc = new ConfigurationCCPropertiesReport(self.host, { + cc = new ConfigurationCCPropertiesReport({ nodeId: controller.ownNodeId, parameter, valueSize: paramInfo.valueSize, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts index acfc5ad840e5..fcf27572380c 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/EnergyProduction.ts @@ -52,7 +52,7 @@ const respondToEnergyProductionGet: MockNodeBehavior = { ) as unknown as keyof typeof capabilities.values ]; - const cc = new EnergyProductionCCReport(self.host, { + const cc = new EnergyProductionCCReport({ nodeId: controller.ownNodeId, parameter: receivedCC.parameter, value: result?.value ?? 0, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ManufacturerSpecific.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ManufacturerSpecific.ts index 1ca966debef4..ad537d1ceed9 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ManufacturerSpecific.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ManufacturerSpecific.ts @@ -7,7 +7,7 @@ import { type MockNodeBehavior } from "@zwave-js/testing"; const respondToManufacturerSpecificGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof ManufacturerSpecificCCGet) { - const cc = new ManufacturerSpecificCCReport(self.host, { + const cc = new ManufacturerSpecificCCReport({ nodeId: self.id, manufacturerId: self.capabilities.manufacturerId, productType: self.capabilities.productType, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts index 281a2638fb97..81424ce67ff2 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Meter.ts @@ -29,7 +29,7 @@ const respondToMeterSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new MeterCCSupportedReport(self.host, { + const cc = new MeterCCSupportedReport({ nodeId: controller.ownNodeId, type: capabilities.meterType, supportedScales: capabilities.supportedScales, @@ -68,7 +68,7 @@ const respondToMeterGet: MockNodeBehavior = { } : value; - const cc = new MeterCCReport(self.host, { + const cc = new MeterCCReport({ nodeId: controller.ownNodeId, type: capabilities.meterType, scale, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts index fc6132e65fab..f968c22693aa 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultiChannel.ts @@ -44,7 +44,7 @@ const encapsulateMultiChannelCC: MockNodeBehavior = { (multiChannelEncap as MultiChannelCCCommandEncapsulation) .destination as number; - response.cc = new MultiChannelCCCommandEncapsulation(self.host, { + response.cc = new MultiChannelCCCommandEncapsulation({ nodeId: response.cc.nodeId, encapsulated: response.cc, endpoint: source, @@ -59,7 +59,7 @@ const encapsulateMultiChannelCC: MockNodeBehavior = { const respondToMultiChannelCCEndPointGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultiChannelCCEndPointGet) { - const cc = new MultiChannelCCEndPointReport(self.host, { + const cc = new MultiChannelCCEndPointReport({ nodeId: controller.ownNodeId, countIsDynamic: false, identicalCapabilities: false, @@ -74,7 +74,7 @@ const respondToMultiChannelCCEndPointFind: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultiChannelCCEndPointFind) { const request = receivedCC; - const cc = new MultiChannelCCEndPointFindReport(self.host, { + const cc = new MultiChannelCCEndPointFindReport({ nodeId: controller.ownNodeId, genericClass: request.genericClass, specificClass: request.specificClass, @@ -92,7 +92,7 @@ const respondToMultiChannelCCCapabilityGet: MockNodeBehavior = { const endpoint = self.endpoints.get( receivedCC.requestedEndpoint, )!; - const cc = new MultiChannelCCCapabilityReport(self.host, { + const cc = new MultiChannelCCCapabilityReport({ nodeId: controller.ownNodeId, endpointIndex: endpoint.index, genericDeviceClass: endpoint?.capabilities.genericDeviceClass diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts index 8a1157757b13..ab824a4bd05a 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSensor.ts @@ -24,7 +24,7 @@ const respondToMultilevelSensorGetSupportedSensor: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new MultilevelSensorCCSupportedSensorReport(self.host, { + const cc = new MultilevelSensorCCSupportedSensorReport({ nodeId: controller.ownNodeId, supportedSensorTypes: Object.keys( capabilities.sensors, @@ -48,7 +48,7 @@ const respondToMultilevelSensorGetSupportedScale: MockNodeBehavior = { const sensorType = receivedCC.sensorType; const supportedScales = capabilities.sensors[sensorType]?.supportedScales ?? []; - const cc = new MultilevelSensorCCSupportedScaleReport(self.host, { + const cc = new MultilevelSensorCCSupportedScaleReport({ nodeId: controller.ownNodeId, sensorType, supportedScales, @@ -79,7 +79,7 @@ const respondToMultilevelSensorGet: MockNodeBehavior = { ?? capabilities.sensors[sensorType].supportedScales[0] ?? 0; const value = capabilities.getValue?.(sensorType, scale) ?? 0; - const cc = new MultilevelSensorCCReport(self.host, { + const cc = new MultilevelSensorCCReport({ nodeId: controller.ownNodeId, type: sensorType, scale, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts index 075f33238104..83784ebd9b9a 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/MultilevelSwitch.ts @@ -43,7 +43,7 @@ const respondToMultilevelSwitchGet: MockNodeBehavior = { ?? capabilities.defaultValue ?? UNKNOWN_STATE ) as MaybeUnknown; - const cc = new MultilevelSwitchCCReport(self.host, { + const cc = new MultilevelSwitchCCReport({ nodeId: controller.ownNodeId, currentValue, // We don't support transitioning yet @@ -73,7 +73,7 @@ const respondToMultilevelSwitchSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new MultilevelSwitchCCSupportedReport(self.host, { + const cc = new MultilevelSwitchCCSupportedReport({ nodeId: controller.ownNodeId, switchType: capabilities.primarySwitchType, }); diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts index 561697580ea0..bed6319a0433 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/Notification.ts @@ -23,7 +23,7 @@ const respondToNotificationSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new NotificationCCSupportedReport(self.host, { + const cc = new NotificationCCSupportedReport({ nodeId: controller.ownNodeId, supportsV1Alarm: capabilities.supportsV1Alarm, supportedNotificationTypes: Object.keys( @@ -49,7 +49,7 @@ const respondToNotificationEventSupportedGet: MockNodeBehavior = { receivedCC.notificationType in capabilities.notificationTypesAndEvents ) { - const cc = new NotificationCCEventSupportedReport(self.host, { + const cc = new NotificationCCEventSupportedReport({ nodeId: controller.ownNodeId, notificationType: receivedCC.notificationType, supportedEvents: capabilities.notificationTypesAndEvents[ diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts index 8995a3788bea..d539f2a3e2ac 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ScheduleEntryLock.ts @@ -58,7 +58,7 @@ const respondToScheduleEntryLockSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new ScheduleEntryLockCCSupportedReport(self.host, { + const cc = new ScheduleEntryLockCCSupportedReport({ nodeId: controller.ownNodeId, ...capabilities, }); @@ -83,7 +83,7 @@ const respondToScheduleEntryLockTimeOffsetSet: MockNodeBehavior = { const respondToScheduleEntryLockTimeOffsetGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof ScheduleEntryLockCCTimeOffsetGet) { - const cc = new ScheduleEntryLockCCTimeOffsetReport(self.host, { + const cc = new ScheduleEntryLockCCTimeOffsetReport({ nodeId: controller.ownNodeId, standardOffset: (self.state.get(StateKeys.standardOffset) ?? 0) as number, @@ -195,7 +195,7 @@ const respondToScheduleEntryLockWeekDayScheduleGet: MockNodeBehavior = { StateKeys.schedule(userId, slotId, kind), ) ?? {}) as AllOrNone; - const cc = new ScheduleEntryLockCCWeekDayScheduleReport(self.host, { + const cc = new ScheduleEntryLockCCWeekDayScheduleReport({ nodeId: controller.ownNodeId, userId, slotId, @@ -294,7 +294,7 @@ const respondToScheduleEntryLockYearDayScheduleGet: MockNodeBehavior = { StateKeys.schedule(userId, slotId, kind), ) ?? {}) as AllOrNone; - const cc = new ScheduleEntryLockCCYearDayScheduleReport(self.host, { + const cc = new ScheduleEntryLockCCYearDayScheduleReport({ nodeId: controller.ownNodeId, userId, slotId, @@ -394,15 +394,12 @@ const respondToScheduleEntryLockDailyRepeatingScheduleGet: MockNodeBehavior = { StateKeys.schedule(userId, slotId, kind), ) ?? {}) as AllOrNone; - const cc = new ScheduleEntryLockCCDailyRepeatingScheduleReport( - self.host, - { - nodeId: controller.ownNodeId, - userId, - slotId, - ...schedule, - }, - ); + const cc = new ScheduleEntryLockCCDailyRepeatingScheduleReport({ + nodeId: controller.ownNodeId, + userId, + slotId, + ...schedule, + }); return { action: "sendCC", cc }; } }, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts index 1ffce5eef991..876e4e708506 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/SoundSwitch.ts @@ -47,7 +47,7 @@ const respondToSoundSwitchConfigurationGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new SoundSwitchCCConfigurationReport(self.host, { + const cc = new SoundSwitchCCConfigurationReport({ nodeId: controller.ownNodeId, defaultToneId: (self.state.get(StateKeys.defaultToneId) as number) @@ -87,7 +87,7 @@ const respondToSoundSwitchToneNumberGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new SoundSwitchCCTonesNumberReport(self.host, { + const cc = new SoundSwitchCCTonesNumberReport({ nodeId: controller.ownNodeId, toneCount: capabilities.tones.length, }); @@ -108,7 +108,7 @@ const respondToSoundSwitchToneInfoGet: MockNodeBehavior = { }; const tone = capabilities.tones[receivedCC.toneId - 1]; if (tone) { - const cc = new SoundSwitchCCToneInfoReport(self.host, { + const cc = new SoundSwitchCCToneInfoReport({ nodeId: controller.ownNodeId, toneId: receivedCC.toneId, ...tone, @@ -176,14 +176,11 @@ const respondToSoundSwitchTonePlaySet: MockNodeBehavior = { self.state.delete(StateKeys.state); // Tell the controller that we're done playing - const cc = new SoundSwitchCCTonePlayReport( - self.host, - { - nodeId: controller.ownNodeId, - toneId: 0, - volume: 0, - }, - ); + const cc = new SoundSwitchCCTonePlayReport({ + nodeId: controller.ownNodeId, + toneId: 0, + volume: 0, + }); await self.sendToController( createMockZWaveRequestFrame(cc, { ackRequested: false, @@ -207,14 +204,11 @@ const respondToSoundSwitchTonePlayGet: MockNodeBehavior = { StateKeys.state, ) as SoundSwitchState | undefined; - const cc = new SoundSwitchCCTonePlayReport( - self.host, - { - nodeId: controller.ownNodeId, - toneId: currentState?.toneId ?? 0, - volume: currentState?.volume ?? 0, - }, - ); + const cc = new SoundSwitchCCTonePlayReport({ + nodeId: controller.ownNodeId, + toneId: currentState?.toneId ?? 0, + volume: currentState?.volume ?? 0, + }); return { action: "sendCC", cc }; } diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts index bac3e9bfb740..32c9c58e8d89 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatMode.ts @@ -45,7 +45,7 @@ const respondToThermostatModeGet: MockNodeBehavior = { ? self.state.get(StateKeys.manufacturerData) : undefined; - const cc = new ThermostatModeCCReport(self.host, { + const cc = new ThermostatModeCCReport({ nodeId: controller.ownNodeId, mode, // @ts-expect-error I know... @@ -67,7 +67,7 @@ const respondToThermostatModeSupportedGet: MockNodeBehavior = { ), }; - const cc = new ThermostatModeCCSupportedReport(self.host, { + const cc = new ThermostatModeCCSupportedReport({ nodeId: controller.ownNodeId, supportedModes: capabilities.supportedModes, }); diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts index 1831e75f3c4a..794a3e1bab1c 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetback.ts @@ -34,7 +34,7 @@ const respondToThermostatSetbackGet: MockNodeBehavior = { ?? "Unused" ) as SetbackState; - const cc = new ThermostatSetbackCCReport(self.host, { + const cc = new ThermostatSetbackCCReport({ nodeId: controller.ownNodeId, setbackType, setbackState, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts index 36809cef47df..dac9ba334d58 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/ThermostatSetpoint.ts @@ -98,14 +98,14 @@ const respondToThermostatSetpointGet: MockNodeBehavior = { let cc: ThermostatSetpointCCReport; if (value !== undefined) { - cc = new ThermostatSetpointCCReport(self.host, { + cc = new ThermostatSetpointCCReport({ nodeId: controller.ownNodeId, type: setpointType, value, scale: scale ?? 0, }); } else { - cc = new ThermostatSetpointCCReport(self.host, { + cc = new ThermostatSetpointCCReport({ nodeId: controller.ownNodeId, type: ThermostatSetpointType["N/A"], scale: 0, @@ -128,7 +128,7 @@ const respondToThermostatSetpointSupportedGet: MockNodeBehavior = { ), }; - const cc = new ThermostatSetpointCCSupportedReport(self.host, { + const cc = new ThermostatSetpointCCSupportedReport({ nodeId: controller.ownNodeId, supportedSetpointTypes: Object.keys(capabilities.setpoints).map( (k) => parseInt(k), @@ -155,7 +155,7 @@ const respondToThermostatSetpointCapabilitiesGet: MockNodeBehavior = { let cc: ThermostatSetpointCCCapabilitiesReport; if (setpointCaps) { - cc = new ThermostatSetpointCCCapabilitiesReport(self.host, { + cc = new ThermostatSetpointCCCapabilitiesReport({ nodeId: controller.ownNodeId, type: setpointType, minValue: setpointCaps.minValue, @@ -164,7 +164,7 @@ const respondToThermostatSetpointCapabilitiesGet: MockNodeBehavior = { maxValueScale: setpointCaps.scale === "°C" ? 0 : 1, }); } else { - cc = new ThermostatSetpointCCCapabilitiesReport(self.host, { + cc = new ThermostatSetpointCCCapabilitiesReport({ nodeId: controller.ownNodeId, type: ThermostatSetpointType["N/A"], minValue: 0, diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts index f12c9537aec6..c72a8369a610 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/UserCode.ts @@ -55,7 +55,7 @@ const respondToUsersNumberGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new UserCodeCCUsersNumberReport(self.host, { + const cc = new UserCodeCCUsersNumberReport({ nodeId: controller.ownNodeId, supportedUsers: capabilities.numUsers ?? 1, }); @@ -77,7 +77,7 @@ const respondToUserGet: MockNodeBehavior = { const userId = receivedCC.userId; let cc: UserCodeCCReport; if (capabilities.numUsers >= userId) { - cc = new UserCodeCCReport(self.host, { + cc = new UserCodeCCReport({ nodeId: controller.ownNodeId, userId, userIdStatus: (self.state.get( @@ -88,7 +88,7 @@ const respondToUserGet: MockNodeBehavior = { ) as string, }); } else { - cc = new UserCodeCCReport(self.host, { + cc = new UserCodeCCReport({ nodeId: controller.ownNodeId, userId, userIdStatus: UserIDStatus.StatusNotAvailable, @@ -137,7 +137,7 @@ const respondToUserCodeCapabilitiesGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new UserCodeCCCapabilitiesReport(self.host, { + const cc = new UserCodeCCCapabilitiesReport({ nodeId: controller.ownNodeId, supportsAdminCode: capabilities.supportsAdminCode!, supportsAdminCodeDeactivation: capabilities @@ -165,7 +165,7 @@ const respondToUserCodeKeypadModeGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new UserCodeCCKeypadModeReport(self.host, { + const cc = new UserCodeCCKeypadModeReport({ nodeId: controller.ownNodeId, keypadMode: (self.state.get(StateKeys.keypadMode) ?? capabilities.supportedKeypadModes?.[0] @@ -242,7 +242,7 @@ const respondToUserCodeAdminCodeGet: MockNodeBehavior = { adminCode = self.state.get(StateKeys.adminCode) as string; } - const cc = new UserCodeCCAdminCodeReport(self.host, { + const cc = new UserCodeCCAdminCodeReport({ nodeId: controller.ownNodeId, adminCode: adminCode ?? "", }); @@ -289,7 +289,7 @@ const respondToUserCodeUserCodeChecksumGet: MockNodeBehavior = { const checksum = data.length > 0 ? CRC16_CCITT(data) : 0x0000; - const cc = new UserCodeCCUserCodeChecksumReport(self.host, { + const cc = new UserCodeCCUserCodeChecksumReport({ nodeId: controller.ownNodeId, userCodeChecksum: checksum, }); diff --git a/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts b/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts index e58846dc4fff..1ac1647d50ff 100644 --- a/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts +++ b/packages/zwave-js/src/lib/node/mockCCBehaviors/WindowCovering.ts @@ -22,7 +22,7 @@ const respondToWindowCoveringSupportedGet: MockNodeBehavior = { receivedCC.endpointIndex, ), }; - const cc = new WindowCoveringCCSupportedReport(self.host, { + const cc = new WindowCoveringCCSupportedReport({ nodeId: controller.ownNodeId, supportedParameters: capabilities.supportedParameters, }); diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index 6c8e14e56443..dd98b3252e41 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -235,7 +235,6 @@ export function translateValueID( ...valueId, }; const ccInstance = CommandClass.createInstanceUnchecked( - applHost, endpoint, valueId.commandClass, ); @@ -351,7 +350,6 @@ export function getDefinedValueIDsInternal( || cc === CommandClasses.Basic ) { const ccInstance = CommandClass.createInstanceUnchecked( - applHost, endpoint, cc, ); diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts index a958a04ac16f..be1f8c2cf027 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationCommandRequest.ts @@ -10,7 +10,6 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -51,12 +50,11 @@ export class ApplicationCommandRequest extends Message implements ICommandClassContainer { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ApplicationCommandRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // first byte is a status flag const status = this.payload[0]; @@ -92,7 +90,7 @@ export class ApplicationCommandRequest extends Message offset += nodeIdBytes; // and a command class const commandLength = this.payload[offset++]; - this.command = CommandClass.from(this.host, { + this.command = CommandClass.from({ data: this.payload.subarray(offset, offset + commandLength), nodeId, origin: options.origin, diff --git a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts index 7facc83d7aea..11d61cd26831 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ApplicationUpdateRequest.ts @@ -11,7 +11,6 @@ import { parseNodeID, parseNodeUpdatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { type DeserializingMessageConstructor, FunctionType, @@ -55,8 +54,8 @@ const { @messageTypes(MessageType.Request, FunctionType.ApplicationUpdateRequest) // this is only received, not sent! export class ApplicationUpdateRequest extends Message { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); if (gotDeserializationOptions(options)) { this.updateType = this.payload[0]; @@ -68,7 +67,7 @@ export class ApplicationUpdateRequest extends Message { CommandConstructor && (new.target as any) !== CommandConstructor ) { - return new CommandConstructor(host, options); + return new CommandConstructor(options); } this.payload = this.payload.subarray(1); @@ -98,12 +97,11 @@ export class ApplicationUpdateRequestWithNodeInfo extends ApplicationUpdateRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ApplicationUpdateRequestWithNodeInfoOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.nodeInformation = parseNodeUpdatePayload( @@ -154,10 +152,9 @@ export class ApplicationUpdateRequestNodeRemoved extends ApplicationUpdateRequest { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); const { nodeId } = parseNodeID(this.payload, options.ctx.nodeIdType, 0); this.nodeId = nodeId; @@ -171,10 +168,9 @@ class ApplicationUpdateRequestSmartStartHomeIDReceivedBase extends ApplicationUpdateRequest { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, @@ -246,10 +242,9 @@ export class ApplicationUpdateRequestSUCIdChanged extends ApplicationUpdateRequest { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); const { nodeId } = parseNodeID(this.payload, options.ctx.nodeIdType, 0); this.sucNodeID = nodeId; diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts index 2b11230284e6..73baeb18babf 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.ts @@ -13,7 +13,6 @@ import { parseNodeBitMask, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -33,10 +32,9 @@ export class BridgeApplicationCommandRequest extends Message implements ICommandClassContainer { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._ownNodeId = options.ctx.ownNodeId; // if (gotDeserializationOptions(options)) { @@ -74,7 +72,7 @@ export class BridgeApplicationCommandRequest extends Message offset += srcNodeIdBytes; // Parse the CC const commandLength = this.payload[offset++]; - this.command = CommandClass.from(this.host, { + this.command = CommandClass.from({ data: this.payload.subarray(offset, offset + commandLength), nodeId: sourceNodeId, origin: options.origin, diff --git a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts index 028f0782a53a..10adc96cf2be 100644 --- a/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/application/SerialAPIStartedRequest.ts @@ -5,7 +5,6 @@ import { encodeCCList, parseCCList, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -60,10 +59,9 @@ export interface SerialAPIStartedRequestOptions extends MessageBaseOptions { @priority(MessagePriority.Normal) export class SerialAPIStartedRequest extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SerialAPIStartedRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.wakeUpReason = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts b/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts index ee6fd3212a26..e2f58de80106 100644 --- a/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/application/ShutdownMessages.ts @@ -1,5 +1,4 @@ import { type MessageOrCCLogEntry, MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -23,10 +22,9 @@ export class ShutdownRequest extends Message {} @messageTypes(MessageType.Response, FunctionType.Shutdown) export class ShutdownResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts index 15b08a5a3be3..b3cfe7bcdb9a 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerCapabilitiesMessages.ts @@ -1,5 +1,4 @@ import { ControllerCapabilityFlags, MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -32,12 +31,11 @@ export interface GetControllerCapabilitiesResponseOptions @messageTypes(MessageType.Response, FunctionType.GetControllerCapabilities) export class GetControllerCapabilitiesResponse extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetControllerCapabilitiesResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const capabilityFlags = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts index d642a83493e2..78a34fe8aecf 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetControllerVersionMessages.ts @@ -1,5 +1,4 @@ import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -30,12 +29,11 @@ export interface GetControllerVersionResponseOptions @messageTypes(MessageType.Response, FunctionType.GetControllerVersion) export class GetControllerVersionResponse extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetControllerVersionResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // The payload consists of a zero-terminated string and a uint8 for the controller type diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts index f92b098ffc3e..e16ed603837c 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetLongRangeNodesMessages.ts @@ -5,7 +5,6 @@ import { encodeLongRangeNodeBitMask, parseLongRangeNodeBitMask, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -28,12 +27,11 @@ export interface GetLongRangeNodesRequestOptions extends MessageBaseOptions { @priority(MessagePriority.Controller) export class GetLongRangeNodesRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetLongRangeNodesRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.segmentNumber = this.payload[0]; @@ -59,12 +57,11 @@ export interface GetLongRangeNodesResponseOptions extends MessageBaseOptions { @messageTypes(MessageType.Response, FunctionType.GetLongRangeNodes) export class GetLongRangeNodesResponse extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetLongRangeNodesResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.moreNodes = this.payload[0] != 0; diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts index 8bd2d83b8630..dbb5c5a54d3f 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetProtocolVersionMessages.ts @@ -1,6 +1,5 @@ import type { ProtocolType } from "@zwave-js/core"; import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -19,10 +18,9 @@ export class GetProtocolVersionRequest extends Message {} @messageTypes(MessageType.Response, FunctionType.GetProtocolVersion) export class GetProtocolVersionResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.protocolType = this.payload[0]; this.protocolVersion = [ this.payload[1], diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts index 032a2b2ec4dc..7cfca7b6d858 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.ts @@ -1,5 +1,4 @@ import { MessagePriority, encodeBitMask, parseBitMask } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -34,12 +33,11 @@ export interface GetSerialApiCapabilitiesResponseOptions @messageTypes(MessageType.Response, FunctionType.GetSerialApiCapabilities) export class GetSerialApiCapabilitiesResponse extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetSerialApiCapabilitiesResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // The first 8 bytes are the api version, manufacturer id, product type and product id diff --git a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts index 9059e4cdaca2..aa57539c5d26 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/GetSerialApiInitDataMessages.ts @@ -12,7 +12,6 @@ import { getChipTypeAndVersion, getZWaveChipType, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -39,12 +38,11 @@ export interface GetSerialApiInitDataResponseOptions @messageTypes(MessageType.Response, FunctionType.GetSerialApiInitData) export class GetSerialApiInitDataResponse extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetSerialApiInitDataResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const apiVersion = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts index ab84895c044f..cf7e121a4bc0 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/HardResetRequest.ts @@ -1,6 +1,5 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -18,21 +17,21 @@ import { @messageTypes(MessageType.Request, FunctionType.HardReset) @priority(MessagePriority.Controller) export class HardResetRequestBase extends Message { - public constructor(host: ZWaveHost, options?: MessageOptions) { + public constructor(options?: MessageOptions) { if (gotDeserializationOptions(options)) { if ( options.origin === MessageOrigin.Host && (new.target as any) !== HardResetRequest ) { - return new HardResetRequest(host, options); + return new HardResetRequest(options); } else if ( options.origin !== MessageOrigin.Host && (new.target as any) !== HardResetCallback ) { - return new HardResetCallback(host, options); + return new HardResetCallback(options); } } - super(host, options); + super(options); } } @@ -56,10 +55,9 @@ export class HardResetRequest extends HardResetRequestBase { export class HardResetCallback extends HardResetRequestBase { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; } diff --git a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts index d21ba28d63cb..d77d783a9b92 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/LongRangeChannelMessages.ts @@ -5,7 +5,6 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { LongRangeChannel } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -30,10 +29,9 @@ export class GetLongRangeChannelRequest extends Message {} @priority(MessagePriority.Controller) export class GetLongRangeChannelResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.channel = this.payload[0]; if (this.payload.length >= 2) { @@ -63,12 +61,11 @@ export interface SetLongRangeChannelRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.SetLongRangeChannel) export class SetLongRangeChannelRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SetLongRangeChannelRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -101,10 +98,9 @@ export class SetLongRangeChannelResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts index 45cc16b23240..1e048bcc3919 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.ts @@ -10,7 +10,6 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageEncodingContext, @@ -87,8 +86,8 @@ function testResponseForSerialAPISetupRequest( @priority(MessagePriority.Controller) @expectedResponse(testResponseForSerialAPISetupRequest) export class SerialAPISetupRequest extends Message { - public constructor(host: ZWaveHost, options: MessageOptions = {}) { - super(host, options); + public constructor(options: MessageOptions = {}) { + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -127,17 +126,16 @@ export class SerialAPISetupRequest extends Message { @messageTypes(MessageType.Response, FunctionType.SerialAPISetup) export class SerialAPISetupResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.command = this.payload[0]; const CommandConstructor = getSubCommandResponseConstructor( this.command, ); if (CommandConstructor && (new.target as any) !== CommandConstructor) { - return new CommandConstructor(host, options); + return new CommandConstructor(options); } this.payload = this.payload.subarray(1); @@ -164,10 +162,9 @@ export class SerialAPISetup_CommandUnsupportedResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); // The payload contains which command is unsupported this.command = this.payload[0]; } @@ -191,8 +188,8 @@ export class SerialAPISetup_CommandUnsupportedResponse export class SerialAPISetup_GetSupportedCommandsRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetSupportedCommands; } } @@ -202,10 +199,9 @@ export class SerialAPISetup_GetSupportedCommandsResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); if (this.payload.length > 1) { @@ -267,12 +263,11 @@ export class SerialAPISetup_SetTXStatusReportRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_SetTXStatusReportOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.SetTxStatusReport; if (gotDeserializationOptions(options)) { @@ -308,10 +303,9 @@ export class SerialAPISetup_SetTXStatusReportResponse implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -341,12 +335,11 @@ export interface SerialAPISetup_SetNodeIDTypeOptions @subCommandRequest(SerialAPISetupCommand.SetNodeIDType) export class SerialAPISetup_SetNodeIDTypeRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_SetNodeIDTypeOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.SetNodeIDType; if (gotDeserializationOptions(options)) { @@ -383,10 +376,9 @@ export class SerialAPISetup_SetNodeIDTypeResponse extends SerialAPISetupResponse implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -409,8 +401,8 @@ export class SerialAPISetup_SetNodeIDTypeResponse extends SerialAPISetupResponse @subCommandRequest(SerialAPISetupCommand.GetRFRegion) export class SerialAPISetup_GetRFRegionRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetRFRegion; } } @@ -418,10 +410,9 @@ export class SerialAPISetup_GetRFRegionRequest extends SerialAPISetupRequest { @subCommandResponse(SerialAPISetupCommand.GetRFRegion) export class SerialAPISetup_GetRFRegionResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.region = this.payload[0]; } @@ -445,12 +436,11 @@ export interface SerialAPISetup_SetRFRegionOptions extends MessageBaseOptions { @subCommandRequest(SerialAPISetupCommand.SetRFRegion) export class SerialAPISetup_SetRFRegionRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_SetRFRegionOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.SetRFRegion; if (gotDeserializationOptions(options)) { @@ -484,10 +474,9 @@ export class SerialAPISetup_SetRFRegionResponse extends SerialAPISetupResponse implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -510,8 +499,8 @@ export class SerialAPISetup_SetRFRegionResponse extends SerialAPISetupResponse @subCommandRequest(SerialAPISetupCommand.GetPowerlevel) export class SerialAPISetup_GetPowerlevelRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetPowerlevel; } } @@ -521,10 +510,9 @@ export class SerialAPISetup_GetPowerlevelResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); // The values are in 0.1 dBm, signed this.powerlevel = this.payload.readInt8(0) / 10; @@ -561,12 +549,11 @@ export interface SerialAPISetup_SetPowerlevelOptions @subCommandRequest(SerialAPISetupCommand.SetPowerlevel) export class SerialAPISetup_SetPowerlevelRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_SetPowerlevelOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.SetPowerlevel; if (gotDeserializationOptions(options)) { @@ -622,10 +609,9 @@ export class SerialAPISetup_SetPowerlevelResponse extends SerialAPISetupResponse implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -650,8 +636,8 @@ export class SerialAPISetup_SetPowerlevelResponse extends SerialAPISetupResponse export class SerialAPISetup_GetPowerlevel16BitRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetPowerlevel16Bit; } } @@ -661,10 +647,9 @@ export class SerialAPISetup_GetPowerlevel16BitResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 4); // The values are in 0.1 dBm, signed this.powerlevel = this.payload.readInt16BE(0) / 10; @@ -703,12 +688,11 @@ export class SerialAPISetup_SetPowerlevel16BitRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_SetPowerlevel16BitOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.SetPowerlevel16Bit; if (gotDeserializationOptions(options)) { @@ -765,10 +749,9 @@ export class SerialAPISetup_SetPowerlevel16BitResponse implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -793,8 +776,8 @@ export class SerialAPISetup_SetPowerlevel16BitResponse export class SerialAPISetup_GetLongRangeMaximumTxPowerRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetLongRangeMaximumTxPower; } } @@ -804,10 +787,9 @@ export class SerialAPISetup_GetLongRangeMaximumTxPowerResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); // The values are in 0.1 dBm, signed this.limit = this.payload.readInt16BE(0) / 10; @@ -841,12 +823,11 @@ export class SerialAPISetup_SetLongRangeMaximumTxPowerRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_SetLongRangeMaximumTxPowerOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.SetLongRangeMaximumTxPower; if (gotDeserializationOptions(options)) { @@ -895,10 +876,9 @@ export class SerialAPISetup_SetLongRangeMaximumTxPowerResponse implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -923,8 +903,8 @@ export class SerialAPISetup_SetLongRangeMaximumTxPowerResponse export class SerialAPISetup_GetMaximumPayloadSizeRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetMaximumPayloadSize; } } @@ -934,10 +914,9 @@ export class SerialAPISetup_GetMaximumPayloadSizeResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.maxPayloadSize = this.payload[0]; } @@ -958,8 +937,8 @@ export class SerialAPISetup_GetMaximumPayloadSizeResponse export class SerialAPISetup_GetLongRangeMaximumPayloadSizeRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetLongRangeMaximumPayloadSize; } } @@ -969,10 +948,9 @@ export class SerialAPISetup_GetLongRangeMaximumPayloadSizeResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.maxPayloadSize = this.payload[0]; } @@ -993,8 +971,8 @@ export class SerialAPISetup_GetLongRangeMaximumPayloadSizeResponse export class SerialAPISetup_GetSupportedRegionsRequest extends SerialAPISetupRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = SerialAPISetupCommand.GetSupportedRegions; } } @@ -1004,10 +982,9 @@ export class SerialAPISetup_GetSupportedRegionsResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 1); const numRegions = this.payload[0]; @@ -1030,12 +1007,11 @@ export interface SerialAPISetup_GetRegionInfoOptions @subCommandRequest(SerialAPISetupCommand.GetRegionInfo) export class SerialAPISetup_GetRegionInfoRequest extends SerialAPISetupRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SerialAPISetup_GetRegionInfoOptions, ) { - super(host, options); + super(options); this.command = SerialAPISetupCommand.GetRegionInfo; if (gotDeserializationOptions(options)) { @@ -1072,10 +1048,9 @@ export class SerialAPISetup_GetRegionInfoResponse extends SerialAPISetupResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.region = this.payload[0]; this.supportsZWave = !!(this.payload[1] & 0b1); this.supportsLongRange = !!(this.payload[1] & 0b10); diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts index 5ea1fed5107b..2fc8f9c42bba 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetApplicationNodeInformationRequest.ts @@ -5,7 +5,6 @@ import { encodeCCList, getCCName, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -31,10 +30,9 @@ export interface SetApplicationNodeInformationRequestOptions @priority(MessagePriority.Controller) export class SetApplicationNodeInformationRequest extends Message { public constructor( - host: ZWaveHost, options: SetApplicationNodeInformationRequestOptions, ) { - super(host, options); + super(options); this.isListening = options.isListening; this.genericDeviceClass = options.genericDeviceClass; this.specificDeviceClass = options.specificDeviceClass; diff --git a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts index c20cdc92cfb0..079df6cfc39b 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SetLongRangeShadowNodeIDsRequest.ts @@ -1,5 +1,4 @@ import { MessagePriority, encodeBitMask, parseBitMask } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -25,12 +24,11 @@ const NUM_LONG_RANGE_SHADOW_NODE_IDS = 4; @priority(MessagePriority.Controller) export class SetLongRangeShadowNodeIDsRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | LongRangeShadowNodeIDsRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.shadowNodeIds = parseBitMask( diff --git a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts index 608cc7577b5f..75126f6c84f7 100644 --- a/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/memory/GetControllerIdMessages.ts @@ -1,6 +1,5 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID, parseNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -28,10 +27,9 @@ export interface GetControllerIdResponseOptions extends MessageBaseOptions { @messageTypes(MessageType.Response, FunctionType.GetControllerId) export class GetControllerIdResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | GetControllerIdResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // The payload is 4 bytes home id, followed by the controller node id this.homeId = this.payload.readUInt32BE(0); diff --git a/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts index 3a112049ea14..62cc328bc90b 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/GetBackgroundRSSIMessages.ts @@ -5,7 +5,6 @@ import { type RSSI, rssiToString, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -25,10 +24,9 @@ export class GetBackgroundRSSIRequest extends Message {} @messageTypes(MessageType.Response, FunctionType.GetBackgroundRSSI) export class GetBackgroundRSSIResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.rssiChannel0 = parseRSSI(this.payload, 0); this.rssiChannel1 = parseRSSI(this.payload, 1); this.rssiChannel2 = tryParseRSSI(this.payload, 2); diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts index fa739bca700e..502f3b30a1c1 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetRFReceiveModeMessages.ts @@ -4,7 +4,6 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -31,10 +30,9 @@ export interface SetRFReceiveModeRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.SetRFReceiveMode) export class SetRFReceiveModeRequest extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SetRFReceiveModeRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -68,10 +66,9 @@ export class SetRFReceiveModeResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts index d404f2c4df34..97ca50aaae70 100644 --- a/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/misc/SetSerialApiTimeoutsMessages.ts @@ -1,5 +1,4 @@ import { MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -22,10 +21,9 @@ interface SetSerialApiTimeoutsRequestOptions extends MessageBaseOptions { @priority(MessagePriority.Controller) export class SetSerialApiTimeoutsRequest extends Message { public constructor( - host: ZWaveHost, options: SetSerialApiTimeoutsRequestOptions, ) { - super(host, options); + super(options); this.ackTimeout = options.ackTimeout; this.byteTimeout = options.byteTimeout; } @@ -45,10 +43,9 @@ export class SetSerialApiTimeoutsRequest extends Message { @messageTypes(MessageType.Response, FunctionType.SetSerialApiTimeouts) export class SetSerialApiTimeoutsResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._oldAckTimeout = this.payload[0] * 10; this._oldByteTimeout = this.payload[1] * 10; } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts index 1dd0ddf9ca03..59609fb46c88 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.ts @@ -11,7 +11,7 @@ import { parseNodeID, parseNodeUpdatePayload, } from "@zwave-js/core"; -import type { GetAllNodes, ZWaveHost } from "@zwave-js/host"; +import type { GetAllNodes } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -94,14 +94,14 @@ export function computeNeighborDiscoveryTimeout( // no expected response, the controller will respond with multiple AddNodeToNetworkRequests @priority(MessagePriority.Controller) export class AddNodeToNetworkRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== AddNodeToNetworkRequestStatusReport ) { - return new AddNodeToNetworkRequestStatusReport(host, options); + return new AddNodeToNetworkRequestStatusReport(options); } - super(host, options); + super(options); } } @@ -135,10 +135,9 @@ function testCallbackForAddNodeRequest( @expectedCallback(testCallbackForAddNodeRequest) export class AddNodeToNetworkRequest extends AddNodeToNetworkRequestBase { public constructor( - host: ZWaveHost, options: AddNodeToNetworkRequestOptions = {}, ) { - super(host, options); + super(options); this.addNodeType = options.addNodeType; this.highPower = !!options.highPower; @@ -211,10 +210,9 @@ export class EnableSmartStartListenRequest extends AddNodeToNetworkRequestBase { export class AddNodeDSKToNetworkRequest extends AddNodeToNetworkRequestBase { public constructor( - host: ZWaveHost, options: AddNodeDSKToNetworkRequestOptions, ) { - super(host, options); + super(options); this.nwiHomeId = options.nwiHomeId; this.authHomeId = options.authHomeId; @@ -277,10 +275,9 @@ export class AddNodeToNetworkRequestStatusReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.status = this.payload[1]; switch (this.status) { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts index f7c84a4c0fbc..3ad9ff228202 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.ts @@ -9,7 +9,6 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -30,18 +29,15 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.AssignPriorityReturnRoute) @priority(MessagePriority.Normal) export class AssignPriorityReturnRouteRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== AssignPriorityReturnRouteRequestTransmitReport ) { - return new AssignPriorityReturnRouteRequestTransmitReport( - host, - options, - ); + return new AssignPriorityReturnRouteRequestTransmitReport(options); } - super(host, options); + super(options); } } @@ -60,12 +56,11 @@ export class AssignPriorityReturnRouteRequest extends AssignPriorityReturnRouteRequestBase { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | AssignPriorityReturnRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -147,10 +142,9 @@ export class AssignPriorityReturnRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.hasStarted = this.payload[0] !== 0; } @@ -173,10 +167,9 @@ export class AssignPriorityReturnRouteRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.transmitStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts index 07e27523a566..4fee6d7b593e 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.ts @@ -9,7 +9,6 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -30,18 +29,17 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.AssignPrioritySUCReturnRoute) @priority(MessagePriority.Normal) export class AssignPrioritySUCReturnRouteRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== AssignPrioritySUCReturnRouteRequestTransmitReport ) { return new AssignPrioritySUCReturnRouteRequestTransmitReport( - host, options, ); } - super(host, options); + super(options); } } @@ -59,12 +57,11 @@ export class AssignPrioritySUCReturnRouteRequest extends AssignPrioritySUCReturnRouteRequestBase { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | AssignPrioritySUCReturnRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -132,10 +129,9 @@ export class AssignPrioritySUCReturnRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.hasStarted = this.payload[0] !== 0; } @@ -158,10 +154,9 @@ export class AssignPrioritySUCReturnRouteRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.transmitStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts index f3e010e22141..256326a5250c 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignReturnRouteMessages.ts @@ -6,7 +6,6 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, @@ -30,14 +29,14 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.AssignReturnRoute) @priority(MessagePriority.Normal) export class AssignReturnRouteRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== AssignReturnRouteRequestTransmitReport ) { - return new AssignReturnRouteRequestTransmitReport(host, options); + return new AssignReturnRouteRequestTransmitReport(options); } - super(host, options); + super(options); } } @@ -52,12 +51,11 @@ export class AssignReturnRouteRequest extends AssignReturnRouteRequestBase implements INodeQuery { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | AssignReturnRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -101,10 +99,9 @@ export class AssignReturnRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.hasStarted = this.payload[0] !== 0; } @@ -127,10 +124,9 @@ export class AssignReturnRouteRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.transmitStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts index fea2b809285d..7b3ceda16802 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.ts @@ -4,7 +4,6 @@ import { TransmitStatus, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, type INodeQuery, @@ -27,26 +26,23 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.AssignSUCReturnRoute) @priority(MessagePriority.Normal) export class AssignSUCReturnRouteRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if (gotDeserializationOptions(options)) { if ( options.origin === MessageOrigin.Host && (new.target as any) !== AssignSUCReturnRouteRequest ) { - return new AssignSUCReturnRouteRequest(host, options); + return new AssignSUCReturnRouteRequest(options); } else if ( options.origin !== MessageOrigin.Host && (new.target as any) !== AssignSUCReturnRouteRequestTransmitReport ) { - return new AssignSUCReturnRouteRequestTransmitReport( - host, - options, - ); + return new AssignSUCReturnRouteRequestTransmitReport(options); } } - super(host, options); + super(options); } } @@ -72,12 +68,11 @@ export class AssignSUCReturnRouteRequest extends AssignSUCReturnRouteRequestBase implements INodeQuery { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | AssignSUCReturnRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.nodeId = this.payload[0]; this.callbackId = this.payload[1]; @@ -109,12 +104,11 @@ export class AssignSUCReturnRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | AssignSUCReturnRouteResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.wasExecuted = this.payload[0] !== 0; } else { @@ -153,12 +147,11 @@ export class AssignSUCReturnRouteRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | AssignSUCReturnRouteRequestTransmitReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.callbackId = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts index 60ce6618ab9b..0dc86ed5a5dd 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.ts @@ -6,7 +6,6 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, @@ -30,14 +29,14 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.DeleteReturnRoute) @priority(MessagePriority.Normal) export class DeleteReturnRouteRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== DeleteReturnRouteRequestTransmitReport ) { - return new DeleteReturnRouteRequestTransmitReport(host, options); + return new DeleteReturnRouteRequestTransmitReport(options); } - super(host, options); + super(options); } } @@ -51,12 +50,11 @@ export class DeleteReturnRouteRequest extends DeleteReturnRouteRequestBase implements INodeQuery { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | DeleteReturnRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -83,10 +81,9 @@ export class DeleteReturnRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.hasStarted = this.payload[0] !== 0; } @@ -109,10 +106,9 @@ export class DeleteReturnRouteRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.transmitStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts index fb0a761e61da..10ed44691215 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.ts @@ -4,7 +4,6 @@ import { TransmitStatus, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { INodeQuery, MessageEncodingContext, @@ -29,26 +28,23 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.DeleteSUCReturnRoute) @priority(MessagePriority.Normal) export class DeleteSUCReturnRouteRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if (gotDeserializationOptions(options)) { if ( options.origin === MessageOrigin.Host && (new.target as any) !== DeleteSUCReturnRouteRequest ) { - return new DeleteSUCReturnRouteRequest(host, options); + return new DeleteSUCReturnRouteRequest(options); } else if ( options.origin !== MessageOrigin.Host && (new.target as any) !== DeleteSUCReturnRouteRequestTransmitReport ) { - return new DeleteSUCReturnRouteRequestTransmitReport( - host, - options, - ); + return new DeleteSUCReturnRouteRequestTransmitReport(options); } } - super(host, options); + super(options); } } @@ -74,12 +70,11 @@ export class DeleteSUCReturnRouteRequest extends DeleteSUCReturnRouteRequestBase implements INodeQuery { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | DeleteSUCReturnRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.nodeId = this.payload[0]; this.callbackId = this.payload[1]; @@ -111,12 +106,11 @@ export class DeleteSUCReturnRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | DeleteSUCReturnRouteResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.wasExecuted = this.payload[0] !== 0; } else { @@ -155,12 +149,11 @@ export class DeleteSUCReturnRouteRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | DeleteSUCReturnRouteRequestTransmitReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.callbackId = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts index 4a475bee26d4..fccd3b49b5ad 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts @@ -12,7 +12,6 @@ import { parseNodeID, parseNodeProtocolInfo, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -36,12 +35,11 @@ interface GetNodeProtocolInfoRequestOptions extends MessageBaseOptions { @priority(MessagePriority.Controller) export class GetNodeProtocolInfoRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetNodeProtocolInfoRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.requestedNodeId = parseNodeID(this.payload, options.ctx.nodeIdType, 0).nodeId; @@ -67,12 +65,11 @@ interface GetNodeProtocolInfoResponseOptions @messageTypes(MessageType.Response, FunctionType.GetNodeProtocolInfo) export class GetNodeProtocolInfoResponse extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | GetNodeProtocolInfoResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { // The context should contain the node ID the protocol info was requested for. diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts index 56213ede4090..4558515637cb 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetPriorityRouteMessages.ts @@ -10,7 +10,6 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -34,10 +33,9 @@ export interface GetPriorityRouteRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.GetPriorityRoute) export class GetPriorityRouteRequest extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | GetPriorityRouteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -72,10 +70,9 @@ export class GetPriorityRouteRequest extends Message { @messageTypes(MessageType.Response, FunctionType.GetPriorityRoute) export class GetPriorityRouteResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( this.payload, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts index c53adb6ce37e..8da062d7f431 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetRoutingInfoMessages.ts @@ -5,7 +5,6 @@ import { encodeNodeID, parseNodeBitMask, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -28,8 +27,8 @@ interface GetRoutingInfoRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.GetRoutingInfo) @priority(MessagePriority.Controller) export class GetRoutingInfoRequest extends Message { - public constructor(host: ZWaveHost, options: GetRoutingInfoRequestOptions) { - super(host, options); + public constructor(options: GetRoutingInfoRequestOptions) { + super(options); this.sourceNodeId = options.nodeId; this.removeNonRepeaters = !!options.removeNonRepeaters; this.removeBadLinks = !!options.removeBadLinks; @@ -67,10 +66,9 @@ export class GetRoutingInfoRequest extends Message { @messageTypes(MessageType.Response, FunctionType.GetRoutingInfo) export class GetRoutingInfoResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); if (this.payload.length === NUM_NODEMASK_BYTES) { // the payload contains a bit mask of all neighbor nodes diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts index e76621862fe5..351262ea3f73 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.ts @@ -1,5 +1,4 @@ import { MessagePriority, encodeNodeID, parseNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -25,10 +24,9 @@ export interface GetSUCNodeIdResponseOptions extends MessageBaseOptions { @messageTypes(MessageType.Response, FunctionType.GetSUCNodeId) export class GetSUCNodeIdResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | GetSUCNodeIdResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.sucNodeId = parseNodeID( diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts index 27d2333e32d9..ab7f7dc71c53 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/IsFailedNodeMessages.ts @@ -1,5 +1,4 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -21,8 +20,8 @@ export interface IsFailedNodeRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.IsFailedNode) @priority(MessagePriority.Controller) export class IsFailedNodeRequest extends Message { - public constructor(host: ZWaveHost, options: IsFailedNodeRequestOptions) { - super(host, options); + public constructor(options: IsFailedNodeRequestOptions) { + super(options); this.failedNodeId = options.failedNodeId; } @@ -38,10 +37,9 @@ export class IsFailedNodeRequest extends Message { @messageTypes(MessageType.Response, FunctionType.IsFailedNode) export class IsFailedNodeResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.result = !!this.payload[0]; } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts index 0919273eed6d..172a1abaab10 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.ts @@ -1,5 +1,4 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -47,14 +46,14 @@ export enum RemoveFailedNodeStatus { @messageTypes(MessageType.Request, FunctionType.RemoveFailedNode) @priority(MessagePriority.Controller) export class RemoveFailedNodeRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== RemoveFailedNodeRequestStatusReport ) { - return new RemoveFailedNodeRequestStatusReport(host, options); + return new RemoveFailedNodeRequestStatusReport(options); } - super(host, options); + super(options); } } @@ -67,10 +66,9 @@ interface RemoveFailedNodeRequestOptions extends MessageBaseOptions { @expectedCallback(FunctionType.RemoveFailedNode) export class RemoveFailedNodeRequest extends RemoveFailedNodeRequestBase { public constructor( - host: ZWaveHost, options: RemoveFailedNodeRequestOptions, ) { - super(host, options); + super(options); this.failedNodeId = options.failedNodeId; } @@ -91,10 +89,9 @@ export class RemoveFailedNodeRequestStatusReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this._removeStatus = this.payload[1]; @@ -115,10 +112,9 @@ export class RemoveFailedNodeResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._removeStatus = this.payload[0]; } diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts index 5f79092ea3ac..cf62859b1074 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.ts @@ -3,7 +3,6 @@ import { MessagePriority, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -54,14 +53,14 @@ interface RemoveNodeFromNetworkRequestOptions extends MessageBaseOptions { // no expected response, the controller will respond with multiple RemoveNodeFromNetworkRequests @priority(MessagePriority.Controller) export class RemoveNodeFromNetworkRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== RemoveNodeFromNetworkRequestStatusReport ) { - return new RemoveNodeFromNetworkRequestStatusReport(host, options); + return new RemoveNodeFromNetworkRequestStatusReport(options); } - super(host, options); + super(options); } } @@ -97,10 +96,9 @@ export class RemoveNodeFromNetworkRequest extends RemoveNodeFromNetworkRequestBase { public constructor( - host: ZWaveHost, options: RemoveNodeFromNetworkRequestOptions = {}, ) { - super(host, options); + super(options); this.removeNodeType = options.removeNodeType; this.highPower = !!options.highPower; @@ -131,10 +129,9 @@ export class RemoveNodeFromNetworkRequestStatusReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.status = this.payload[1]; switch (this.status) { diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts index de05d1f742e1..2514eaafa4f6 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.ts @@ -1,5 +1,4 @@ import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -47,14 +46,14 @@ export enum ReplaceFailedNodeStatus { @messageTypes(MessageType.Request, FunctionType.ReplaceFailedNode) @priority(MessagePriority.Controller) export class ReplaceFailedNodeRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== ReplaceFailedNodeRequestStatusReport ) { - return new ReplaceFailedNodeRequestStatusReport(host, options); + return new ReplaceFailedNodeRequestStatusReport(options); } - super(host, options); + super(options); } } @@ -66,10 +65,9 @@ interface ReplaceFailedNodeRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.ReplaceFailedNode) export class ReplaceFailedNodeRequest extends ReplaceFailedNodeRequestBase { public constructor( - host: ZWaveHost, options: ReplaceFailedNodeRequestOptions, ) { - super(host, options); + super(options); this.failedNodeId = options.failedNodeId; } @@ -90,10 +88,9 @@ export class ReplaceFailedNodeResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._replaceStatus = this.payload[0]; } @@ -112,10 +109,9 @@ export class ReplaceFailedNodeRequestStatusReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this._replaceStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts index ced2a7d7c954..5a058a6619fe 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeInfoMessages.ts @@ -4,7 +4,6 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, type INodeQuery, @@ -34,10 +33,9 @@ export class RequestNodeInfoResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | RequestNodeInfoResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.wasSent = this.payload[0] !== 0; } else { @@ -85,10 +83,9 @@ function testCallbackForRequestNodeInfoRequest( @priority(MessagePriority.NodeQuery) export class RequestNodeInfoRequest extends Message implements INodeQuery { public constructor( - host: ZWaveHost, options: RequestNodeInfoRequestOptions | MessageDeserializationOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.nodeId = parseNodeID( this.payload, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts index 5c861605a824..93f95cdcb764 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.ts @@ -1,6 +1,5 @@ import type { MessageOrCCLogEntry } from "@zwave-js/core"; import { MessagePriority, encodeNodeID } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, MultiStageCallback, @@ -37,14 +36,14 @@ export interface RequestNodeNeighborUpdateRequestOptions @messageTypes(MessageType.Request, FunctionType.RequestNodeNeighborUpdate) @priority(MessagePriority.Controller) export class RequestNodeNeighborUpdateRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== RequestNodeNeighborUpdateReport ) { - return new RequestNodeNeighborUpdateReport(host, options); + return new RequestNodeNeighborUpdateReport(options); } - super(host, options); + super(options); } } @@ -53,10 +52,9 @@ export class RequestNodeNeighborUpdateRequest extends RequestNodeNeighborUpdateRequestBase { public constructor( - host: ZWaveHost, options: RequestNodeNeighborUpdateRequestOptions, ) { - super(host, options); + super(options); this.nodeId = options.nodeId; this.discoveryTimeout = options.discoveryTimeout; } @@ -90,10 +88,9 @@ export class RequestNodeNeighborUpdateReport implements SuccessIndicator, MultiStageCallback { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this._updateStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts index 29bfc735bc75..849c484748cc 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetLearnModeMessages.ts @@ -5,7 +5,6 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -48,14 +47,14 @@ export enum LearnModeStatus { @messageTypes(MessageType.Request, FunctionType.SetLearnMode) @priority(MessagePriority.Controller) export class SetLearnModeRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== SetLearnModeCallback ) { - return new SetLearnModeCallback(host, options); + return new SetLearnModeCallback(options); } - super(host, options); + super(options); } } @@ -67,10 +66,9 @@ export interface SetLearnModeRequestOptions extends MessageBaseOptions { // The callback may come much (30+ seconds), so we wait for it outside of the queue export class SetLearnModeRequest extends SetLearnModeRequestBase { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SetLearnModeRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -107,10 +105,9 @@ export class SetLearnModeRequest extends SetLearnModeRequestBase { @messageTypes(MessageType.Response, FunctionType.SetLearnMode) export class SetLearnModeResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } @@ -132,10 +129,9 @@ export class SetLearnModeCallback extends SetLearnModeRequestBase implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.status = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts index f168d53ecb4b..555a632091bd 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetPriorityRouteMessages.ts @@ -10,7 +10,6 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -40,12 +39,11 @@ export type SetPriorityRouteRequestOptions = @expectedResponse(FunctionType.SetPriorityRoute) export class SetPriorityRouteRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | (MessageBaseOptions & SetPriorityRouteRequestOptions), ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -133,10 +131,9 @@ export class SetPriorityRouteResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); // Byte(s) 0/1 are the node ID - this is missing from the Host API specs const { /* nodeId, */ bytesRead } = parseNodeID( this.payload, diff --git a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts index 20d6e581873b..e4bb2c02473d 100644 --- a/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.ts @@ -6,7 +6,6 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -41,14 +40,14 @@ export interface SetSUCNodeIdRequestOptions extends MessageBaseOptions { @messageTypes(MessageType.Request, FunctionType.SetSUCNodeId) @priority(MessagePriority.Controller) export class SetSUCNodeIdRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== SetSUCNodeIdRequestStatusReport ) { - return new SetSUCNodeIdRequestStatusReport(host, options); + return new SetSUCNodeIdRequestStatusReport(options); } - super(host, options); + super(options); } } @@ -56,10 +55,9 @@ export class SetSUCNodeIdRequestBase extends Message { @expectedCallback(FunctionType.SetSUCNodeId) export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SetSUCNodeIdRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -107,10 +105,9 @@ export class SetSUCNodeIdRequest extends SetSUCNodeIdRequestBase { @messageTypes(MessageType.Response, FunctionType.SetSUCNodeId) export class SetSUCNodeIdResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._wasExecuted = this.payload[0] !== 0; } @@ -135,10 +132,9 @@ export class SetSUCNodeIdRequestStatusReport extends SetSUCNodeIdRequestBase implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this._status = this.payload[1]; diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts index c4c84b3d0721..750daeb548e9 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.ts @@ -4,7 +4,6 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -29,12 +28,11 @@ export interface ExtNVMReadLongBufferRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.ExtNVMReadLongBuffer) export class ExtNVMReadLongBufferRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ExtNVMReadLongBufferRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -83,10 +81,9 @@ export class ExtNVMReadLongBufferRequest extends Message { @messageTypes(MessageType.Response, FunctionType.ExtNVMReadLongBuffer) export class ExtNVMReadLongBufferResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.buffer = this.payload; } diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts index cd748277f557..30ed8ca21abd 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMReadLongByteMessages.ts @@ -4,7 +4,6 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -28,12 +27,11 @@ export interface ExtNVMReadLongByteRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.ExtNVMReadLongByte) export class ExtNVMReadLongByteRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ExtNVMReadLongByteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -69,10 +67,9 @@ export class ExtNVMReadLongByteRequest extends Message { @messageTypes(MessageType.Response, FunctionType.ExtNVMReadLongByte) export class ExtNVMReadLongByteResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.byte = this.payload[0]; } diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts index 280acbee33d6..8b27db4fe920 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.ts @@ -4,7 +4,6 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -31,12 +30,11 @@ export interface ExtNVMWriteLongBufferRequestOptions @expectedResponse(FunctionType.ExtNVMWriteLongBuffer) export class ExtNVMWriteLongBufferRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ExtNVMWriteLongBufferRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -87,10 +85,9 @@ export class ExtNVMWriteLongBufferRequest extends Message { @messageTypes(MessageType.Response, FunctionType.ExtNVMWriteLongBuffer) export class ExtNVMWriteLongBufferResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts index a8919c8aaa48..b645d01ecefb 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.ts @@ -4,7 +4,6 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -29,12 +28,11 @@ export interface ExtNVMWriteLongByteRequestOptions extends MessageBaseOptions { @expectedResponse(FunctionType.ExtExtWriteLongByte) export class ExtNVMWriteLongByteRequest extends Message { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ExtNVMWriteLongByteRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -82,10 +80,9 @@ export class ExtNVMWriteLongByteRequest extends Message { @messageTypes(MessageType.Response, FunctionType.ExtExtWriteLongByte) export class ExtNVMWriteLongByteResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.success = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts index 9f51e2e18408..4bfd2177595b 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/ExtendedNVMOperationsMessages.ts @@ -6,7 +6,6 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -76,8 +75,8 @@ export class ExtendedNVMOperationsRequest extends Message { export class ExtendedNVMOperationsOpenRequest extends ExtendedNVMOperationsRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = ExtendedNVMOperationsCommand.Open; } } @@ -87,8 +86,8 @@ export class ExtendedNVMOperationsOpenRequest export class ExtendedNVMOperationsCloseRequest extends ExtendedNVMOperationsRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = ExtendedNVMOperationsCommand.Close; } } @@ -106,12 +105,11 @@ export class ExtendedNVMOperationsReadRequest extends ExtendedNVMOperationsRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ExtendedNVMOperationsReadRequestOptions, ) { - super(host, options); + super(options); this.command = ExtendedNVMOperationsCommand.Read; if (gotDeserializationOptions(options)) { @@ -175,12 +173,11 @@ export class ExtendedNVMOperationsWriteRequest extends ExtendedNVMOperationsRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | ExtendedNVMOperationsWriteRequestOptions, ) { - super(host, options); + super(options); this.command = ExtendedNVMOperationsCommand.Write; if (gotDeserializationOptions(options)) { @@ -240,10 +237,9 @@ export class ExtendedNVMOperationsResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.status = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts index 53b257187d2d..874d40ce710d 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/FirmwareUpdateNVMMessages.ts @@ -7,7 +7,6 @@ import { createSimpleReflectionDecorator, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import type { DeserializingMessageConstructor, MessageBaseOptions, @@ -71,8 +70,8 @@ function testResponseForFirmwareUpdateNVMRequest( @priority(MessagePriority.Controller) @expectedResponse(testResponseForFirmwareUpdateNVMRequest) export class FirmwareUpdateNVMRequest extends Message { - public constructor(host: ZWaveHost, options: MessageOptions = {}) { - super(host, options); + public constructor(options: MessageOptions = {}) { + super(options); if (gotDeserializationOptions(options)) { throw new ZWaveError( `${this.constructor.name}: deserialization not implemented`, @@ -111,17 +110,16 @@ export class FirmwareUpdateNVMRequest extends Message { @messageTypes(MessageType.Response, FunctionType.FirmwareUpdateNVM) export class FirmwareUpdateNVMResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.command = this.payload[0]; const CommandConstructor = getSubCommandResponseConstructor( this.command, ); if (CommandConstructor && (new.target as any) !== CommandConstructor) { - return new CommandConstructor(host, options); + return new CommandConstructor(options); } this.payload = this.payload.subarray(1); @@ -151,10 +149,9 @@ export class FirmwareUpdateNVM_InitRequest extends FirmwareUpdateNVMRequest {} @subCommandResponse(FirmwareUpdateNVMCommand.Init) export class FirmwareUpdateNVM_InitResponse extends FirmwareUpdateNVMResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.supported = this.payload[0] !== 0; } @@ -182,12 +179,11 @@ export class FirmwareUpdateNVM_SetNewImageRequest extends FirmwareUpdateNVMRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | FirmwareUpdateNVM_SetNewImageRequestOptions, ) { - super(host, options); + super(options); this.command = FirmwareUpdateNVMCommand.SetNewImage; if (gotDeserializationOptions(options)) { @@ -222,10 +218,9 @@ export class FirmwareUpdateNVM_SetNewImageResponse extends FirmwareUpdateNVMResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.changed = this.payload[0] !== 0; } @@ -252,10 +247,9 @@ export class FirmwareUpdateNVM_GetNewImageResponse extends FirmwareUpdateNVMResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.newImage = this.payload[0] !== 0; } @@ -285,12 +279,11 @@ export class FirmwareUpdateNVM_UpdateCRC16Request extends FirmwareUpdateNVMRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | FirmwareUpdateNVM_UpdateCRC16RequestOptions, ) { - super(host, options); + super(options); this.command = FirmwareUpdateNVMCommand.UpdateCRC16; if (gotDeserializationOptions(options)) { @@ -339,10 +332,9 @@ export class FirmwareUpdateNVM_UpdateCRC16Response extends FirmwareUpdateNVMResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.crc16 = this.payload.readUint16BE(0); } @@ -375,10 +367,9 @@ export class FirmwareUpdateNVM_IsValidCRC16Response extends FirmwareUpdateNVMResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.isValid = this.payload[0] !== 0; // There are two more bytes containing the CRC result, but we don't care about that } @@ -406,12 +397,11 @@ export interface FirmwareUpdateNVM_WriteRequestOptions @subCommandRequest(FirmwareUpdateNVMCommand.Write) export class FirmwareUpdateNVM_WriteRequest extends FirmwareUpdateNVMRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | FirmwareUpdateNVM_WriteRequestOptions, ) { - super(host, options); + super(options); this.command = FirmwareUpdateNVMCommand.Write; if (gotDeserializationOptions(options)) { @@ -453,10 +443,9 @@ export class FirmwareUpdateNVM_WriteRequest extends FirmwareUpdateNVMRequest { @subCommandResponse(FirmwareUpdateNVMCommand.Write) export class FirmwareUpdateNVM_WriteResponse extends FirmwareUpdateNVMResponse { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.overwritten = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts index 8dfa52d06847..32fbe189dd50 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/GetNVMIdMessages.ts @@ -1,5 +1,4 @@ import { type MessageOrCCLogEntry, MessagePriority } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -74,10 +73,9 @@ export class GetNVMIdRequest extends Message {} @messageTypes(MessageType.Response, FunctionType.GetNVMId) export class GetNVMIdResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.nvmManufacturerId = this.payload[1]; this.memoryType = this.payload[2]; this.memorySize = this.payload[3]; diff --git a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts index 08d3f3a95f11..0b8854f803aa 100644 --- a/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/nvm/NVMOperationsMessages.ts @@ -6,7 +6,6 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -68,8 +67,8 @@ export class NVMOperationsRequest extends Message { // ============================================================================= export class NVMOperationsOpenRequest extends NVMOperationsRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = NVMOperationsCommand.Open; } } @@ -77,8 +76,8 @@ export class NVMOperationsOpenRequest extends NVMOperationsRequest { // ============================================================================= export class NVMOperationsCloseRequest extends NVMOperationsRequest { - public constructor(host: ZWaveHost, options?: MessageOptions) { - super(host, options); + public constructor(options?: MessageOptions) { + super(options); this.command = NVMOperationsCommand.Close; } } @@ -92,12 +91,11 @@ export interface NVMOperationsReadRequestOptions extends MessageBaseOptions { export class NVMOperationsReadRequest extends NVMOperationsRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | NVMOperationsReadRequestOptions, ) { - super(host, options); + super(options); this.command = NVMOperationsCommand.Read; if (gotDeserializationOptions(options)) { @@ -157,12 +155,11 @@ export interface NVMOperationsWriteRequestOptions extends MessageBaseOptions { export class NVMOperationsWriteRequest extends NVMOperationsRequest { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | NVMOperationsWriteRequestOptions, ) { - super(host, options); + super(options); this.command = NVMOperationsCommand.Write; if (gotDeserializationOptions(options)) { @@ -220,10 +217,9 @@ export class NVMOperationsWriteRequest extends NVMOperationsRequest { @messageTypes(MessageType.Response, FunctionType.NVMOperations) export class NVMOperationsResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); validatePayload(this.payload.length >= 2); this.status = this.payload[0]; diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts index c52dd4b459ab..d26e049f9cc1 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataBridgeMessages.ts @@ -12,7 +12,7 @@ import { ZWaveErrorCodes, encodeNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext } from "@zwave-js/host"; import type { MessageEncodingContext, SuccessIndicator, @@ -40,14 +40,14 @@ import { parseTXReport, txReportToMessageRecord } from "./SendDataShared"; @messageTypes(MessageType.Request, FunctionType.SendDataBridge) @priority(MessagePriority.Normal) export class SendDataBridgeRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== SendDataBridgeRequestTransmitReport ) { - return new SendDataBridgeRequestTransmitReport(host, options); + return new SendDataBridgeRequestTransmitReport(options); } - super(host, options); + super(options); } } @@ -67,10 +67,9 @@ export class SendDataBridgeRequest implements ICommandClassContainer { public constructor( - host: ZWaveHost, options: SendDataBridgeRequestOptions, ) { - super(host, options); + super(options); if (!options.command.isSinglecast() && !options.command.isBroadcast()) { throw new ZWaveError( @@ -190,12 +189,11 @@ export class SendDataBridgeRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SendDataBridgeRequestTransmitReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.callbackId = this.payload[0]; @@ -241,10 +239,9 @@ export class SendDataBridgeResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._wasSent = this.payload[0] !== 0; } @@ -268,18 +265,15 @@ export class SendDataBridgeResponse extends Message @messageTypes(MessageType.Request, FunctionType.SendDataMulticastBridge) @priority(MessagePriority.Normal) export class SendDataMulticastBridgeRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== SendDataMulticastBridgeRequestTransmitReport ) { - return new SendDataMulticastBridgeRequestTransmitReport( - host, - options, - ); + return new SendDataMulticastBridgeRequestTransmitReport(options); } - super(host, options); + super(options); } } @@ -298,10 +292,9 @@ export class SendDataMulticastBridgeRequest< CCType extends CommandClass = CommandClass, > extends SendDataMulticastBridgeRequestBase implements ICommandClassContainer { public constructor( - host: ZWaveHost, options: SendDataMulticastBridgeRequestOptions, ) { - super(host, options); + super(options); if (!options.command.isMulticast()) { throw new ZWaveError( @@ -417,12 +410,11 @@ export class SendDataMulticastBridgeRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SendDataMulticastBridgeRequestTransmitReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.callbackId = this.payload[0]; @@ -461,10 +453,9 @@ export class SendDataMulticastBridgeResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this._wasSent = this.payload[0] !== 0; } diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts index 33bd3cf5f5e5..7023067ab38f 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendDataMessages.ts @@ -16,7 +16,7 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { CCEncodingContext, ZWaveHost } from "@zwave-js/host"; +import type { CCEncodingContext } from "@zwave-js/host"; import { FunctionType, Message, @@ -48,21 +48,21 @@ export const MAX_SEND_ATTEMPTS = 5; @messageTypes(MessageType.Request, FunctionType.SendData) @priority(MessagePriority.Normal) export class SendDataRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if (gotDeserializationOptions(options)) { if ( options.origin === MessageOrigin.Host && (new.target as any) !== SendDataRequest ) { - return new SendDataRequest(host, options); + return new SendDataRequest(options); } else if ( options.origin !== MessageOrigin.Host && (new.target as any) !== SendDataRequestTransmitReport ) { - return new SendDataRequestTransmitReport(host, options); + return new SendDataRequestTransmitReport(options); } } - super(host, options); + super(options); } } @@ -81,10 +81,9 @@ export class SendDataRequest implements ICommandClassContainer { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SendDataRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { let offset = 0; @@ -105,7 +104,7 @@ export class SendDataRequest ); if (options.parseCCs !== false) { - this.command = CommandClass.from(host, { + this.command = CommandClass.from({ nodeId, data: this.payload, origin: options.origin, @@ -226,12 +225,11 @@ export class SendDataRequestTransmitReport extends SendDataRequestBase implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SendDataRequestTransmitReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.callbackId = this.payload[0]; @@ -297,10 +295,9 @@ export interface SendDataResponseOptions extends MessageBaseOptions { @messageTypes(MessageType.Response, FunctionType.SendData) export class SendDataResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SendDataResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.wasSent = this.payload[0] !== 0; } else { @@ -330,26 +327,23 @@ export class SendDataResponse extends Message implements SuccessIndicator { @messageTypes(MessageType.Request, FunctionType.SendDataMulticast) @priority(MessagePriority.Normal) export class SendDataMulticastRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if (gotDeserializationOptions(options)) { if ( options.origin === MessageOrigin.Host && (new.target as any) !== SendDataMulticastRequest ) { - return new SendDataMulticastRequest(host, options); + return new SendDataMulticastRequest(options); } else if ( options.origin !== MessageOrigin.Host && (new.target as any) !== SendDataMulticastRequestTransmitReport ) { - return new SendDataMulticastRequestTransmitReport( - host, - options, - ); + return new SendDataMulticastRequestTransmitReport(options); } } - super(host, options); + super(options); } } @@ -367,12 +361,11 @@ export class SendDataMulticastRequest< CCType extends CommandClass = CommandClass, > extends SendDataMulticastRequestBase implements ICommandClassContainer { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SendDataMulticastRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { const numNodeIDs = this.payload[0]; @@ -403,7 +396,7 @@ export class SendDataMulticastRequest< this.payload = serializedCC; if (options.parseCCs !== false) { - this.command = CommandClass.from(host, { + this.command = CommandClass.from({ nodeId: this._nodeIds[0], data: this.payload, origin: options.origin, @@ -525,12 +518,11 @@ export class SendDataMulticastRequestTransmitReport implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SendDataMulticastRequestTransmitReportOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.callbackId = this.payload[0]; @@ -580,12 +572,11 @@ export class SendDataMulticastResponse extends Message implements SuccessIndicator { public constructor( - host: ZWaveHost, options: | MessageDeserializationOptions | SendDataMulticastResponseOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { this.wasSent = this.payload[0] !== 0; } else { diff --git a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts index 484a2d106c50..9224515076ea 100644 --- a/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts +++ b/packages/zwave-js/src/lib/serialapi/transport/SendTestFrameMessages.ts @@ -6,7 +6,6 @@ import { encodeNodeID, parseNodeID, } from "@zwave-js/core"; -import type { ZWaveHost } from "@zwave-js/host"; import { FunctionType, Message, @@ -27,14 +26,14 @@ import { getEnumMemberName } from "@zwave-js/shared"; @messageTypes(MessageType.Request, FunctionType.SendTestFrame) @priority(MessagePriority.Normal) export class SendTestFrameRequestBase extends Message { - public constructor(host: ZWaveHost, options: MessageOptions) { + public constructor(options: MessageOptions) { if ( gotDeserializationOptions(options) && (new.target as any) !== SendTestFrameTransmitReport ) { - return new SendTestFrameTransmitReport(host, options); + return new SendTestFrameTransmitReport(options); } - super(host, options); + super(options); } } @@ -47,10 +46,9 @@ export interface SendTestFrameRequestOptions extends MessageBaseOptions { @expectedCallback(FunctionType.SendTestFrame) export class SendTestFrameRequest extends SendTestFrameRequestBase { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions | SendTestFrameRequestOptions, ) { - super(host, options); + super(options); if (gotDeserializationOptions(options)) { let offset = 0; const { nodeId, bytesRead: nodeIdBytes } = parseNodeID( @@ -101,10 +99,9 @@ export class SendTestFrameRequest extends SendTestFrameRequestBase { @messageTypes(MessageType.Response, FunctionType.SendTestFrame) export class SendTestFrameResponse extends Message { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.wasSent = this.payload[0] !== 0; } @@ -122,10 +119,9 @@ export class SendTestFrameTransmitReport extends SendTestFrameRequestBase implements SuccessIndicator { public constructor( - host: ZWaveHost, options: MessageDeserializationOptions, ) { - super(host, options); + super(options); this.callbackId = this.payload[0]; this.transmitStatus = this.payload[1]; diff --git a/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts b/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts index d67a0d433b97..cbd179e574c3 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts @@ -24,7 +24,7 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { // Unsupported report from root endpoint - let cc: CommandClass = new MultilevelSensorCCReport(mockNode.host, { + let cc: CommandClass = new MultilevelSensorCCReport({ nodeId: mockController.ownNodeId, type: 0x01, // Temperature scale: 0x00, // Celsius @@ -37,13 +37,13 @@ integrationTest( ); // Report from endpoint 1, unsupported on root - cc = new MultilevelSensorCCReport(mockNode.host, { + cc = new MultilevelSensorCCReport({ nodeId: mockController.ownNodeId, type: 0x01, // Temperature scale: 0x00, // Celsius value: 25.12, }); - cc = new MultiChannelCCCommandEncapsulation(mockNode.host, { + cc = new MultiChannelCCCommandEncapsulation({ nodeId: mockController.ownNodeId, endpoint: 1, destination: 0, @@ -56,13 +56,13 @@ integrationTest( ); // Unsupported Report from endpoint 1, supported on root - cc = new MeterCCReport(mockNode.host, { + cc = new MeterCCReport({ nodeId: mockController.ownNodeId, type: 0x01, // Electric scale: 0x00, // kWh value: 1.234, }); - cc = new MultiChannelCCCommandEncapsulation(mockNode.host, { + cc = new MultiChannelCCCommandEncapsulation({ nodeId: mockController.ownNodeId, endpoint: 1, destination: 0, @@ -75,7 +75,7 @@ integrationTest( ); // Supported report from root endpoint - cc = new MeterCCReport(mockNode.host, { + cc = new MeterCCReport({ nodeId: mockController.ownNodeId, type: 0x01, // Electric scale: 0x00, // kWh diff --git a/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts b/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts index f8d7f3320652..b99c1977ba42 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts @@ -18,7 +18,7 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { const valueId = DoorLockCCValues.currentMode.id; - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x01, // Manual Lock Operation @@ -33,7 +33,7 @@ integrationTest( t.is(node.getValue(valueId), DoorLockMode.Secured); - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x06, // Keypad Unlock Operation diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts index f78f514a8311..3c935c56b20a 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts @@ -49,7 +49,7 @@ integrationTest( }); // Send notifications to the node - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x0f, notificationEvent: 0x01, @@ -66,7 +66,7 @@ integrationTest( let value = node.getValue(valveOperationStatusId); t.is(value, 0x00); - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x0f, notificationEvent: 0x01, @@ -124,7 +124,7 @@ integrationTest( }); // Send notifications to the node - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, @@ -141,7 +141,7 @@ integrationTest( let value = node.getValue(doorStateValueId); t.is(value, 0x1600); - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, @@ -157,7 +157,7 @@ integrationTest( value = node.getValue(doorStateValueId); t.is(value, 0x1601); - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // open @@ -172,7 +172,7 @@ integrationTest( value = node.getValue(doorStateValueId); t.is(value, 0x16); - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x17, // closed @@ -240,7 +240,7 @@ integrationTest("The 'simple' Door state value works correctly", { ); const valueSimple = NotificationCCValues.doorStateSimple; - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -259,7 +259,7 @@ integrationTest("The 'simple' Door state value works correctly", { // === - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -278,7 +278,7 @@ integrationTest("The 'simple' Door state value works correctly", { // === - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -296,7 +296,7 @@ integrationTest("The 'simple' Door state value works correctly", { // === - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x17, // Window/door is closed @@ -346,7 +346,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { t.false(hasTiltVID()); // Send a notification to the node where the window is not tilted - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -366,7 +366,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // === // Again with tilt - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -387,7 +387,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // === // Again without tilt - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -406,7 +406,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // === // Again with tilt to be able to detect changes - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -425,7 +425,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // === // And now without the enum - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x17, // Window/door is closed @@ -443,7 +443,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // === // Again with tilt to be able to detect changes - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -462,7 +462,7 @@ integrationTest("The synthetic 'Door tilt state' value works correctly", { // === // And again without the enum - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, notificationEvent: 0x16, // Window/door is open @@ -520,7 +520,7 @@ integrationTest( }); // Send notifications to the node - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x05, notificationEvent: 0x07, @@ -538,7 +538,7 @@ integrationTest( t.is(value, 0x02); // Now send one without an event parameter - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x05, notificationEvent: 0x07, @@ -553,7 +553,7 @@ integrationTest( value = node.getValue(waterPressureAlarmValueId); t.is(value, 0x01); - // cc = new NotificationCCReport(mockNode.host, { + // cc = new NotificationCCReport({ // nodeId: mockController.ownNodeId, // notificationType: 0x06, // notificationEvent: 0x16, // open @@ -568,7 +568,7 @@ integrationTest( // value = node.getValue(waterPressureAlarmValueId); // t.is(value, 0x16); - // cc = new NotificationCCReport(mockNode.host, { + // cc = new NotificationCCReport({ // nodeId: mockController.ownNodeId, // notificationType: 0x06, // notificationEvent: 0x17, // closed diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts index 35f73d45cfa8..736216c9a9c3 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts @@ -17,7 +17,7 @@ integrationTest("Notification values can get idled manually", { "Alarm status", ).id; - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x01, // Smoke Alarm notificationEvent: 0x03, // Smoke alarm test @@ -46,7 +46,7 @@ integrationTest("Notification values can get idled manually", { "Door state", ).id; - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control notificationEvent: 0x16, // Door state @@ -80,7 +80,7 @@ integrationTest( "Alarm status", ).id; - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x01, // Smoke Alarm notificationEvent: 0x03, // Smoke alarm test @@ -108,7 +108,7 @@ integrationTest( "Door state", ).id; - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control notificationEvent: 0x16, // Door state diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts index 3b5c77ffc139..ddc52c574833 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts @@ -22,7 +22,7 @@ integrationTest( "Lock state", ).id; - let cc = new NotificationCCReport(mockNode.host, { + let cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x0b, // Lock jammed @@ -37,7 +37,7 @@ integrationTest( t.is(node.getValue(lockStateValueId), 0x0b /* Lock jammed */); - cc = new NotificationCCReport(mockNode.host, { + cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0x06, // Keypad Unlock Operation diff --git a/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts b/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts index 9077749337ad..e1ed5ddb699f 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts @@ -18,7 +18,7 @@ integrationTest( const targetValueValueID = BinarySwitchCCValues.targetValue.id; node.valueDB.setValue(targetValueValueID, false); - const cc = new BinarySwitchCCReport(mockNode.host, { + const cc = new BinarySwitchCCReport({ nodeId: mockController.ownNodeId, currentValue: true, }); diff --git a/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts b/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts index 4926670410fc..0cc050765dc9 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts @@ -18,7 +18,7 @@ integrationTest( ), testBody: async (t, driver, node, mockController, mockNode) => { - const cc = new NotificationCCReport(mockNode.host, { + const cc = new NotificationCCReport({ nodeId: mockController.ownNodeId, notificationType: 0x06, // Access Control, notificationEvent: 0xfd, // Manual Lock Operation diff --git a/packages/zwave-js/src/lib/test/cc/API.test.ts b/packages/zwave-js/src/lib/test/cc/API.test.ts index 97762861ac6e..5770a3b76845 100644 --- a/packages/zwave-js/src/lib/test/cc/API.test.ts +++ b/packages/zwave-js/src/lib/test/cc/API.test.ts @@ -51,6 +51,6 @@ test.after.always(async (t) => { test.serial(`supportsCommand() returns NOT_KNOWN by default`, (t) => { const { node2, driver } = t.context; - const API = new DummyCCAPI(driver, node2); + const API = new DummyCCAPI(node2); t.is(API.supportsCommand(null as any), NOT_KNOWN); }); diff --git a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts index c983331c5a5e..2ea9287042b8 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts @@ -23,7 +23,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the SupportedGroupingsGet command should serialize correctly", (t) => { - const cc = new AssociationCCSupportedGroupingsGet(host, { + const cc = new AssociationCCSupportedGroupingsGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -41,7 +41,7 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t 7, // # of groups ]), ); - const cc = new AssociationCCSupportedGroupingsReport(host, { + const cc = new AssociationCCSupportedGroupingsReport({ nodeId: 2, data: ccData, context: {} as any, @@ -51,7 +51,7 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t }); test("the Set command should serialize correctly", (t) => { - const cc = new AssociationCCSet(host, { + const cc = new AssociationCCSet({ nodeId: 2, groupId: 5, nodeIds: [1, 2, 5], @@ -69,7 +69,7 @@ test("the Set command should serialize correctly", (t) => { t.deepEqual(cc.serialize({} as any), expected); }); test("the Get command should serialize correctly", (t) => { - const cc = new AssociationCCGet(host, { + const cc = new AssociationCCGet({ nodeId: 1, groupId: 9, }); @@ -95,7 +95,7 @@ test("the Report command should be deserialized correctly", (t) => { 5, ]), ); - const cc = new AssociationCCReport(host, { + const cc = new AssociationCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -108,7 +108,7 @@ test("the Report command should be deserialized correctly", (t) => { }); test("the Remove command should serialize correctly", (t) => { - const cc = new AssociationCCRemove(host, { + const cc = new AssociationCCRemove({ nodeId: 2, groupId: 5, nodeIds: [1, 2, 5], @@ -127,7 +127,7 @@ test("the Remove command should serialize correctly", (t) => { }); test("the Remove command should serialize correctly (empty node list)", (t) => { - const cc = new AssociationCCRemove(host, { + const cc = new AssociationCCRemove({ nodeId: 2, groupId: 5, }); @@ -145,7 +145,7 @@ test("the Remove command should serialize correctly (empty node list)", (t) => { // 1, // Buffer.from([255]), // not a valid command // ); -// const cc: any = new AssociationCC(host, { +// const cc: any = new AssociationCC({ // data: serializedCC, // }); // t.is(cc.constructor, AssociationCC); diff --git a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts index 901f4419d375..dd9b5bb70c26 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts @@ -26,7 +26,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the NameGet command should serialize correctly", (t) => { - const cc = new AssociationGroupInfoCCNameGet(host, { + const cc = new AssociationGroupInfoCCNameGet({ nodeId: 1, groupId: 7, }); @@ -54,7 +54,7 @@ test("the NameReport command should be deserialized correctly", (t) => { 0x72, ]), ); - const cc = new AssociationGroupInfoCCNameReport(host, { + const cc = new AssociationGroupInfoCCNameReport({ nodeId: 1, data: ccData, context: {} as any, @@ -65,7 +65,7 @@ test("the NameReport command should be deserialized correctly", (t) => { }); test("the InfoGet command should serialize correctly (no flag set)", (t) => { - const cc = new AssociationGroupInfoCCInfoGet(host, { + const cc = new AssociationGroupInfoCCInfoGet({ nodeId: 1, groupId: 7, listMode: false, @@ -82,7 +82,7 @@ test("the InfoGet command should serialize correctly (no flag set)", (t) => { }); test("the InfoGet command should serialize correctly (refresh cache flag set)", (t) => { - const cc = new AssociationGroupInfoCCInfoGet(host, { + const cc = new AssociationGroupInfoCCInfoGet({ nodeId: 1, groupId: 7, listMode: false, @@ -99,7 +99,7 @@ test("the InfoGet command should serialize correctly (refresh cache flag set)", }); test("the InfoGet command should serialize correctly (list mode flag set)", (t) => { - const cc = new AssociationGroupInfoCCInfoGet(host, { + const cc = new AssociationGroupInfoCCInfoGet({ nodeId: 1, groupId: 7, listMode: true, @@ -141,7 +141,7 @@ test("the Info Report command should be deserialized correctly", (t) => { 0, ]), ); - const cc = new AssociationGroupInfoCCInfoReport(host, { + const cc = new AssociationGroupInfoCCInfoReport({ nodeId: 1, data: ccData, context: {} as any, @@ -158,7 +158,7 @@ test("the Info Report command should be deserialized correctly", (t) => { }); test("the CommandListGet command should serialize correctly", (t) => { - const cc = new AssociationGroupInfoCCCommandListGet(host, { + const cc = new AssociationGroupInfoCCCommandListGet({ nodeId: 1, groupId: 6, allowCache: true, @@ -187,7 +187,7 @@ test("the CommandListReport command should be deserialized correctly", (t) => { 0x05, ]), ); - const cc = new AssociationGroupInfoCCCommandListReport(host, { + const cc = new AssociationGroupInfoCCCommandListReport({ nodeId: 1, data: ccData, context: {} as any, @@ -206,7 +206,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new AssociationGroupInfoCC(host, { + const cc: any = new AssociationGroupInfoCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts index 9d89bb144a52..f7080e9f28ff 100644 --- a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts @@ -25,7 +25,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const basicCC = new BasicCCGet(host, { nodeId: 1 }); + const basicCC = new BasicCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ BasicCommand.Get, // CC Command @@ -35,7 +35,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly", (t) => { - const basicCC = new BasicCCSet(host, { + const basicCC = new BasicCCSet({ nodeId: 2, targetValue: 55, }); @@ -55,7 +55,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 55, // current value ]), ); - const basicCC = new BasicCCReport(host, { + const basicCC = new BasicCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -75,7 +75,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { 1, // duration ]), ); - const basicCC = new BasicCCReport(host, { + const basicCC = new BasicCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -91,7 +91,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const basicCC: any = new BasicCC(host, { + const basicCC: any = new BasicCC({ nodeId: 2, data: serializedCC, context: {} as any, @@ -137,7 +137,7 @@ test("getDefinedValueIDs() should include the target value for all endpoints exc }); test("BasicCCSet should expect no response", (t) => { - const cc = new BasicCCSet(host, { + const cc = new BasicCCSet({ nodeId: 2, endpoint: 2, targetValue: 7, @@ -146,12 +146,12 @@ test("BasicCCSet should expect no response", (t) => { }); test("BasicCCSet => BasicCCReport = unexpected", (t) => { - const ccRequest = new BasicCCSet(host, { + const ccRequest = new BasicCCSet({ nodeId: 2, endpoint: 2, targetValue: 7, }); - const ccResponse = new BasicCCReport(host, { + const ccResponse = new BasicCCReport({ nodeId: ccRequest.nodeId, currentValue: 7, }); @@ -160,17 +160,17 @@ test("BasicCCSet => BasicCCReport = unexpected", (t) => { }); test("BasicCCGet should expect a response", (t) => { - const cc = new BasicCCGet(host, { + const cc = new BasicCCGet({ nodeId: 2, }); t.true(cc.expectsCCResponse()); }); test("BasicCCGet => BasicCCReport = expected", (t) => { - const ccRequest = new BasicCCGet(host, { + const ccRequest = new BasicCCGet({ nodeId: 2, }); - const ccResponse = new BasicCCReport(host, { + const ccResponse = new BasicCCReport({ nodeId: ccRequest.nodeId, currentValue: 7, }); @@ -179,10 +179,10 @@ test("BasicCCGet => BasicCCReport = expected", (t) => { }); test("BasicCCGet => BasicCCReport (wrong node) = unexpected", (t) => { - const ccRequest = new BasicCCGet(host, { + const ccRequest = new BasicCCGet({ nodeId: 2, }); - const ccResponse = new BasicCCReport(host, { + const ccResponse = new BasicCCReport({ nodeId: (ccRequest.nodeId as number) + 1, currentValue: 7, }); @@ -191,10 +191,10 @@ test("BasicCCGet => BasicCCReport (wrong node) = unexpected", (t) => { }); test("BasicCCGet => BasicCCSet = unexpected", (t) => { - const ccRequest = new BasicCCGet(host, { + const ccRequest = new BasicCCGet({ nodeId: 2, }); - const ccResponse = new BasicCCSet(host, { + const ccResponse = new BasicCCSet({ nodeId: ccRequest.nodeId, targetValue: 7, }); @@ -203,7 +203,7 @@ test("BasicCCGet => BasicCCSet = unexpected", (t) => { }); test("Looking up CC values for a CC instance should work", (t) => { - const cc = new BasicCCGet(host, { + const cc = new BasicCCGet({ nodeId: 2, }); const values = getCCValues(cc) as typeof BasicCCValues; diff --git a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts index 7a52ff0a36f5..d54671ffc6c9 100644 --- a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts @@ -13,7 +13,7 @@ import test from "ava"; const host = createTestingHost(); test("the Get command should serialize correctly", (t) => { - const batteryCC = new BatteryCCGet(host, { nodeId: 1 }); + const batteryCC = new BatteryCCGet({ nodeId: 1 }); const expected = Buffer.from([ CommandClasses.Battery, // CC BatteryCommand.Get, // CC Command @@ -27,7 +27,7 @@ test("the Report command (v1) should be deserialized correctly: when the battery BatteryCommand.Report, // CC Command 55, // current value ]); - const batteryCC = new BatteryCC(host, { + const batteryCC = new BatteryCC({ nodeId: 7, data: ccData, context: {} as any, @@ -43,7 +43,7 @@ test("the Report command (v1) should be deserialized correctly: when the battery BatteryCommand.Report, // CC Command 0xff, // current value ]); - const batteryCC = new BatteryCC(host, { + const batteryCC = new BatteryCC({ nodeId: 7, data: ccData, context: {} as any, @@ -61,7 +61,7 @@ test("the Report command (v2) should be deserialized correctly: all flags set", 0b00_1111_00, 1, // disconnected ]); - const batteryCC = new BatteryCC(host, { + const batteryCC = new BatteryCC({ nodeId: 7, data: ccData, context: {} as any, @@ -82,7 +82,7 @@ test("the Report command (v2) should be deserialized correctly: charging status" 0b10_000000, // Maintaining 0, ]); - const batteryCC = new BatteryCC(host, { + const batteryCC = new BatteryCC({ nodeId: 7, data: ccData, context: {} as any, @@ -99,7 +99,7 @@ test("the Report command (v2) should be deserialized correctly: recharge or repl 0b11, // Maintaining 0, ]); - const batteryCC = new BatteryCC(host, { + const batteryCC = new BatteryCC({ nodeId: 7, data: ccData, context: {} as any, @@ -113,7 +113,7 @@ test("deserializing an unsupported command should return an unspecified version CommandClasses.Battery, // CC 255, // not a valid command ]); - const basicCC: any = new BatteryCC(host, { + const basicCC: any = new BatteryCC({ nodeId: 7, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts index 073cf4ec7f4d..31d5251a1dca 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts @@ -23,7 +23,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly (no sensor type)", (t) => { - const cc = new BinarySensorCCGet(host, { nodeId: 1 }); + const cc = new BinarySensorCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ BinarySensorCommand.Get, // CC Command @@ -34,7 +34,7 @@ test("the Get command should serialize correctly (no sensor type)", (t) => { }); test("the Get command should serialize correctly", (t) => { - const cc = new BinarySensorCCGet(host, { + const cc = new BinarySensorCCGet({ nodeId: 1, sensorType: BinarySensorType.CO, }); @@ -51,7 +51,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0xff, // current value ]), ); - const cc = new BinarySensorCCReport(host, { + const cc = new BinarySensorCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -68,7 +68,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { BinarySensorType.CO2, ]), ); - const cc = new BinarySensorCCReport(host, { + const cc = new BinarySensorCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -79,7 +79,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { }); test("the SupportedGet command should serialize correctly", (t) => { - const cc = new BinarySensorCCSupportedGet(host, { nodeId: 1 }); + const cc = new BinarySensorCCSupportedGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ BinarySensorCommand.SupportedGet, // CC Command @@ -96,7 +96,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { 0b10, ]), ); - const cc = new BinarySensorCCSupportedReport(host, { + const cc = new BinarySensorCCSupportedReport({ nodeId: 1, data: ccData, context: {} as any, @@ -115,7 +115,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new BinarySensorCC(host, { + const cc: any = new BinarySensorCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts index 77bae2a99407..3e6495c77ff5 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts @@ -21,7 +21,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new BinarySwitchCCGet(host, { nodeId: 1 }); + const cc = new BinarySwitchCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ BinarySwitchCommand.Get, // CC Command @@ -31,7 +31,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly (no duration)", (t) => { - const cc = new BinarySwitchCCSet(host, { + const cc = new BinarySwitchCCSet({ nodeId: 2, targetValue: false, }); @@ -53,7 +53,7 @@ test("the Set command should serialize correctly (no duration)", (t) => { test("the Set command should serialize correctly", (t) => { const duration = new Duration(2, "minutes"); - const cc = new BinarySwitchCCSet(host, { + const cc = new BinarySwitchCCSet({ nodeId: 2, targetValue: true, duration, @@ -81,7 +81,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0xff, // current value ]), ); - const cc = new BinarySwitchCCReport(host, { + const cc = new BinarySwitchCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -101,7 +101,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { 1, // duration ]), ); - const cc = new BinarySwitchCCReport(host, { + const cc = new BinarySwitchCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -117,7 +117,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new BinarySwitchCC(host, { + const cc: any = new BinarySwitchCC({ nodeId: 2, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts index 4a48f506f282..75904afa7c30 100644 --- a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts @@ -13,7 +13,7 @@ import test from "ava"; const host = createTestingHost(); test("should be detected as an encapsulating CC", (t) => { - const basicCCSet = new BasicCCSet(host, { + const basicCCSet = new BasicCCSet({ nodeId: 3, targetValue: 89, }); @@ -23,7 +23,7 @@ test("should be detected as an encapsulating CC", (t) => { test("should match the specs", (t) => { // SDS13783 contains the following sample encapsulated command: - const basicCCGet = new BasicCCGet(host, { nodeId: 1 }); + const basicCCGet = new BasicCCGet({ nodeId: 1 }); const crc16 = CRC16CC.encapsulate(host, basicCCGet); const serialized = crc16.serialize({} as any); const expected = Buffer.from("560120024d26", "hex"); @@ -31,7 +31,7 @@ test("should match the specs", (t) => { }); test("serialization and deserialization should be compatible", (t) => { - const basicCCSet = new BasicCCSet(host, { + const basicCCSet = new BasicCCSet({ nodeId: 3, targetValue: 89, }); @@ -40,7 +40,7 @@ test("serialization and deserialization should be compatible", (t) => { t.is(crc16.encapsulated, basicCCSet); const serialized = crc16.serialize({} as any); - const deserialized = CommandClass.from(host, { + const deserialized = CommandClass.from({ nodeId: basicCCSet.nodeId as number, data: serialized, context: {} as any, @@ -54,7 +54,7 @@ test("serialization and deserialization should be compatible", (t) => { }); test("deserializing a CC with a wrong checksum should result in an invalid CC", (t) => { - const basicCCSet = new BasicCCSet(host, { + const basicCCSet = new BasicCCSet({ nodeId: 3, targetValue: 89, }); @@ -64,7 +64,7 @@ test("deserializing a CC with a wrong checksum should result in an invalid CC", const serialized = crc16.serialize({} as any); serialized[serialized.length - 1] ^= 0xff; - const decoded = CommandClass.from(host, { + const decoded = CommandClass.from({ nodeId: basicCCSet.nodeId as number, data: serialized, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts index 0df8766b8eba..0121b582754a 100644 --- a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts @@ -25,7 +25,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the ConfigurationGet command should serialize correctly", (t) => { - const cc = new CentralSceneCCConfigurationGet(host, { + const cc = new CentralSceneCCConfigurationGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -37,7 +37,7 @@ test("the ConfigurationGet command should serialize correctly", (t) => { }); test("the ConfigurationSet command should serialize correctly (flags set)", (t) => { - const cc = new CentralSceneCCConfigurationSet(host, { + const cc = new CentralSceneCCConfigurationSet({ nodeId: 2, slowRefresh: true, }); @@ -51,7 +51,7 @@ test("the ConfigurationSet command should serialize correctly (flags set)", (t) }); test("the ConfigurationSet command should serialize correctly (flags not set)", (t) => { - const cc = new CentralSceneCCConfigurationSet(host, { + const cc = new CentralSceneCCConfigurationSet({ nodeId: 2, slowRefresh: false, }); @@ -71,7 +71,7 @@ test("the ConfigurationReport command should be deserialized correctly", (t) => 0b1000_0000, ]), ); - const cc = new CentralSceneCCConfigurationReport(host, { + const cc = new CentralSceneCCConfigurationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -81,7 +81,7 @@ test("the ConfigurationReport command should be deserialized correctly", (t) => }); test("the SupportedGet command should serialize correctly", (t) => { - const cc = new CentralSceneCCSupportedGet(host, { + const cc = new CentralSceneCCSupportedGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -104,7 +104,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { 0, ]), ); - const cc = new CentralSceneCCSupportedReport(host, { + const cc = new CentralSceneCCSupportedReport({ nodeId: 1, data: ccData, context: {} as any, @@ -127,7 +127,7 @@ test("the Notification command should be deserialized correctly", (t) => { 8, // scene number ]), ); - const cc = new CentralSceneCCNotification(host, { + const cc = new CentralSceneCCNotification({ nodeId: 1, data: ccData, context: {} as any, @@ -149,7 +149,7 @@ test("the Notification command should be deserialized correctly (KeyHeldDown)", 8, // scene number ]), ); - const cc = new CentralSceneCCNotification(host, { + const cc = new CentralSceneCCNotification({ nodeId: 1, data: ccData, context: {} as any, @@ -165,7 +165,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new CentralSceneCC(host, { + const cc: any = new CentralSceneCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts index 8381339036f5..e0ed797ac7f2 100644 --- a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts @@ -31,7 +31,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the SupportedGet command should serialize correctly", (t) => { - const cc = new ColorSwitchCCSupportedGet(host, { + const cc = new ColorSwitchCCSupportedGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -50,7 +50,7 @@ test("the SupportedReport command should deserialize correctly", (t) => { 0b0000_0001, ]), ); - const cc = new ColorSwitchCCSupportedReport(host, { + const cc = new ColorSwitchCCSupportedReport({ nodeId: 1, data: ccData, context: {} as any, @@ -72,7 +72,7 @@ test("the SupportedReport command should deserialize correctly", (t) => { }); test("the Get command should serialize correctly", (t) => { - const cc = new ColorSwitchCCGet(host, { + const cc = new ColorSwitchCCGet({ nodeId: 1, colorComponent: ColorComponent.Red, }); @@ -93,7 +93,7 @@ test("the Report command should deserialize correctly (version 1)", (t) => { 0b1111_1111, // value: 255 ]), ); - const cc = new ColorSwitchCCReport(host, { + const cc = new ColorSwitchCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -115,7 +115,7 @@ test("the Report command should deserialize correctly (version 3)", (t) => { 0b0000_0001, // duration: 1 ]), ); - const cc = new ColorSwitchCCReport(host, { + const cc = new ColorSwitchCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -129,7 +129,7 @@ test("the Report command should deserialize correctly (version 3)", (t) => { }); test("the Set command should serialize correctly (without duration)", (t) => { - const cc = new ColorSwitchCCSet(host, { + const cc = new ColorSwitchCCSet({ nodeId: 1, red: 128, green: 255, @@ -158,7 +158,7 @@ test("the Set command should serialize correctly (without duration)", (t) => { }); test("the Set command should serialize correctly (version 2)", (t) => { - const cc = new ColorSwitchCCSet(host, { + const cc = new ColorSwitchCCSet({ nodeId: 1, red: 128, green: 255, @@ -187,7 +187,7 @@ test("the Set command should serialize correctly (version 2)", (t) => { }); test("the StartLevelChange command should serialize correctly", (t) => { - const cc = new ColorSwitchCCStartLevelChange(host, { + const cc = new ColorSwitchCCStartLevelChange({ nodeId: 1, startLevel: 5, ignoreStartLevel: true, @@ -214,7 +214,7 @@ test("the StartLevelChange command should serialize correctly", (t) => { }); test("the StopLevelChange command should serialize correctly", (t) => { - const cc = new ColorSwitchCCStopLevelChange(host, { + const cc = new ColorSwitchCCStopLevelChange({ nodeId: 1, colorComponent: ColorComponent.Red, }); diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts index 2e22d9589137..83a03979d623 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts @@ -71,7 +71,7 @@ test(`persistValues() should not update "interviewComplete" in the value DB`, (t const { node2, driver } = t.context; // Repro for #383 - const cc = new BasicCCSet(driver, { + const cc = new BasicCCSet({ nodeId: node2.id, targetValue: 55, }); @@ -91,7 +91,7 @@ test(`persistValues() should not update "interviewComplete" in the value DB`, (t test(`persistValues() should not store values marked as "events" (non-stateful)`, async (t) => { const { node2, driver } = t.context; - const cc = new CentralSceneCCNotification(driver, { + const cc = new CentralSceneCCNotification({ nodeId: node2.id, data: Buffer.from([ CommandClasses["Central Scene"], diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts index b15ad4d12f21..eb17d9ecc98b 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts @@ -29,13 +29,13 @@ class DummyCCSubClass2 extends DummyCC { test(`creating and serializing should work for unspecified commands`, (t) => { // Repro for #1219 - const cc = new CommandClass(host, { + const cc = new CommandClass({ nodeId: 2, ccId: 0x5d, ccCommand: 0x02, payload: Buffer.from([1, 2, 3]), }); - const msg = new SendDataRequest(host, { + const msg = new SendDataRequest({ command: cc, callbackId: 0xfe, }); @@ -47,7 +47,7 @@ test(`creating and serializing should work for unspecified commands`, (t) => { test("from() returns an un-specialized instance when receiving a non-implemented CC", (t) => { // This is a Node Provisioning CC. Change it when that CC is implemented - const cc = CommandClass.from(host, { + const cc = CommandClass.from({ data: Buffer.from("78030100", "hex"), nodeId: 5, context: {} as any, @@ -61,7 +61,7 @@ test("from() returns an un-specialized instance when receiving a non-implemented test("from() does not throw when the CC is implemented", (t) => { t.notThrows(() => - CommandClass.from(host, { + CommandClass.from({ // CRC-16 with BasicCC data: Buffer.from("560120024d26", "hex"), nodeId: 5, @@ -71,7 +71,7 @@ test("from() does not throw when the CC is implemented", (t) => { }); test("getImplementedVersion() should return the implemented version for a CommandClass instance", (t) => { - const cc = new BasicCC(host, { nodeId: 1 }); + const cc = new BasicCC({ nodeId: 1 }); t.is(getImplementedVersion(cc), 2); }); @@ -86,7 +86,7 @@ test("getImplementedVersion() should return 0 for a non-existing CC", (t) => { }); test("getImplementedVersion() should work with inheritance", (t) => { - const cc = new BasicCCGet(host, { nodeId: 1 }); + const cc = new BasicCCGet({ nodeId: 1 }); t.is(getImplementedVersion(cc), 2); }); @@ -99,12 +99,12 @@ test("getImplementedVersionStatic() should work on inherited classes", (t) => { }); test("expectMoreMessages() returns false by default", (t) => { - const cc = new DummyCC(host, { nodeId: 1 }); + const cc = new DummyCC({ nodeId: 1 }); t.false(cc.expectMoreMessages([])); }); test("getExpectedCCResponse() returns the expected CC response like it was defined", (t) => { - const cc = new DummyCCSubClass2(host, { nodeId: 1 }); + const cc = new DummyCCSubClass2({ nodeId: 1 }); const actual = getExpectedCCResponse(cc); t.is(actual, DummyCCSubClass1); }); diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts index 702bb1a61f9c..ac5bf54758d2 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockCC.test.ts @@ -40,7 +40,7 @@ valueDB2.setValue(DoorLockCCValues.boltSupported.id, true); valueDB2.setValue(DoorLockCCValues.latchSupported.id, true); test("the OperationGet command should serialize correctly", (t) => { - const cc = new DoorLockCCOperationGet(host, { nodeId: 1 }); + const cc = new DoorLockCCOperationGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ DoorLockCommand.OperationGet, // CC Command @@ -50,7 +50,7 @@ test("the OperationGet command should serialize correctly", (t) => { }); test("the OperationSet command should serialize correctly", (t) => { - const cc = new DoorLockCCOperationSet(host, { + const cc = new DoorLockCCOperationSet({ nodeId: 2, mode: DoorLockMode.OutsideUnsecured, }); @@ -74,7 +74,7 @@ test("the OperationReport command (v1-v3) should be deserialized correctly", (t) 20, // timeout seconds ]), ); - const cc = new DoorLockCCOperationReport(host, { + const cc = new DoorLockCCOperationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -104,7 +104,7 @@ test("the OperationReport command (v4) should be deserialized correctly", (t) => 0x01, // 1 second left ]), ); - const cc = new DoorLockCCOperationReport(host, { + const cc = new DoorLockCCOperationReport({ nodeId: 2, data: ccData, context: {} as any, @@ -130,7 +130,7 @@ test("the OperationReport command (v4) should be deserialized correctly", (t) => }); test("the ConfigurationGet command should serialize correctly", (t) => { - const cc = new DoorLockCCConfigurationGet(host, { nodeId: 1 }); + const cc = new DoorLockCCConfigurationGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ DoorLockCommand.ConfigurationGet, // CC Command @@ -149,7 +149,7 @@ test("the ConfigurationReport command (v1-v3) should be deserialized correctly", 20, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport(host, { + const cc = new DoorLockCCConfigurationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -185,7 +185,7 @@ test("the ConfigurationReport command must ignore invalid timeouts (constant)", 20, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport(host, { + const cc = new DoorLockCCConfigurationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -204,7 +204,7 @@ test("the ConfigurationReport command must ignore invalid timeouts (invalid minu 20, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport(host, { + const cc = new DoorLockCCConfigurationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -223,7 +223,7 @@ test("the ConfigurationReport command must ignore invalid timeouts (invalid seco 0xff, // timeout seconds ]), ); - const cc = new DoorLockCCConfigurationReport(host, { + const cc = new DoorLockCCConfigurationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -248,7 +248,7 @@ test("the ConfigurationReport command (v4) should be deserialized correctly", (t 0b01, // flags ]), ); - const cc = new DoorLockCCConfigurationReport(host, { + const cc = new DoorLockCCConfigurationReport({ nodeId: 1, data: ccData, context: {} as any, @@ -261,7 +261,7 @@ test("the ConfigurationReport command (v4) should be deserialized correctly", (t }); test("the ConfigurationSet command (v4) should serialize correctly", (t) => { - const cc = new DoorLockCCConfigurationSet(host, { + const cc = new DoorLockCCConfigurationSet({ nodeId: 2, operationType: DoorLockOperationType.Timed, outsideHandlesCanOpenDoorConfiguration: [false, true, true, true], @@ -290,7 +290,7 @@ test("the ConfigurationSet command (v4) should serialize correctly", (t) => { }); test("the CapabilitiesGet command should serialize correctly", (t) => { - const cc = new DoorLockCCCapabilitiesGet(host, { nodeId: 1 }); + const cc = new DoorLockCCCapabilitiesGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ DoorLockCommand.CapabilitiesGet, // CC Command @@ -314,7 +314,7 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { 0b1010, // feature flags ]), ); - const cc = new DoorLockCCCapabilitiesReport(host, { + const cc = new DoorLockCCCapabilitiesReport({ nodeId: 1, data: ccData, context: {} as any, @@ -349,7 +349,7 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { // 1, // duration // ]), // ); -// const cc = new DoorLockCCReport(host, { data: ccData }); +// const cc = new DoorLockCCReport({ data: ccData }); // t.is(cc.currentValue, 55); // t.is(cc.targetValue, 66); @@ -362,7 +362,7 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { // 1, // Buffer.from([255]), // not a valid command // ); -// const cc: any = new DoorLockCC(host, { +// const cc: any = new DoorLockCC({ // data: serializedCC, // }); // t.is(cc.constructor, DoorLockCC); diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts index c82487f7c8fc..9cb09032a6a6 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts @@ -22,7 +22,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the RecordsCountGet command should serialize correctly", (t) => { - const cc = new DoorLockLoggingCCRecordsSupportedGet(host, { + const cc = new DoorLockLoggingCCRecordsSupportedGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -40,7 +40,7 @@ test("the RecordsCountReport command should be deserialized correctly", (t) => { 0x14, // max records supported (20) ]), ); - const cc = new DoorLockLoggingCCRecordsSupportedReport(host, { + const cc = new DoorLockLoggingCCRecordsSupportedReport({ nodeId: 1, data: ccData, context: {} as any, @@ -50,7 +50,7 @@ test("the RecordsCountReport command should be deserialized correctly", (t) => { }); test("the RecordGet command should serialize correctly", (t) => { - const cc = new DoorLockLoggingCCRecordGet(host, { + const cc = new DoorLockLoggingCCRecordGet({ nodeId: 1, recordNumber: 1, }); @@ -82,7 +82,7 @@ test("the RecordReport command should be deserialized correctly", (t) => { ]), ); - const cc = new DoorLockLoggingCCRecordReport(host, { + const cc = new DoorLockLoggingCCRecordReport({ nodeId: 1, data: ccData, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts index 5cfb64a224e7..630b9bb5aa01 100644 --- a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts @@ -45,7 +45,7 @@ test("the Notification command should deserialize correctly", (t) => { ]), ); - const cc = new EntryControlCCNotification(host, { + const cc = new EntryControlCCNotification({ nodeId: 1, data, context: {} as any, @@ -58,7 +58,7 @@ test("the Notification command should deserialize correctly", (t) => { }); test("the ConfigurationGet command should serialize correctly", (t) => { - const cc = new EntryControlCCConfigurationGet(host, { + const cc = new EntryControlCCConfigurationGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -70,7 +70,7 @@ test("the ConfigurationGet command should serialize correctly", (t) => { }); test("the ConfigurationSet command should serialize correctly", (t) => { - const cc = new EntryControlCCConfigurationSet(host, { + const cc = new EntryControlCCConfigurationSet({ nodeId: 1, keyCacheSize: 1, keyCacheTimeout: 2, @@ -94,7 +94,7 @@ test("the ConfigurationReport command should be deserialize correctly", (t) => { ]), ); - const cc = new EntryControlCCConfigurationReport(host, { + const cc = new EntryControlCCConfigurationReport({ nodeId: 1, data, context: {} as any, @@ -105,7 +105,7 @@ test("the ConfigurationReport command should be deserialize correctly", (t) => { }); test("the EventSupportedGet command should serialize correctly", (t) => { - const cc = new EntryControlCCEventSupportedGet(host, { + const cc = new EntryControlCCEventSupportedGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -134,7 +134,7 @@ test("the EventSupportedReport command should be deserialize correctly", (t) => ]), ); - const cc = new EntryControlCCEventSupportedReport(host, { + const cc = new EntryControlCCEventSupportedReport({ nodeId: 1, data, context: {} as any, @@ -154,7 +154,7 @@ test("the EventSupportedReport command should be deserialize correctly", (t) => }); test("the KeySupportedGet command should serialize correctly", (t) => { - const cc = new EntryControlCCKeySupportedGet(host, { nodeId: 1 }); + const cc = new EntryControlCCKeySupportedGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ EntryControlCommand.KeySupportedGet, // CC Command @@ -172,7 +172,7 @@ test("the KeySupportedReport command should be deserialize correctly", (t) => { ]), ); - const cc = new EntryControlCCKeySupportedReport(host, { + const cc = new EntryControlCCKeySupportedReport({ nodeId: 1, data, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts index 33ca24da25f0..ecfa727c74e0 100644 --- a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts @@ -26,7 +26,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Set Tilt command should serialize correctly", (t) => { - const cc = new FibaroVenetianBlindCCSet(host, { + const cc = new FibaroVenetianBlindCCSet({ nodeId: 2, tilt: 99, }); @@ -50,7 +50,7 @@ test("the Report command should be deserialized correctly", (t) => { 0x00, // Tilt ]), ); - const cc = CommandClass.from(host, { + const cc = CommandClass.from({ nodeId: 2, data: ccData, context: {} as any, @@ -61,7 +61,7 @@ test("the Report command should be deserialized correctly", (t) => { }); test("FibaroVenetianBlindCCSet should expect no response", (t) => { - const cc = new FibaroVenetianBlindCCSet(host, { + const cc = new FibaroVenetianBlindCCSet({ nodeId: 2, tilt: 7, }); @@ -69,18 +69,18 @@ test("FibaroVenetianBlindCCSet should expect no response", (t) => { }); test("FibaroVenetianBlindCCGet should expect a response", (t) => { - const cc = new FibaroVenetianBlindCCGet(host, { + const cc = new FibaroVenetianBlindCCGet({ nodeId: 2, }); t.true(cc.expectsCCResponse()); }); test("FibaroVenetianBlindCCSet => FibaroVenetianBlindCCReport = unexpected", (t) => { - const ccRequest = new FibaroVenetianBlindCCSet(host, { + const ccRequest = new FibaroVenetianBlindCCSet({ nodeId: 2, tilt: 7, }); - const ccResponse = new FibaroVenetianBlindCCReport(host, { + const ccResponse = new FibaroVenetianBlindCCReport({ nodeId: 2, data: buildCCBuffer( Buffer.from([ @@ -97,10 +97,10 @@ test("FibaroVenetianBlindCCSet => FibaroVenetianBlindCCReport = unexpected", (t) }); test("FibaroVenetianBlindCCGet => FibaroVenetianBlindCCReport = expected", (t) => { - const ccRequest = new FibaroVenetianBlindCCGet(host, { + const ccRequest = new FibaroVenetianBlindCCGet({ nodeId: 2, }); - const ccResponse = new FibaroVenetianBlindCCReport(host, { + const ccResponse = new FibaroVenetianBlindCCReport({ nodeId: 2, data: buildCCBuffer( Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts index e4070aa7277c..fb39ca7a96c7 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlModeCC.test.ts @@ -25,7 +25,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new HumidityControlModeCCGet(host, { + const cc = new HumidityControlModeCCGet({ nodeId, }); const expected = buildCCBuffer( @@ -37,7 +37,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly", (t) => { - const cc = new HumidityControlModeCCSet(host, { + const cc = new HumidityControlModeCCSet({ nodeId, mode: HumidityControlMode.Auto, }); @@ -57,7 +57,7 @@ test("the Report command should be deserialized correctly", (t) => { HumidityControlMode.Auto, // current value ]), ); - const cc = new HumidityControlModeCCReport(host, { + const cc = new HumidityControlModeCCReport({ nodeId, data: ccData, context: {} as any, @@ -73,7 +73,7 @@ test("the Report command should set the correct value", (t) => { HumidityControlMode.Auto, // current value ]), ); - const report = new HumidityControlModeCCReport(host, { + const report = new HumidityControlModeCCReport({ nodeId, data: ccData, context: {} as any, @@ -94,7 +94,7 @@ test("the Report command should set the correct metadata", (t) => { HumidityControlMode.Auto, // current value ]), ); - const cc = new HumidityControlModeCCReport(host, { + const cc = new HumidityControlModeCCReport({ nodeId, data: ccData, context: {} as any, @@ -112,7 +112,7 @@ test("the Report command should set the correct metadata", (t) => { }); test("the SupportedGet command should serialize correctly", (t) => { - const cc = new HumidityControlModeCCSupportedGet(host, { + const cc = new HumidityControlModeCCSupportedGet({ nodeId, }); const expected = buildCCBuffer( @@ -130,7 +130,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { (1 << HumidityControlMode.Off) | (1 << HumidityControlMode.Auto), ]), ); - const cc = new HumidityControlModeCCSupportedReport(host, { + const cc = new HumidityControlModeCCSupportedReport({ nodeId, data: ccData, context: {} as any, @@ -149,7 +149,7 @@ test("the SupportedReport command should set the correct metadata", (t) => { (1 << HumidityControlMode.Off) | (1 << HumidityControlMode.Auto), ]), ); - const cc = new HumidityControlModeCCSupportedReport(host, { + const cc = new HumidityControlModeCCSupportedReport({ nodeId, data: ccData, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts index b9306f6e4f84..0242cd68f4f1 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts @@ -20,7 +20,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new HumidityControlOperatingStateCCGet(host, { + const cc = new HumidityControlOperatingStateCCGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -38,7 +38,7 @@ test("the Report command should be deserialized correctly", (t) => { HumidityControlOperatingState.Humidifying, // state ]), ); - const cc = new HumidityControlOperatingStateCCReport(host, { + const cc = new HumidityControlOperatingStateCCReport({ nodeId: 1, data: ccData, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts index 3d51bc842047..4166dbda4fdc 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlSetpointCC.test.ts @@ -28,7 +28,7 @@ const host = createTestingHost(); const nodeId = 2; test("the Get command should serialize correctly", (t) => { - const cc = new HumidityControlSetpointCCGet(host, { + const cc = new HumidityControlSetpointCCGet({ nodeId: nodeId, setpointType: HumidityControlSetpointType.Humidifier, }); @@ -42,7 +42,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly", (t) => { - const cc = new HumidityControlSetpointCCSet(host, { + const cc = new HumidityControlSetpointCCSet({ nodeId: nodeId, setpointType: HumidityControlSetpointType.Humidifier, value: 57, @@ -70,7 +70,7 @@ test("the Report command should be deserialized correctly", (t) => { encodeFloatWithScale(12, 1), ]), ); - const cc = new HumidityControlSetpointCCReport(host, { + const cc = new HumidityControlSetpointCCReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -96,7 +96,7 @@ test("the Report command should set the correct value", (t) => { encodeFloatWithScale(12, 1), ]), ); - const report = new HumidityControlSetpointCCReport(host, { + const report = new HumidityControlSetpointCCReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -128,7 +128,7 @@ test("the Report command should set the correct metadata", (t) => { encodeFloatWithScale(12, 1), ]), ); - const report = new HumidityControlSetpointCCReport(host, { + const report = new HumidityControlSetpointCCReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -149,7 +149,7 @@ test("the Report command should set the correct metadata", (t) => { }); test("the SupportedGet command should serialize correctly", (t) => { - const cc = new HumidityControlSetpointCCSupportedGet(host, { + const cc = new HumidityControlSetpointCCSupportedGet({ nodeId: nodeId, }); const expected = buildCCBuffer( @@ -168,7 +168,7 @@ test("the SupportedReport command should be deserialized correctly", (t) => { | (1 << HumidityControlSetpointType.Auto), ]), ); - const cc = new HumidityControlSetpointCCSupportedReport(host, { + const cc = new HumidityControlSetpointCCSupportedReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -188,7 +188,7 @@ test("the SupportedReport command should set the correct value", (t) => { | (1 << HumidityControlSetpointType.Auto), ]), ); - const report = new HumidityControlSetpointCCSupportedReport(host, { + const report = new HumidityControlSetpointCCSupportedReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -206,7 +206,7 @@ test("the SupportedReport command should set the correct value", (t) => { }); test("the ScaleSupportedGet command should serialize correctly", (t) => { - const cc = new HumidityControlSetpointCCScaleSupportedGet(host, { + const cc = new HumidityControlSetpointCCScaleSupportedGet({ nodeId: nodeId, setpointType: HumidityControlSetpointType.Auto, }); @@ -226,7 +226,7 @@ test("the ScaleSupportedReport command should be deserialized correctly", (t) => 0b11, // percent + absolute ]), ); - const cc = new HumidityControlSetpointCCScaleSupportedReport(host, { + const cc = new HumidityControlSetpointCCScaleSupportedReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -245,7 +245,7 @@ test("the ScaleSupportedReport command should be deserialized correctly", (t) => }); test("the CapabilitiesGet command should serialize correctly", (t) => { - const cc = new HumidityControlSetpointCCCapabilitiesGet(host, { + const cc = new HumidityControlSetpointCCCapabilitiesGet({ nodeId: nodeId, setpointType: HumidityControlSetpointType.Auto, }); @@ -269,7 +269,7 @@ test("the CapabilitiesReport command should be deserialized correctly", (t) => { encodeFloatWithScale(90, 1), ]), ); - const cc = new HumidityControlSetpointCCCapabilitiesReport(host, { + const cc = new HumidityControlSetpointCCCapabilitiesReport({ nodeId: nodeId, data: ccData, context: {} as any, @@ -293,7 +293,7 @@ test("the CapabilitiesReport command should set the correct metadata", (t) => { encodeFloatWithScale(90, 1), ]), ); - const report = new HumidityControlSetpointCCCapabilitiesReport(host, { + const report = new HumidityControlSetpointCCCapabilitiesReport({ nodeId: nodeId, data: ccData, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts b/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts index a289db4fd407..05a6cd7f2f03 100644 --- a/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/IndicatorCC.test.ts @@ -24,7 +24,7 @@ function buildCCBuffer(payload: Buffer): Buffer { const host = createTestingHost(); test("the Get command (V1) should serialize correctly", (t) => { - const cc = new IndicatorCCGet(host, { nodeId: 1 }); + const cc = new IndicatorCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ IndicatorCommand.Get, // CC Command @@ -34,7 +34,7 @@ test("the Get command (V1) should serialize correctly", (t) => { }); test("the Get command (V2) should serialize correctly", (t) => { - const cc = new IndicatorCCGet(host, { + const cc = new IndicatorCCGet({ nodeId: 1, indicatorId: 5, }); @@ -48,7 +48,7 @@ test("the Get command (V2) should serialize correctly", (t) => { }); test("the Set command (v1) should serialize correctly", (t) => { - const cc = new IndicatorCCSet(host, { + const cc = new IndicatorCCSet({ nodeId: 2, value: 23, }); @@ -62,7 +62,7 @@ test("the Set command (v1) should serialize correctly", (t) => { }); test("the Set command (v2) should serialize correctly", (t) => { - const cc = new IndicatorCCSet(host, { + const cc = new IndicatorCCSet({ nodeId: 2, values: [ { @@ -100,7 +100,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 55, // value ]), ); - const cc = new IndicatorCCReport(host, { + const cc = new IndicatorCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -124,7 +124,7 @@ test("the Report command (v2) should be deserialized correctly", (t) => { 1, // value ]), ); - const cc = new IndicatorCCReport(host, { + const cc = new IndicatorCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -151,7 +151,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new IndicatorCC(host, { + const cc: any = new IndicatorCC({ nodeId: 1, data: serializedCC, context: {} as any, @@ -163,7 +163,6 @@ test("the value IDs should be translated properly", (t) => { const valueId = IndicatorCCValues.valueV2(0x43, 2).endpoint(2); const testNode = createTestNode(host, { id: 2 }); const ccInstance = CommandClass.createInstanceUnchecked( - host, testNode, CommandClasses.Indicator, )!; diff --git a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts index 65670b823004..123641b29e2f 100644 --- a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts @@ -21,7 +21,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new LanguageCCGet(host, { nodeId: 1 }); + const cc = new LanguageCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ LanguageCommand.Get, // CC Command @@ -31,7 +31,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly (w/o country code)", (t) => { - const cc = new LanguageCCSet(host, { + const cc = new LanguageCCSet({ nodeId: 2, language: "deu", }); @@ -48,7 +48,7 @@ test("the Set command should serialize correctly (w/o country code)", (t) => { }); test("the Set command should serialize correctly (w/ country code)", (t) => { - const cc = new LanguageCCSet(host, { + const cc = new LanguageCCSet({ nodeId: 2, language: "deu", country: "DE", @@ -78,7 +78,7 @@ test("the Report command should be deserialized correctly (w/o country code)", ( 0x75, ]), ); - const cc = new LanguageCCReport(host, { + const cc = new LanguageCCReport({ nodeId: 4, data: ccData, context: {} as any, @@ -101,7 +101,7 @@ test("the Report command should be deserialized correctly (w/ country code)", (t 0x45, ]), ); - const cc = new LanguageCCReport(host, { + const cc = new LanguageCCReport({ nodeId: 4, data: ccData, context: {} as any, @@ -115,7 +115,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new LanguageCC(host, { + const cc: any = new LanguageCC({ nodeId: 4, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts index 9b81d16e3b1f..ecb39a3c1f84 100644 --- a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts @@ -19,7 +19,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new ManufacturerSpecificCCGet(host, { nodeId: 1 }); + const cc = new ManufacturerSpecificCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ ManufacturerSpecificCommand.Get, // CC Command @@ -40,7 +40,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0x06, ]), ); - const cc = new ManufacturerSpecificCCReport(host, { + const cc = new ManufacturerSpecificCCReport({ nodeId: 2, data: ccData, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts index 4d4e960ebdac..a335be76bad0 100644 --- a/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MeterCC.test.ts @@ -31,7 +31,7 @@ const host = createTestingHost(); const node2 = createTestNode(host, { id: 2 }); test("the Get command (V1) should serialize correctly", (t) => { - const cc = new MeterCCGet(host, { nodeId: 1 }); + const cc = new MeterCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ MeterCommand.Get, // CC Command @@ -47,7 +47,7 @@ test("the Get command (V1) should serialize correctly", (t) => { }); test("the Get command (V2) should serialize correctly", (t) => { - const cc = new MeterCCGet(host, { nodeId: 1, scale: 0x03 }); + const cc = new MeterCCGet({ nodeId: 1, scale: 0x03 }); const expected = buildCCBuffer( Buffer.from([ MeterCommand.Get, // CC Command @@ -64,7 +64,7 @@ test("the Get command (V2) should serialize correctly", (t) => { }); test("the Get command (V3) should serialize correctly", (t) => { - const cc = new MeterCCGet(host, { nodeId: 1, scale: 0x06 }); + const cc = new MeterCCGet({ nodeId: 1, scale: 0x06 }); const expected = buildCCBuffer( Buffer.from([ MeterCommand.Get, // CC Command @@ -81,7 +81,7 @@ test("the Get command (V3) should serialize correctly", (t) => { }); test("the Get command (V4) should serialize correctly", (t) => { - const cc = new MeterCCGet(host, { nodeId: 1, scale: 0x0f }); + const cc = new MeterCCGet({ nodeId: 1, scale: 0x0f }); const expected = buildCCBuffer( Buffer.from([ MeterCommand.Get, // CC Command @@ -99,7 +99,7 @@ test("the Get command (V4) should serialize correctly", (t) => { }); test("the SupportedGet command should serialize correctly", (t) => { - const cc = new MeterCCSupportedGet(host, { nodeId: 1 }); + const cc = new MeterCCSupportedGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ MeterCommand.SupportedGet, // CC Command @@ -109,7 +109,7 @@ test("the SupportedGet command should serialize correctly", (t) => { }); test("the Reset command (V2) should serialize correctly", (t) => { - const cc = new MeterCCReset(host, { nodeId: 1 }); + const cc = new MeterCCReset({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ MeterCommand.Reset, // CC Command @@ -119,7 +119,7 @@ test("the Reset command (V2) should serialize correctly", (t) => { }); test("the Reset command (V6) should serialize correctly", (t) => { - const cc = new MeterCCReset(host, { + const cc = new MeterCCReset({ nodeId: 1, type: 7, scale: 3, @@ -146,7 +146,7 @@ test("the Report command (V1) should be deserialized correctly", (t) => { 55, // value ]), ); - const cc = new MeterCCReport(host, { + const cc = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -171,7 +171,7 @@ test("the Report command (V2) should be deserialized correctly (no time delta)", 0, ]), ); - const cc = new MeterCCReport(host, { + const cc = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -197,7 +197,7 @@ test("the Report command (V2) should be deserialized correctly (with time delta) 54, // previous value ]), ); - const cc = new MeterCCReport(host, { + const cc = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -223,7 +223,7 @@ test("the Report command (V3) should be deserialized correctly", (t) => { 54, // previous value ]), ); - const cc = new MeterCCReport(host, { + const cc = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -245,7 +245,7 @@ test("the Report command (V4) should be deserialized correctly", (t) => { 0b01, // Scale2 ]), ); - const cc = new MeterCCReport(host, { + const cc = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -268,7 +268,7 @@ test("the Report command should validate that a known meter type is given", (t) ]), ); - const report = new MeterCCReport(host, { + const report = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -294,7 +294,7 @@ test("the Report command should validate that a known meter scale is given", (t) ]), ); - const report = new MeterCCReport(host, { + const report = new MeterCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -327,7 +327,7 @@ test("the SupportedReport command (V2/V3) should be deserialized correctly", (t) 0b01101110, // supported scales ]), ); - const cc = new MeterCCSupportedReport(host, { + const cc = new MeterCCSupportedReport({ nodeId: 1, data: ccData, context: {} as any, @@ -350,7 +350,7 @@ test("the SupportedReport command (V4/V5) should be deserialized correctly", (t) 1, ]), ); - const cc = new MeterCCSupportedReport(host, { + const cc = new MeterCCSupportedReport({ nodeId: 1, data: ccData, context: {} as any, @@ -373,7 +373,7 @@ test("the SupportedReport command (V4/V5) should be deserialized correctly", (t) // 1, // ]), // ); -// const cc = new MeterCCSupportedReport(host, { +// const cc = new MeterCCSupportedReport({ // nodeId: 1, // data: ccData, // }); @@ -388,7 +388,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new MeterCC(host, { + const cc: any = new MeterCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts index 89d5907970a5..c30089a19a20 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts @@ -23,7 +23,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the SupportedGroupingsGet command should serialize correctly", (t) => { - const cc = new MultiChannelAssociationCCSupportedGroupingsGet(host, { + const cc = new MultiChannelAssociationCCSupportedGroupingsGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -41,7 +41,7 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t 7, // # of groups ]), ); - const cc = new MultiChannelAssociationCCSupportedGroupingsReport(host, { + const cc = new MultiChannelAssociationCCSupportedGroupingsReport({ nodeId: 4, data: ccData, context: {} as any, @@ -51,7 +51,7 @@ test("the SupportedGroupingsReport command should be deserialized correctly", (t }); test("the Set command should serialize correctly (node IDs only)", (t) => { - const cc = new MultiChannelAssociationCCSet(host, { + const cc = new MultiChannelAssociationCCSet({ nodeId: 2, groupId: 5, nodeIds: [1, 2, 5], @@ -70,7 +70,7 @@ test("the Set command should serialize correctly (node IDs only)", (t) => { }); test("the Set command should serialize correctly (endpoint addresses only)", (t) => { - const cc = new MultiChannelAssociationCCSet(host, { + const cc = new MultiChannelAssociationCCSet({ nodeId: 2, groupId: 5, endpoints: [ @@ -101,7 +101,7 @@ test("the Set command should serialize correctly (endpoint addresses only)", (t) }); test("the Set command should serialize correctly (both options)", (t) => { - const cc = new MultiChannelAssociationCCSet(host, { + const cc = new MultiChannelAssociationCCSet({ nodeId: 2, groupId: 5, nodeIds: [1, 2, 3], @@ -137,7 +137,7 @@ test("the Set command should serialize correctly (both options)", (t) => { }); test("the Get command should serialize correctly", (t) => { - const cc = new MultiChannelAssociationCCGet(host, { + const cc = new MultiChannelAssociationCCGet({ nodeId: 1, groupId: 9, }); @@ -163,7 +163,7 @@ test("the Report command should be deserialized correctly (node IDs only)", (t) 5, ]), ); - const cc = new MultiChannelAssociationCCReport(host, { + const cc = new MultiChannelAssociationCCReport({ nodeId: 4, data: ccData, context: {} as any, @@ -192,7 +192,7 @@ test("the Report command should be deserialized correctly (endpoint addresses on 0b11010111, ]), ); - const cc = new MultiChannelAssociationCCReport(host, { + const cc = new MultiChannelAssociationCCReport({ nodeId: 4, data: ccData, context: {} as any, @@ -230,7 +230,7 @@ test("the Report command should be deserialized correctly (both options)", (t) = 0b11010111, ]), ); - const cc = new MultiChannelAssociationCCReport(host, { + const cc = new MultiChannelAssociationCCReport({ nodeId: 4, data: ccData, context: {} as any, @@ -250,7 +250,7 @@ test("the Report command should be deserialized correctly (both options)", (t) = }); test("the Remove command should serialize correctly (node IDs only)", (t) => { - const cc = new MultiChannelAssociationCCRemove(host, { + const cc = new MultiChannelAssociationCCRemove({ nodeId: 2, groupId: 5, nodeIds: [1, 2, 5], @@ -269,7 +269,7 @@ test("the Remove command should serialize correctly (node IDs only)", (t) => { }); test("the Remove command should serialize correctly (endpoint addresses only)", (t) => { - const cc = new MultiChannelAssociationCCRemove(host, { + const cc = new MultiChannelAssociationCCRemove({ nodeId: 2, groupId: 5, endpoints: [ @@ -300,7 +300,7 @@ test("the Remove command should serialize correctly (endpoint addresses only)", }); test("the Remove command should serialize correctly (both options)", (t) => { - const cc = new MultiChannelAssociationCCRemove(host, { + const cc = new MultiChannelAssociationCCRemove({ nodeId: 2, groupId: 5, nodeIds: [1, 2, 3], @@ -336,7 +336,7 @@ test("the Remove command should serialize correctly (both options)", (t) => { }); test("the Remove command should serialize correctly (both empty)", (t) => { - const cc = new MultiChannelAssociationCCRemove(host, { + const cc = new MultiChannelAssociationCCRemove({ nodeId: 2, groupId: 5, }); @@ -354,7 +354,7 @@ test("the Remove command should serialize correctly (both empty)", (t) => { // 1, // Buffer.from([255]), // not a valid command // ); -// const cc: any = new MultiChannelAssociationCC(host, { +// const cc: any = new MultiChannelAssociationCC({ // data: serializedCC, // }); // t.is(cc.constructor, MultiChannelAssociationCC); diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts index 078204441cfa..71fe1285885d 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts @@ -31,7 +31,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("is an encapsulating CommandClass", (t) => { - let cc: CommandClass = new BasicCCSet(host, { + let cc: CommandClass = new BasicCCSet({ nodeId: 1, targetValue: 50, }); @@ -40,7 +40,7 @@ test("is an encapsulating CommandClass", (t) => { }); test("the EndPointGet command should serialize correctly", (t) => { - const cc = new MultiChannelCCEndPointGet(host, { nodeId: 1 }); + const cc = new MultiChannelCCEndPointGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ MultiChannelCommand.EndPointGet, // CC Command @@ -50,7 +50,7 @@ test("the EndPointGet command should serialize correctly", (t) => { }); test("the CapabilityGet command should serialize correctly", (t) => { - const cc = new MultiChannelCCCapabilityGet(host, { + const cc = new MultiChannelCCCapabilityGet({ nodeId: 2, requestedEndpoint: 7, }); @@ -64,7 +64,7 @@ test("the CapabilityGet command should serialize correctly", (t) => { }); test("the EndPointFind command should serialize correctly", (t) => { - const cc = new MultiChannelCCEndPointFind(host, { + const cc = new MultiChannelCCEndPointFind({ nodeId: 2, genericClass: 0x01, specificClass: 0x02, @@ -80,7 +80,7 @@ test("the EndPointFind command should serialize correctly", (t) => { }); test("the CommandEncapsulation command should serialize correctly", (t) => { - let cc: CommandClass = new BasicCCSet(host, { + let cc: CommandClass = new BasicCCSet({ nodeId: 2, targetValue: 5, endpoint: 7, @@ -100,7 +100,7 @@ test("the CommandEncapsulation command should serialize correctly", (t) => { }); test("the AggregatedMembersGet command should serialize correctly", (t) => { - const cc = new MultiChannelCCAggregatedMembersGet(host, { + const cc = new MultiChannelCCAggregatedMembersGet({ nodeId: 2, requestedEndpoint: 6, }); @@ -115,14 +115,14 @@ test("the AggregatedMembersGet command should serialize correctly", (t) => { test("the CommandEncapsulation command should also accept V1CommandEncapsulation as a response", (t) => { // GH#938 - const sent = new MultiChannelCCCommandEncapsulation(host, { + const sent = new MultiChannelCCCommandEncapsulation({ nodeId: 2, destination: 2, - encapsulated: new BasicCCGet(host, { nodeId: 2 }), + encapsulated: new BasicCCGet({ nodeId: 2 }), }); - const received = new MultiChannelCCV1CommandEncapsulation(host, { + const received = new MultiChannelCCV1CommandEncapsulation({ nodeId: 2, - encapsulated: new BasicCCReport(host, { + encapsulated: new BasicCCReport({ nodeId: 2, currentValue: 50, }), @@ -141,7 +141,7 @@ test("the CommandEncapsulation command should also accept V1CommandEncapsulation // 1, // duration // ]), // ); -// const cc = new MultiChannelCCReport(host, { data: ccData }); +// const cc = new MultiChannelCCReport({ data: ccData }); // t.is(cc.currentValue, 55); // t.is(cc.targetValue, 66); @@ -153,7 +153,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new MultiChannelCC(host, { + const cc: any = new MultiChannelCC({ nodeId: 1, data: serializedCC, context: {} as any, @@ -190,7 +190,7 @@ test("deserializing an unsupported command should return an unspecified version test("MultiChannelCC/BasicCCGet should expect a response", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new BasicCCGet(host, { + new BasicCCGet({ nodeId: 2, endpoint: 2, }), @@ -201,7 +201,7 @@ test("MultiChannelCC/BasicCCGet should expect a response", (t) => { test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new BasicCCGet(host, { + new BasicCCGet({ nodeId: 2, endpoint: 2, }), @@ -214,7 +214,7 @@ test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => { test("MultiChannelCC/BasicCCSet should expect NO response", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new BasicCCSet(host, { + new BasicCCSet({ nodeId: 2, endpoint: 2, targetValue: 7, @@ -226,14 +226,14 @@ test("MultiChannelCC/BasicCCSet should expect NO response", (t) => { test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCReport = expected", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new BasicCCGet(host, { + new BasicCCGet({ nodeId: 2, endpoint: 2, }), ); const ccResponse = MultiChannelCC.encapsulate( host, - new BasicCCReport(host, { + new BasicCCReport({ nodeId: ccRequest.nodeId, currentValue: 7, }), @@ -246,14 +246,14 @@ test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCReport = expected", (t) test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCGet = unexpected", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new BasicCCGet(host, { + new BasicCCGet({ nodeId: 2, endpoint: 2, }), ); const ccResponse = MultiChannelCC.encapsulate( host, - new BasicCCGet(host, { + new BasicCCGet({ nodeId: ccRequest.nodeId, endpoint: 2, }), @@ -266,13 +266,13 @@ test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCGet = unexpected", (t) test("MultiChannelCC/BasicCCGet => MultiCommandCC/BasicCCReport = unexpected", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new BasicCCGet(host, { + new BasicCCGet({ nodeId: 2, endpoint: 2, }), ); const ccResponse = MultiCommandCC.encapsulate(host, [ - new BasicCCReport(host, { + new BasicCCReport({ nodeId: ccRequest.nodeId, currentValue: 7, }), diff --git a/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts index 660e6d9abfc2..5d7fdf794583 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts @@ -10,7 +10,7 @@ import test from "ava"; const host = createTestingHost(); test("is a multi-encapsulating CommandClass", (t) => { - let cc: CommandClass = new BasicCCSet(host, { + let cc: CommandClass = new BasicCCSet({ nodeId: 1, targetValue: 50, }); diff --git a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts index 9d2a54aafe15..9abaca1e6c75 100644 --- a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts @@ -24,7 +24,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new MultilevelSwitchCCGet(host, { nodeId: 1 }); + const cc = new MultilevelSwitchCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ MultilevelSwitchCommand.Get, // CC Command @@ -34,7 +34,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly (no duration)", (t) => { - const cc = new MultilevelSwitchCCSet(host, { + const cc = new MultilevelSwitchCCSet({ nodeId: 2, targetValue: 55, }); @@ -55,7 +55,7 @@ test("the Set command should serialize correctly (no duration)", (t) => { }); test("the Set command (V2) should serialize correctly", (t) => { - const cc = new MultilevelSwitchCCSet(host, { + const cc = new MultilevelSwitchCCSet({ nodeId: 2, targetValue: 55, duration: new Duration(2, "minutes"), @@ -83,7 +83,7 @@ test("the Report command (V1) should be deserialized correctly", (t) => { 55, // current value ]), ); - const cc = new MultilevelSwitchCCReport(host, { + const cc = new MultilevelSwitchCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -103,7 +103,7 @@ test("the Report command (v4) should be deserialized correctly", (t) => { 1, // duration ]), ); - const cc = new MultilevelSwitchCCReport(host, { + const cc = new MultilevelSwitchCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -116,7 +116,7 @@ test("the Report command (v4) should be deserialized correctly", (t) => { }); test("the StopLevelChange command should serialize correctly", (t) => { - const cc = new MultilevelSwitchCCStopLevelChange(host, { + const cc = new MultilevelSwitchCCStopLevelChange({ nodeId: 1, }); const expected = buildCCBuffer( @@ -128,7 +128,7 @@ test("the StopLevelChange command should serialize correctly", (t) => { }); test("the StartLevelChange command (V2) should serialize correctly (down, ignore start level, with duration)", (t) => { - const cc = new MultilevelSwitchCCStartLevelChange(host, { + const cc = new MultilevelSwitchCCStartLevelChange({ nodeId: 2, direction: "down", ignoreStartLevel: true, @@ -153,7 +153,7 @@ test("the StartLevelChange command (V2) should serialize correctly (down, ignore }); test("the SupportedGet command should serialize correctly", (t) => { - const cc = new MultilevelSwitchCCSupportedGet(host, { + const cc = new MultilevelSwitchCCSupportedGet({ nodeId: 1, }); const expected = buildCCBuffer( @@ -168,7 +168,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new MultilevelSwitchCC(host, { + const cc: any = new MultilevelSwitchCC({ nodeId: 2, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts b/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts index d64dbae3f886..6e989b490328 100644 --- a/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts @@ -15,7 +15,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the CC should serialize correctly", (t) => { - const cc = new NoOperationCC(host, { nodeId: 1 }); + const cc = new NoOperationCC({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([]), // No command! ); @@ -27,6 +27,6 @@ test("the CC should be deserialized correctly", (t) => { Buffer.from([]), // No command! ); t.notThrows(() => - new NoOperationCC(host, { nodeId: 2, data: ccData, context: {} as any }) + new NoOperationCC({ nodeId: 2, data: ccData, context: {} as any }) ); }); diff --git a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts index 84e196f00247..0505807c0410 100644 --- a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts @@ -22,7 +22,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new PowerlevelCCGet(host, { nodeId: 1 }); + const cc = new PowerlevelCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ PowerlevelCommand.Get, // CC Command @@ -32,7 +32,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set NormalPower command should serialize correctly", (t) => { - const cc = new PowerlevelCCSet(host, { + const cc = new PowerlevelCCSet({ nodeId: 2, powerlevel: Powerlevel["Normal Power"], }); @@ -47,7 +47,7 @@ test("the Set NormalPower command should serialize correctly", (t) => { }); test("the Set NormalPower command with timeout should serialize correctly", (t) => { - const cc = new PowerlevelCCSet(host, { + const cc = new PowerlevelCCSet({ nodeId: 2, powerlevel: Powerlevel["Normal Power"], timeout: 50, @@ -63,7 +63,7 @@ test("the Set NormalPower command with timeout should serialize correctly", (t) }); test("the Set Custom power command should serialize correctly", (t) => { - const cc = new PowerlevelCCSet(host, { + const cc = new PowerlevelCCSet({ nodeId: 2, powerlevel: Powerlevel["-1 dBm"], timeout: 50, @@ -86,7 +86,7 @@ test("the Report command should be deserialized correctly (NormalPower)", (t) => 50, // timeout (ignored because NormalPower) ]), ); - const cc = new PowerlevelCCReport(host, { + const cc = new PowerlevelCCReport({ nodeId: 5, data: ccData, context: {} as any, @@ -104,7 +104,7 @@ test("the Report command should be deserialized correctly (custom power)", (t) = 50, // timeout (ignored because NormalPower) ]), ); - const cc = new PowerlevelCCReport(host, { + const cc = new PowerlevelCCReport({ nodeId: 5, data: ccData, context: {} as any, @@ -118,7 +118,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new PowerlevelCC(host, { + const cc: any = new PowerlevelCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts index 816011639a55..670ead3b48bb 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts @@ -19,7 +19,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Set command (without Duration) should serialize correctly", (t) => { - const cc = new SceneActivationCCSet(host, { + const cc = new SceneActivationCCSet({ nodeId: 2, sceneId: 55, }); @@ -34,7 +34,7 @@ test("the Set command (without Duration) should serialize correctly", (t) => { }); test("the Set command (with Duration) should serialize correctly", (t) => { - const cc = new SceneActivationCCSet(host, { + const cc = new SceneActivationCCSet({ nodeId: 2, sceneId: 56, dimmingDuration: new Duration(1, "minutes"), @@ -57,7 +57,7 @@ test("the Set command should be deserialized correctly", (t) => { 0x00, // 0 seconds ]), ); - const cc = new SceneActivationCCSet(host, { + const cc = new SceneActivationCCSet({ nodeId: 2, data: ccData, context: {} as any, @@ -71,7 +71,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new SceneActivationCC(host, { + const cc: any = new SceneActivationCC({ nodeId: 2, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts index e07fbbe8552d..7a017569ec06 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts @@ -21,7 +21,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new SceneActuatorConfigurationCCGet(host, { + const cc = new SceneActuatorConfigurationCCGet({ nodeId: 2, sceneId: 1, }); @@ -35,7 +35,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly with level", (t) => { - const cc = new SceneActuatorConfigurationCCSet(host, { + const cc = new SceneActuatorConfigurationCCSet({ nodeId: 2, sceneId: 2, level: 0x00, @@ -54,7 +54,7 @@ test("the Set command should serialize correctly with level", (t) => { }); test("the Set command should serialize correctly with undefined level", (t) => { - const cc = new SceneActuatorConfigurationCCSet(host, { + const cc = new SceneActuatorConfigurationCCSet({ nodeId: 2, sceneId: 2, // level: undefined, @@ -81,7 +81,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0x05, // dimmingDuration ]), ); - const cc = new SceneActuatorConfigurationCCReport(host, { + const cc = new SceneActuatorConfigurationCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -96,7 +96,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new SceneActuatorConfigurationCC(host, { + const cc: any = new SceneActuatorConfigurationCC({ nodeId: 2, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts index 43bd787b9846..4bef4a2f4dcf 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts @@ -34,7 +34,7 @@ function prepareTest(): { host: TestingHost; node2: IZWaveNode } { test("the Get command should serialize correctly", (t) => { const { host } = prepareTest(); - const cc = new SceneControllerConfigurationCCGet(host, { + const cc = new SceneControllerConfigurationCCGet({ nodeId: 2, groupId: 1, }); @@ -51,7 +51,7 @@ test.skip("the Get command should throw if GroupId > groupCount", (t) => { const { host } = prepareTest(); // TODO: This check now lives on the CC API t.notThrows(() => { - new SceneControllerConfigurationCCGet(host, { + new SceneControllerConfigurationCCGet({ nodeId: 2, groupId: fakeGroupCount + 1, }); @@ -60,7 +60,7 @@ test.skip("the Get command should throw if GroupId > groupCount", (t) => { test("the Set command should serialize correctly", (t) => { const { host } = prepareTest(); - const cc = new SceneControllerConfigurationCCSet(host, { + const cc = new SceneControllerConfigurationCCSet({ nodeId: 2, groupId: 3, sceneId: 240, @@ -79,7 +79,7 @@ test("the Set command should serialize correctly", (t) => { test("the Set command should serialize correctly with undefined duration", (t) => { const { host } = prepareTest(); - const cc = new SceneControllerConfigurationCCSet(host, { + const cc = new SceneControllerConfigurationCCSet({ nodeId: 2, groupId: 3, sceneId: 240, @@ -101,7 +101,7 @@ test.skip("the Set command should throw if GroupId > groupCount", (t) => { // TODO: This check now lives on the CC API t.notThrows( () => - new SceneControllerConfigurationCCSet(host, { + new SceneControllerConfigurationCCSet({ nodeId: 2, groupId: fakeGroupCount + 1, sceneId: 240, @@ -120,7 +120,7 @@ test("the Report command (v1) should be deserialized correctly", (t) => { 0x05, // dimming duration ]), ); - const cc = new SceneControllerConfigurationCCReport(host, { + const cc = new SceneControllerConfigurationCCReport({ nodeId: 2, data: ccData, context: {} as any, @@ -136,7 +136,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new SceneControllerConfigurationCC(host, { + const cc: any = new SceneControllerConfigurationCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts b/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts index 2e0be00a4c6c..b382c7c9e1ce 100644 --- a/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts @@ -8,7 +8,7 @@ const host = createTestingHost(); test("SupervisionCCGet should expect a response", (t) => { const ccRequest = SupervisionCC.encapsulate( host, - new BasicCCSet(host, { + new BasicCCSet({ nodeId: 2, targetValue: 5, }), @@ -19,12 +19,12 @@ test("SupervisionCCGet should expect a response", (t) => { test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = expected", (t) => { const ccRequest = SupervisionCC.encapsulate( host, - new BasicCCSet(host, { + new BasicCCSet({ nodeId: 2, targetValue: 5, }), ); - const ccResponse = new SupervisionCCReport(host, { + const ccResponse = new SupervisionCCReport({ nodeId: 2, moreUpdatesFollow: false, sessionId: ccRequest.sessionId, @@ -37,12 +37,12 @@ test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = exp test("SupervisionCC/BasicCCSet => SupervisionCCReport (wrong session ID) = unexpected", (t) => { const ccRequest = SupervisionCC.encapsulate( host, - new BasicCCSet(host, { + new BasicCCSet({ nodeId: 2, targetValue: 5, }), ); - const ccResponse = new SupervisionCCReport(host, { + const ccResponse = new SupervisionCCReport({ nodeId: 2, moreUpdatesFollow: false, sessionId: ccRequest.sessionId + 1, diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts index f03eac134009..47f13f581a62 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts @@ -21,7 +21,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new ThermostatFanModeCCGet(host, { nodeId: 5 }); + const cc = new ThermostatFanModeCCGet({ nodeId: 5 }); const expected = buildCCBuffer( Buffer.from([ ThermostatFanModeCommand.Get, // CC Command @@ -31,7 +31,7 @@ test("the Get command should serialize correctly", (t) => { }); test("the Set command should serialize correctly (off = false)", (t) => { - const cc = new ThermostatFanModeCCSet(host, { + const cc = new ThermostatFanModeCCSet({ nodeId: 5, mode: ThermostatFanMode["Auto medium"], off: false, @@ -46,7 +46,7 @@ test("the Set command should serialize correctly (off = false)", (t) => { }); test("the Set command should serialize correctly (off = true)", (t) => { - const cc = new ThermostatFanModeCCSet(host, { + const cc = new ThermostatFanModeCCSet({ nodeId: 5, mode: ThermostatFanMode["Auto medium"], off: true, @@ -67,7 +67,7 @@ test("the Report command should be deserialized correctly", (t) => { 0b1000_0010, // Off bit set to 1 and Auto high mode ]), ); - const cc = new ThermostatFanModeCCReport(host, { + const cc = new ThermostatFanModeCCReport({ nodeId: 5, data: ccData, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts index 4b17d6c55f25..a8267806d3bd 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts @@ -21,7 +21,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the Get command should serialize correctly", (t) => { - const cc = new ThermostatFanStateCCGet(host, { nodeId: 1 }); + const cc = new ThermostatFanStateCCGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ ThermostatFanStateCommand.Get, // CC Command @@ -37,7 +37,7 @@ test("the Report command (v1 - v2) should be deserialized correctly", (t) => { ThermostatFanState["Idle / off"], // state ]), ); - const cc = new ThermostatFanStateCCReport(host, { + const cc = new ThermostatFanStateCCReport({ nodeId: 1, data: ccData, context: {} as any, @@ -50,7 +50,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new ThermostatFanStateCC(host, { + const cc: any = new ThermostatFanStateCC({ nodeId: 1, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts index c7837be7fe59..682b49f2ce30 100644 --- a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts @@ -22,7 +22,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("the TimeGet command should serialize correctly", (t) => { - const cc = new TimeCCTimeGet(host, { nodeId: 1 }); + const cc = new TimeCCTimeGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ TimeCommand.TimeGet, // CC Command @@ -40,7 +40,7 @@ test("the TimeReport command should be deserialized correctly", (t) => { 59, ]), ); - const cc = new TimeCCTimeReport(host, { + const cc = new TimeCCTimeReport({ nodeId: 8, data: ccData, context: {} as any, @@ -52,7 +52,7 @@ test("the TimeReport command should be deserialized correctly", (t) => { }); test("the DateGet command should serialize correctly", (t) => { - const cc = new TimeCCDateGet(host, { nodeId: 1 }); + const cc = new TimeCCDateGet({ nodeId: 1 }); const expected = buildCCBuffer( Buffer.from([ TimeCommand.DateGet, // CC Command @@ -71,7 +71,7 @@ test("the DateReport command should be deserialized correctly", (t) => { 17, ]), ); - const cc = new TimeCCDateReport(host, { + const cc = new TimeCCDateReport({ nodeId: 8, data: ccData, context: {} as any, @@ -86,7 +86,7 @@ test("deserializing an unsupported command should return an unspecified version const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); - const cc: any = new TimeCC(host, { + const cc: any = new TimeCC({ nodeId: 8, data: serializedCC, context: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts index 02be66cedd84..8fb60a603854 100644 --- a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts @@ -11,7 +11,7 @@ import { randomBytes } from "node:crypto"; const host = createTestingHost(); test("WakeUpCCNoMoreInformation should expect no response", (t) => { - const cc = new WakeUpCCNoMoreInformation(host, { + const cc = new WakeUpCCNoMoreInformation({ nodeId: 2, endpoint: 2, }); @@ -21,7 +21,7 @@ test("WakeUpCCNoMoreInformation should expect no response", (t) => { test("MultiChannelCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { const ccRequest = MultiChannelCC.encapsulate( host, - new WakeUpCCNoMoreInformation(host, { + new WakeUpCCNoMoreInformation({ nodeId: 2, endpoint: 2, }), @@ -45,7 +45,7 @@ test("SecurityCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { host, host.ownNodeId, securityManager as any, - new WakeUpCCNoMoreInformation(host, { + new WakeUpCCNoMoreInformation({ nodeId: 2, endpoint: 2, }), diff --git a/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts b/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts index c8339cc93297..f9764aec4e6f 100644 --- a/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts @@ -15,7 +15,7 @@ function buildCCBuffer(payload: Buffer): Buffer { } test("The Get command should serialize correctly", (t) => { - const cc = new ZWavePlusCCGet(host, { + const cc = new ZWavePlusCCGet({ nodeId: 1, }); const expected = buildCCBuffer( diff --git a/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts b/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts index 6ea72a92123b..456fbdbe0297 100644 --- a/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts +++ b/packages/zwave-js/src/lib/test/compat/binarySensorReportAnyUseFirstSupported.test.ts @@ -39,7 +39,7 @@ integrationTest( }; // Incorrectly respond with 0xFF as the sensor type - const cc = new BinarySensorCCReport(self.host, { + const cc = new BinarySensorCCReport({ nodeId: controller.ownNodeId, type: BinarySensorType.Any, value: true, diff --git a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts index ef03665fe741..502a31cfc079 100644 --- a/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts +++ b/packages/zwave-js/src/lib/test/compat/invalidCallbackFunctionTypes.test.ts @@ -44,7 +44,7 @@ integrationTest( customSetup: async (driver, controller, mockNode) => { // Incorrectly respond to AssignSUCReturnRoute with DeleteSUCReturnRoute const handleAssignSUCReturnRoute: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof AssignSUCReturnRouteRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -70,7 +70,6 @@ integrationTest( // Send the command to the node const node = controller.nodes.get(msg.getNodeId()!)!; const command = new ZWaveProtocolCCAssignSUCReturnRoute( - host, { nodeId: node.id, destinationNodeId: controller.ownNodeId, @@ -86,7 +85,7 @@ integrationTest( const ackPromise = controller.sendToNode(node, frame); // Notify the host that the message was sent - const res = new AssignSUCReturnRouteResponse(host, { + const res = new AssignSUCReturnRouteResponse({ wasExecuted: true, }); await controller.sendMessageToHost(res); @@ -114,15 +113,12 @@ integrationTest( if (expectCallback) { const cb = - new DeleteSUCReturnRouteRequestTransmitReport( - host, - { - callbackId: msg.callbackId!, - transmitStatus: ack - ? TransmitStatus.OK - : TransmitStatus.NoAck, - }, - ); + new DeleteSUCReturnRouteRequestTransmitReport({ + callbackId: msg.callbackId!, + transmitStatus: ack + ? TransmitStatus.OK + : TransmitStatus.NoAck, + }); await controller.sendMessageToHost(cb); } @@ -134,7 +130,7 @@ integrationTest( // Incorrectly respond to DeleteSUCReturnRoute with a message with function type 0 const handleDeleteSUCReturnRoute: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof DeleteSUCReturnRouteRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -160,7 +156,6 @@ integrationTest( // Send the command to the node const node = controller.nodes.get(msg.getNodeId()!)!; const command = new ZWaveProtocolCCAssignSUCReturnRoute( - host, { nodeId: node.id, destinationNodeId: controller.ownNodeId, @@ -176,7 +171,7 @@ integrationTest( const ackPromise = controller.sendToNode(node, frame); // Notify the host that the message was sent - const res = new DeleteSUCReturnRouteResponse(host, { + const res = new DeleteSUCReturnRouteResponse({ wasExecuted: true, }); await controller.sendMessageToHost(res); @@ -204,15 +199,12 @@ integrationTest( if (expectCallback) { const cb = - new DeleteSUCReturnRouteRequestTransmitReport( - host, - { - callbackId: msg.callbackId!, - transmitStatus: ack - ? TransmitStatus.OK - : TransmitStatus.NoAck, - }, - ); + new DeleteSUCReturnRouteRequestTransmitReport({ + callbackId: msg.callbackId!, + transmitStatus: ack + ? TransmitStatus.OK + : TransmitStatus.NoAck, + }); // @ts-expect-error 0 is not a valid function type cb.functionType = 0; diff --git a/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts b/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts index f6efbff44482..e0b90d97733b 100644 --- a/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts +++ b/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts @@ -31,7 +31,7 @@ integrationTest( async testBody(t, driver, node, mockController, mockNode) { // Send a report that should be mapped to notifications - const cc = new NotificationCCReport(mockNode.host, { + const cc = new NotificationCCReport({ nodeId: 2, alarmType: 18, alarmLevel: 2, diff --git a/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts b/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts index 4fa3c8a31040..f124ca57ec5e 100644 --- a/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts +++ b/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts @@ -31,7 +31,7 @@ integrationTest( await wait(500); // Send a NIF to trigger the re-interview - const cc = new ZWaveProtocolCCNodeInformationFrame(mockNode.host, { + const cc = new ZWaveProtocolCCNodeInformationFrame({ nodeId: mockNode.id, ...mockNode.capabilities, supportedCCs: [...mockNode.implementedCCs] diff --git a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts index b7f2867a0fd8..5ea59f9ac67a 100644 --- a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts @@ -79,7 +79,7 @@ integrationTest( const nonce = sm2Node.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -110,10 +110,10 @@ integrationTest( ); // The node sends an S2-encapsulated command, but with a lower security class than expected - let innerCC: CommandClass = new TimeCCTimeGet(mockNode.host, { + let innerCC: CommandClass = new TimeCCTimeGet({ nodeId: mockController.ownNodeId, }); - let cc = new Security2CCMessageEncapsulation(mockNode.host, { + let cc = new Security2CCMessageEncapsulation({ nodeId: mockController.ownNodeId, ownNodeId: mockNode.id, encapsulated: innerCC, @@ -153,11 +153,11 @@ integrationTest( mockNode.clearReceivedControllerFrames(); // Now the node queries our securely supported commands - innerCC = new Security2CCCommandsSupportedGet(mockNode.host, { + innerCC = new Security2CCCommandsSupportedGet({ nodeId: mockController.ownNodeId, }); - cc = new Security2CCMessageEncapsulation(mockNode.host, { + cc = new Security2CCMessageEncapsulation({ nodeId: mockController.ownNodeId, ownNodeId: mockNode.id, encapsulated: innerCC, diff --git a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts index 151ba627d994..32612ed3beab 100644 --- a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts @@ -75,7 +75,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -102,7 +102,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -128,8 +128,7 @@ integrationTest( // Send a secure command that should be handled let nodeToHost: CommandClass = Security2CC.encapsulate( - mockNode.host, - new BasicCCReport(mockNode.host, { + new BasicCCReport({ nodeId: mockController.ownNodeId, currentValue: 99, }), @@ -149,7 +148,7 @@ integrationTest( t.is(currentValue, 99); // Then send an unencypted one that should be discarded - nodeToHost = new BasicCCReport(mockNode.host, { + nodeToHost = new BasicCCReport({ nodeId: mockController.ownNodeId, currentValue: 1, }); diff --git a/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts b/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts index e8261ce512e5..4fd87ee2aa53 100644 --- a/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/encapsulationAnswerAsAsked.test.ts @@ -41,10 +41,10 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { // We know that the driver must respond to Z-Wave Plus Info Get // so we can use that to test - const zwpRequest = new ZWavePlusCCGet(mockNode.host, { + const zwpRequest = new ZWavePlusCCGet({ nodeId: mockController.ownNodeId, }); - const cc = CRC16CC.encapsulate(mockNode.host, zwpRequest); + const cc = CRC16CC.encapsulate(zwpRequest); await mockNode.sendToController(createMockZWaveRequestFrame(cc)); const { payload: response } = await mockNode.expectControllerFrame( @@ -88,10 +88,10 @@ integrationTest( testBody: async (t, driver, node, mockController, mockNode) => { // We know that the driver must respond to Z-Wave Plus Info Get // so we can use that to test - const zwpRequest = new ZWavePlusCCGet(mockNode.host, { + const zwpRequest = new ZWavePlusCCGet({ nodeId: mockController.ownNodeId, }); - const cc = MultiChannelCC.encapsulate(mockNode.host, zwpRequest); + const cc = MultiChannelCC.encapsulate(zwpRequest); cc.endpointIndex = 2; await mockNode.sendToController(createMockZWaveRequestFrame(cc)); @@ -138,12 +138,11 @@ integrationTest( }, testBody: async (t, driver, node, mockController, mockNode) => { - const basicReport = new BasicCCReport(mockNode.host, { + const basicReport = new BasicCCReport({ nodeId: mockController.ownNodeId, currentValue: 0, }); const cc = SupervisionCC.encapsulate( - mockNode.host, basicReport, driver.getNextSupervisionSessionId(mockNode.id), ); @@ -193,16 +192,15 @@ integrationTest( }, testBody: async (t, driver, node, mockController, mockNode) => { - const basicReport = new BasicCCReport(mockNode.host, { + const basicReport = new BasicCCReport({ nodeId: mockController.ownNodeId, currentValue: 0, }); const supervised = SupervisionCC.encapsulate( - mockNode.host, basicReport, driver.getNextSupervisionSessionId(mockNode.id), ); - const cc = MultiChannelCC.encapsulate(mockNode.host, supervised); + const cc = MultiChannelCC.encapsulate(supervised); cc.endpointIndex = 2; await mockNode.sendToController(createMockZWaveRequestFrame(cc)); diff --git a/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts b/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts index 5ccefaf26cd4..0e86c08eb1c1 100644 --- a/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/handleMultiCommandPayload.test.ts @@ -31,15 +31,15 @@ integrationTest("All CCs contained in a Multi Command CC are handled", { testBody: async (t, driver, node, mockController, mockNode) => { // This one requires a response - const zwpRequest = new ZWavePlusCCGet(mockNode.host, { + const zwpRequest = new ZWavePlusCCGet({ nodeId: mockController.ownNodeId, }); // This one updates a value - const scaSet = new SceneActivationCCSet(mockNode.host, { + const scaSet = new SceneActivationCCSet({ nodeId: mockController.ownNodeId, sceneId: 7, }); - const cc = MultiCommandCC.encapsulate(mockNode.host, [ + const cc = MultiCommandCC.encapsulate([ zwpRequest, scaSet, ]); diff --git a/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts b/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts index 6b71f4157d8d..45c276005024 100644 --- a/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/secureNodeSecureEndpoint.test.ts @@ -126,7 +126,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -153,7 +153,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -183,8 +183,7 @@ integrationTest( ); const cc = Security2CC.encapsulate( - self.host, - new Security2CCCommandsSupportedReport(self.host, { + new Security2CCCommandsSupportedReport({ nodeId: controller.ownNodeId, supportedCCs: isHighestGranted ? [...mockNode.implementedCCs.entries()] @@ -217,8 +216,7 @@ integrationTest( instanceof MultiChannelCCEndPointGet ) { const cc = Security2CC.encapsulate( - self.host, - new MultiChannelCCEndPointReport(self.host, { + new MultiChannelCCEndPointReport({ nodeId: controller.ownNodeId, countIsDynamic: false, identicalCapabilities: false, @@ -243,8 +241,7 @@ integrationTest( ) { const request = receivedCC.encapsulated; const cc = Security2CC.encapsulate( - self.host, - new MultiChannelCCEndPointFindReport(self.host, { + new MultiChannelCCEndPointFindReport({ nodeId: controller.ownNodeId, genericClass: request.genericClass, specificClass: request.specificClass, @@ -272,8 +269,7 @@ integrationTest( receivedCC.encapsulated.requestedEndpoint, )!; const cc = Security2CC.encapsulate( - self.host, - new MultiChannelCCCapabilityReport(self.host, { + new MultiChannelCCCapabilityReport({ nodeId: controller.ownNodeId, endpointIndex: endpoint.index, genericDeviceClass: diff --git a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts index 78494ae333e1..7506bfe66368 100644 --- a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts @@ -50,7 +50,7 @@ test.afterEach.always(async (t) => { test.serial("returns true when a non-partial CC is received", (t) => { const { driver } = t.context; - const cc = new BasicCCSet(driver, { nodeId: 2, targetValue: 50 }); + const cc = new BasicCCSet({ nodeId: 2, targetValue: 50 }); const msg = new ApplicationCommandRequest(driver, { command: cc, }); @@ -61,7 +61,7 @@ test.serial( "returns true when a partial CC is received that expects no more reports", (t) => { const { driver } = t.context; - const cc = new AssociationCCReport(driver, { + const cc = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -86,7 +86,7 @@ test.serial( "returns false when a partial CC is received that expects more reports", (t) => { const { driver } = t.context; - const cc = new AssociationCCReport(driver, { + const cc = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -111,7 +111,7 @@ test.serial( "returns true when the final partial CC is received and merges its data", (t) => { const { driver } = t.context; - const cc1 = new AssociationCCReport(driver, { + const cc1 = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -125,7 +125,7 @@ test.serial( ]), context: {} as any, }); - const cc2 = new AssociationCCReport(driver, { + const cc2 = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -158,9 +158,9 @@ test.serial( test.serial("does not crash when receiving a Multi Command CC", (t) => { const { driver } = t.context; - const cc1 = new BasicCCSet(driver, { nodeId: 2, targetValue: 25 }); - const cc2 = new BasicCCSet(driver, { nodeId: 2, targetValue: 50 }); - const cc = new MultiCommandCCCommandEncapsulation(driver, { + const cc1 = new BasicCCSet({ nodeId: 2, targetValue: 25 }); + const cc2 = new BasicCCSet({ nodeId: 2, targetValue: 50 }); + const cc = new MultiCommandCCCommandEncapsulation({ nodeId: 2, encapsulated: [cc1, cc2], }); @@ -172,8 +172,8 @@ test.serial("does not crash when receiving a Multi Command CC", (t) => { test.serial("supports nested partial/non-partial CCs", (t) => { const { driver } = t.context; - const cc1 = new BasicCCSet(driver, { nodeId: 2, targetValue: 25 }); - const cc = new SecurityCCCommandEncapsulation(driver, { + const cc1 = new BasicCCSet({ nodeId: 2, targetValue: 25 }); + const cc = new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, @@ -189,7 +189,7 @@ test.serial("supports nested partial/non-partial CCs", (t) => { test.serial("supports nested partial/partial CCs (part 1)", (t) => { const { driver } = t.context; - const cc = new SecurityCCCommandEncapsulation(driver, { + const cc = new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, @@ -214,7 +214,7 @@ test.serial("supports nested partial/partial CCs (part 1)", (t) => { test.serial("supports nested partial/partial CCs (part 2)", (t) => { const { driver } = t.context; - const cc = new SecurityCCCommandEncapsulation(driver, { + const cc = new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, @@ -241,7 +241,7 @@ test.serial( "returns false when a partial CC throws Deserialization_NotImplemented during merging", (t) => { const { driver } = t.context; - const cc = new AssociationCCReport(driver, { + const cc = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -272,7 +272,7 @@ test.serial( "returns false when a partial CC throws CC_NotImplemented during merging", (t) => { const { driver } = t.context; - const cc = new AssociationCCReport(driver, { + const cc = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -303,7 +303,7 @@ test.serial( "returns false when a partial CC throws PacketFormat_InvalidPayload during merging", (t) => { const { driver } = t.context; - const cc = new AssociationCCReport(driver, { + const cc = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, @@ -332,7 +332,7 @@ test.serial( test.serial("passes other errors during merging through", (t) => { const { driver } = t.context; - const cc = new AssociationCCReport(driver, { + const cc = new AssociationCCReport({ nodeId: 2, data: Buffer.from([ CommandClasses.Association, diff --git a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts index 12d094559ec5..d8d6e79bf0e8 100644 --- a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts +++ b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts @@ -44,7 +44,7 @@ test.afterEach.always(async (t) => { test("should compute the correct net payload sizes", (t) => { const { driver } = t.context; const testMsg1 = new SendDataRequest(driver, { - command: new SecurityCCCommandEncapsulation(driver, { + command: new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, @@ -55,13 +55,13 @@ test("should compute the correct net payload sizes", (t) => { testMsg1.command.encapsulated = undefined as any; t.is(driver.computeNetCCPayloadSize(testMsg1), 26); - const multiChannelCC = new MultiChannelCCCommandEncapsulation(driver, { + const multiChannelCC = new MultiChannelCCCommandEncapsulation({ nodeId: 2, destination: 1, encapsulated: {} as any, }); const testMsg2 = new SendDataRequest(driver, { - command: new SecurityCCCommandEncapsulation(driver, { + command: new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, securityManager: driver.securityManager!, @@ -72,7 +72,7 @@ test("should compute the correct net payload sizes", (t) => { multiChannelCC.encapsulated = undefined as any; t.is(driver.computeNetCCPayloadSize(testMsg2), 54 - 20 - 4); - const testMsg3 = new FirmwareUpdateMetaDataCC(driver, { + const testMsg3 = new FirmwareUpdateMetaDataCC({ nodeId: 2, }); testMsg3.toggleEncapsulationFlag(EncapsulationFlags.Security, true); diff --git a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts index 6cae0c34b127..74beb19e964a 100644 --- a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts +++ b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts @@ -42,7 +42,7 @@ integrationTest("update the controller status and wait if TX status is Fail", { customSetup: async (driver, controller, mockNode) => { // Return a TX status of Fail when desired const handleSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof SendDataRequest) { if (!shouldFail) { // Defer to the default behavior @@ -69,7 +69,7 @@ integrationTest("update the controller status and wait if TX status is Fail", { ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -81,7 +81,7 @@ integrationTest("update the controller status and wait if TX status is Fail", { MockControllerCommunicationState.Idle, ); - const cb = new SendDataRequestTransmitReport(host, { + const cb = new SendDataRequestTransmitReport({ callbackId: msg.callbackId!, transmitStatus: TransmitStatus.Fail, txReport: { @@ -159,7 +159,7 @@ integrationTest( customSetup: async (driver, controller, mockNode) => { // Return a TX status of Fail when desired const handleSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // Soft reset should restore normal operation if (msg instanceof SoftResetRequest) { shouldFail = false; @@ -192,7 +192,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -204,7 +204,7 @@ integrationTest( MockControllerCommunicationState.Idle, ); - const cb = new SendDataRequestTransmitReport(host, { + const cb = new SendDataRequestTransmitReport({ callbackId: msg.callbackId!, transmitStatus: TransmitStatus.Fail, txReport: { @@ -305,7 +305,7 @@ integrationTestMulti( customSetup: async (driver, controller, mockNodes) => { // Return a TX status of Fail when desired const handleSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof SendDataRequest) { // Commands to node 3 work normally if (msg.getNodeId() === 3) { @@ -333,7 +333,7 @@ integrationTestMulti( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -345,7 +345,7 @@ integrationTestMulti( MockControllerCommunicationState.Idle, ); - const cb = new SendDataRequestTransmitReport(host, { + const cb = new SendDataRequestTransmitReport({ callbackId: msg.callbackId!, transmitStatus: TransmitStatus.Fail, txReport: { diff --git a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts index 4a5d62822cb4..42219793a1f7 100644 --- a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts +++ b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts @@ -19,7 +19,7 @@ integrationTest("CC values are created using the known CC version", { ), testBody: async (t, driver, node, mockController, mockNode) => { - const batteryReport = new BatteryCCReport(mockNode.host, { + const batteryReport = new BatteryCCReport({ nodeId: mockController.ownNodeId, isLow: true, }); diff --git a/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts index 47ba91182e00..4da3efc61d06 100644 --- a/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/handleNonImplementedCCs.test.ts @@ -22,7 +22,7 @@ integrationTest( 1000, ); - const cc = new CommandClass(mockNode.host, { + const cc = new CommandClass({ nodeId: mockController.ownNodeId, ccId: CommandClasses["Anti-Theft"], ccCommand: 0x02, // Get diff --git a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts index 5124e74f5e0d..dca5da8aca41 100644 --- a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts @@ -77,7 +77,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -104,7 +104,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -130,18 +130,14 @@ integrationTest( instanceof Security2CCCommandsSupportedGet ) { let cc: CommandClass = - new Security2CCCommandsSupportedReport( - self.host, - { - nodeId: controller.ownNodeId, - supportedCCs: [ - // The node supports Version CC securely - CommandClasses.Version, - ], - }, - ); + new Security2CCCommandsSupportedReport({ + nodeId: controller.ownNodeId, + supportedCCs: [ + // The node supports Version CC securely + CommandClasses.Version, + ], + }); cc = Security2CC.encapsulate( - self.host, cc, self.id, self.securityManagers, @@ -162,17 +158,12 @@ integrationTest( && receivedCC.encapsulated.requestedCC === CommandClasses["Security 2"] ) { - let cc: CommandClass = new VersionCCCommandClassReport( - self.host, - { - nodeId: controller.ownNodeId, - requestedCC: - receivedCC.encapsulated.requestedCC, - ccVersion: 0, - }, - ); + let cc: CommandClass = new VersionCCCommandClassReport({ + nodeId: controller.ownNodeId, + requestedCC: receivedCC.encapsulated.requestedCC, + ccVersion: 0, + }); cc = Security2CC.encapsulate( - self.host, cc, self.id, self.securityManagers, @@ -227,7 +218,7 @@ integrationTest( controller.ownNodeId, 8, ); - const cc = new SecurityCCNonceReport(self.host, { + const cc = new SecurityCCNonceReport({ nodeId: controller.ownNodeId, nonce, }); @@ -244,7 +235,7 @@ integrationTest( && receivedCC.encapsulated instanceof SecurityCCCommandsSupportedGet ) { - const nonceGet = new SecurityCCNonceGet(self.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: controller.ownNodeId, }); await self.sendToController( @@ -267,19 +258,15 @@ integrationTest( const receiverNonce = nonceReport.payload.nonce; const response: CommandClass = - new SecurityCCCommandsSupportedReport( - self.host, - { - nodeId: controller.ownNodeId, - supportedCCs: [ - // The node supports Version CC securely - CommandClasses.Version, - ], - controlledCCs: [], - }, - ); + new SecurityCCCommandsSupportedReport({ + nodeId: controller.ownNodeId, + supportedCCs: [ + // The node supports Version CC securely + CommandClasses.Version, + ], + controlledCCs: [], + }); const cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, response, @@ -308,7 +295,7 @@ integrationTest( === CommandClasses.Security ) { await wait(100); - const nonceGet = new SecurityCCNonceGet(self.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: controller.ownNodeId, }); await self.sendToController( @@ -331,18 +318,14 @@ integrationTest( const receiverNonce = nonceReport.payload.nonce; const response: CommandClass = - new VersionCCCommandClassReport( - self.host, - { - nodeId: controller.ownNodeId, - requestedCC: - receivedCC.encapsulated.requestedCC, - ccVersion: 0, - }, - ); + new VersionCCCommandClassReport({ + nodeId: controller.ownNodeId, + requestedCC: + receivedCC.encapsulated.requestedCC, + ccVersion: 0, + }); const cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, response, diff --git a/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts b/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts index 5b45f9ef9859..abfd5aa06510 100644 --- a/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts +++ b/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts @@ -37,7 +37,7 @@ integrationTest( async handleCC(controller, self, receivedCC) { if (receivedCC instanceof ConfigurationCCNameGet) { await wait(700); - let cc = new ConfigurationCCNameReport(self.host, { + let cc = new ConfigurationCCNameReport({ nodeId: controller.ownNodeId, parameter: receivedCC.parameter, name: "Test para", @@ -51,7 +51,7 @@ integrationTest( await wait(700); - cc = new ConfigurationCCNameReport(self.host, { + cc = new ConfigurationCCNameReport({ nodeId: controller.ownNodeId, parameter: receivedCC.parameter, name: "meter", @@ -100,16 +100,13 @@ integrationTest( const respondToConfigurationNameGet: MockNodeBehavior = { async handleCC(controller, self, receivedCC) { if (receivedCC instanceof ConfigurationCCNameGet) { - const configCC = new ConfigurationCCNameReport( - self.host, - { - nodeId: controller.ownNodeId, - parameter: receivedCC.parameter, - name: - "Veeeeeeeeeeeeeeeeeeeeeeeeery loooooooooooooooooong parameter name", - reportsToFollow: 0, - }, - ); + const configCC = new ConfigurationCCNameReport({ + nodeId: controller.ownNodeId, + parameter: receivedCC.parameter, + name: + "Veeeeeeeeeeeeeeeeeeeeeeeeery loooooooooooooooooong parameter name", + reportsToFollow: 0, + }); const serialized = configCC.serialize(); const segment1 = serialized.subarray( 0, @@ -119,25 +116,19 @@ integrationTest( const sessionId = 7; - const tsFS = new TransportServiceCCFirstSegment( - self.host, - { - nodeId: controller.ownNodeId, - sessionId, - datagramSize: serialized.length, - partialDatagram: segment1, - }, - ); - const tsSS = new TransportServiceCCSubsequentSegment( - self.host, - { - nodeId: controller.ownNodeId, - sessionId, - datagramSize: serialized.length, - datagramOffset: segment1.length, - partialDatagram: segment2, - }, - ); + const tsFS = new TransportServiceCCFirstSegment({ + nodeId: controller.ownNodeId, + sessionId, + datagramSize: serialized.length, + partialDatagram: segment1, + }); + const tsSS = new TransportServiceCCSubsequentSegment({ + nodeId: controller.ownNodeId, + sessionId, + datagramSize: serialized.length, + datagramOffset: segment1.length, + partialDatagram: segment2, + }); await wait(700); await self.sendToController( @@ -185,7 +176,7 @@ integrationTest("GET requests DO time out if there's no matching response", { handleCC(controller, self, receivedCC) { if (receivedCC instanceof ConfigurationCCNameGet) { // This is not the response you're looking for - const cc = new BasicCCReport(self.host, { + const cc = new BasicCCReport({ nodeId: controller.ownNodeId, currentValue: 1, }); diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts index 8d5c8c740bd3..73a87927d27e 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts @@ -49,7 +49,7 @@ integrationTest( controller.ownNodeId, 8, ); - const cc = new SecurityCCNonceReport(self.host, { + const cc = new SecurityCCNonceReport({ nodeId: controller.ownNodeId, nonce, }); @@ -85,7 +85,7 @@ integrationTest( node.markAsAsleep(); mockNode.autoAckControllerFrames = false; - let nonceRequest = new SecurityCCNonceGet(mockNode.host, { + let nonceRequest = new SecurityCCNonceGet({ nodeId: mockController.ownNodeId, }); await mockNode.sendToController( @@ -123,7 +123,7 @@ integrationTest( mockNode.autoAckControllerFrames = true; // And subsequent requests must be answered - nonceRequest = new SecurityCCNonceGet(mockNode.host, { + nonceRequest = new SecurityCCNonceGet({ nodeId: mockController.ownNodeId, }); await mockNode.sendToController( diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts index ccf364258096..4b7ced4e020a 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts @@ -23,7 +23,7 @@ integrationTest( t.is(node2.status, NodeStatus.Awake); - const command1 = new BasicCCSet(driver, { + const command1 = new BasicCCSet({ nodeId: 2, targetValue: 99, }); @@ -31,7 +31,7 @@ integrationTest( maxSendAttempts: 1, }); - const command2 = new BasicCCGet(driver, { + const command2 = new BasicCCGet({ nodeId: 2, }); driver.sendCommand(command2, { diff --git a/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts b/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts index 943270a0dba5..a5d07c6e0b85 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts @@ -20,7 +20,7 @@ integrationTest( t.is(node2.status, NodeStatus.Alive); - const command1 = new BasicCCSet(driver, { + const command1 = new BasicCCSet({ nodeId: 2, targetValue: 99, }); @@ -33,7 +33,7 @@ integrationTest( driver.driverLog.print("basicSetPromise rejected"); }); // Don't throw here, do it below - const command2 = new BasicCCGet(driver, { + const command2 = new BasicCCGet({ nodeId: 2, }); const basicGetPromise = driver.sendCommand(command2, { @@ -88,7 +88,7 @@ integrationTest( t.is(node2.status, NodeStatus.Alive); - const command1 = new BasicCCSet(driver, { + const command1 = new BasicCCSet({ nodeId: 2, targetValue: 99, }); @@ -101,7 +101,7 @@ integrationTest( driver.driverLog.print("basicSetPromise rejected"); }); - const command2 = new BasicCCGet(driver, { + const command2 = new BasicCCGet({ nodeId: 2, }); const basicGetPromise = driver.sendCommand(command2, { diff --git a/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts b/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts index 8c3655868a75..9a684da3dd2c 100644 --- a/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts +++ b/packages/zwave-js/src/lib/test/driver/notificationPushNoAGI.test.ts @@ -35,7 +35,7 @@ integrationTest( if (receivedCC instanceof NotificationCCGet) { const notificationType = receivedCC.notificationType || 0x06; - const cc = new NotificationCCReport(self.host, { + const cc = new NotificationCCReport({ nodeId: controller.ownNodeId, notificationType, notificationEvent: notificationType === 0x06 diff --git a/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts b/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts index 5c8b1d94c5f7..1c6cfb43015a 100644 --- a/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts +++ b/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts @@ -25,7 +25,7 @@ integrationTest("Assume a node to be awake at the start of a re-interview", { await wait(100); // Send a WakeUpNotification to the node to trigger the interview - const cc = new WakeUpCCWakeUpNotification(mockNode.host, { + const cc = new WakeUpCCWakeUpNotification({ nodeId: mockController.ownNodeId, }); await mockNode.sendToController( @@ -47,7 +47,7 @@ integrationTest("Assume a node to be awake at the start of a re-interview", { waitForWakeup: true, }); - const cc = new WakeUpCCWakeUpNotification(mockNode.host, { + const cc = new WakeUpCCWakeUpNotification({ nodeId: mockController.ownNodeId, }); await mockNode.sendToController( diff --git a/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts b/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts index 3e68b58bb74f..866dd57275c1 100644 --- a/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts +++ b/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts @@ -37,7 +37,7 @@ test.serial( async (t) => { const { driver, controller } = t.context; const req = new ApplicationCommandRequest(driver, { - command: new WakeUpCCIntervalSet(driver, { + command: new WakeUpCCIntervalSet({ nodeId: 1, controllerNodeId: 2, wakeUpInterval: 5, diff --git a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts index 0815debba5ad..ea33e8ce33fe 100644 --- a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts @@ -95,7 +95,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { controller.ownNodeId, 8, ); - const cc = new SecurityCCNonceReport(self.host, { + const cc = new SecurityCCNonceReport({ nodeId: controller.ownNodeId, nonce, }); @@ -124,7 +124,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { const nonce = sm2Node.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -151,7 +151,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { const nonce = sm2Node.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -173,14 +173,13 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { receivedCC instanceof Security2CCMessageEncapsulation && receivedCC.encapsulated instanceof SupervisionCCGet ) { - let cc: CommandClass = new SupervisionCCReport(self.host, { + let cc: CommandClass = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.encapsulated.sessionId, moreUpdatesFollow: false, status: SupervisionStatus.Success, }); cc = Security2CC.encapsulate( - self.host, cc, self.id, self.securityManagers, diff --git a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts index ef746bf84148..6d64a8924894 100644 --- a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts @@ -49,7 +49,7 @@ integrationTest("Communication via Security S0 works", { controller.ownNodeId, 8, ); - const cc = new SecurityCCNonceReport(self.host, { + const cc = new SecurityCCNonceReport({ nodeId: controller.ownNodeId, nonce, }); @@ -67,7 +67,7 @@ integrationTest("Communication via Security S0 works", { && receivedCC.encapsulated instanceof SecurityCCCommandsSupportedGet ) { - const nonceGet = new SecurityCCNonceGet(self.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: controller.ownNodeId, }); await self.sendToController( @@ -88,14 +88,11 @@ integrationTest("Communication via Security S0 works", { ); const receiverNonce = nonceReport.payload.nonce; - const response = new SecurityCCCommandsSupportedReport( - self.host, - { - nodeId: controller.ownNodeId, - supportedCCs: [CommandClasses.Basic], - controlledCCs: [], - }, - ); + const response = new SecurityCCCommandsSupportedReport({ + nodeId: controller.ownNodeId, + supportedCCs: [CommandClasses.Basic], + controlledCCs: [], + }); const cc = SecurityCC.encapsulate( self.host, self.id, @@ -124,7 +121,7 @@ integrationTest("Communication via Security S0 works", { receivedCC instanceof SecurityCCCommandEncapsulation && receivedCC.encapsulated instanceof BasicCCGet ) { - const nonceGet = new SecurityCCNonceGet(self.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: controller.ownNodeId, }); await self.sendToController( @@ -145,7 +142,7 @@ integrationTest("Communication via Security S0 works", { ); const receiverNonce = nonceReport.payload.nonce; - const response = new BasicCCReport(self.host, { + const response = new BasicCCReport({ nodeId: controller.ownNodeId, currentValue: ++queryCount, }); diff --git a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts index 4a54fa3a7762..81257b1e38cb 100644 --- a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts @@ -70,7 +70,7 @@ integrationTest( controller.ownNodeId, 8, ); - const cc = new SecurityCCNonceReport(self.host, { + const cc = new SecurityCCNonceReport({ nodeId: controller.ownNodeId, nonce, }); @@ -88,7 +88,7 @@ integrationTest( && receivedCC.encapsulated instanceof SecurityCCCommandsSupportedGet ) { - const nonceGet = new SecurityCCNonceGet(self.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: controller.ownNodeId, }); await self.sendToController( @@ -113,14 +113,11 @@ integrationTest( const receiverNonce = nonceReport.payload.nonce; const response = - new SecurityCCCommandsSupportedReport( - self.host, - { - nodeId: controller.ownNodeId, - supportedCCs: [CommandClasses.Basic], - controlledCCs: [], - }, - ); + new SecurityCCCommandsSupportedReport({ + nodeId: controller.ownNodeId, + supportedCCs: [CommandClasses.Basic], + controlledCCs: [], + }); const cc = SecurityCC.encapsulate( self.host, self.id, @@ -156,7 +153,7 @@ integrationTest( await wait(750); } - const nonceGet = new SecurityCCNonceGet(self.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: controller.ownNodeId, }); await self.sendToController( @@ -180,7 +177,7 @@ integrationTest( ); const receiverNonce = nonceReport.payload.nonce; - const response = new BasicCCReport(self.host, { + const response = new BasicCCReport({ nodeId: controller.ownNodeId, currentValue: queryCount, }); diff --git a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts index 2dd4c0a3e4a4..be1ff71d905b 100644 --- a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts @@ -87,7 +87,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -114,7 +114,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -138,17 +138,13 @@ integrationTest( && receivedCC.encapsulated instanceof SupervisionCCGet ) { - let cc: CommandClass = new SupervisionCCReport( - self.host, - { - nodeId: controller.ownNodeId, - sessionId: receivedCC.encapsulated.sessionId, - moreUpdatesFollow: false, - status: SupervisionStatus.Success, - }, - ); + let cc: CommandClass = new SupervisionCCReport({ + nodeId: controller.ownNodeId, + sessionId: receivedCC.encapsulated.sessionId, + moreUpdatesFollow: false, + status: SupervisionStatus.Success, + }); cc = Security2CC.encapsulate( - self.host, cc, self.id, self.securityManagers, @@ -172,8 +168,7 @@ integrationTest( // Now create a collision by having both parties send at the same time const nodeToHost = Security2CC.encapsulate( - mockNode.host, - new BinarySwitchCCReport(mockNode.host, { + new BinarySwitchCCReport({ nodeId: mockController.ownNodeId, currentValue: true, }), @@ -264,7 +259,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -291,7 +286,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -319,8 +314,7 @@ integrationTest( // Now create a collision by having both parties send at the same time const nodeToHost = Security2CC.encapsulate( - mockNode.host, - new BasicCCReport(mockNode.host, { + new BasicCCReport({ nodeId: mockController.ownNodeId, currentValue: 99, }), @@ -404,7 +398,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -431,7 +425,7 @@ integrationTest( const nonce = smNode.generateNonce( controller.ownNodeId, ); - const cc = new Security2CCNonceReport(self.host, { + const cc = new Security2CCNonceReport({ nodeId: controller.ownNodeId, ownNodeId: self.id, securityManagers: self.securityManagers, @@ -455,17 +449,13 @@ integrationTest( && receivedCC.encapsulated instanceof SupervisionCCGet ) { - let cc: CommandClass = new SupervisionCCReport( - self.host, - { - nodeId: controller.ownNodeId, - sessionId: receivedCC.encapsulated.sessionId, - moreUpdatesFollow: false, - status: SupervisionStatus.Success, - }, - ); + let cc: CommandClass = new SupervisionCCReport({ + nodeId: controller.ownNodeId, + sessionId: receivedCC.encapsulated.sessionId, + moreUpdatesFollow: false, + status: SupervisionStatus.Success, + }); cc = Security2CC.encapsulate( - self.host, cc, self.id, self.securityManagers, @@ -493,15 +483,11 @@ integrationTest( const turnOff = node.commandClasses["Binary Switch"].set(false); // Node sends supervised Binary Switch report at the same time - let nodeToHost: CommandClass = new BinarySwitchCCReport( - mockNode.host, - { - nodeId: mockController.ownNodeId, - currentValue: true, - }, - ); + let nodeToHost: CommandClass = new BinarySwitchCCReport({ + nodeId: mockController.ownNodeId, + currentValue: true, + }); nodeToHost = SupervisionCC.encapsulate( - mockNode.host, nodeToHost, driver.getNextSupervisionSessionId( mockController.ownNodeId, @@ -509,7 +495,6 @@ integrationTest( false, ); nodeToHost = Security2CC.encapsulate( - mockNode.host, nodeToHost, mockNode.id, mockNode.securityManagers, @@ -539,8 +524,7 @@ integrationTest( // // Now create a collision by having both parties send at the same time // const nodeToHost = Security2CC.encapsulate( - // mockNode.host, - // new BasicCCReport(mockNode.host, { + // new BasicCCReport({ // nodeId: mockController.ownNodeId, // currentValue: 99, // }), diff --git a/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts index a31756586112..18d87f88d962 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataAbortAfterTimeout.test.ts @@ -38,7 +38,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -65,7 +65,7 @@ integrationTest( lastCallbackId = msg.callbackId!; // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -73,7 +73,7 @@ integrationTest( return true; } else if (msg instanceof SendDataAbort) { // Finish the transmission by sending the callback - const cb = new SendDataRequestTransmitReport(host, { + const cb = new SendDataRequestTransmitReport({ callbackId: lastCallbackId, transmitStatus: TransmitStatus.NoAck, }); @@ -95,7 +95,7 @@ integrationTest( mockController.defineBehavior(handleBrokenSendData); const handleSoftReset: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { // Soft reset should restore normal operation if (msg instanceof SoftResetRequest) { shouldTimeOut = false; @@ -160,7 +160,7 @@ integrationTest( // customSetup: async (driver, mockController, mockNode) => { // // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent // const handleBrokenSendData: MockControllerBehavior = { -// async onHostMessage(host, controller, msg) { +// async onHostMessage(controller, msg) { // if (msg instanceof SendDataRequest) { // // Check if this command is legal right now // const state = controller.state.get( @@ -182,7 +182,7 @@ integrationTest( // ); // // Notify the host that the message was sent -// const res = new SendDataResponse(host, { +// const res = new SendDataResponse({ // wasSent: true, // }); // await controller.sendMessageToHost(res); @@ -255,7 +255,7 @@ integrationTest( // customSetup: async (driver, mockController, mockNode) => { // // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent // const handleBrokenSendData: MockControllerBehavior = { -// async onHostMessage(host, controller, msg) { +// async onHostMessage(controller, msg) { // // If the controller is operating normally, defer to the default behavior // if (!shouldTimeOut) return false; @@ -280,7 +280,7 @@ integrationTest( // ); // // Notify the host that the message was sent -// const res = new SendDataResponse(host, { +// const res = new SendDataResponse({ // wasSent: true, // }); // await controller.sendMessageToHost(res); @@ -300,7 +300,7 @@ integrationTest( // mockController.defineBehavior(handleBrokenSendData); // const handleSoftReset: MockControllerBehavior = { -// onHostMessage(host, controller, msg) { +// onHostMessage(controller, msg) { // // Soft reset should restore normal operation // if (msg instanceof SoftResetRequest) { // shouldTimeOut = false; @@ -356,10 +356,10 @@ integrationTest( // customSetup: async (driver, mockController, mockNode) => { // // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent // const handleBrokenRequestNodeInfo: MockControllerBehavior = { -// async onHostMessage(host, controller, msg) { +// async onHostMessage(controller, msg) { // if (msg instanceof RequestNodeInfoRequest) { // // Notify the host that the message was sent -// const res = new RequestNodeInfoResponse(host, { +// const res = new RequestNodeInfoResponse({ // wasSent: true, // }); // await controller.sendMessageToHost(res); diff --git a/packages/zwave-js/src/lib/test/driver/sendDataFailThrow.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataFailThrow.test.ts index 64f25107e7de..f43ae4ca1503 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataFailThrow.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataFailThrow.test.ts @@ -67,7 +67,7 @@ test.serial( const ACK = Buffer.from([MessageHeaders.ACK]); - const command = new BasicCCSet(driver, { + const command = new BasicCCSet({ nodeId: 2, targetValue: 99, }); @@ -132,7 +132,7 @@ test.serial( const ACK = Buffer.from([MessageHeaders.ACK]); - const command = new BasicCCSet(driver, { + const command = new BasicCCSet({ nodeId: 2, targetValue: 99, }); diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts index 6dd90d3264c7..1ffdf8940737 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts @@ -54,7 +54,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -79,7 +79,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -99,7 +99,7 @@ integrationTest( mockController.defineBehavior(handleBrokenSendData); const handleSoftReset: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { // Soft reset should restore normal operation if (msg instanceof SoftResetRequest) { shouldTimeOut = false; @@ -158,7 +158,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof SendDataRequest) { // Check if this command is legal right now const state = controller.state.get( @@ -180,7 +180,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -253,7 +253,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -278,7 +278,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -298,7 +298,7 @@ integrationTest( mockController.defineBehavior(handleBrokenSendData); const handleSoftReset: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { // Soft reset should restore normal operation if (msg instanceof SoftResetRequest) { shouldTimeOut = false; @@ -354,10 +354,10 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenRequestNodeInfo: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { if (msg instanceof RequestNodeInfoRequest) { // Notify the host that the message was sent - const res = new RequestNodeInfoResponse(host, { + const res = new RequestNodeInfoResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -409,7 +409,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -434,7 +434,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -520,7 +520,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -545,7 +545,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -628,7 +628,7 @@ integrationTestMulti( customSetup: async (driver, mockController, mockNodes) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -653,7 +653,7 @@ integrationTestMulti( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); @@ -740,7 +740,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -765,7 +765,7 @@ integrationTest( ); // Notify the host that the message was sent - const res = new SendDataResponse(host, { + const res = new SendDataResponse({ wasSent: true, }); await controller.sendMessageToHost(res); diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts index e0ef16c14cb0..4d65daafb1dc 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts @@ -37,7 +37,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the response and callback never get sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -60,7 +60,7 @@ integrationTest( return true; } else if (msg instanceof SendDataAbort) { // Finish the transmission by sending the callback - const cb = new SendDataRequestTransmitReport(host, { + const cb = new SendDataRequestTransmitReport({ callbackId: lastCallbackId, transmitStatus: TransmitStatus.NoAck, }); @@ -131,7 +131,7 @@ integrationTest( customSetup: async (driver, mockController, mockNode) => { // This is almost a 1:1 copy of the default behavior, except that the response and callback never get sent const handleBrokenSendData: MockControllerBehavior = { - async onHostMessage(host, controller, msg) { + async onHostMessage(controller, msg) { // If the controller is operating normally, defer to the default behavior if (!shouldTimeOut) return false; @@ -213,7 +213,7 @@ integrationTest( // customSetup: async (driver, mockController, mockNode) => { // // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent // const handleBrokenSendData: MockControllerBehavior = { -// async onHostMessage(host, controller, msg) { +// async onHostMessage(controller, msg) { // if (msg instanceof SendDataRequest) { // // Check if this command is legal right now // const state = controller.state.get( @@ -235,7 +235,7 @@ integrationTest( // ); // // Notify the host that the message was sent -// const res = new SendDataResponse(host, { +// const res = new SendDataResponse({ // wasSent: true, // }); // await controller.sendMessageToHost(res); @@ -308,7 +308,7 @@ integrationTest( // customSetup: async (driver, mockController, mockNode) => { // // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent // const handleBrokenSendData: MockControllerBehavior = { -// async onHostMessage(host, controller, msg) { +// async onHostMessage(controller, msg) { // // If the controller is operating normally, defer to the default behavior // if (!shouldTimeOut) return false; @@ -333,7 +333,7 @@ integrationTest( // ); // // Notify the host that the message was sent -// const res = new SendDataResponse(host, { +// const res = new SendDataResponse({ // wasSent: true, // }); // await controller.sendMessageToHost(res); @@ -353,7 +353,7 @@ integrationTest( // mockController.defineBehavior(handleBrokenSendData); // const handleSoftReset: MockControllerBehavior = { -// onHostMessage(host, controller, msg) { +// onHostMessage(controller, msg) { // // Soft reset should restore normal operation // if (msg instanceof SoftResetRequest) { // shouldTimeOut = false; @@ -409,10 +409,10 @@ integrationTest( // customSetup: async (driver, mockController, mockNode) => { // // This is almost a 1:1 copy of the default behavior, except that the callback never gets sent // const handleBrokenRequestNodeInfo: MockControllerBehavior = { -// async onHostMessage(host, controller, msg) { +// async onHostMessage(controller, msg) { // if (msg instanceof RequestNodeInfoRequest) { // // Notify the host that the message was sent -// const res = new RequestNodeInfoResponse(host, { +// const res = new RequestNodeInfoResponse({ // wasSent: true, // }); // await controller.sendMessageToHost(res); diff --git a/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts b/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts index c42947f2cb4d..07d31ad25340 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts @@ -32,7 +32,7 @@ integrationTest( const respondToSupervisionGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { - const cc = new SupervisionCCReport(self.host, { + const cc = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, @@ -47,7 +47,7 @@ integrationTest( const respondToBinarySwitchGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { - const cc = new BinarySwitchCCReport(self.host, { + const cc = new BinarySwitchCCReport({ nodeId: controller.ownNodeId, currentValue: false, }); diff --git a/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts b/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts index a61159b46ade..e956097502aa 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts @@ -29,7 +29,7 @@ integrationTest("setValue without supervision: expect validation GET", { const respondToBinarySwitchGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { - const cc = new BinarySwitchCCReport(self.host, { + const cc = new BinarySwitchCCReport({ nodeId: controller.ownNodeId, currentValue: false, }); diff --git a/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts index 5103ae634f6d..216ec6dadf6f 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts @@ -46,11 +46,11 @@ integrationTest( return { action: "stop" }; } - let cc: CommandClass = new BasicCCReport(self.host, { + let cc: CommandClass = new BasicCCReport({ nodeId: controller.ownNodeId, currentValue: Math.round(Math.random() * 99), }); - cc = new MultiChannelCCCommandEncapsulation(self.host, { + cc = new MultiChannelCCCommandEncapsulation({ nodeId: controller.ownNodeId, destination: receivedCC.endpointIndex, endpoint: receivedCC.destination as number, diff --git a/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts index b3abc96466ac..b33e29ec0735 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts @@ -32,7 +32,7 @@ integrationTest( const respondToSupervisionGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { - const cc = new SupervisionCCReport(self.host, { + const cc = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts index 6c078727c23e..ff0c5d8d4e75 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts @@ -32,7 +32,7 @@ integrationTest( const respondToSupervisionGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { - const cc = new SupervisionCCReport(self.host, { + const cc = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, @@ -54,7 +54,7 @@ integrationTest( && !!receivedCC.encapsulated.duration ?.toMilliseconds() ) { - const cc1 = new SupervisionCCReport(self.host, { + const cc1 = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: true, @@ -62,7 +62,7 @@ integrationTest( duration: receivedCC.encapsulated.duration, }); - const cc2 = new SupervisionCCReport(self.host, { + const cc2 = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, @@ -118,7 +118,7 @@ integrationTest( const respondToMultilevelSwitchGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultilevelSwitchCCGet) { - const cc = new MultilevelSwitchCCReport(self.host, { + const cc = new MultilevelSwitchCCReport({ nodeId: controller.ownNodeId, targetValue: 88, currentValue: 88, diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts index 563d7da2cc0f..37646ee63fec 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts @@ -31,7 +31,7 @@ integrationTest( const respondToSupervisionGet: MockNodeBehavior = { async handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { - const cc = new SupervisionCCReport(self.host, { + const cc = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: true, // <-- this is the important part diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts index 1d433b7284de..a5b315070b79 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts @@ -43,7 +43,7 @@ integrationTest( const respondToSupervisionGet: MockNodeBehavior = { async handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { - let cc = new SupervisionCCReport(self.host, { + let cc = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: true, @@ -58,7 +58,7 @@ integrationTest( await wait(2000); - cc = new SupervisionCCReport(self.host, { + cc = new SupervisionCCReport({ nodeId: controller.ownNodeId, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, diff --git a/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts b/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts index 82b7d41eacc6..eee929d1fc53 100644 --- a/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts +++ b/packages/zwave-js/src/lib/test/driver/targetValueVersionUnknown.test.ts @@ -37,7 +37,7 @@ integrationTest( const respondToBinarySwitchGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { - const cc = new BinarySwitchCCReport(self.host, { + const cc = new BinarySwitchCCReport({ nodeId: controller.ownNodeId, currentValue: true, }); @@ -73,7 +73,7 @@ integrationTest( const respondToBinarySwitchGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BinarySwitchCCGet) { - const cc = new BinarySwitchCCReport(self.host, { + const cc = new BinarySwitchCCReport({ nodeId: controller.ownNodeId, currentValue: true, }); diff --git a/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts b/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts index 12847b6cedb2..a8d0b7d34dae 100644 --- a/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts +++ b/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts @@ -44,7 +44,7 @@ integrationTest(`Basic Reports with the UNKNOWN state are correctly handled`, { const respondToBasicGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof BasicCCGet) { - const cc = new BasicCCReport(self.host, { + const cc = new BasicCCReport({ nodeId: controller.ownNodeId, currentValue: 0, targetValue: 0, @@ -66,7 +66,7 @@ integrationTest(`Basic Reports with the UNKNOWN state are correctly handled`, { t.is(node.getValue(currentValueId), 0); // Send an update with UNKNOWN state - const cc = new BasicCCReport(mockNode.host, { + const cc = new BasicCCReport({ nodeId: mockController.ownNodeId, currentValue: 254, targetValue: 254, @@ -113,7 +113,7 @@ integrationTest( t.is(node.getValue(currentValueId), UNKNOWN_STATE); // Send an initial state - let cc = new MultilevelSwitchCCReport(mockNode.host, { + let cc = new MultilevelSwitchCCReport({ nodeId: mockController.ownNodeId, currentValue: 0, targetValue: 0, @@ -131,7 +131,7 @@ integrationTest( t.is(node.getValue(currentValueId), 0); // Send an update with UNKNOWN state - cc = new MultilevelSwitchCCReport(mockNode.host, { + cc = new MultilevelSwitchCCReport({ nodeId: mockController.ownNodeId, currentValue: 254, targetValue: 254, @@ -185,7 +185,7 @@ integrationTest( t.is(node.getValue(currentValueId), NOT_KNOWN); // Send an initial state - let cc = new BinarySwitchCCReport(mockNode.host, { + let cc = new BinarySwitchCCReport({ nodeId: mockController.ownNodeId, currentValue: false, targetValue: false, @@ -204,7 +204,7 @@ integrationTest( t.is(node.getValue(currentValueId), false); // Send an update with UNKNOWN state - cc = new BinarySwitchCCReport(mockNode.host, { + cc = new BinarySwitchCCReport({ nodeId: mockController.ownNodeId, currentValue: UNKNOWN_STATE, targetValue: UNKNOWN_STATE, diff --git a/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts b/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts index 6bee1771cc01..6cb55c48f74d 100644 --- a/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts +++ b/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts @@ -19,7 +19,7 @@ integrationTest( async customSetup(driver, mockController, mockNode) { const doNotRespond: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { if (!shouldRespond) { // Soft reset should restore normal operation if (msg instanceof SoftResetRequest) { @@ -72,7 +72,7 @@ integrationTest( async customSetup(driver, mockController, mockNode) { const doNotRespond: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { if (!shouldRespond) return true; return false; @@ -144,7 +144,7 @@ integrationTest( async customSetup(driver, mockController, mockNode) { const doNotRespond: MockControllerBehavior = { - onHostMessage(host, controller, msg) { + onHostMessage(controller, msg) { if (!shouldRespond) { return true; } diff --git a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts index 967805cd7a4a..8e7a1dba50e4 100644 --- a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts +++ b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts @@ -51,7 +51,7 @@ integrationTest( const respondToMultilevelSwitchGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof MultilevelSwitchCCGet) { - const cc = new MultilevelSwitchCCReport(self.host, { + const cc = new MultilevelSwitchCCReport({ nodeId: controller.ownNodeId, targetValue: 88, currentValue: 88, diff --git a/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts b/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts deleted file mode 100644 index d68d894f5f16..000000000000 --- a/packages/zwave-js/src/lib/zniffer/CCParsingContext.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { getImplementedVersion } from "@zwave-js/cc"; -import { DeviceConfig } from "@zwave-js/config"; -import { - type CommandClasses, - type MaybeNotKnown, - SecurityClass, - type SecurityManager, - type SecurityManager2, -} from "@zwave-js/core"; -import { type ZWaveHost } from "@zwave-js/host"; - -export class ZnifferCCParsingContext implements ZWaveHost { - public constructor( - public readonly ownNodeId: number, - public readonly homeId: number, - public readonly securityManager: SecurityManager | undefined, - public readonly securityManager2: SecurityManager2 | undefined, - public readonly securityManagerLR: SecurityManager2 | undefined, - ) {} - - getSafeCCVersion( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): number { - // We don't know any versions of the node. Try parsing with the highest version we support - return getImplementedVersion(cc); - } - - getSupportedCCVersion( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): number { - // We don't know any versions of the node. Try parsing with the highest version we support - return getImplementedVersion(cc); - } - - isCCSecure( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): boolean { - // Don't care when parsing - return false; - } - - getHighestSecurityClass(nodeId: number): MaybeNotKnown { - return SecurityClass.S2_AccessControl; - } - - hasSecurityClass( - nodeId: number, - securityClass: SecurityClass, - ): MaybeNotKnown { - // We don't actually know. Attempt parsing with all security classes - return true; - } - - setSecurityClass( - nodeId: number, - securityClass: SecurityClass, - granted: boolean, - ): void { - // Do nothing - } - - getDeviceConfig(nodeId: number): DeviceConfig | undefined { - // Disable strict validation while parsing certain CCs - // Most of this stuff isn't actually needed, only the compat flags... - return new DeviceConfig( - "unknown.json", - false, - "UNKNOWN_MANUFACTURER", - 0x0000, - "UNKNOWN_PRODUCT", - "UNKNOWN_DESCRIPTION", - [], - { - min: "0.0", - max: "255.255", - }, - true, - undefined, - undefined, - undefined, - undefined, - // ...down here: - { - disableStrictEntryControlDataValidation: true, - disableStrictMeasurementValidation: true, - }, - ); - } -} diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 5972a5f080ec..2dda6357f7fe 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -5,6 +5,7 @@ import { Security2CCNonceReport, SecurityCCNonceReport, } from "@zwave-js/cc"; +import { DeviceConfig } from "@zwave-js/config"; import { CommandClasses, type LogConfig, @@ -67,7 +68,6 @@ import fs from "node:fs/promises"; import { sdkVersionGte } from "../controller/utils"; import { type ZWaveOptions } from "../driver/ZWaveOptions"; import { ZnifferLogger } from "../log/Zniffer"; -import { ZnifferCCParsingContext } from "./CCParsingContext"; import { type CorruptedFrame, type Frame, @@ -227,6 +227,34 @@ export class Zniffer extends TypedEventEmitter { ): void { // Do nothing }, + + getDeviceConfig(_nodeId: number): DeviceConfig | undefined { + // Disable strict validation while parsing certain CCs + // Most of this stuff isn't actually needed, only the compat flags... + return new DeviceConfig( + "unknown.json", + false, + "UNKNOWN_MANUFACTURER", + 0x0000, + "UNKNOWN_PRODUCT", + "UNKNOWN_DESCRIPTION", + [], + { + min: "0.0", + max: "255.255", + }, + true, + undefined, + undefined, + undefined, + undefined, + // ...down here: + { + disableStrictEntryControlDataValidation: true, + disableStrictMeasurementValidation: true, + }, + ); + }, }; } @@ -536,16 +564,8 @@ supported frequencies: ${ } // TODO: Support parsing multicast S2 frames - - const ctx = new ZnifferCCParsingContext( - destNodeId, - mpdu.homeId, - destSecurityManager, - destSecurityManager2, - destSecurityManagerLR, - ); try { - cc = CommandClass.from(ctx, { + cc = CommandClass.from({ data: mpdu.payload, fromEncapsulation: false, nodeId: mpdu.sourceNodeId, @@ -553,6 +573,9 @@ supported frequencies: ${ homeId: mpdu.homeId, ownNodeId: destNodeId, sourceNodeId: mpdu.sourceNodeId, + securityManager: destSecurityManager, + securityManager2: destSecurityManager2, + securityManagerLR: destSecurityManagerLR, ...this.parsingContext, }, }); From 7f0342c34485a9cb138f3e46a1d7c2fa1cc18345 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 15 Oct 2024 23:25:38 +0200 Subject: [PATCH 40/60] fix: tests --- .../src/lib/driver/Transaction.test.ts | 12 +++---- packages/zwave-js/src/lib/log/Driver.test.ts | 2 +- .../BridgeApplicationCommandRequest.test.ts | 2 +- .../capability/SerialAPISetupMessages.test.ts | 4 +-- .../zwave-js/src/lib/test/cc/CRC16CC.test.ts | 8 ++--- .../cc/CommandClass.nonImplemented.test.ts | 2 +- .../src/lib/test/cc/MultiChannelCC.test.ts | 14 ++------ .../src/lib/test/cc/MultiCommandCC.test.ts | 2 +- .../src/lib/test/cc/SupervisionCC.test.ts | 3 -- .../zwave-js/src/lib/test/cc/WakeUpCC.test.ts | 2 -- .../compliance/zwavePlusInfoResponse.test.ts | 2 +- .../test/driver/assemblePartialCCs.test.ts | 26 +++++++------- .../driver/computeNetCCPayloadSize.test.ts | 4 +-- .../driver/nodeAsleepMessageOrder.test.ts | 18 ++++------ .../driver/nodeUpdateBeforeCallback.test.ts | 2 +- .../lib/test/driver/receiveMessages.test.ts | 2 +- .../lib/test/driver/s0Encapsulation.test.ts | 2 -- .../driver/s0EncapsulationTwoNodes.test.ts | 4 +-- .../sendDataMissingCallbackAbort.test.ts | 2 +- .../driver/supervisionRepeatedReport.test.ts | 2 +- packages/zwave-js/src/lib/test/mocks.ts | 5 +-- .../lib/test/node/Node.handleCommand.test.ts | 34 ++++++++----------- .../legacyRefreshActuatorSensorCCs.test.ts | 24 ++++++------- 23 files changed, 71 insertions(+), 107 deletions(-) diff --git a/packages/zwave-js/src/lib/driver/Transaction.test.ts b/packages/zwave-js/src/lib/driver/Transaction.test.ts index fa2081225a7e..0c8b418767c1 100644 --- a/packages/zwave-js/src/lib/driver/Transaction.test.ts +++ b/packages/zwave-js/src/lib/driver/Transaction.test.ts @@ -164,12 +164,12 @@ test("NodeQuery comparisons should prioritize listening nodes", (t) => { ) { const driver = driverMock as any as Driver; const msg = nodeId != undefined - ? new SendDataRequest(driver, { + ? new SendDataRequest({ command: new NoOperationCC({ nodeId, }), }) - : new GetControllerVersionRequest(driver); + : new GetControllerVersionRequest(); const ret = createDummyTransaction(driverMock, { priority, message: msg, @@ -273,7 +273,7 @@ test("Messages in the wakeup queue should be preferred over lesser priorities on function createTransaction(nodeId: number, priority: MessagePriority) { const driver = driverMock as any as Driver; - const msg = new SendDataRequest(driver, { + const msg = new SendDataRequest({ command: new NoOperationCC({ nodeId }), }); const ret = createDummyTransaction(driverMock, { @@ -380,14 +380,14 @@ test("Controller message should be preferred over messages for sleeping nodes", return ret; } - const msgForSleepingNode = new SendDataRequest(driverMock, { - command: new NoOperationCC(driverMock, { nodeId: 2 }), + const msgForSleepingNode = new SendDataRequest({ + command: new NoOperationCC({ nodeId: 2 }), }); const tSleepingNode = createTransaction( msgForSleepingNode, MessagePriority.WakeUp, ); - const msgForController = new RemoveFailedNodeRequest(driverMock, { + const msgForController = new RemoveFailedNodeRequest({ failedNodeId: 3, }); const tController = createTransaction(msgForController); diff --git a/packages/zwave-js/src/lib/log/Driver.test.ts b/packages/zwave-js/src/lib/log/Driver.test.ts index 589d00921085..849c597323b1 100644 --- a/packages/zwave-js/src/lib/log/Driver.test.ts +++ b/packages/zwave-js/src/lib/log/Driver.test.ts @@ -88,7 +88,7 @@ function createMessage( driver: Driver, options: Partial, ) { - return new Message(driver, { + return new Message({ type: options.type || MessageType.Request, functionType: options.functionType || (0x00 as any), }); diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts index af6a095402db..cfeaed9dc9f5 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts @@ -10,7 +10,7 @@ test("BridgeApplicationCommandRequest can be parsed without RSSI", async (t) => // Repro for https://github.com/zwave-js/node-zwave-js/issues/4335 t.notThrows(() => - Message.from(host, { + Message.from({ data: Buffer.from( "011200a80001020a320221340000000000000069", "hex", diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts index 2a20792032fc..f013c4fc354e 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts @@ -11,7 +11,7 @@ test("GetSupportedCommandsResponse with extended bitmask parses correctly (pre-7 "hex", ); - const msg = Message.from(host, { + const msg = Message.from({ data, sdkVersion: "7.19.0", ctx: {} as any, @@ -32,7 +32,7 @@ test("GetSupportedCommandsResponse with extended bitmask parses correctly (post- "hex", ); - const msg = Message.from(host, { + const msg = Message.from({ data, sdkVersion: "7.19.1", ctx: {} as any, diff --git a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts index 75904afa7c30..e7b47b43c866 100644 --- a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts @@ -17,14 +17,14 @@ test("should be detected as an encapsulating CC", (t) => { nodeId: 3, targetValue: 89, }); - const crc16 = CRC16CC.encapsulate(host, basicCCSet); + const crc16 = CRC16CC.encapsulate(basicCCSet); t.true(isEncapsulatingCommandClass(crc16)); }); test("should match the specs", (t) => { // SDS13783 contains the following sample encapsulated command: const basicCCGet = new BasicCCGet({ nodeId: 1 }); - const crc16 = CRC16CC.encapsulate(host, basicCCGet); + const crc16 = CRC16CC.encapsulate(basicCCGet); const serialized = crc16.serialize({} as any); const expected = Buffer.from("560120024d26", "hex"); t.deepEqual(serialized, expected); @@ -35,7 +35,7 @@ test("serialization and deserialization should be compatible", (t) => { nodeId: 3, targetValue: 89, }); - const crc16 = CRC16CC.encapsulate(host, basicCCSet); + const crc16 = CRC16CC.encapsulate(basicCCSet); t.is(crc16.nodeId, basicCCSet.nodeId); t.is(crc16.encapsulated, basicCCSet); const serialized = crc16.serialize({} as any); @@ -58,7 +58,7 @@ test("deserializing a CC with a wrong checksum should result in an invalid CC", nodeId: 3, targetValue: 89, }); - const crc16 = CRC16CC.encapsulate(host, basicCCSet); + const crc16 = CRC16CC.encapsulate(basicCCSet); t.is(crc16.nodeId, basicCCSet.nodeId); t.is(crc16.encapsulated, basicCCSet); const serialized = crc16.serialize({} as any); diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.nonImplemented.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.nonImplemented.test.ts index 6eabd644a761..40ba6a78e7fc 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.nonImplemented.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.nonImplemented.test.ts @@ -9,7 +9,7 @@ integrationTest( async testBody(t, driver, node, mockController, mockNode) { // This CC will never be supported (certification requirement) - const cc = new CommandClass(driver, { + const cc = new CommandClass({ nodeId: 2, ccId: CommandClasses["Anti-Theft"], ccCommand: 0x02, diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts index 71fe1285885d..837d4ce6fd49 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts @@ -35,7 +35,7 @@ test("is an encapsulating CommandClass", (t) => { nodeId: 1, targetValue: 50, }); - cc = MultiChannelCC.encapsulate(host, cc); + cc = MultiChannelCC.encapsulate(cc); t.true(isEncapsulatingCommandClass(cc)); }); @@ -85,7 +85,7 @@ test("the CommandEncapsulation command should serialize correctly", (t) => { targetValue: 5, endpoint: 7, }); - cc = MultiChannelCC.encapsulate(host, cc); + cc = MultiChannelCC.encapsulate(cc); const expected = buildCCBuffer( Buffer.from([ MultiChannelCommand.CommandEncapsulation, // CC Command @@ -189,7 +189,6 @@ test("deserializing an unsupported command should return an unspecified version test("MultiChannelCC/BasicCCGet should expect a response", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new BasicCCGet({ nodeId: 2, endpoint: 2, @@ -200,7 +199,6 @@ test("MultiChannelCC/BasicCCGet should expect a response", (t) => { test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new BasicCCGet({ nodeId: 2, endpoint: 2, @@ -213,7 +211,6 @@ test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => { test("MultiChannelCC/BasicCCSet should expect NO response", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new BasicCCSet({ nodeId: 2, endpoint: 2, @@ -225,14 +222,12 @@ test("MultiChannelCC/BasicCCSet should expect NO response", (t) => { test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCReport = expected", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new BasicCCGet({ nodeId: 2, endpoint: 2, }), ); const ccResponse = MultiChannelCC.encapsulate( - host, new BasicCCReport({ nodeId: ccRequest.nodeId, currentValue: 7, @@ -245,14 +240,12 @@ test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCReport = expected", (t) test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCGet = unexpected", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new BasicCCGet({ nodeId: 2, endpoint: 2, }), ); const ccResponse = MultiChannelCC.encapsulate( - host, new BasicCCGet({ nodeId: ccRequest.nodeId, endpoint: 2, @@ -265,13 +258,12 @@ test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCGet = unexpected", (t) test("MultiChannelCC/BasicCCGet => MultiCommandCC/BasicCCReport = unexpected", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new BasicCCGet({ nodeId: 2, endpoint: 2, }), ); - const ccResponse = MultiCommandCC.encapsulate(host, [ + const ccResponse = MultiCommandCC.encapsulate([ new BasicCCReport({ nodeId: ccRequest.nodeId, currentValue: 7, diff --git a/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts index 5d7fdf794583..ec558c7d4099 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts @@ -14,6 +14,6 @@ test("is a multi-encapsulating CommandClass", (t) => { nodeId: 1, targetValue: 50, }); - cc = MultiCommandCC.encapsulate(host, [cc]); + cc = MultiCommandCC.encapsulate([cc]); t.true(isMultiEncapsulatingCommandClass(cc)); }); diff --git a/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts b/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts index b382c7c9e1ce..99d8cb0ad2e6 100644 --- a/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts @@ -7,7 +7,6 @@ const host = createTestingHost(); test("SupervisionCCGet should expect a response", (t) => { const ccRequest = SupervisionCC.encapsulate( - host, new BasicCCSet({ nodeId: 2, targetValue: 5, @@ -18,7 +17,6 @@ test("SupervisionCCGet should expect a response", (t) => { test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = expected", (t) => { const ccRequest = SupervisionCC.encapsulate( - host, new BasicCCSet({ nodeId: 2, targetValue: 5, @@ -36,7 +34,6 @@ test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = exp test("SupervisionCC/BasicCCSet => SupervisionCCReport (wrong session ID) = unexpected", (t) => { const ccRequest = SupervisionCC.encapsulate( - host, new BasicCCSet({ nodeId: 2, targetValue: 5, diff --git a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts index 8fb60a603854..9e86bdd31298 100644 --- a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts @@ -20,7 +20,6 @@ test("WakeUpCCNoMoreInformation should expect no response", (t) => { test("MultiChannelCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { const ccRequest = MultiChannelCC.encapsulate( - host, new WakeUpCCNoMoreInformation({ nodeId: 2, endpoint: 2, @@ -42,7 +41,6 @@ test("SecurityCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { }; const ccRequest = SecurityCC.encapsulate( - host, host.ownNodeId, securityManager as any, new WakeUpCCNoMoreInformation({ diff --git a/packages/zwave-js/src/lib/test/compliance/zwavePlusInfoResponse.test.ts b/packages/zwave-js/src/lib/test/compliance/zwavePlusInfoResponse.test.ts index 5ec609b59f43..d1cd190b1ad3 100644 --- a/packages/zwave-js/src/lib/test/compliance/zwavePlusInfoResponse.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/zwavePlusInfoResponse.test.ts @@ -27,7 +27,7 @@ integrationTest("Response to Z-Wave Plus Info Get", { }, testBody: async (t, driver, node, mockController, mockNode) => { - const zwpRequest = new ZWavePlusCCGet(mockController.host, { + const zwpRequest = new ZWavePlusCCGet({ nodeId: mockNode.id, }); await mockNode.sendToController( diff --git a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts index 7506bfe66368..b63ee216c405 100644 --- a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts @@ -51,7 +51,7 @@ test.afterEach.always(async (t) => { test.serial("returns true when a non-partial CC is received", (t) => { const { driver } = t.context; const cc = new BasicCCSet({ nodeId: 2, targetValue: 50 }); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.true(driver["assemblePartialCCs"](msg)); @@ -75,7 +75,7 @@ test.serial( ]), context: {} as any, }); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.true(driver["assemblePartialCCs"](msg)); @@ -100,7 +100,7 @@ test.serial( ]), context: {} as any, }); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.false(driver["assemblePartialCCs"](msg)); @@ -139,12 +139,12 @@ test.serial( ]), context: {} as any, }); - const msg1 = new ApplicationCommandRequest(driver, { + const msg1 = new ApplicationCommandRequest({ command: cc1, }); t.false(driver["assemblePartialCCs"](msg1)); - const msg2 = new ApplicationCommandRequest(driver, { + const msg2 = new ApplicationCommandRequest({ command: cc2, }); t.true(driver["assemblePartialCCs"](msg2)); @@ -164,7 +164,7 @@ test.serial("does not crash when receiving a Multi Command CC", (t) => { nodeId: 2, encapsulated: [cc1, cc2], }); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.true(driver["assemblePartialCCs"](msg)); @@ -181,7 +181,7 @@ test.serial("supports nested partial/non-partial CCs", (t) => { }); cc.encapsulated = undefined as any; cc["decryptedCCBytes"] = cc1.serialize({} as any); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.true(driver["assemblePartialCCs"](msg)); @@ -206,7 +206,7 @@ test.serial("supports nested partial/partial CCs (part 1)", (t) => { 2, 3, ]); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.false(driver["assemblePartialCCs"](msg)); @@ -231,7 +231,7 @@ test.serial("supports nested partial/partial CCs (part 2)", (t) => { 2, 3, ]); - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.true(driver["assemblePartialCCs"](msg)); @@ -261,7 +261,7 @@ test.serial( ZWaveErrorCodes.Deserialization_NotImplemented, ); }; - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.false(driver["assemblePartialCCs"](msg)); @@ -292,7 +292,7 @@ test.serial( ZWaveErrorCodes.CC_NotImplemented, ); }; - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.false(driver["assemblePartialCCs"](msg)); @@ -323,7 +323,7 @@ test.serial( ZWaveErrorCodes.PacketFormat_InvalidPayload, ); }; - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.false(driver["assemblePartialCCs"](msg)); @@ -349,7 +349,7 @@ test.serial("passes other errors during merging through", (t) => { cc.mergePartialCCs = () => { throw new ZWaveError("invalid", ZWaveErrorCodes.Argument_Invalid); }; - const msg = new ApplicationCommandRequest(driver, { + const msg = new ApplicationCommandRequest({ command: cc, }); t.throws(() => driver["assemblePartialCCs"](msg), { message: /invalid/ }); diff --git a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts index d8d6e79bf0e8..b7d5311af2bd 100644 --- a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts +++ b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts @@ -43,7 +43,7 @@ test.afterEach.always(async (t) => { test("should compute the correct net payload sizes", (t) => { const { driver } = t.context; - const testMsg1 = new SendDataRequest(driver, { + const testMsg1 = new SendDataRequest({ command: new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, @@ -60,7 +60,7 @@ test("should compute the correct net payload sizes", (t) => { destination: 1, encapsulated: {} as any, }); - const testMsg2 = new SendDataRequest(driver, { + const testMsg2 = new SendDataRequest({ command: new SecurityCCCommandEncapsulation({ nodeId: 2, ownNodeId: driver.ownNodeId, diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts index 2612e9463eae..994574552cbe 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts @@ -171,12 +171,9 @@ integrationTest( // Node 10 wakes up mockNode10.autoAckControllerFrames = true; - const cc: CommandClass = new WakeUpCCWakeUpNotification( - mockNode10.host, - { - nodeId: mockController.ownNodeId, - }, - ); + const cc: CommandClass = new WakeUpCCWakeUpNotification({ + nodeId: mockController.ownNodeId, + }); mockNode10.sendToController(createMockZWaveRequestFrame(cc, { ackRequested: false, })); @@ -306,12 +303,9 @@ integrationTest( // Node 10 wakes up mockNode10.autoAckControllerFrames = true; - const cc: CommandClass = new WakeUpCCWakeUpNotification( - mockNode10.host, - { - nodeId: mockController.ownNodeId, - }, - ); + const cc: CommandClass = new WakeUpCCWakeUpNotification({ + nodeId: mockController.ownNodeId, + }); mockNode10.sendToController(createMockZWaveRequestFrame(cc, { ackRequested: false, })); diff --git a/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts b/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts index 62db5673455f..a76f267286c0 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts @@ -30,7 +30,7 @@ integrationTest( const respondToBasicGetWithDelayedAck: MockNodeBehavior = { async handleCC(controller, self, receivedCC) { if (receivedCC instanceof BasicCCGet) { - const cc = new BasicCCReport(controller.host, { + const cc = new BasicCCReport({ nodeId: self.id, currentValue: 55, }); diff --git a/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts b/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts index 866dd57275c1..d5c1d155ad4c 100644 --- a/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts +++ b/packages/zwave-js/src/lib/test/driver/receiveMessages.test.ts @@ -36,7 +36,7 @@ test.serial( "should not crash if a message is received that cannot be deserialized", async (t) => { const { driver, controller } = t.context; - const req = new ApplicationCommandRequest(driver, { + const req = new ApplicationCommandRequest({ command: new WakeUpCCIntervalSet({ nodeId: 1, controllerNodeId: 2, diff --git a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts index 6d64a8924894..8e5cde068156 100644 --- a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts @@ -94,7 +94,6 @@ integrationTest("Communication via Security S0 works", { controlledCCs: [], }); const cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, response, @@ -147,7 +146,6 @@ integrationTest("Communication via Security S0 works", { currentValue: ++queryCount, }); const cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, response, diff --git a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts index 81257b1e38cb..800d14e5119e 100644 --- a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts @@ -119,7 +119,6 @@ integrationTest( controlledCCs: [], }); const cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, response, @@ -182,7 +181,6 @@ integrationTest( currentValue: queryCount, }); const cc = SecurityCC.encapsulate( - self.host, self.id, self.securityManagers.securityManager!, response, @@ -234,7 +232,7 @@ integrationTest( await wait(150); // Now send a Nonce Get from node 3, which must be answered immediately - const nonceGet = new SecurityCCNonceGet(mockNode3.host, { + const nonceGet = new SecurityCCNonceGet({ nodeId: mockController.ownNodeId, }); await mockNode3.sendToController( diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts index 1ffdf8940737..b9de6e4f3b09 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts @@ -803,7 +803,7 @@ integrationTest( MockControllerCommunicationState.Idle, ); - const ret = new SerialAPIStartedRequest(mockController.host, { + const ret = new SerialAPIStartedRequest({ wakeUpReason: SerialAPIWakeUpReason.WatchdogReset, watchdogEnabled: true, isListening: true, diff --git a/packages/zwave-js/src/lib/test/driver/supervisionRepeatedReport.test.ts b/packages/zwave-js/src/lib/test/driver/supervisionRepeatedReport.test.ts index 3e212e4ec7b5..1883f8109adc 100644 --- a/packages/zwave-js/src/lib/test/driver/supervisionRepeatedReport.test.ts +++ b/packages/zwave-js/src/lib/test/driver/supervisionRepeatedReport.test.ts @@ -42,7 +42,7 @@ integrationTest( const respondToSupervisionGet: MockNodeBehavior = { handleCC(controller, self, receivedCC) { if (receivedCC instanceof SupervisionCCGet) { - const cc = new SupervisionCCReport(controller.host, { + const cc = new SupervisionCCReport({ nodeId: self.id, sessionId: receivedCC.sessionId, moreUpdatesFollow: false, diff --git a/packages/zwave-js/src/lib/test/mocks.ts b/packages/zwave-js/src/lib/test/mocks.ts index b407a372d5d1..9e15f4923e3c 100644 --- a/packages/zwave-js/src/lib/test/mocks.ts +++ b/packages/zwave-js/src/lib/test/mocks.ts @@ -27,7 +27,6 @@ import { priority, } from "@zwave-js/serial"; import sinon from "sinon"; -import type { Driver } from "../driver/Driver"; import type { ZWaveNode } from "../node/Node"; import * as nodeUtils from "../node/utils"; import { SendDataRequest } from "../serialapi/transport/SendDataMessages"; @@ -171,9 +170,7 @@ export function createEmptyMockDriver() { }, }; ret.sendCommand.callsFake(async (command, options) => { - const msg = new SendDataRequest(ret as unknown as Driver, { - command, - }); + const msg = new SendDataRequest({ command }); const resp = await ret.sendMessage(msg, options); return resp?.command; }); diff --git a/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts b/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts index 4f02cb584b6a..a356fdc2d349 100644 --- a/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.handleCommand.test.ts @@ -64,18 +64,15 @@ test.serial( } as any; // Handle a command for the root endpoint - const command = new BinarySwitchCCReport( - fakeDriver as unknown as Driver, - { - nodeId: 2, - data: Buffer.from([ - CommandClasses["Binary Switch"], - BinarySwitchCommand.Report, - 0xff, - ]), - context: {} as any, - }, - ); + const command = new BinarySwitchCCReport({ + nodeId: 2, + data: Buffer.from([ + CommandClasses["Binary Switch"], + BinarySwitchCommand.Report, + 0xff, + ]), + context: {} as any, + }); await node.handleCommand(command); t.true( @@ -120,14 +117,11 @@ test.serial( Buffer.alloc(12, 0xff), ]); - const command = new EntryControlCCNotification( - fakeDriver as unknown as Driver, - { - nodeId: node.id, - data: buf, - context: {} as any, - }, - ); + const command = new EntryControlCCNotification({ + nodeId: node.id, + data: buf, + context: {} as any, + }); await node.handleCommand(command); diff --git a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts index 8e7a1dba50e4..f1730da94fb9 100644 --- a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts +++ b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts @@ -64,21 +64,17 @@ integrationTest( }, testBody: async (t, driver, node, mockController, mockNode) => { - const nif = new ApplicationUpdateRequestNodeInfoReceived( - mockController.host, - { - nodeInformation: { - nodeId: node.id, - basicDeviceClass: - mockNode.capabilities.basicDeviceClass, - genericDeviceClass: - mockNode.capabilities.genericDeviceClass, - specificDeviceClass: - mockNode.capabilities.specificDeviceClass, - supportedCCs: [...mockNode.implementedCCs.keys()], - }, + const nif = new ApplicationUpdateRequestNodeInfoReceived({ + nodeInformation: { + nodeId: node.id, + basicDeviceClass: mockNode.capabilities.basicDeviceClass, + genericDeviceClass: + mockNode.capabilities.genericDeviceClass, + specificDeviceClass: + mockNode.capabilities.specificDeviceClass, + supportedCCs: [...mockNode.implementedCCs.keys()], }, - ); + }); await mockController.sendMessageToHost(nif); await wait(100); From 4c342cd3a37acfa9bb37ec83ff97d37d12779743 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 09:13:53 +0200 Subject: [PATCH 41/60] refactor: split up ZWaveApplicationHost more, remove unnecessary methods --- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 22 +---- packages/cc/src/cc/ManufacturerSpecificCC.ts | 4 +- packages/cc/src/cc/WakeUpCC.ts | 2 +- packages/cc/src/lib/CommandClass.ts | 8 +- .../core/src/abstractions/ICommandClass.ts | 1 + packages/host/src/ZWaveHost.ts | 88 ++++++++----------- packages/host/src/mocks.ts | 18 +--- packages/zwave-js/src/lib/driver/Driver.ts | 22 ++--- .../src/lib/node/mixins/70_FirmwareUpdate.ts | 43 +++++---- packages/zwave-js/src/lib/node/utils.ts | 2 +- 10 files changed, 83 insertions(+), 127 deletions(-) diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index b5dbdf38ead9..1286c83b33a8 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -43,7 +43,6 @@ import { V } from "../lib/Values"; import { FirmwareDownloadStatus, FirmwareUpdateActivationStatus, - type FirmwareUpdateInitResult, type FirmwareUpdateMetaData, FirmwareUpdateMetaDataCommand, FirmwareUpdateRequestStatus, @@ -161,12 +160,12 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { /** * Requests the device to start the firmware update process. - * WARNING: This method may wait up to 60 seconds for a reply. + * This does not wait for the reply - that is up to the caller of this method. */ @validateArgs() public async requestUpdate( options: FirmwareUpdateMetaDataCCRequestGetOptions, - ): Promise { + ): Promise { this.assertSupportsCommand( FirmwareUpdateMetaDataCommand, FirmwareUpdateMetaDataCommand.RequestGet, @@ -177,29 +176,12 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - // Since the response may take longer than with other commands, - // we do not use the built-in waiting functionality, which would block - // all other communication. await this.applHost.sendCommand(cc, { ...this.commandOptions, // Do not wait for Nonce Reports s2VerifyDelivery: false, }); - const result = await this.applHost - .waitForCommand< - FirmwareUpdateMetaDataCCRequestReport - >( - (cc) => - cc instanceof FirmwareUpdateMetaDataCCRequestReport - && cc.nodeId === this.endpoint.nodeId, - 60000, - ); - return pick(result, [ - "status", - "resume", - "nonSecureTransfer", - ]); } /** diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 5bf1db1f1c35..56bc0febeafd 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -190,7 +190,7 @@ export class ManufacturerSpecificCC extends CommandClass { endpoint, ).withOptions({ priority: MessagePriority.NodeQuery }); - if (!applHost.isControllerNode(node.id)) { + if (node.id !== applHost.ownNodeId) { applHost.controllerLog.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, @@ -207,7 +207,7 @@ export class ManufacturerSpecificCC extends CommandClass { const logMessage = `received response for manufacturer information: manufacturer: ${ - applHost.configManager.lookupManufacturer( + applHost.lookupManufacturer( mfResp.manufacturerId, ) || "unknown" diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index b17942fc252a..55c84591d7a4 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -242,7 +242,7 @@ export class WakeUpCC extends CommandClass { direction: "none", }); - if (applHost.isControllerNode(node.id)) { + if (node.id === applHost.ownNodeId) { applHost.controllerLog.logNode( node.id, `skipping wakeup configuration for the controller`, diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index b027147469f3..0050b16184b9 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -143,12 +143,16 @@ export type CCNode = export function getEffectiveCCVersion( ctx: GetSupportedCCVersion, - cc: CommandClass, + cc: CCId, defaultVersion?: number, ): number { // For multicast and broadcast CCs, just use the highest implemented version to serialize // Older nodes will ignore the additional fields - if (!cc.isSinglecast()) { + if ( + typeof cc.nodeId !== "number" + || cc.nodeId === NODE_ID_BROADCAST + || cc.nodeId === NODE_ID_BROADCAST_LR + ) { return getImplementedVersion(cc.ccId); } // For singlecast CCs, set the CC version as high as possible diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts index e66bdce35195..98b7a08ce799 100644 --- a/packages/core/src/abstractions/ICommandClass.ts +++ b/packages/core/src/abstractions/ICommandClass.ts @@ -20,6 +20,7 @@ export interface SecurityManagers { /** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ export interface CCId { nodeId: number | MulticastDestination; + endpointIndex?: number; ccId: CommandClasses; ccCommand?: number; } diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 17b4d78fc076..e0ca54461fa1 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -1,11 +1,10 @@ -import type { ConfigManager, DeviceConfig } from "@zwave-js/config"; +import type { DeviceConfig } from "@zwave-js/config"; import type { CCId, CommandClasses, ControllerLogger, FrameType, MaybeNotKnown, - NodeIDType, NodeId, SecurityClass, SecurityManagers, @@ -51,6 +50,19 @@ export interface GetSupportedCCVersion { ): number; } +export interface GetSafeCCVersion { + /** + * Retrieves the maximum version of a command class that can be used to communicate with a node. + * Returns 1 if the node claims that it does not support a CC. + * Returns `undefined` for CCs that are not implemented in this library yet. + */ + getSafeCCVersion( + cc: CommandClasses, + nodeId: number, + endpointIndex?: number, + ): number | undefined; +} + /** Additional context needed for deserializing CCs */ export interface CCParsingContext extends Readonly, GetDeviceConfig, HostIDs @@ -118,6 +130,20 @@ export interface GetAllNodes { getAllNodes(): T[]; } +/** Allows looking up Z-Wave manufacturers by manufacturer ID */ +export interface LookupManufacturer { + /** Looks up the name of the manufacturer with the given ID in the configuration DB */ + lookupManufacturer(manufacturerId: number): string | undefined; +} + +/** Allows sending commands to one or more nodes */ +export interface SendCommand { + sendCommand( + command: CCId, + options?: SendCommandOptions, + ): Promise>; +} + export interface ZWaveApplicationHost extends GetValueDB, @@ -125,66 +151,26 @@ export interface ZWaveApplicationHost GetNode, GetAllNodes, SecurityManagers, - GetDeviceConfig + GetDeviceConfig, + LookupManufacturer, + SchedulePoll, + GetSupportedCCVersion, + GetSafeCCVersion, + SendCommand { - /** Gives access to the configuration files */ - configManager: ConfigManager; - options: ZWaveHostOptions; - readonly nodeIdType?: NodeIDType; - // TODO: There's probably a better fitting name for this now controllerLog: ControllerLogger; +} - /** Whether the node with the given ID is the controller */ - isControllerNode(nodeId: number): boolean; - - sendCommand( - command: CCId, - options?: SendCommandOptions, - ): Promise>; - - waitForCommand( - predicate: (cc: CCId) => boolean, - timeout: number, - ): Promise; - +/** Allows scheduling a value refresh (poll) for a later time */ +export interface SchedulePoll { schedulePoll( nodeId: number, valueId: ValueID, options: NodeSchedulePollOptions, ): boolean; - - /** - * Retrieves the maximum version of a command class that can be used to communicate with a node. - * Returns 1 if the node claims that it does not support a CC. - * Returns `undefined` for CCs that are not implemented in this library yet. - */ - getSafeCCVersion( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): number | undefined; - - /** - * Retrieves the maximum version of a command class the given node/endpoint has reported support for. - * Returns 0 when the CC is not supported or that information is not known yet. - */ - getSupportedCCVersion( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): number; - - /** - * Determines whether a CC must be secure for a given node and endpoint. - */ - isCCSecure( - cc: CommandClasses, - nodeId: number, - endpointIndex?: number, - ): boolean; } export interface NodeSchedulePollOptions { diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index babd0e065c2e..fc2ef8e157a6 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -1,10 +1,8 @@ /* eslint-disable @typescript-eslint/require-await */ -import { ConfigManager } from "@zwave-js/config"; import { type EndpointId, type GetEndpoint, type IsCCSecure, - NodeIDType, type NodeId, type QuerySecurityClasses, type SetSecurityClass, @@ -54,8 +52,6 @@ export function createTestingHost< const ret: TestingHost = { homeId: options.homeId ?? 0x7e570001, ownNodeId: options.ownNodeId ?? 1, - nodeIdType: NodeIDType.Short, - isControllerNode: (nodeId) => nodeId === ret.ownNodeId, securityManager: undefined, securityManager2: undefined, securityManagerLR: undefined, @@ -67,7 +63,7 @@ export function createTestingHost< }; }, }), - configManager: new ConfigManager(), + lookupManufacturer: () => undefined, options: { attempts: { nodeInterview: 1, @@ -114,15 +110,6 @@ export function createTestingHost< tryGetValueDB: (nodeId) => { return ret.getValueDB(nodeId); }, - isCCSecure: (ccId, nodeId, endpointIndex = 0) => { - const node = nodes.get(nodeId); - const endpoint = node?.getEndpoint(endpointIndex); - return ( - node?.isSecure !== false - && !!(endpoint ?? node)?.isCCSecure(ccId) - && !!(ret.securityManager || ret.securityManager2) - ); - }, // getHighestSecurityClass: (nodeId) => { // const node = nodes.getOrThrow(nodeId); // return node.getHighestSecurityClass(); @@ -138,9 +125,6 @@ export function createTestingHost< sendCommand: async (_command, _options) => { return undefined as any; }, - waitForCommand: async (_predicate, _timeout) => { - return undefined as any; - }, schedulePoll: (_nodeId, _valueId, _options) => { return false; }, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 1477004adc88..97f60ce53aea 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -726,7 +726,7 @@ export class Driver extends TypedEventEmitter ...this.messageEncodingContext, ownNodeId: this.controller.ownNodeId!, homeId: this.controller.homeId!, - nodeIdType: this.nodeIdType, + nodeIdType: this._controller?.nodeIdType ?? NodeIDType.Short, securityManager: this.securityManager, securityManager2: this.securityManager2, securityManagerLR: this.securityManagerLR, @@ -740,7 +740,7 @@ export class Driver extends TypedEventEmitter ...this.messageParsingContext, ownNodeId: this.controller.ownNodeId!, homeId: this.controller.homeId!, - nodeIdType: this.nodeIdType, + nodeIdType: this._controller?.nodeIdType ?? NodeIDType.Short, securityManager: this.securityManager, securityManager2: this.securityManager2, securityManagerLR: this.securityManagerLR, @@ -983,10 +983,6 @@ export class Driver extends TypedEventEmitter return this.controller.ownNodeId!; } - public get nodeIdType(): NodeIDType { - return this._controller?.nodeIdType ?? NodeIDType.Short; - } - /** @internal Used for compatibility with the ZWaveApplicationHost interface */ public getNode(nodeId: number): ZWaveNode | undefined { return this.controller.nodes.get(nodeId); @@ -1042,6 +1038,10 @@ export class Driver extends TypedEventEmitter return this.controller.nodes.get(nodeId)?.deviceConfig; } + public lookupManufacturer(manufacturerId: number): string | undefined { + return this.configManager.lookupManufacturer(manufacturerId); + } + public getHighestSecurityClass( nodeId: number, ): MaybeNotKnown { @@ -1074,16 +1074,6 @@ export class Driver extends TypedEventEmitter node.setSecurityClass(securityClass, granted); } - /** - * **!!! INTERNAL !!!** - * - * Not intended to be used by applications. Use `node.isControllerNode` instead! - */ - public isControllerNode(nodeId: number): boolean { - // This is needed for the ZWaveHost interface - return nodeId === this.ownNodeId; - } - /** Updates the logging configuration without having to restart the driver. */ public updateLogConfig(config: Partial): void { this._logContainer.updateConfiguration(config); diff --git a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts index 7a049b6ffd8f..8214c9756b92 100644 --- a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts +++ b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts @@ -1,10 +1,10 @@ import { - type FirmwareUpdateInitResult, type FirmwareUpdateMetaData, FirmwareUpdateMetaDataCC, FirmwareUpdateMetaDataCCGet, type FirmwareUpdateMetaDataCCMetaDataGet, FirmwareUpdateMetaDataCCReport, + FirmwareUpdateMetaDataCCRequestReport, FirmwareUpdateMetaDataCCStatusReport, type FirmwareUpdateOptions, type FirmwareUpdateProgress, @@ -636,7 +636,7 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin } /** Kicks off a firmware update of a single target. Returns whether the node accepted resuming and non-secure transfer */ - private *beginFirmwareUpdateInternal( + private async *beginFirmwareUpdateInternal( data: Buffer, target: number, meta: FirmwareUpdateMetaData, @@ -655,21 +655,30 @@ export abstract class FirmwareUpdateMixin extends SchedulePollMixin direction: "outbound", }); - // Request the node to start the upgrade. Pause the task until this is done, - // since the call can block for a long time - const result: FirmwareUpdateInitResult = yield () => - api.requestUpdate({ - // TODO: Should manufacturer id and firmware id be provided externally? - manufacturerId: meta.manufacturerId, - firmwareId: target == 0 - ? meta.firmwareId - : meta.additionalFirmwareIDs[target - 1], - firmwareTarget: target, - fragmentSize, - checksum, - resume, - nonSecureTransfer, - }); + // Request the node to start the upgrade + await api.requestUpdate({ + // TODO: Should manufacturer id and firmware id be provided externally? + manufacturerId: meta.manufacturerId, + firmwareId: target == 0 + ? meta.firmwareId + : meta.additionalFirmwareIDs[target - 1], + firmwareTarget: target, + fragmentSize, + checksum, + resume, + nonSecureTransfer, + }); + // Pause the task until the response is received, because that can take + // up to a minute + const result: FirmwareUpdateMetaDataCCRequestReport = yield () => + this.driver + .waitForCommand( + (cc) => + cc instanceof FirmwareUpdateMetaDataCCRequestReport + && cc.nodeId === this.id, + 60000, + ); + switch (result.status) { case FirmwareUpdateRequestStatus.Error_AuthenticationExpected: throw new ZWaveError( diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index dd98b3252e41..15ba32c92139 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -327,7 +327,7 @@ export function getDefinedValueIDsInternal( includeInternal: boolean = false, ): TranslatedValueID[] { // The controller has no values. Even if some ended up in the cache somehow, do not return any. - if (applHost.isControllerNode(node.id)) return []; + if (node.id === applHost.ownNodeId) return []; let ret: ValueID[] = []; const allowControlled: CommandClasses[] = [ From dc7e12d4462dfd498d0e47bf0f4a31c63c367355 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 09:32:41 +0200 Subject: [PATCH 42/60] refactor: split up ZWaveApplicationHost even more --- packages/cc/src/cc/AlarmSensorCC.ts | 14 +++--- packages/cc/src/cc/AssociationCC.ts | 14 +++--- packages/cc/src/cc/AssociationGroupInfoCC.ts | 12 ++--- packages/cc/src/cc/BarrierOperatorCC.ts | 14 +++--- packages/cc/src/cc/BasicCC.ts | 8 ++-- packages/cc/src/cc/BatteryCC.ts | 10 ++-- packages/cc/src/cc/BinarySensorCC.ts | 16 +++---- packages/cc/src/cc/BinarySwitchCC.ts | 6 +-- packages/cc/src/cc/CentralSceneCC.ts | 12 ++--- packages/cc/src/cc/ClockCC.ts | 6 +-- packages/cc/src/cc/ColorSwitchCC.ts | 10 ++-- packages/cc/src/cc/ConfigurationCC.ts | 36 +++++++-------- packages/cc/src/cc/DoorLockCC.ts | 14 +++--- packages/cc/src/cc/DoorLockLoggingCC.ts | 8 ++-- packages/cc/src/cc/EnergyProductionCC.ts | 4 +- packages/cc/src/cc/EntryControlCC.ts | 16 +++---- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 8 ++-- packages/cc/src/cc/HumidityControlModeCC.ts | 12 ++--- .../src/cc/HumidityControlOperatingStateCC.ts | 6 +-- .../cc/src/cc/HumidityControlSetpointCC.ts | 18 ++++---- packages/cc/src/cc/IndicatorCC.ts | 16 +++---- packages/cc/src/cc/IrrigationCC.ts | 22 ++++----- packages/cc/src/cc/LanguageCC.ts | 6 +-- packages/cc/src/cc/LockCC.ts | 6 +-- .../cc/src/cc/ManufacturerProprietaryCC.ts | 4 +- packages/cc/src/cc/ManufacturerSpecificCC.ts | 6 +-- packages/cc/src/cc/MeterCC.ts | 12 ++--- .../cc/src/cc/MultiChannelAssociationCC.ts | 18 ++++---- packages/cc/src/cc/MultiChannelCC.ts | 42 ++++++++--------- packages/cc/src/cc/MultilevelSensorCC.ts | 37 +++++++-------- packages/cc/src/cc/MultilevelSwitchCC.ts | 8 ++-- packages/cc/src/cc/NodeNamingCC.ts | 10 ++-- packages/cc/src/cc/NotificationCC.ts | 26 +++++------ packages/cc/src/cc/ProtectionCC.ts | 18 ++++---- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 4 +- .../src/cc/SceneControllerConfigurationCC.ts | 10 ++-- packages/cc/src/cc/ScheduleEntryLockCC.ts | 8 ++-- packages/cc/src/cc/Security2CC.ts | 18 ++++---- packages/cc/src/cc/SecurityCC.ts | 12 ++--- packages/cc/src/cc/SoundSwitchCC.ts | 16 +++---- packages/cc/src/cc/ThermostatFanModeCC.ts | 12 ++--- packages/cc/src/cc/ThermostatFanStateCC.ts | 6 +-- packages/cc/src/cc/ThermostatModeCC.ts | 12 ++--- .../cc/src/cc/ThermostatOperatingStateCC.ts | 6 +-- packages/cc/src/cc/ThermostatSetbackCC.ts | 6 +-- packages/cc/src/cc/ThermostatSetpointCC.ts | 20 ++++---- packages/cc/src/cc/TimeCC.ts | 4 +- packages/cc/src/cc/TimeParametersCC.ts | 4 +- packages/cc/src/cc/UserCodeCC.ts | 24 +++++----- packages/cc/src/cc/VersionCC.ts | 24 +++++----- packages/cc/src/cc/WakeUpCC.ts | 18 ++++---- packages/cc/src/cc/WindowCoveringCC.ts | 8 ++-- packages/cc/src/cc/ZWavePlusCC.ts | 6 +-- .../cc/manufacturerProprietary/FibaroCC.ts | 6 +-- packages/cc/src/lib/API.ts | 15 +++--- packages/cc/src/lib/utils.ts | 40 ++++++++-------- packages/host/src/ZWaveHost.ts | 27 +++++++++-- packages/host/src/mocks.ts | 38 ++++++++------- packages/zwave-js/src/lib/driver/Driver.ts | 46 +++++++++++++++++-- 59 files changed, 463 insertions(+), 402 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 848b61fbf3fd..0e15dad7491b 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -177,7 +177,7 @@ export class AlarmSensorCC extends CommandClass { // Skip the interview in favor of Notification CC if possible if (endpoint.supportsCC(CommandClasses.Notification)) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: skipping interview because Notification CC is supported...`, @@ -195,14 +195,14 @@ export class AlarmSensorCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Find out which sensor types this sensor supports - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported sensor types...", direction: "outbound", @@ -215,13 +215,13 @@ export class AlarmSensorCC extends CommandClass { .map((name) => `\n· ${name}`) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported sensor types timed out, skipping interview...", @@ -262,7 +262,7 @@ export class AlarmSensorCC extends CommandClass { const sensorName = getEnumMemberName(AlarmSensorType, type); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value for ${sensorName}...`, direction: "outbound", @@ -279,7 +279,7 @@ severity: ${currentValue.severity}`; message += ` duration: ${currentValue.duration}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message, direction: "inbound", diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index c7ae11f24924..08e4caf1327d 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -401,7 +401,7 @@ export class AssociationCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -412,20 +412,20 @@ export class AssociationCC extends CommandClass { // multi channel association groups // Find out how many groups are supported - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying number of association groups...", direction: "outbound", }); const groupCount = await api.getGroupCount(); if (groupCount != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `supports ${groupCount} association groups`, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying association groups timed out, skipping interview...", @@ -439,7 +439,7 @@ export class AssociationCC extends CommandClass { // Skip the remaining Association CC interview in favor of Multi Channel Association if possible if (endpoint.supportsCC(CommandClasses["Multi Channel Association"])) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: delaying configuration of lifeline associations until after Multi Channel Association interview...`, @@ -476,7 +476,7 @@ export class AssociationCC extends CommandClass { // Query each association group for (let groupId = 1; groupId <= groupCount; groupId++) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying association group #${groupId}...`, direction: "outbound", @@ -487,7 +487,7 @@ export class AssociationCC extends CommandClass { `received information for association group #${groupId}: maximum # of nodes: ${group.maxNodes} currently assigned nodes: ${group.nodeIds.map(String).join(", ")}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index cff849ff794f..8900691ac888 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -364,7 +364,7 @@ export class AssociationGroupInfoCC extends CommandClass { endpoint, ).withOptions({ priority: MessagePriority.NodeQuery }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -378,7 +378,7 @@ export class AssociationGroupInfoCC extends CommandClass { for (let groupId = 1; groupId <= associationGroupCount; groupId++) { // First get the group's name - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Association group #${groupId}: Querying name...`, direction: "outbound", @@ -387,7 +387,7 @@ export class AssociationGroupInfoCC extends CommandClass { if (name) { const logMessage = `Association group #${groupId} has name "${name}"`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -395,7 +395,7 @@ export class AssociationGroupInfoCC extends CommandClass { } // Then the command list - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Association group #${groupId}: Querying command list...`, @@ -436,7 +436,7 @@ export class AssociationGroupInfoCC extends CommandClass { for (let groupId = 1; groupId <= associationGroupCount; groupId++) { // Then its information - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Association group #${groupId}: Querying info...`, direction: "outbound", @@ -452,7 +452,7 @@ profile: ${ info.profile, ) }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 2ae3ace6b665..67461983206c 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -433,7 +433,7 @@ export class BarrierOperatorCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -442,13 +442,13 @@ export class BarrierOperatorCC extends CommandClass { // Create targetState value if it does not exist this.ensureMetadata(applHost, BarrierOperatorCCValues.targetState); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "Querying signaling capabilities...", direction: "outbound", }); const resp = await api.getSignalingCapabilities(); if (resp) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Received supported subsystem types: ${ resp .map((t) => @@ -465,7 +465,7 @@ export class BarrierOperatorCC extends CommandClass { // for valid values and throws otherwise. if (!isEnumMember(SubsystemType, subsystemType)) continue; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Enabling subsystem ${ getEnumMemberName( SubsystemType, @@ -508,7 +508,7 @@ export class BarrierOperatorCC extends CommandClass { // for valid values and throws otherwise. if (!isEnumMember(SubsystemType, subsystemType)) continue; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Querying event signaling state for subsystem ${ getEnumMemberName( SubsystemType, @@ -519,7 +519,7 @@ export class BarrierOperatorCC extends CommandClass { }); const state = await api.getEventSignaling(subsystemType); if (state != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Subsystem ${ getEnumMemberName( SubsystemType, @@ -531,7 +531,7 @@ export class BarrierOperatorCC extends CommandClass { } } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying current barrier state...", direction: "outbound", }); diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 6832cd5755da..fef4b9fa2463 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -259,7 +259,7 @@ export class BasicCC extends CommandClass { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -275,7 +275,7 @@ export class BasicCC extends CommandClass { if ( this.getValue(applHost, BasicCCValues.currentValue) == undefined ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "No response to Basic Get command, assuming Basic CC is unsupported...", @@ -306,7 +306,7 @@ export class BasicCC extends CommandClass { }); // try to query the current state - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Basic CC state...", direction: "outbound", @@ -321,7 +321,7 @@ current value: ${basicResponse.currentValue}`; target value: ${basicResponse.targetValue} remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 1858b978b92b..5790c3421032 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -282,7 +282,7 @@ export class BatteryCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -308,7 +308,7 @@ export class BatteryCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying battery status...", direction: "outbound", @@ -335,7 +335,7 @@ needs to be replaced or charged: ${ is low temperature ${batteryStatus.lowTemperatureStatus} is disconnected: ${batteryStatus.disconnected}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -344,7 +344,7 @@ is disconnected: ${batteryStatus.disconnected}`; if (api.version >= 2) { // always query the health - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying battery health...", direction: "outbound", @@ -355,7 +355,7 @@ is disconnected: ${batteryStatus.disconnected}`; const logMessage = `received response for battery health: max. capacity: ${batteryHealth.maximumCapacity} % temperature: ${batteryHealth.temperature} °C`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index c3d4d02bc77b..fd14e2916439 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -203,7 +203,7 @@ export class BinarySensorCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -211,7 +211,7 @@ export class BinarySensorCC extends CommandClass { // Find out which sensor types this sensor supports if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported sensor types...", direction: "outbound", @@ -226,13 +226,13 @@ export class BinarySensorCC extends CommandClass { .map((name) => `\n· ${name}`) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported sensor types timed out, skipping interview...", @@ -263,14 +263,14 @@ export class BinarySensorCC extends CommandClass { // Query (all of) the sensor's current value(s) if (api.version === 1) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current value...", direction: "outbound", }); const currentValue = await api.get(); if (currentValue != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received current value: ${currentValue}`, direction: "inbound", @@ -289,14 +289,14 @@ export class BinarySensorCC extends CommandClass { if (!isEnumMember(BinarySensorType, type)) continue; const sensorName = getEnumMemberName(BinarySensorType, type); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value for ${sensorName}...`, direction: "outbound", }); const currentValue = await api.get(type); if (currentValue != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received current value for ${sensorName}: ${currentValue}`, diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 9c2a132b8169..8b12eb50f730 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -246,7 +246,7 @@ export class BinarySwitchCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -272,7 +272,7 @@ export class BinarySwitchCC extends CommandClass { }); // Query the current state - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Binary Switch state...", direction: "outbound", @@ -287,7 +287,7 @@ current value: ${resp.currentValue}`; target value: ${resp.targetValue} remaining duration: ${resp.duration?.toString() ?? "undefined"}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index d5ba86452aa8..ac476a27385b 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -232,7 +232,7 @@ export class CentralSceneCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -248,7 +248,7 @@ export class CentralSceneCC extends CommandClass { CentralSceneCommand.Notification, ); } catch { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -259,7 +259,7 @@ export class CentralSceneCC extends CommandClass { }); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported scenes...", direction: "outbound", @@ -269,13 +269,13 @@ export class CentralSceneCC extends CommandClass { const logMessage = `received supported scenes: # of scenes: ${ccSupported.sceneCount} supports slow refresh: ${ccSupported.supportsSlowRefresh}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported scenes timed out, skipping interview...", @@ -286,7 +286,7 @@ supports slow refresh: ${ccSupported.supportsSlowRefresh}`; // The slow refresh capability should be enabled whenever possible if (api.version >= 3 && ccSupported?.supportsSlowRefresh) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Enabling slow refresh capability...", direction: "outbound", diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index c7993bb071b9..92e932b8b9cb 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -96,7 +96,7 @@ export class ClockCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -121,7 +121,7 @@ export class ClockCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "requesting current clock setting...", direction: "outbound", }); @@ -134,7 +134,7 @@ export class ClockCC extends CommandClass { }${response.hour < 10 ? "0" : ""}${response.hour}:${ response.minute < 10 ? "0" : "" }${response.minute}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 302060033a75..7f079d3206d6 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -558,20 +558,20 @@ export class ColorSwitchCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported colors...", direction: "outbound", }); const supportedColors = await api.getSupported(); if (!supportedColors) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported colors timed out, skipping interview...", @@ -580,7 +580,7 @@ export class ColorSwitchCC extends CommandClass { return; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received supported colors:${ supportedColors @@ -653,7 +653,7 @@ export class ColorSwitchCC extends CommandClass { if (!isEnumMember(ColorComponent, color)) continue; const colorName = getEnumMemberName(ColorComponent, color); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current color state (${colorName})`, direction: "outbound", diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 95f3099630f4..3049262279b3 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -550,7 +550,7 @@ export class ConfigurationCCAPI extends CCAPI { isSignedPartial(valueBitMask, paramInfo.format), ); } - this.applHost.controllerLog.logNode(this.endpoint.nodeId, { + this.applHost.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: `Received unexpected ConfigurationReport (param = ${response.parameter}, value = ${response.value.toString()})`, @@ -982,7 +982,7 @@ export class ConfigurationCCAPI extends CCAPI { this.assertPhysicalEndpoint(this.endpoint); // TODO: Reduce the priority of the messages - this.applHost.controllerLog.logNode(this.endpoint.nodeId, { + this.applHost.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: `Scanning available parameters...`, }); @@ -990,7 +990,7 @@ export class ConfigurationCCAPI extends CCAPI { for (let param = 1; param <= 255; param++) { // Check if the parameter is readable let originalValue: ConfigValue | undefined; - this.applHost.controllerLog.logNode(this.endpoint.nodeId, { + this.applHost.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: ` trying param ${param}...`, direction: "outbound", @@ -1010,7 +1010,7 @@ export class ConfigurationCCAPI extends CCAPI { .valueSize } value = ${originalValue.toString()}`; - this.applHost.controllerLog.logNode(this.endpoint.nodeId, { + this.applHost.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: logMessage, direction: "inbound", @@ -1051,7 +1051,7 @@ export class ConfigurationCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -1064,7 +1064,7 @@ export class ConfigurationCC extends CommandClass { this.endpointIndex, ); if (paramInfo) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: Loading configuration parameters from device config`, @@ -1077,7 +1077,7 @@ export class ConfigurationCC extends CommandClass { ); if (api.version >= 3) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "finding first configuration parameter...", direction: "outbound", @@ -1087,7 +1087,7 @@ export class ConfigurationCC extends CommandClass { if (param0props) { param = param0props.nextParameter; if (param === 0) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `didn't report any config params, trying #1 just to be sure...`, @@ -1096,7 +1096,7 @@ export class ConfigurationCC extends CommandClass { param = 1; } } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Finding first configuration parameter timed out, skipping interview...", @@ -1106,7 +1106,7 @@ export class ConfigurationCC extends CommandClass { } while (param > 0) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying parameter #${param} information...`, direction: "outbound", @@ -1118,7 +1118,7 @@ export class ConfigurationCC extends CommandClass { () => undefined, ); if (!props) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying parameter #${param} information timed out, skipping scan...`, @@ -1175,7 +1175,7 @@ is advanced (UI): ${!!properties.isAdvanced} has bulk support: ${!properties.noBulkSupport} alters capabilities: ${!!properties.altersCapabilities}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -1230,7 +1230,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; alreadyQueried.add(param.parameter); // Query the current value - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying parameter #${param.parameter} value...`, @@ -1239,14 +1239,14 @@ alters capabilities: ${!!properties.altersCapabilities}`; // ... at least try to const paramValue = await api.get(param.parameter); if (typeof paramValue === "number") { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `parameter #${param.parameter} has value: ${paramValue}`, direction: "inbound", }); } else if (!paramValue) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received no value for parameter #${param.parameter}`, @@ -1256,7 +1256,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; } } } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: skipping interview because CC version is < 3 and there is no config file`, @@ -1274,14 +1274,14 @@ alters capabilities: ${!!properties.altersCapabilities}`; if ( this.getParamInformation(applHost, param).readable !== false ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying parameter #${param} value...`, direction: "outbound", }); await api.get(param); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `not querying parameter #${param} value, because it is writeonly`, diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 90d1728687eb..3f0f1683422c 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -608,7 +608,7 @@ export class DoorLockCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -624,7 +624,7 @@ export class DoorLockCC extends CommandClass { let latchSupported = true; if (api.version >= 4) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting lock capabilities...", direction: "outbound", @@ -656,7 +656,7 @@ supports auto-relock: ${resp.autoRelockSupported} supports hold-and-release: ${resp.holdAndReleaseSupported} supports twist assist: ${resp.twistAssistSupported} supports block to block: ${resp.blockToBlockSupported}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -735,7 +735,7 @@ supports block to block: ${resp.blockToBlockSupported}`; priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting lock configuration...", direction: "outbound", @@ -773,14 +773,14 @@ twist assist ${!!config.twistAssist} block to block ${!!config.blockToBlock}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current lock status...", direction: "outbound", @@ -810,7 +810,7 @@ bolt status: ${status.boltStatus}`; logMessage += ` latch status: ${status.latchStatus}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index 543bf87dc997..ae08542c8750 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -176,7 +176,7 @@ export class DoorLockLoggingCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -201,7 +201,7 @@ export class DoorLockLoggingCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported number of records...", direction: "outbound", @@ -209,7 +209,7 @@ export class DoorLockLoggingCC extends CommandClass { const recordsCount = await api.getRecordsCount(); if (!recordsCount) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Door Lock Logging records count query timed out, skipping interview...", @@ -221,7 +221,7 @@ export class DoorLockLoggingCC extends CommandClass { const recordsCountLogMessage = `supports ${recordsCount} record${ recordsCount === 1 ? "" : "s" }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: recordsCountLogMessage, direction: "inbound", diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index 15cd08892ed0..77f4680faf63 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -138,7 +138,7 @@ export class EnergyProductionCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -172,7 +172,7 @@ export class EnergyProductionCC extends CommandClass { EnergyProductionParameter["Total Time"], ] as const ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying energy production (${ getEnumMemberName( diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index 5449503ade1e..e766342f20e0 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -283,7 +283,7 @@ export class EntryControlCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -299,7 +299,7 @@ export class EntryControlCC extends CommandClass { EntryControlCommand.Notification, ); } catch { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -310,7 +310,7 @@ export class EntryControlCC extends CommandClass { }); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting entry control supported keys...", direction: "outbound", @@ -318,7 +318,7 @@ export class EntryControlCC extends CommandClass { const supportedKeys = await api.getSupportedKeys(); if (supportedKeys) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received entry control supported keys: ${supportedKeys.toString()}`, @@ -326,7 +326,7 @@ export class EntryControlCC extends CommandClass { }); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting entry control supported events...", direction: "outbound", @@ -334,7 +334,7 @@ export class EntryControlCC extends CommandClass { const eventCapabilities = await api.getEventCapabilities(); if (eventCapabilities) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received entry control supported keys: data types: ${ @@ -374,7 +374,7 @@ max key cache timeout: ${eventCapabilities.maxKeyCacheTimeout} seconds`, priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting entry control configuration...", direction: "outbound", @@ -382,7 +382,7 @@ max key cache timeout: ${eventCapabilities.maxKeyCacheTimeout} seconds`, const conf = await api.getConfiguration(); if (conf) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received entry control configuration: key cache size: ${conf.keyCacheSize} diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index 1286c83b33a8..b593662d28dd 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -260,13 +260,13 @@ export class FirmwareUpdateMetaDataCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying firmware update capabilities...", direction: "outbound", @@ -291,13 +291,13 @@ export class FirmwareUpdateMetaDataCC extends CommandClass { } else { logMessage += `\nfirmware upgradeable: false`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Firmware update capability query timed out", direction: "inbound", diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index 420952c27566..cfa1ca604c01 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -199,14 +199,14 @@ export class HumidityControlModeCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First query the possible modes to set the metadata - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported humidity control modes...", direction: "outbound", @@ -224,13 +224,13 @@ export class HumidityControlModeCC extends CommandClass { ) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported humidity control modes timed out, skipping interview...", @@ -259,14 +259,14 @@ export class HumidityControlModeCC extends CommandClass { }); // Query the current status - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current humidity control mode...", direction: "outbound", }); const currentMode = await api.get(); if (currentMode) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "received current humidity control mode: " + getEnumMemberName(HumidityControlMode, currentMode), diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index c82b18931e67..d99c311f5a9e 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -113,7 +113,7 @@ export class HumidityControlOperatingStateCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -139,14 +139,14 @@ export class HumidityControlOperatingStateCC extends CommandClass { }); // Query the current status - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current humidity control operating state...", direction: "outbound", }); const currentStatus = await api.get(); if (currentStatus) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "received current humidity control operating state: " + getEnumMemberName( diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 87c5a9f13adc..a5ffc60b36b2 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -361,7 +361,7 @@ export class HumidityControlSetpointCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -369,7 +369,7 @@ export class HumidityControlSetpointCC extends CommandClass { // Query the supported setpoint types let setpointTypes: HumidityControlSetpointType[] = []; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving supported setpoint types...", direction: "outbound", @@ -385,13 +385,13 @@ export class HumidityControlSetpointCC extends CommandClass { .map((name) => `· ${name}`) .join("\n"); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported setpoint types timed out, skipping interview...", @@ -406,7 +406,7 @@ export class HumidityControlSetpointCC extends CommandClass { type, ); // Find out the capabilities of this setpoint - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `retrieving capabilities for setpoint ${setpointName}...`, @@ -421,7 +421,7 @@ ${ .map((t) => `\n· ${t.key} ${t.unit} - ${t.label}`) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -450,7 +450,7 @@ ${ `received capabilities for setpoint ${setpointName}: minimum value: ${setpointCaps.minValue} ${minValueUnit} maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -490,7 +490,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; type, ); // Every time, query the current value - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value of setpoint ${setpointName}...`, @@ -502,7 +502,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; `received current value of setpoint ${setpointName}: ${setpoint.value} ${ getScale(setpoint.scale).unit ?? "" }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 9f0c2a7322d1..6f4300f14415 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -704,14 +704,14 @@ export class IndicatorCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); if (api.version > 1) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "scanning supported indicator IDs...", direction: "outbound", @@ -722,7 +722,7 @@ export class IndicatorCC extends CommandClass { do { const supportedResponse = await api.getSupported(curId); if (!supportedResponse) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Time out while scanning supported indicator IDs, skipping interview...", @@ -748,7 +748,7 @@ export class IndicatorCC extends CommandClass { ", ", ) }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -758,7 +758,7 @@ export class IndicatorCC extends CommandClass { const manufacturerDefinedIndicatorIds = supportedIndicatorIds .filter((id) => isManufacturerDefinedIndicator(id)); if (manufacturerDefinedIndicatorIds.length > 0) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving description for manufacturer-defined indicator IDs...", @@ -793,7 +793,7 @@ export class IndicatorCC extends CommandClass { }); if (api.version === 1) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current indicator value...", direction: "outbound", @@ -805,7 +805,7 @@ export class IndicatorCC extends CommandClass { IndicatorCCValues.supportedIndicatorIds, ) ?? []; for (const indicatorId of supportedIndicatorIds) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `requesting current indicator value (id = ${ num2hex( @@ -1080,7 +1080,7 @@ export class IndicatorCCReport extends IndicatorCC { } else { if (this.isSinglecast()) { // Don't! - applHost.controllerLog.logNode(this.nodeId, { + applHost.logNode(this.nodeId, { message: `ignoring V1 indicator report because the node supports V2 indicators`, direction: "none", diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index c2b09fbda68c..d95d8b508bc2 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1170,20 +1170,20 @@ export class IrrigationCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying irrigation system info...", direction: "outbound", }); const systemInfo = await api.getSystemInfo(); if (!systemInfo) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Time out while querying irrigation system info, skipping interview...", @@ -1196,7 +1196,7 @@ supports master valve: ${systemInfo.supportsMasterValve} no. of valves: ${systemInfo.numValves} no. of valve tables: ${systemInfo.numValveTables} max. valve table size: ${systemInfo.maxValveTableSize}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -1237,7 +1237,7 @@ max. valve table size: ${systemInfo.maxValveTableSize}`; }); // Query the current system config - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying irrigation system configuration...", direction: "outbound", @@ -1266,7 +1266,7 @@ moisture sensor polarity: ${ ) }`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -1275,7 +1275,7 @@ moisture sensor polarity: ${ // and status // Query the current system config - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying irrigation system status...", direction: "outbound", @@ -1284,14 +1284,14 @@ moisture sensor polarity: ${ // for each valve, query the current status and configuration if (IrrigationCC.supportsMasterValveCached(applHost, endpoint)) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying master valve configuration...", direction: "outbound", }); await api.getValveConfig("master"); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying master valve status...", direction: "outbound", @@ -1304,7 +1304,7 @@ moisture sensor polarity: ${ i <= (IrrigationCC.getNumValvesCached(applHost, endpoint) ?? 0); i++ ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying configuration for valve ${ padStart( @@ -1317,7 +1317,7 @@ moisture sensor polarity: ${ }); await api.getValveConfig(i); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying status for valve ${ padStart( diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 7cc894aacb8c..a44eda9c5e95 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -119,7 +119,7 @@ export class LanguageCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -144,7 +144,7 @@ export class LanguageCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "requesting language setting...", direction: "outbound", }); @@ -154,7 +154,7 @@ export class LanguageCC extends CommandClass { const logMessage = `received current language setting: ${language}${ country != undefined ? `-${country}` : "" }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 97aa071a5338..254eecc19012 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -143,7 +143,7 @@ export class LockCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -168,13 +168,13 @@ export class LockCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "requesting current lock state...", direction: "outbound", }); const locked = await api.get(); const logMessage = `the lock is ${locked ? "locked" : "unlocked"}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index a6a8b80e9357..54c8d16a1a6c 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -238,7 +238,7 @@ export class ManufacturerProprietaryCC extends CommandClass { if (pcInstance) { await pcInstance.interview(applHost); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `${this.constructor.name}: skipping interview refresh because the matching proprietary CC is not implemented...`, direction: "none", @@ -265,7 +265,7 @@ export class ManufacturerProprietaryCC extends CommandClass { if (pcInstance) { await pcInstance.refreshValues(applHost); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `${this.constructor.name}: skipping value refresh because the matching proprietary CC is not implemented...`, direction: "none", diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 56bc0febeafd..9260a1d66ba5 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -191,13 +191,13 @@ export class ManufacturerSpecificCC extends CommandClass { ).withOptions({ priority: MessagePriority.NodeQuery }); if (node.id !== applHost.ownNodeId) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying manufacturer information...", direction: "outbound", @@ -214,7 +214,7 @@ export class ManufacturerSpecificCC extends CommandClass { } (${num2hex(mfResp.manufacturerId)}) product type: ${num2hex(mfResp.productType)} product id: ${num2hex(mfResp.productId)}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 23493e0de167..491e0b2066c5 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -643,14 +643,14 @@ export class MeterCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying meter support...", direction: "outbound", @@ -677,13 +677,13 @@ supported rate types: ${ .join("") } supports reset: ${suppResp.supportsReset}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying meter support timed out, skipping interview...", @@ -714,7 +714,7 @@ supports reset: ${suppResp.supportsReset}`; }); if (api.version === 1) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying default meter value...`, direction: "outbound", @@ -735,7 +735,7 @@ supports reset: ${suppResp.supportsReset}`; : [undefined]; for (const rateType of rateTypes) { for (const scale of supportedScales) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying meter value (type = ${ getMeterName(type) diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index fc8b61bc9e21..9ca24ed40698 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -474,28 +474,28 @@ export class MultiChannelAssociationCC extends CommandClass { endpoint, ); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First find out how many groups are supported as multi channel - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying number of multi channel association groups...", direction: "outbound", }); const mcGroupCount = await mcAPI.getGroupCount(); if (mcGroupCount != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `supports ${mcGroupCount} multi channel association groups`, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying multi channel association groups timed out, skipping interview...", @@ -546,7 +546,7 @@ export class MultiChannelAssociationCC extends CommandClass { // Then query each multi channel association group for (let groupId = 1; groupId <= mcGroupCount; groupId++) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying multi channel association group #${groupId}...`, @@ -571,7 +571,7 @@ currently assigned endpoints: ${ }) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -580,7 +580,7 @@ currently assigned endpoints: ${ // Check if there are more non-multi-channel association groups we haven't queried yet if (assocAPI.isSupported() && assocGroupCount > mcGroupCount) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying additional non-multi-channel association groups...`, @@ -591,7 +591,7 @@ currently assigned endpoints: ${ groupId <= assocGroupCount; groupId++ ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying association group #${groupId}...`, direction: "outbound", @@ -602,7 +602,7 @@ currently assigned endpoints: ${ `received information for association group #${groupId}: maximum # of nodes: ${group.maxNodes} currently assigned nodes: ${group.nodeIds.map(String).join(", ")}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 3c58ca9d4f3d..2bc42821c8fc 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -449,7 +449,7 @@ export class MultiChannelCC extends CommandClass { const removeEndpoints = applHost.getDeviceConfig?.(node.id)?.compat ?.removeEndpoints; if (removeEndpoints === "*") { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Skipping ${this.ccName} interview b/c all endpoints are ignored by the device config file...`, @@ -458,7 +458,7 @@ export class MultiChannelCC extends CommandClass { return; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -479,14 +479,14 @@ export class MultiChannelCC extends CommandClass { const valueDB = this.getValueDB(applHost); // Step 1: Retrieve general information about end points - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying device endpoint information...", direction: "outbound", }); const multiResponse = await api.getEndpoints(); if (!multiResponse) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying device endpoint information timed out, aborting interview...", @@ -503,7 +503,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; logMessage += `\nendpoint count (aggregated): ${multiResponse.aggregatedEndpointCount}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -523,7 +523,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; }; if (api.supportsCommand(MultiChannelCommand.EndPointFind)) { // Step 2a: Find all endpoints - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying all endpoints...", direction: "outbound", @@ -533,7 +533,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; if (foundEndpoints) allEndpoints.push(...foundEndpoints); if (!allEndpoints.length) { // Create a sequential list of endpoints - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Endpoint query returned no results, assuming that endpoints are sequential`, @@ -541,7 +541,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; }); addSequentialEndpoints(); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received endpoints: ${ allEndpoints @@ -553,7 +553,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; } } else { // Step 2b: Assume that the endpoints are in sequential order - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `does not support EndPointFind, assuming that endpoints are sequential`, @@ -564,7 +564,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; // Step 2.5: remove ignored endpoints if (removeEndpoints?.length) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `The following endpoints are ignored through the config file: ${ @@ -587,7 +587,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; && ccVersion >= 4 ) { // Find members of aggregated end point - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying members of aggregated endpoint #${endpoint}...`, @@ -595,7 +595,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; }); const members = await api.getAggregatedMembers(endpoint); if (members) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `aggregated endpoint #${endpoint} has members ${ @@ -611,7 +611,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; // When the device reports identical capabilities for all endpoints, // we don't need to query them all if (multiResponse.identicalCapabilities && hasQueriedCapabilities) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `all endpoints identical, skipping capability query for endpoint #${endpoint}...`, @@ -639,7 +639,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; continue; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying capabilities for endpoint #${endpoint}...`, direction: "outbound", @@ -656,13 +656,13 @@ supported CCs:`; for (const cc of caps.supportedCCs) { logMessage += `\n · ${getCCName(cc)}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying endpoint #${endpoint} capabilities timed out, aborting interview...`, @@ -682,13 +682,13 @@ supported CCs:`; ?.preserveEndpoints; if (!preserve) { allEndpoints = []; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Endpoints seem unnecessary b/c they have different device classes, ignoring all...`, }); } else if (preserve === "*") { // preserve all endpoints, do nothing - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Endpoints seem unnecessary, but are configured to be preserved.`, }); @@ -696,7 +696,7 @@ supported CCs:`; allEndpoints = allEndpoints.filter((ep) => preserve.includes(ep) ); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Endpoints seem unnecessary, but endpoints ${ allEndpoints.join( ", ", @@ -743,7 +743,7 @@ supported CCs:`; ); const endpointCounts = new Map(); for (const ccId of supportedCCs) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `Querying endpoint count for CommandClass ${ getCCName( ccId, @@ -755,7 +755,7 @@ supported CCs:`; if (endpointCount != undefined) { endpointCounts.set(ccId, endpointCount); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `CommandClass ${ getCCName( ccId, diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 95be6d1b8431..e53d5da1ca84 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -113,10 +113,11 @@ function getPreferredSensorScale( sensorType: number, supportedScales: readonly number[], ): number { + const preferences = applHost.getUserPreferences(); const sensor = getSensor(sensorType); // If the sensor type is unknown, we have no default. Use the user-provided scale or 0 if (!sensor) { - const preferred = applHost.options.preferences?.scales[sensorType]; + const preferred = preferences?.scales[sensorType]; // We cannot look up strings for unknown sensor types, so this must be a number or we use the fallback if (typeof preferred !== "number") return 0; return preferred; @@ -126,11 +127,11 @@ function getPreferredSensorScale( let preferred: number | string | undefined; // Named scales apply to multiple sensor types. To be able to override the scale for single types // we need to look at the preferences by sensor type first - preferred = applHost.options.preferences?.scales[sensorType]; + preferred = preferences?.scales[sensorType]; // If the scale is named, we can then try to use the named preference const scaleGroupName = sensor.scaleGroupName; if (preferred == undefined && scaleGroupName) { - preferred = applHost.options.preferences?.scales[scaleGroupName]; + preferred = preferences?.scales[scaleGroupName]; } // Then attempt reading the scale from the corresponding value if (preferred == undefined) { @@ -142,7 +143,7 @@ function getPreferredSensorScale( const scale = metadata?.ccSpecific?.scale; if (typeof scale === "number" && supportedScales.includes(scale)) { preferred = scale; - applHost.controllerLog.logNode(nodeId, { + applHost.logNode(nodeId, { endpoint: endpointIndex, message: `No scale preference for sensor type ${sensorType}, using the last-used scale ${preferred}`, @@ -152,7 +153,7 @@ function getPreferredSensorScale( // Then fall back to the first supported scale if (preferred == undefined) { preferred = supportedScales[0] ?? 0; - applHost.controllerLog.logNode(nodeId, { + applHost.logNode(nodeId, { endpoint: endpointIndex, message: `No scale preference for sensor type ${sensorType}, using the first supported scale ${preferred}`, @@ -172,7 +173,7 @@ function getPreferredSensorScale( if (typeof preferred === "string") { // Looking up failed - applHost.controllerLog.logNode(nodeId, { + applHost.logNode(nodeId, { endpoint: endpointIndex, message: `Preferred scale "${preferred}" for sensor type ${sensorType} not found, using the first supported scale ${ @@ -187,7 +188,7 @@ function getPreferredSensorScale( // No info about supported scales, just use the preferred one return preferred; } else if (!supportedScales.includes(preferred)) { - applHost.controllerLog.logNode(nodeId, { + applHost.logNode(nodeId, { endpoint: endpointIndex, message: `Preferred scale ${preferred} not supported for sensor type ${sensorType}, using the first supported scale`, @@ -397,7 +398,7 @@ export class MultilevelSensorCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -405,7 +406,7 @@ export class MultilevelSensorCC extends CommandClass { if (api.version >= 5) { // Query the supported sensor types - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving supported sensor types...", direction: "outbound", @@ -417,13 +418,13 @@ export class MultilevelSensorCC extends CommandClass { .map((t) => getSensorName(t)) .map((name) => `· ${name}`) .join("\n"); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported sensor types timed out, skipping interview...", @@ -435,7 +436,7 @@ export class MultilevelSensorCC extends CommandClass { // As well as the supported scales for each sensor for (const type of sensorTypes) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying supported scales for ${ getSensorName(type) @@ -453,13 +454,13 @@ export class MultilevelSensorCC extends CommandClass { ) .map((name) => `· ${name}`) .join("\n"); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported scales timed out, skipping interview...", @@ -492,7 +493,7 @@ export class MultilevelSensorCC extends CommandClass { if (api.version <= 4) { // Sensors up to V4 only support a single value - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current sensor reading...", direction: "outbound", @@ -508,7 +509,7 @@ sensor type: ${getSensorName(mlsResponse.type)} value: ${mlsResponse.value}${ sensorScale?.unit ? ` ${sensorScale.unit}` : "" }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -523,7 +524,7 @@ value: ${mlsResponse.value}${ }) || []; for (const type of sensorTypes) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying ${ getSensorName(type) @@ -536,7 +537,7 @@ value: ${mlsResponse.value}${ const logMessage = `received current ${ getSensorName(type) } sensor reading: ${value.value} ${value.scale.unit || ""}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 7e9d996b7142..fe9993acbbe8 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -533,7 +533,7 @@ export class MultilevelSwitchCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -541,14 +541,14 @@ export class MultilevelSwitchCC extends CommandClass { if (api.version >= 3) { // Find out which kind of switch this is - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting switch type...", direction: "outbound", }); const switchType = await api.getSupported(); if (switchType != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `has switch type ${ getEnumMemberName( @@ -584,7 +584,7 @@ export class MultilevelSwitchCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current switch state...", direction: "outbound", diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 6381e23a266c..b41531eac120 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -215,7 +215,7 @@ export class NodeNamingAndLocationCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -240,25 +240,25 @@ export class NodeNamingAndLocationCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "retrieving node name...", direction: "outbound", }); const name = await api.getName(); if (name != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `is named "${name}"`, direction: "inbound", }); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "retrieving node location...", direction: "outbound", }); const location = await api.getLocation(); if (location != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `received location: ${location}`, direction: "inbound", }); diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index cf7d49e947c8..b5b1b7ee3552 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -516,7 +516,7 @@ export class NotificationCC extends CommandClass { } } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `determining whether this node is pull or push...`, direction: "outbound", @@ -573,7 +573,7 @@ export class NotificationCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -589,7 +589,7 @@ export class NotificationCC extends CommandClass { NotificationCommand.Report, ); } catch { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -602,7 +602,7 @@ export class NotificationCC extends CommandClass { let supportsV1Alarm = false; if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported notification types...", direction: "outbound", @@ -610,7 +610,7 @@ export class NotificationCC extends CommandClass { const suppResponse = await api.getSupported(); if (!suppResponse) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported notification types timed out, skipping interview...", @@ -634,7 +634,7 @@ export class NotificationCC extends CommandClass { .map((name) => `\n· ${name}`) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -646,7 +646,7 @@ export class NotificationCC extends CommandClass { const type = supportedNotificationTypes[i]; const name = supportedNotificationNames[i]; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying supported notification events for ${name}...`, @@ -655,7 +655,7 @@ export class NotificationCC extends CommandClass { const supportedEvents = await api.getSupportedEvents(type); if (supportedEvents) { supportedNotificationEvents.set(type, supportedEvents); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received supported notification events for ${name}: ${ @@ -696,7 +696,7 @@ export class NotificationCC extends CommandClass { const notification = getNotification(type); // Enable reports for each notification type - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `enabling notifications for ${name}...`, direction: "outbound", @@ -857,7 +857,7 @@ export class NotificationCC extends CommandClass { const name = supportedNotificationNames[i]; // Always query each notification for its current status - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying notification status for ${name}...`, direction: "outbound", @@ -1053,7 +1053,7 @@ export class NotificationCCReport extends NotificationCC { && supportedNotificationEvents.includes(this.alarmLevel) ) { // This alarm frame corresponds to a valid notification event - applHost.controllerLog.logNode( + applHost.logNode( this.nodeId as number, `treating V1 Alarm frame as Notification Report`, ); @@ -1075,7 +1075,7 @@ export class NotificationCCReport extends NotificationCC { || m.from.alarmLevel === this.alarmLevel), ); if (match) { - applHost.controllerLog.logNode( + applHost.logNode( this.nodeId as number, `compat mapping found, treating V1 Alarm frame as Notification Report`, ); @@ -1323,7 +1323,7 @@ export class NotificationCCReport extends NotificationCC { userId: this.eventParameters[2], }; } else { - applHost.controllerLog.logNode( + applHost.logNode( this.nodeId as number, `Failed to parse Notification CC event parameters, ignoring them...`, "error", diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 9942c4a67fe9..8604f7900a36 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -370,7 +370,7 @@ export class ProtectionCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -382,7 +382,7 @@ export class ProtectionCC extends CommandClass { // First find out what the device supports if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying protection capabilities...", direction: "outbound", }); @@ -407,7 +407,7 @@ RF protection states: ${ .map((str) => `\n· ${str}`) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -445,7 +445,7 @@ RF protection states: ${ ); // Query the current state - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying protection status...", direction: "outbound", }); @@ -457,7 +457,7 @@ local: ${getEnumMemberName(LocalProtectionState, protectionResp.local)}`; logMessage += ` rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -465,13 +465,13 @@ rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; if (supportsTimeout) { // Query the current timeout - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying protection timeout...", direction: "outbound", }); const timeout = await api.getTimeout(); if (timeout) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `received timeout: ${timeout.toString()}`, direction: "inbound", }); @@ -480,13 +480,13 @@ rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; if (supportsExclusiveControl) { // Query the current timeout - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying exclusive control node...", direction: "outbound", }); const nodeId = await api.getExclusiveControl(); if (nodeId != undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: (nodeId !== 0 ? `Node ${padStart(nodeId.toString(), 3, "0")}` : `no node`) + ` has exclusive control`, diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index ede5b7bb0db3..c482f6f8e454 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -303,7 +303,7 @@ export class SceneActuatorConfigurationCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `${this.constructor.name}: setting metadata`, direction: "none", }); @@ -334,7 +334,7 @@ export class SceneActuatorConfigurationCC extends CommandClass { // ].withOptions({ // priority: MessagePriority.NodeQuery, // }); - // this.applHost.controllerLog.logNode(node.id, { + // this.applHost.logNode(node.id, { // message: "querying all scene actuator configs...", // direction: "outbound", // }); diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 9e9e176bb310..55a881ac8261 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -381,7 +381,7 @@ export class SceneControllerConfigurationCC extends CommandClass { const node = this.getNode(applHost)!; const endpoint = this.getEndpoint(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -392,7 +392,7 @@ export class SceneControllerConfigurationCC extends CommandClass { endpoint, ); if (groupCount === 0) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `skipping Scene Controller Configuration interview because Association group count is unknown`, @@ -437,12 +437,12 @@ export class SceneControllerConfigurationCC extends CommandClass { endpoint, ); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying all scene controller configurations...", direction: "outbound", }); for (let groupId = 1; groupId <= groupCount; groupId++) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying scene configuration for group #${groupId}...`, @@ -454,7 +454,7 @@ export class SceneControllerConfigurationCC extends CommandClass { `received scene configuration for group #${groupId}: scene ID: ${group.sceneId} dimming duration: ${group.dimmingDuration.toString()}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 836317694bac..57ec6a4bde91 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -709,13 +709,13 @@ export class ScheduleEntryLockCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported number of schedule slots...", direction: "outbound", @@ -729,7 +729,7 @@ day of year: ${slotsResp.numYearDaySlots}`; logMessage += ` daily repeating: ${slotsResp.numDailyRepeatingSlots}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -742,7 +742,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; && (!endpoint.supportsCC(CommandClasses.Time) || endpoint.getCCVersion(CommandClasses.Time) < 2) ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "setting timezone information...", direction: "outbound", diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 4a6dfd290219..139f9e27cbdb 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -696,7 +696,7 @@ export class Security2CC extends CommandClass { ]; } else { // For endpoint interviews, the security class MUST be known - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Cannot query securely supported commands for endpoint because the node's security class isn't known...`, @@ -720,7 +720,7 @@ export class Security2CC extends CommandClass { if ( !securityManager?.hasKeysForSecurityClass(secClass) ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Cannot query securely supported commands (${ getEnumMemberName( @@ -733,7 +733,7 @@ export class Security2CC extends CommandClass { continue; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -770,7 +770,7 @@ export class Security2CC extends CommandClass { ) { if (attempts < MAX_ATTEMPTS) { // We definitely know the highest security class - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -783,7 +783,7 @@ export class Security2CC extends CommandClass { await wait(500); continue; } else if (endpoint.index > 0) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -802,7 +802,7 @@ export class Security2CC extends CommandClass { break; } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -829,7 +829,7 @@ export class Security2CC extends CommandClass { // unless we were sure about the security class node.setSecurityClass(secClass, false); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `The node was NOT granted the security class ${ getEnumMemberName( SecurityClass, @@ -846,7 +846,7 @@ export class Security2CC extends CommandClass { // Mark the security class as granted unless we were sure about the security class node.setSecurityClass(secClass, true); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `The node was granted the security class ${ getEnumMemberName( SecurityClass, @@ -872,7 +872,7 @@ export class Security2CC extends CommandClass { for (const cc of supportedCCs) { logLines.push(`· ${getCCName(cc)}`); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: logLines.join("\n"), direction: "inbound", diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 23bb7289336d..cc65c79a597d 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -391,7 +391,7 @@ export class SecurityCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "Querying securely supported commands (S0)...", direction: "outbound", }); @@ -408,7 +408,7 @@ export class SecurityCC extends CommandClass { controlledCCs = resp.controlledCCs; break; } else if (attempts < MAX_ATTEMPTS) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying securely supported commands (S0), attempt ${attempts}/${MAX_ATTEMPTS} failed. Retrying in 500ms...`, @@ -420,7 +420,7 @@ export class SecurityCC extends CommandClass { if (!supportedCCs || !controlledCCs) { if (node.hasSecurityClass(SecurityClass.S0_Legacy) === true) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying securely supported commands (S0) failed", level: "warn", @@ -429,7 +429,7 @@ export class SecurityCC extends CommandClass { } else { // We didn't know if the node was secure and it didn't respond, // assume that it doesn't have the S0 security class - applHost.controllerLog.logNode( + applHost.logNode( node.id, `The node was not granted the S0 security class. Continuing interview non-securely.`, ); @@ -449,7 +449,7 @@ export class SecurityCC extends CommandClass { for (const cc of controlledCCs) { logLines.push(`· ${getCCName(cc)}`); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logLines.join("\n"), direction: "inbound", }); @@ -485,7 +485,7 @@ export class SecurityCC extends CommandClass { // We know for sure that the node is included securely if (node.hasSecurityClass(SecurityClass.S0_Legacy) !== true) { node.setSecurityClass(SecurityClass.S0_Legacy, true); - applHost.controllerLog.logNode( + applHost.logNode( node.id, `The node was granted the S0 security class`, ); diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index dd54f54dbf79..f242965f03bb 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -386,25 +386,25 @@ export class SoundSwitchCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "requesting tone count...", direction: "outbound", }); const toneCount = await api.getToneCount(); if (toneCount != undefined) { const logMessage = `supports ${toneCount} tones`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying tone count timed out, skipping interview...", level: "warn", @@ -412,7 +412,7 @@ export class SoundSwitchCC extends CommandClass { return; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "requesting current sound configuration...", direction: "outbound", }); @@ -421,7 +421,7 @@ export class SoundSwitchCC extends CommandClass { const logMessage = `received current sound configuration: default tone ID: ${config.defaultToneId} default volume: ${config.defaultVolume}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -429,7 +429,7 @@ default volume: ${config.defaultVolume}`; const metadataStates: Record = {}; for (let toneId = 1; toneId <= toneCount; toneId++) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: `requesting info for tone #${toneId}`, direction: "outbound", }); @@ -438,7 +438,7 @@ default volume: ${config.defaultVolume}`; const logMessage = `received info for tone #${toneId}: name: ${info.name} duration: ${info.duration} seconds`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index bdb2cb881950..b9228cac83c6 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -251,14 +251,14 @@ export class ThermostatFanModeCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First query the possible modes to set the metadata - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported thermostat fan modes...", direction: "outbound", @@ -274,13 +274,13 @@ export class ThermostatFanModeCC extends CommandClass { ) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported thermostat fan modes timed out, skipping interview...", @@ -308,7 +308,7 @@ export class ThermostatFanModeCC extends CommandClass { }); // Query the current status - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current thermostat fan mode...", direction: "outbound", @@ -324,7 +324,7 @@ export class ThermostatFanModeCC extends CommandClass { if (currentStatus.off != undefined) { logMessage += ` (turned off)`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index e64d52b1386d..583a9cc60316 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -105,7 +105,7 @@ export class ThermostatFanStateCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -131,14 +131,14 @@ export class ThermostatFanStateCC extends CommandClass { }); // Query the current status - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current thermostat fan state...", direction: "outbound", }); const currentStatus = await api.get(); if (currentStatus) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "received current thermostat fan state: " + getEnumMemberName(ThermostatFanState, currentStatus), diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index 0a3f5ac74e7d..b7c4b41430ee 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -232,14 +232,14 @@ export class ThermostatModeCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First query the possible modes to set the metadata - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported thermostat modes...", direction: "outbound", @@ -254,13 +254,13 @@ export class ThermostatModeCC extends CommandClass { ) .join("") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported thermostat modes timed out, skipping interview...", @@ -289,14 +289,14 @@ export class ThermostatModeCC extends CommandClass { }); // Query the current status - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current thermostat mode...", direction: "outbound", }); const currentStatus = await api.get(); if (currentStatus) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "received current thermostat mode: " + getEnumMemberName(ThermostatMode, currentStatus.mode), diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index df3aaf543391..e857e40229ce 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -109,7 +109,7 @@ export class ThermostatOperatingStateCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -135,7 +135,7 @@ export class ThermostatOperatingStateCC extends CommandClass { }); // Query the current state - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying thermostat operating state...", direction: "outbound", @@ -143,7 +143,7 @@ export class ThermostatOperatingStateCC extends CommandClass { const state = await api.get(); if (state) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `received current thermostat operating state: ${ getEnumMemberName( diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index eb9c6251ad9f..444e56cc30f7 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -123,7 +123,7 @@ export class ThermostatSetbackCC extends CommandClass { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -149,7 +149,7 @@ export class ThermostatSetbackCC extends CommandClass { }); // Query the thermostat state - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying the current thermostat state...", direction: "outbound", @@ -159,7 +159,7 @@ export class ThermostatSetbackCC extends CommandClass { const logMessage = `received current state: setback type: ${getEnumMemberName(SetbackType, setbackResp.setbackType)} setback state: ${setbackResp.setbackState}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 025ed981942a..179aeb7e5123 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -353,7 +353,7 @@ export class ThermostatSetpointCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -384,7 +384,7 @@ export class ThermostatSetpointCC extends CommandClass { type, ); // Every time, query the current value - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value of setpoint ${setpointName}...`, @@ -406,7 +406,7 @@ export class ThermostatSetpointCC extends CommandClass { // We're sure about the interpretation - this should not happen logMessage = `setpoint ${setpointName} is not supported`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -424,7 +424,7 @@ export class ThermostatSetpointCC extends CommandClass { // Query the supported setpoint types let setpointTypes: ThermostatSetpointType[] = []; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving supported setpoint types...", direction: "outbound", @@ -439,13 +439,13 @@ export class ThermostatSetpointCC extends CommandClass { ) .map((name) => `· ${name}`) .join("\n"); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported setpoint types timed out, skipping interview...", @@ -460,7 +460,7 @@ export class ThermostatSetpointCC extends CommandClass { type, ); // Find out the capabilities of this setpoint - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `retrieving capabilities for setpoint ${setpointName}...`, @@ -478,7 +478,7 @@ export class ThermostatSetpointCC extends CommandClass { `received capabilities for setpoint ${setpointName}: minimum value: ${setpointCaps.minValue} ${minValueUnit} maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -519,7 +519,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; type, ); // Every time, query the current value - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value of setpoint ${setpointName}...`, @@ -531,7 +531,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; `received current value of setpoint ${setpointName}: ${setpoint.value} ${ setpoint.scale.unit ?? "" }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 7ab9834abaa8..81a6a3142a67 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -205,7 +205,7 @@ export class TimeCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -213,7 +213,7 @@ export class TimeCC extends CommandClass { // Synchronize the slave's time if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "setting timezone information...", direction: "outbound", diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index dbfcbe6d683f..d93bebae2c03 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -235,14 +235,14 @@ export class TimeParametersCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Synchronize the node's time - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "setting current time...", direction: "outbound", diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 22474bd99e38..ca473d509a52 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -898,7 +898,7 @@ export class UserCodeCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -906,13 +906,13 @@ export class UserCodeCC extends CommandClass { // Query capabilities first to determine what needs to be done when refreshing if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying capabilities...", direction: "outbound", }); const caps = await api.getCapabilities(); if (!caps) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "User Code capabilities query timed out, skipping interview...", @@ -922,13 +922,13 @@ export class UserCodeCC extends CommandClass { } } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying number of user codes...", direction: "outbound", }); const supportedUsers = await api.getUsersCount(); if (supportedUsers == undefined) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying number of user codes timed out, skipping interview...", @@ -942,7 +942,7 @@ export class UserCodeCC extends CommandClass { } // Synchronize user codes and settings - if (applHost.options.interview?.queryAllUserCodes) { + if (applHost.getInterviewOptions()?.queryAllUserCodes) { await this.refreshValues(applHost); } @@ -984,14 +984,14 @@ export class UserCodeCC extends CommandClass { // Check for changed values and codes if (api.version >= 2) { if (supportsAdminCode) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying admin code...", direction: "outbound", }); await api.getAdminCode(); } if (supportedKeypadModes.length > 1) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying active keypad mode...", direction: "outbound", }); @@ -1002,7 +1002,7 @@ export class UserCodeCC extends CommandClass { let currentUserCodeChecksum: number | undefined = 0; if (supportsUserCodeChecksum) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "retrieving current user code checksum...", direction: "outbound", }); @@ -1012,7 +1012,7 @@ export class UserCodeCC extends CommandClass { !supportsUserCodeChecksum || currentUserCodeChecksum !== storedUserCodeChecksum ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "checksum changed or is not supported, querying all user codes...", direction: "outbound", @@ -1026,7 +1026,7 @@ export class UserCodeCC extends CommandClass { if (response) { nextUserId = response.nextUserId; } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying user code #${nextUserId} timed out, skipping the remaining interview...`, @@ -1044,7 +1044,7 @@ export class UserCodeCC extends CommandClass { } } else { // V1 - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "querying all user codes...", direction: "outbound", }); diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index ad756b7cd467..23261fe79206 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -438,7 +438,7 @@ export class VersionCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -449,7 +449,7 @@ export class VersionCC extends CommandClass { // but there are Z-Wave certification tests that require us to query all CCs const maxImplemented = getImplementedVersion(cc); if (maxImplemented === 0) { - applHost.controllerLog.logNode( + applHost.logNode( node.id, ` skipping query for ${CommandClasses[cc]} (${ num2hex( @@ -460,7 +460,7 @@ export class VersionCC extends CommandClass { return; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: ` querying the CC version for ${getCCName(cc)}...`, direction: "outbound", @@ -524,12 +524,12 @@ export class VersionCC extends CommandClass { } } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `CC version query for ${ getCCName( @@ -551,7 +551,7 @@ export class VersionCC extends CommandClass { await queryCCVersion(CommandClasses.Version); // Step 2: Query node versions - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying node versions...", direction: "outbound", @@ -568,7 +568,7 @@ export class VersionCC extends CommandClass { logMessage += `\n hardware version: ${versionGetResponse.hardwareVersion}`; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -577,7 +577,7 @@ export class VersionCC extends CommandClass { } // Step 3: Query all other CC versions - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying CC versions...", direction: "outbound", @@ -603,7 +603,7 @@ export class VersionCC extends CommandClass { // Step 4: Query VersionCC capabilities (root device only) if (this.endpointIndex === 0 && api.version >= 3) { // Step 4a: Support for SoftwareGet - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying if Z-Wave Software Get is supported...", direction: "outbound", @@ -611,7 +611,7 @@ export class VersionCC extends CommandClass { const capsResponse = await api.getCapabilities(); if (capsResponse) { const { supportsZWaveSoftwareGet } = capsResponse; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Z-Wave Software Get is${ supportsZWaveSoftwareGet ? "" : " not" @@ -621,13 +621,13 @@ export class VersionCC extends CommandClass { if (supportsZWaveSoftwareGet) { // Step 4b: Query Z-Wave Software versions - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Z-Wave software versions...", direction: "outbound", }); await api.getZWaveSoftware(); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "received Z-Wave software versions", direction: "inbound", diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 55c84591d7a4..4111a6465269 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -236,19 +236,19 @@ export class WakeUpCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); if (node.id === applHost.ownNodeId) { - applHost.controllerLog.logNode( + applHost.logNode( node.id, `skipping wakeup configuration for the controller`, ); } else if (node.isFrequentListening) { - applHost.controllerLog.logNode( + applHost.logNode( node.id, `skipping wakeup configuration for frequent listening device`, ); @@ -260,7 +260,7 @@ export class WakeUpCC extends CommandClass { // Retrieve the allowed wake up intervals and wake on demand support if possible if (api.version >= 2) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving wakeup capabilities from the device...", @@ -274,7 +274,7 @@ minimum wakeup interval: ${wakeupCaps.minWakeUpInterval} seconds maximum wakeup interval: ${wakeupCaps.maxWakeUpInterval} seconds wakeup interval steps: ${wakeupCaps.wakeUpIntervalSteps} seconds wakeup on demand supported: ${wakeupCaps.wakeUpOnDemandSupported}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -288,7 +288,7 @@ wakeup on demand supported: ${wakeupCaps.wakeUpOnDemandSupported}`; // We have no intention of changing the interval (maybe some time in the future) // So for now get the current interval and just set the controller ID - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving wakeup interval from the device...", direction: "outbound", @@ -299,7 +299,7 @@ wakeup on demand supported: ${wakeupCaps.wakeUpOnDemandSupported}`; const logMessage = `received wakeup configuration: wakeup interval: ${wakeupResp.wakeUpInterval} seconds controller node: ${wakeupResp.controllerNodeId}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -330,7 +330,7 @@ controller node: ${wakeupResp.controllerNodeId}`; ); } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "configuring wakeup destination node", direction: "outbound", @@ -341,7 +341,7 @@ controller node: ${wakeupResp.controllerNodeId}`; WakeUpCCValues.controllerNodeId, ownNodeId, ); - applHost.controllerLog.logNode( + applHost.logNode( node.id, "wakeup destination node changed!", ); diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 25a8d7c6b734..9fbd42469a9f 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -594,13 +594,13 @@ export class WindowCoveringCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported window covering parameters...", direction: "outbound", @@ -615,7 +615,7 @@ ${ ) .join("\n") }`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -649,7 +649,7 @@ ${ // And for the odd parameters (with position support), query the position if (param % 2 === 1) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `querying position for parameter ${ getEnumMemberName( diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index 4c6d7284ed3c..1f1d82892fcc 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -135,13 +135,13 @@ export class ZWavePlusCC extends CommandClass { priority: MessagePriority.NodeQuery, }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Z-Wave+ information...", direction: "outbound", @@ -155,7 +155,7 @@ role type: ${ZWavePlusRoleType[zwavePlusResponse.roleType]} node type: ${ZWavePlusNodeType[zwavePlusResponse.nodeType]} installer icon: ${num2hex(zwavePlusResponse.installerIcon)} user icon: ${num2hex(zwavePlusResponse.userIcon)}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index bf17cf524e8f..e814b2a5914b 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -329,7 +329,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing Fibaro Venetian Blind CC...`, direction: "none", @@ -344,7 +344,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { ): Promise { const node = this.getNode(applHost)!; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: "Requesting venetian blind position and tilt...", direction: "outbound", }); @@ -358,7 +358,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { const logMessage = `received venetian blind state: position: ${resp.position} tilt: ${resp.tilt}`; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index ea230d6e2557..a33641a4b7e2 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -340,9 +340,10 @@ export class CCAPI { // Figure out the delay. If a non-zero duration was given or this is a "fast" transition, // use/add the short delay. Otherwise, default to the long delay. const durationMs = duration?.toMilliseconds() ?? 0; + const timeouts = this.applHost.getCommunicationTimeouts(); const additionalDelay = !!durationMs || transition === "fast" - ? this.applHost.options.timeouts.refreshValueAfterTransition - : this.applHost.options.timeouts.refreshValue; + ? timeouts.refreshValueAfterTransition + : timeouts.refreshValue; const timeoutMs = durationMs + additionalDelay; if (this.isSinglecast()) { @@ -628,7 +629,7 @@ function overrideQueriesWrapper( ); if (!match) return fallback.call(this, ...args); - applHost.controllerLog.logNode(endpoint.nodeId, { + applHost.logNode(endpoint.nodeId, { message: `API call ${method} for ${ getCCName( ccId, @@ -680,7 +681,7 @@ function overrideQueriesWrapper( value, ); } else { - applHost.controllerLog.logNode(endpoint.nodeId, { + applHost.logNode(endpoint.nodeId, { message: `Failed to persist value ${prop} during overridden API call: value does not exist`, level: "error", @@ -688,7 +689,7 @@ function overrideQueriesWrapper( }); } } catch (e) { - applHost.controllerLog.logNode(endpoint.nodeId, { + applHost.logNode(endpoint.nodeId, { message: `Failed to persist value ${prop} during overridden API call: ${ getErrorMessage( @@ -720,7 +721,7 @@ function overrideQueriesWrapper( }, ); } else { - applHost.controllerLog.logNode(endpoint.nodeId, { + applHost.logNode(endpoint.nodeId, { message: `Failed to extend value metadata ${prop} during overridden API call: value does not exist`, level: "error", @@ -728,7 +729,7 @@ function overrideQueriesWrapper( }); } } catch (e) { - applHost.controllerLog.logNode(endpoint.nodeId, { + applHost.logNode(endpoint.nodeId, { message: `Failed to extend value metadata ${prop} during overridden API call: ${ getErrorMessage( diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index 9fd28a70dc0a..52cc58fd5785 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -754,7 +754,7 @@ export async function configureLifelineAssociations( } if (lifelineGroups.length === 0) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: "No information about Lifeline associations, cannot assign ourselves!", @@ -768,7 +768,7 @@ export async function configureLifelineAssociations( return; } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Checking/assigning lifeline groups: ${ lifelineGroups.join( @@ -815,7 +815,7 @@ supports multi channel associations: ${!!mcInstance}`, } } - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Configuring lifeline group #${group}: group supports multi channel: ${groupSupportsMultiChannelAssociation} @@ -903,7 +903,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, && mcAPI.isSupported() && groupSupportsMultiChannelAssociation ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Found invalid lifeline associations in group #${group}, removing them...`, @@ -935,7 +935,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (isAssignedAsNodeAssociation(endpoint)) { // We already have the correct association hasLifeline = true; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} is already assigned with a node association`, @@ -948,7 +948,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, > 0 ) { // We can use a node association, but first remove any possible endpoint associations - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Association CC...`, @@ -972,14 +972,14 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, hasLifeline = !!groupReport?.nodeIds.includes(ownNodeId); if (hasLifeline) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} was assigned with a node association via Association CC`, direction: "none", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Association CC did not work`, @@ -995,7 +995,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, && mcInstance!.getMaxNodesCached(applHost, endpoint, group) > 0 ) { // We can use a node association, but first remove any possible endpoint associations - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Multi Channel Association CC...`, @@ -1017,14 +1017,14 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, hasLifeline = !!groupReport?.nodeIds.includes(ownNodeId); if (hasLifeline) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} was assigned with a node association via Multi Channel Association CC`, direction: "none", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Multi Channel Association CC did not work`, @@ -1040,7 +1040,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (isAssignedAsEndpointAssociation(endpoint)) { // We already have the correct association hasLifeline = true; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} is already assigned with an endpoint association`, @@ -1052,7 +1052,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, && mcInstance!.getMaxNodesCached(applHost, endpoint, group) > 0 ) { // We can use a multi channel association, but first remove any possible node associations - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a multi channel association...`, @@ -1086,14 +1086,14 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, ); if (hasLifeline) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} was assigned with a multi channel association`, direction: "none", }); } else { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a multi channel association did not work`, @@ -1118,7 +1118,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, const rootMustUseNodeAssociation = !nodeSupportsMultiChannel || rootAssocConfig?.multiChannel === false; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Checking root device for fallback assignment of lifeline group #${group}: @@ -1131,7 +1131,7 @@ must use node association: ${rootMustUseNodeAssociation}`, if (isAssignedAsEndpointAssociation(node)) { // We already have the correct association hasLifeline = true; - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} is already assigned with a multi channel association on the root device`, @@ -1149,7 +1149,7 @@ must use node association: ${rootMustUseNodeAssociation}`, node, ); if (rootMCAPI.isSupported()) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a multi channel association on the root device...`, @@ -1187,7 +1187,7 @@ must use node association: ${rootMustUseNodeAssociation}`, } if (!hasLifeline) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `All attempts to assign lifeline group #${group} failed, skipping...`, @@ -1234,7 +1234,7 @@ export async function assignLifelineIssueingCommand( (a) => a.nodeId === applHost.ownNodeId, ) ) { - applHost.controllerLog.logNode(node.id, { + applHost.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index e0ca54461fa1..799723e85fd0 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -144,6 +144,23 @@ export interface SendCommand { ): Promise>; } +/** Allows reading options to use for interviewing devices */ +export interface GetInterviewOptions { + getInterviewOptions(): ZWaveHostOptions["interview"]; +} + +/** Allows reading user preferences */ +export interface GetUserPreferences { + getUserPreferences(): ZWaveHostOptions["preferences"]; +} + +/** Allows reading user preferences */ +export interface GetCommunicationTimeouts { + getCommunicationTimeouts(): ZWaveHostOptions["timeouts"]; +} + +export type LogNode = Pick; + export interface ZWaveApplicationHost extends GetValueDB, @@ -156,12 +173,12 @@ export interface ZWaveApplicationHost SchedulePoll, GetSupportedCCVersion, GetSafeCCVersion, - SendCommand + SendCommand, + GetInterviewOptions, + GetUserPreferences, + GetCommunicationTimeouts, + LogNode { - options: ZWaveHostOptions; - - // TODO: There's probably a better fitting name for this now - controllerLog: ControllerLogger; } /** Allows scheduling a value refresh (poll) for a later time */ diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index fc2ef8e157a6..28086c85aadf 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -56,25 +56,31 @@ export function createTestingHost< securityManager2: undefined, securityManagerLR: undefined, getDeviceConfig: undefined, - controllerLog: new Proxy({} as any, { - get() { - return () => { - /* intentionally empty */ - }; - }, - }), lookupManufacturer: () => undefined, - options: { - attempts: { - nodeInterview: 1, - // openSerialPort: 1, - sendData: 3, - controller: 3, - }, - timeouts: { + 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); diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 97f60ce53aea..adf403794e64 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -58,6 +58,7 @@ import { EncapsulationFlags, type KeyPair, type LogConfig, + type LogNodeOptions, MAX_SUPERVISION_SESSION_ID, MAX_TRANSPORT_SERVICE_SESSION_ID, MPANState, @@ -113,6 +114,7 @@ import type { HostIDs, NodeSchedulePollOptions, ZWaveApplicationHost, + ZWaveHostOptions, } from "@zwave-js/host"; import { type BootloaderChunk, @@ -858,15 +860,22 @@ export class Driver extends TypedEventEmitter } private _controllerLog: ControllerLogger; - /** - * **!!! INTERNAL !!!** - * - * Not intended to be used by applications - */ + /** @internal */ public get controllerLog(): ControllerLogger { return this._controllerLog; } + public logNode( + nodeId: number, + message: string, + level?: LogNodeOptions["level"], + ): void; + public logNode(nodeId: number, options: LogNodeOptions): void; + public logNode(...args: any[]): void { + // @ts-expect-error + this._controllerLog.logNode(...args); + } + private _controller: ZWaveController | undefined; /** Encapsulates information about the Z-Wave controller and provides access to its nodes */ public get controller(): ZWaveController { @@ -1094,6 +1103,33 @@ export class Driver extends TypedEventEmitter ); } + /** + * **!!! INTERNAL !!!** + * + * Not intended to be used by applications + */ + public getUserPreferences(): ZWaveHostOptions["preferences"] { + return this._options.preferences; + } + + /** + * **!!! INTERNAL !!!** + * + * Not intended to be used by applications + */ + public getInterviewOptions(): ZWaveHostOptions["interview"] { + return this._options.interview; + } + + /** + * **!!! INTERNAL !!!** + * + * Not intended to be used by applications + */ + public getCommunicationTimeouts(): ZWaveHostOptions["timeouts"] { + return this._options.timeouts; + } + /** * Enumerates all existing serial ports. * @param local Whether to include local serial ports From c280d4e4f2d0ccf3606e8543604ecff19296b03d Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 11:29:19 +0200 Subject: [PATCH 43/60] refactor: change host type of CCAPI to traits --- packages/cc/src/cc/AlarmSensorCC.ts | 4 +- packages/cc/src/cc/AssociationCC.ts | 27 ++--- packages/cc/src/cc/AssociationGroupInfoCC.ts | 18 +-- packages/cc/src/cc/BinarySensorCC.ts | 4 +- packages/cc/src/cc/ConfigurationCC.ts | 38 +++--- packages/cc/src/cc/DoorLockCC.ts | 28 ++--- packages/cc/src/cc/IndicatorCC.ts | 4 +- packages/cc/src/cc/IrrigationCC.ts | 12 +- .../cc/src/cc/ManufacturerProprietaryCC.ts | 4 +- packages/cc/src/cc/MeterCC.ts | 16 +-- .../cc/src/cc/MultiChannelAssociationCC.ts | 42 +++---- packages/cc/src/cc/MultilevelSensorCC.ts | 24 ++-- packages/cc/src/cc/NotificationCC.ts | 4 +- .../src/cc/SceneControllerConfigurationCC.ts | 13 +- packages/cc/src/cc/ScheduleEntryLockCC.ts | 82 ++++++------- packages/cc/src/cc/TimeParametersCC.ts | 5 +- packages/cc/src/cc/UserCodeCC.ts | 36 +++--- packages/cc/src/lib/API.ts | 40 ++++++- packages/cc/src/lib/CommandClass.ts | 56 ++++----- packages/cc/src/lib/Values.ts | 4 +- packages/host/src/ZWaveHost.ts | 5 +- packages/host/src/mocks.ts | 2 +- .../src/codeshifts/refactorGetXCached.ts | 113 ++++++++++++++++++ packages/serial/src/message/Message.ts | 6 +- packages/testing/src/MockController.ts | 2 + packages/testing/src/MockNode.ts | 2 + packages/zwave-js/src/lib/driver/Driver.ts | 2 + 27 files changed, 369 insertions(+), 224 deletions(-) create mode 100644 packages/maintenance/src/codeshifts/refactorGetXCached.ts diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 0e15dad7491b..8cd720a2d5b4 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -293,10 +293,10 @@ duration: ${currentValue.duration}`; * This only works AFTER the interview process */ public static getSupportedSensorTypesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( AlarmSensorCCValues.supportedSensorTypes.endpoint( diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 08e4caf1327d..7da51e3bde0e 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -16,6 +16,7 @@ import { import type { CCEncodingContext, CCParsingContext, + GetDeviceConfig, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -323,16 +324,14 @@ export class AssociationCC extends CommandClass { * This only works AFTER the interview process */ public static getGroupCountCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): number { - return ( - applHost - .getValueDB(endpoint.nodeId) - .getValue( - AssociationCCValues.groupCount.endpoint(endpoint.index), - ) || 0 - ); + return ctx + .getValueDB(endpoint.nodeId) + .getValue( + AssociationCCValues.groupCount.endpoint(endpoint.index), + ) || 0; } /** @@ -340,12 +339,12 @@ export class AssociationCC extends CommandClass { * This only works AFTER the interview process */ public static getMaxNodesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, endpoint: EndpointId, groupId: number, ): number { return ( - applHost + ctx .getValueDB(endpoint.nodeId) .getValue( AssociationCCValues.maxNodes(groupId).endpoint( @@ -354,7 +353,7 @@ export class AssociationCC extends CommandClass { ) // If the information is not available, fall back to the configuration file if possible // This can happen on some legacy devices which have "hidden" association groups - ?? applHost + ?? ctx .getDeviceConfig?.(endpoint.nodeId) ?.getAssociationConfigForEndpoint(endpoint.index, groupId) ?.maxNodes @@ -367,12 +366,12 @@ export class AssociationCC extends CommandClass { * This only works AFTER the interview process */ public static getAllDestinationsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): ReadonlyMap { const ret = new Map(); - const groupCount = this.getGroupCountCached(applHost, endpoint); - const valueDB = applHost.getValueDB(endpoint.nodeId); + const groupCount = this.getGroupCountCached(ctx, endpoint); + const valueDB = ctx.getValueDB(endpoint.nodeId); for (let i = 1; i <= groupCount; i++) { // Add all root destinations const nodes = valueDB.getValue( diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 8900691ac888..524a9dc51332 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -257,11 +257,11 @@ export class AssociationGroupInfoCC extends CommandClass { /** Returns the name of an association group */ public static getGroupNameCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, groupId: number, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( AssociationGroupInfoCCValues.groupName(groupId).endpoint( @@ -272,11 +272,11 @@ export class AssociationGroupInfoCC extends CommandClass { /** Returns the association profile for an association group */ public static getGroupProfileCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, groupId: number, ): MaybeNotKnown { - return applHost.getValueDB(endpoint.nodeId).getValue<{ + return ctx.getValueDB(endpoint.nodeId).getValue<{ profile: AssociationGroupInfoProfile; }>( AssociationGroupInfoCCValues.groupInfo(groupId).endpoint( @@ -288,11 +288,11 @@ export class AssociationGroupInfoCC extends CommandClass { /** Returns the dictionary of all commands issued by the given association group */ public static getIssuedCommandsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, groupId: number, ): MaybeNotKnown> { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( AssociationGroupInfoCCValues.commands(groupId).endpoint( @@ -332,7 +332,7 @@ export class AssociationGroupInfoCC extends CommandClass { } private static getAssociationGroupCountCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId & SupportsCC, ): number { // The association group count is either determined by the @@ -342,12 +342,12 @@ export class AssociationGroupInfoCC extends CommandClass { // First query the Multi Channel Association CC (endpoint.supportsCC(CommandClasses["Multi Channel Association"]) && MultiChannelAssociationCC.getGroupCountCached( - applHost, + ctx, endpoint, )) // Then the Association CC || (endpoint.supportsCC(CommandClasses.Association) - && AssociationCC.getGroupCountCached(applHost, endpoint)) + && AssociationCC.getGroupCountCached(ctx, endpoint)) // And fall back to 0 || 0 ); diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index fd14e2916439..e97fcdab6ea7 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -312,10 +312,10 @@ export class BinarySensorCC extends CommandClass { * This only works AFTER the interview process */ public static getSupportedSensorTypesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( BinarySensorCCValues.supportedSensorTypes.endpoint( diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 3049262279b3..8c2253b43b80 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -27,6 +27,8 @@ import { import type { CCEncodingContext, CCParsingContext, + GetDeviceConfig, + GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -155,7 +157,7 @@ function createConfigurationCCInstance( } function normalizeConfigurationCCAPISetOptions( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: CCAPIEndpoint, options: ConfigurationCCAPISetOptions, ): NormalizedConfigurationCCAPISetOptions { @@ -163,7 +165,7 @@ function normalizeConfigurationCCAPISetOptions( // Variant 3: Partial param, look it up in the device config const ccc = createConfigurationCCInstance(endpoint); const paramInfo = ccc.getParamInformation( - applHost, + ctx, options.parameter, options.bitMask, ); @@ -192,7 +194,7 @@ function normalizeConfigurationCCAPISetOptions( // Variant 1: Normal parameter, defined in a config file const ccc = createConfigurationCCInstance(endpoint); const paramInfo = ccc.getParamInformation( - applHost, + ctx, options.parameter, options.bitMask, ); @@ -212,7 +214,7 @@ function normalizeConfigurationCCAPISetOptions( } function bulkMergePartialParamValues( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: CCAPIEndpoint, options: NormalizedConfigurationCCAPISetOptions[], ): (NormalizedConfigurationCCAPISetOptions & { bitMask?: undefined })[] { @@ -236,7 +238,7 @@ function bulkMergePartialParamValues( allParams.push({ parameter, value: ccc.composePartialParamValues( - applHost, + ctx, parameter, partials.map((p) => ({ bitMask: p.bitMask!, @@ -277,11 +279,11 @@ function reInterpretSignedValue( } function getParamInformationFromConfigFile( - applHost: ZWaveApplicationHost, + ctx: GetDeviceConfig, nodeId: number, endpointIndex: number, ): ParamInfoMap | undefined { - const deviceConfig = applHost.getDeviceConfig?.(nodeId); + const deviceConfig = ctx.getDeviceConfig?.(nodeId); if (endpointIndex === 0) { return ( deviceConfig?.paramInformation @@ -1368,13 +1370,13 @@ alters capabilities: ${!!properties.altersCapabilities}`; * Returns stored config parameter metadata for this CC's node */ public getParamInformation( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, parameter: number, valueBitMask?: number, ): ConfigurationMetadata { return ( this.getMetadata( - applHost, + ctx, ConfigurationCCValues.paramInformation(parameter, valueBitMask), ) ?? { ...ValueMetadata.Any, @@ -1387,17 +1389,17 @@ alters capabilities: ${!!properties.altersCapabilities}`; * and does not include partial parameters. */ public getQueriedParamInfos( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetSupportedCCVersion & GetDeviceConfig, ): Record { const parameters = distinct( - this.getDefinedValueIDs(applHost) + this.getDefinedValueIDs(ctx) .map((v) => v.property) .filter((p) => typeof p === "number"), ); return composeObject( parameters.map((p) => [ p as any, - this.getParamInformation(applHost, p), + this.getParamInformation(ctx, p), ]), ); } @@ -1406,10 +1408,10 @@ alters capabilities: ${!!properties.altersCapabilities}`; * Returns stored config parameter metadata for all partial config params addressed with the given parameter number */ public getPartialParamInfos( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, parameter: number, ): (ValueID & { metadata: ConfigurationMetadata })[] { - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); return valueDB.findMetadata( (id) => id.commandClass === this.ccId @@ -1423,12 +1425,12 @@ alters capabilities: ${!!properties.altersCapabilities}`; * Computes the full value of a parameter after applying a partial param value */ public composePartialParamValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, parameter: number, bitMask: number, partialValue: number, ): number { - return this.composePartialParamValues(applHost, parameter, [ + return this.composePartialParamValues(ctx, parameter, [ { bitMask, partialValue }, ]); } @@ -1437,14 +1439,14 @@ alters capabilities: ${!!properties.altersCapabilities}`; * Computes the full value of a parameter after applying multiple partial param values */ public composePartialParamValues( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, parameter: number, partials: { bitMask: number; partialValue: number; }[], ): number { - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); // Add the other values together const otherValues = valueDB.findValues( (id) => diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 3f0f1683422c..4b84767ac026 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -254,10 +254,10 @@ export const DoorLockCCValues = Object.freeze({ }); function shouldAutoCreateLatchStatusValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.latchSupported.endpoint(endpoint.index), @@ -265,10 +265,10 @@ function shouldAutoCreateLatchStatusValue( } function shouldAutoCreateBoltStatusValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.boltSupported.endpoint(endpoint.index), @@ -276,10 +276,10 @@ function shouldAutoCreateBoltStatusValue( } function shouldAutoCreateDoorStatusValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.doorSupported.endpoint(endpoint.index), @@ -287,10 +287,10 @@ function shouldAutoCreateDoorStatusValue( } function shouldAutoCreateTwistAssistConfigValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.twistAssistSupported.endpoint(endpoint.index), @@ -298,10 +298,10 @@ function shouldAutoCreateTwistAssistConfigValue( } function shouldAutoCreateBlockToBlockConfigValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.blockToBlockSupported.endpoint(endpoint.index), @@ -309,10 +309,10 @@ function shouldAutoCreateBlockToBlockConfigValue( } function shouldAutoCreateAutoRelockConfigValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.autoRelockSupported.endpoint(endpoint.index), @@ -320,10 +320,10 @@ function shouldAutoCreateAutoRelockConfigValue( } function shouldAutoCreateHoldAndReleaseConfigValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; return !!valueDB.getValue( DoorLockCCValues.holdAndReleaseSupported.endpoint(endpoint.index), diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 6f4300f14415..0ceaa3d379c2 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -868,11 +868,11 @@ export class IndicatorCC extends CommandClass { } public static getSupportedPropertyIDsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, indicatorId: number, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( IndicatorCCValues.supportedPropertyIDs(indicatorId).endpoint( diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index d95d8b508bc2..1f396a39dee9 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1119,10 +1119,10 @@ export class IrrigationCC extends CommandClass { * This only works AFTER the node has been interviewed. */ public static getMaxValveTableSizeCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( IrrigationCCValues.maxValveTableSize.endpoint(endpoint.index), @@ -1134,10 +1134,10 @@ export class IrrigationCC extends CommandClass { * This only works AFTER the node has been interviewed. */ public static getNumValvesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue(IrrigationCCValues.numValves.endpoint(endpoint.index)); } @@ -1147,10 +1147,10 @@ export class IrrigationCC extends CommandClass { * This only works AFTER the node has been interviewed. */ public static supportsMasterValveCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - return !!applHost + return !!ctx .getValueDB(endpoint.nodeId) .getValue( IrrigationCCValues.supportsMasterValve.endpoint(endpoint.index), diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index 54c8d16a1a6c..13b2c88aedeb 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -10,7 +10,7 @@ import type { } from "@zwave-js/host/safe"; import { staticExtends } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { CCAPI, type CCAPIEndpoint, type CCAPINode } from "../lib/API"; +import { CCAPI, type CCAPIEndpoint, type CCAPIHost } from "../lib/API"; import { type CCCommandOptions, type CCNode, @@ -42,7 +42,7 @@ export type ManufacturerProprietaryCCConstructor< @API(CommandClasses["Manufacturer Proprietary"]) export class ManufacturerProprietaryCCAPI extends CCAPI { public constructor( - applHost: ZWaveApplicationHost, + applHost: CCAPIHost, endpoint: CCAPIEndpoint, ) { super(applHost, endpoint); diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 491e0b2066c5..285b82a8c265 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -787,10 +787,10 @@ supports reset: ${suppResp.supportsReset}`; * This only works AFTER the interview process */ public static getMeterTypeCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue(MeterCCValues.type.endpoint(endpoint.index)); } @@ -800,10 +800,10 @@ supports reset: ${suppResp.supportsReset}`; * This only works AFTER the interview process */ public static getSupportedScalesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue(MeterCCValues.supportedScales.endpoint(endpoint.index)); } @@ -813,10 +813,10 @@ supports reset: ${suppResp.supportsReset}`; * This only works AFTER the interview process */ public static supportsResetCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue(MeterCCValues.supportsReset.endpoint(endpoint.index)); } @@ -826,10 +826,10 @@ supports reset: ${suppResp.supportsReset}`; * This only works AFTER the interview process */ public static getSupportedRateTypesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( MeterCCValues.supportedRateTypes.endpoint(endpoint.index), diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 9ca24ed40698..a78d2724a097 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -371,18 +371,16 @@ export class MultiChannelAssociationCC extends CommandClass { * This only works AFTER the interview process */ public static getGroupCountCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): number { - return ( - applHost - .getValueDB(endpoint.nodeId) - .getValue( - MultiChannelAssociationCCValues.groupCount.endpoint( - endpoint.index, - ), - ) || 0 - ); + return ctx + .getValueDB(endpoint.nodeId) + .getValue( + MultiChannelAssociationCCValues.groupCount.endpoint( + endpoint.index, + ), + ) || 0; } /** @@ -390,19 +388,17 @@ export class MultiChannelAssociationCC extends CommandClass { * This only works AFTER the interview process */ public static getMaxNodesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, groupId: number, ): number { - return ( - applHost - .getValueDB(endpoint.nodeId) - .getValue( - MultiChannelAssociationCCValues.maxNodes(groupId).endpoint( - endpoint.index, - ), - ) ?? 0 - ); + return ctx + .getValueDB(endpoint.nodeId) + .getValue( + MultiChannelAssociationCCValues.maxNodes(groupId).endpoint( + endpoint.index, + ), + ) ?? 0; } /** @@ -410,12 +406,12 @@ export class MultiChannelAssociationCC extends CommandClass { * This only works AFTER the interview process */ public static getAllDestinationsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): ReadonlyMap { const ret = new Map(); - const groupCount = this.getGroupCountCached(applHost, endpoint); - const valueDB = applHost.getValueDB(endpoint.nodeId); + const groupCount = this.getGroupCountCached(ctx, endpoint); + const valueDB = ctx.getValueDB(endpoint.nodeId); for (let i = 1; i <= groupCount; i++) { const groupDestinations: AssociationAddress[] = []; // Add all node destinations diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index e53d5da1ca84..268303f5c0bc 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -27,7 +27,9 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetUserPreferences, GetValueDB, + LogNode, ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; @@ -107,13 +109,13 @@ export const MultilevelSensorCCValues = Object.freeze({ * followed by the most recently used scale, otherwile falls back to the first supported one. */ function getPreferredSensorScale( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetUserPreferences & LogNode, nodeId: number, endpointIndex: number, sensorType: number, supportedScales: readonly number[], ): number { - const preferences = applHost.getUserPreferences(); + const preferences = ctx.getUserPreferences(); const sensor = getSensor(sensorType); // If the sensor type is unknown, we have no default. Use the user-provided scale or 0 if (!sensor) { @@ -137,13 +139,13 @@ function getPreferredSensorScale( if (preferred == undefined) { const sensorName = getSensorName(sensorType); const sensorValue = MultilevelSensorCCValues.value(sensorName); - const metadata = applHost + const metadata = ctx .tryGetValueDB(nodeId) ?.getMetadata(sensorValue.endpoint(endpointIndex)); const scale = metadata?.ccSpecific?.scale; if (typeof scale === "number" && supportedScales.includes(scale)) { preferred = scale; - applHost.logNode(nodeId, { + ctx.logNode(nodeId, { endpoint: endpointIndex, message: `No scale preference for sensor type ${sensorType}, using the last-used scale ${preferred}`, @@ -153,7 +155,7 @@ function getPreferredSensorScale( // Then fall back to the first supported scale if (preferred == undefined) { preferred = supportedScales[0] ?? 0; - applHost.logNode(nodeId, { + ctx.logNode(nodeId, { endpoint: endpointIndex, message: `No scale preference for sensor type ${sensorType}, using the first supported scale ${preferred}`, @@ -173,7 +175,7 @@ function getPreferredSensorScale( if (typeof preferred === "string") { // Looking up failed - applHost.logNode(nodeId, { + ctx.logNode(nodeId, { endpoint: endpointIndex, message: `Preferred scale "${preferred}" for sensor type ${sensorType} not found, using the first supported scale ${ @@ -188,7 +190,7 @@ function getPreferredSensorScale( // No info about supported scales, just use the preferred one return preferred; } else if (!supportedScales.includes(preferred)) { - applHost.logNode(nodeId, { + ctx.logNode(nodeId, { endpoint: endpointIndex, message: `Preferred scale ${preferred} not supported for sensor type ${sensorType}, using the first supported scale`, @@ -574,10 +576,10 @@ value: ${mlsResponse.value}${ * This only works AFTER the interview process */ public static getSupportedSensorTypesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( MultilevelSensorCCValues.supportedSensorTypes.endpoint( @@ -591,11 +593,11 @@ value: ${mlsResponse.value}${ * This only works AFTER the interview process */ public static getSupportedScalesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, sensorType: number, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( MultilevelSensorCCValues.supportedScales(sensorType).endpoint( diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index b5b1b7ee3552..d490a444a72d 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -215,10 +215,10 @@ export const NotificationCCValues = Object.freeze({ }); function shouldAutoCreateSimpleDoorSensorValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost.tryGetValueDB(endpoint.nodeId); + const valueDB = ctx.tryGetValueDB(endpoint.nodeId); if (!valueDB) return false; const supportedACEvents = valueDB.getValue( NotificationCCValues.supportedNotificationEvents( diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 55a881ac8261..0e651bf7a625 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -14,6 +14,7 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -469,15 +470,13 @@ dimming duration: ${group.dimmingDuration.toString()}`; * or the AssociationCC. */ public static getGroupCountCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, endpoint: EndpointId, ): number { - return ( - applHost.getDeviceConfig?.(endpoint.nodeId)?.compat - ?.forceSceneControllerGroupCount - ?? AssociationCC.getGroupCountCached(applHost, endpoint) - ?? 0 - ); + return ctx.getDeviceConfig?.(endpoint.nodeId)?.compat + ?.forceSceneControllerGroupCount + ?? AssociationCC.getGroupCountCached(ctx, endpoint) + ?? 0; } } diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 57ec6a4bde91..671656a54a68 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -116,7 +116,7 @@ function toPropertyKey( /** Caches information about a schedule */ function persistSchedule( this: ScheduleEntryLockCC, - applHost: ZWaveApplicationHost, + ctx: GetValueDB, scheduleKind: ScheduleEntryLockScheduleKind, userId: number, slotId: number, @@ -134,20 +134,20 @@ function persistSchedule( ); if (schedule != undefined) { - this.setValue(applHost, scheduleValue, schedule); + this.setValue(ctx, scheduleValue, schedule); } else { - this.removeValue(applHost, scheduleValue); + this.removeValue(ctx, scheduleValue); } } /** Updates the schedule kind assumed to be active for user in the cache */ function setUserCodeScheduleKindCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, userId: number, scheduleKind: ScheduleEntryLockScheduleKind, ): void { - applHost + ctx .getValueDB(endpoint.nodeId) .setValue( ScheduleEntryLockCCValues.scheduleKind(userId).endpoint( @@ -159,13 +159,13 @@ function setUserCodeScheduleKindCached( /** Updates whether scheduling is active for one or all user(s) in the cache */ function setUserCodeScheduleEnabledCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, userId: number | undefined, enabled: boolean, ): void { const setEnabled = (userId: number) => { - applHost + ctx .getValueDB(endpoint.nodeId) .setValue( ScheduleEntryLockCCValues.userEnabled(userId).endpoint( @@ -177,7 +177,7 @@ function setUserCodeScheduleEnabledCached( if (userId == undefined) { // Enable/disable all users - const numUsers = UserCodeCC.getSupportedUsersCached(applHost, endpoint) + const numUsers = UserCodeCC.getSupportedUsersCached(ctx, endpoint) ?? 0; for (let userId = 1; userId <= numUsers; userId++) { @@ -761,18 +761,16 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; * This only works AFTER the interview process */ public static getNumWeekDaySlotsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): number { - return ( - applHost - .getValueDB(endpoint.nodeId) - .getValue( - ScheduleEntryLockCCValues.numWeekDaySlots.endpoint( - endpoint.index, - ), - ) || 0 - ); + return ctx + .getValueDB(endpoint.nodeId) + .getValue( + ScheduleEntryLockCCValues.numWeekDaySlots.endpoint( + endpoint.index, + ), + ) || 0; } /** @@ -780,18 +778,16 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; * This only works AFTER the interview process */ public static getNumYearDaySlotsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): number { - return ( - applHost - .getValueDB(endpoint.nodeId) - .getValue( - ScheduleEntryLockCCValues.numYearDaySlots.endpoint( - endpoint.index, - ), - ) || 0 - ); + return ctx + .getValueDB(endpoint.nodeId) + .getValue( + ScheduleEntryLockCCValues.numYearDaySlots.endpoint( + endpoint.index, + ), + ) || 0; } /** @@ -799,18 +795,16 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; * This only works AFTER the interview process */ public static getNumDailyRepeatingSlotsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): number { - return ( - applHost - .getValueDB(endpoint.nodeId) - .getValue( - ScheduleEntryLockCCValues.numDailyRepeatingSlots.endpoint( - endpoint.index, - ), - ) || 0 - ); + return ctx + .getValueDB(endpoint.nodeId) + .getValue( + ScheduleEntryLockCCValues.numDailyRepeatingSlots.endpoint( + endpoint.index, + ), + ) || 0; } /** @@ -822,11 +816,11 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; * only the desired ones. */ public static getUserCodeScheduleEnabledCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, userId: number, ): boolean { - return !!applHost + return !!ctx .getValueDB(endpoint.nodeId) .getValue( ScheduleEntryLockCCValues.userEnabled(userId).endpoint( @@ -844,11 +838,11 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; * which will automatically switch the user to that scheduling kind. */ public static getUserCodeScheduleKindCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, userId: number, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( ScheduleEntryLockCCValues.scheduleKind(userId).endpoint( @@ -904,7 +898,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; * This only works AFTER the interview process. */ public static getScheduleCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind, userId: number, @@ -915,7 +909,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; | ScheduleEntryLockDailyRepeatingSchedule | false > { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( ScheduleEntryLockCCValues.schedule( diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index d93bebae2c03..0bf088c7e139 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -15,6 +15,7 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -64,7 +65,7 @@ export const TimeParametersCCValues = Object.freeze({ * Determines if the node expects local time instead of UTC. */ function shouldUseLocalTime( - applHost: ZWaveApplicationHost, + ctx: GetDeviceConfig, endpoint: EndpointId & SupportsCC & ControlsCC, ): boolean { // GH#311 Some nodes have no way to determine the time zone offset, @@ -76,7 +77,7 @@ function shouldUseLocalTime( // Incidentally, this is also true when they don't support TimeCC at all // Use UTC though when the device config file explicitly requests it - const forceUTC = !!applHost.getDeviceConfig?.(endpoint.nodeId)?.compat + const forceUTC = !!ctx.getDeviceConfig?.(endpoint.nodeId)?.compat ?.useUTCInTimeParametersCC; if (forceUTC) return false; diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index ca473d509a52..50659e711315 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -1059,10 +1059,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static getSupportedUsersCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue(UserCodeCCValues.supportedUsers.endpoint(endpoint.index)); } @@ -1072,10 +1072,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static getSupportedKeypadModesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( UserCodeCCValues.supportedKeypadModes.endpoint(endpoint.index), @@ -1087,10 +1087,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static getSupportedUserIDStatusesCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( UserCodeCCValues.supportedUserIDStatuses.endpoint( @@ -1104,10 +1104,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static getSupportedASCIICharsCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( UserCodeCCValues.supportedASCIIChars.endpoint(endpoint.index), @@ -1119,10 +1119,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static supportsAdminCodeCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost + const valueDB = ctx .getValueDB(endpoint.nodeId); return valueDB.getValue( UserCodeCCValues.supportsAdminCode.endpoint( @@ -1140,10 +1140,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static supportsAdminCodeDeactivationCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - const valueDB = applHost + const valueDB = ctx .getValueDB(endpoint.nodeId); return valueDB.getValue( UserCodeCCValues.supportsAdminCodeDeactivation.endpoint( @@ -1162,10 +1162,10 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the interview process */ public static supportsMultipleUserCodeSetCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ): boolean { - return !!applHost + return !!ctx .getValueDB(endpoint.nodeId) .getValue( UserCodeCCValues.supportsMultipleUserCodeSet.endpoint( @@ -1179,11 +1179,11 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the user IDs have been queried. */ public static getUserIdStatusCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, userId: number, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( UserCodeCCValues.userIdStatus(userId).endpoint(endpoint.index), @@ -1195,11 +1195,11 @@ export class UserCodeCC extends CommandClass { * This only works AFTER the user IDs have been queried. */ public static getUserCodeCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, userId: number, ): MaybeNotKnown { - return applHost + return ctx .getValueDB(endpoint.nodeId) .getValue( UserCodeCCValues.userCode(userId).endpoint(endpoint.index), diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index a33641a4b7e2..ed325ca58a80 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -13,6 +13,7 @@ import { type NodeId, type PhysicalNodes, type QueryNodeStatus, + type SecurityManagers, type SendCommandOptions, type SupervisionResult, type SupportsCC, @@ -26,7 +27,19 @@ import { getCCName, stripUndefined, } from "@zwave-js/core"; -import type { ZWaveApplicationHost } from "@zwave-js/host"; +import type { + GetCommunicationTimeouts, + GetDeviceConfig, + GetNode, + GetSafeCCVersion, + GetSupportedCCVersion, + GetUserPreferences, + GetValueDB, + HostIDs, + LogNode, + SchedulePoll, + SendCommand, +} from "@zwave-js/host"; import { type AllOrNone, type OnlyMethods, @@ -153,6 +166,21 @@ export interface SchedulePollOptions { transition?: "fast" | "slow"; } +// Defines the necessary traits the host passed to a CC API must have +export type CCAPIHost = + & HostIDs + & GetNode + & GetValueDB + & GetSupportedCCVersion + & GetSafeCCVersion + & SecurityManagers + & GetDeviceConfig + & SendCommand + & GetCommunicationTimeouts + & GetUserPreferences + & SchedulePoll + & LogNode; + // Defines the necessary traits a node passed to a CC API must have export type CCAPINode = NodeId & ListenBehavior & QueryNodeStatus; @@ -188,7 +216,7 @@ export type VirtualCCAPIEndpoint = CCAPIEndpoint & VirtualEndpointId; */ export class CCAPI { public constructor( - protected readonly applHost: ZWaveApplicationHost, + protected readonly applHost: CCAPIHost, protected readonly endpoint: CCAPIEndpoint, ) { this.ccId = getCommandClass(this); @@ -196,7 +224,7 @@ export class CCAPI { public static create( ccId: T, - applHost: ZWaveApplicationHost, + applHost: CCAPIHost, endpoint: CCAPIEndpoint, requireSupport?: boolean, ): CommandClasses extends T ? CCAPI : CCToAPI { @@ -612,7 +640,7 @@ export class CCAPI { } function overrideQueriesWrapper( - applHost: ZWaveApplicationHost, + applHost: GetValueDB & LogNode, endpoint: PhysicalCCAPIEndpoint, ccId: CommandClasses, method: string, @@ -752,7 +780,7 @@ function overrideQueriesWrapper( /** A CC API that is only available for physical endpoints */ export class PhysicalCCAPI extends CCAPI { public constructor( - applHost: ZWaveApplicationHost, + applHost: CCAPIHost, endpoint: CCAPIEndpoint, ) { super(applHost, endpoint); @@ -763,7 +791,7 @@ export class PhysicalCCAPI extends CCAPI { } export type APIConstructor = new ( - applHost: ZWaveApplicationHost, + applHost: CCAPIHost, endpoint: CCAPIEndpoint, ) => T; diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 0050b16184b9..b459ac38c746 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -36,6 +36,8 @@ import { import type { CCEncodingContext, CCParsingContext, + GetDeviceConfig, + GetNode, GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, @@ -605,7 +607,7 @@ export class CommandClass implements CCId { * Returns the node this CC is linked to. Throws if the controller is not yet ready. */ public getNode( - applHost: ZWaveApplicationHost, + applHost: GetNode, ): T | undefined { if (this.isSinglecast()) { return applHost.getNode(this.nodeId); @@ -617,7 +619,7 @@ export class CommandClass implements CCId { * Returns the node this CC is linked to (or undefined if the node doesn't exist) */ public getNodeUnsafe( - applHost: ZWaveApplicationHost, + applHost: GetNode, ): T | undefined { try { return this.getNode(applHost); @@ -632,16 +634,16 @@ export class CommandClass implements CCId { } public getEndpoint( - applHost: ZWaveApplicationHost>, + applHost: GetNode>, ): T | undefined { return this.getNode(applHost)?.getEndpoint(this.endpointIndex); } /** Returns the value DB for this CC's node */ - protected getValueDB(host: GetValueDB): ValueDB { + protected getValueDB(ctx: GetValueDB): ValueDB { if (this.isSinglecast()) { try { - return host.getValueDB(this.nodeId); + return ctx.getValueDB(this.nodeId); } catch { throw new ZWaveError( "The node for this CC does not exist or the driver is not ready yet", @@ -661,11 +663,11 @@ export class CommandClass implements CCId { * @param meta Will be used in place of the predefined metadata when given */ protected ensureMetadata( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, meta?: ValueMetadata, ): void { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); if (!valueDB.hasMetadata(valueId)) { valueDB.setMetadata(valueId, meta ?? ccValue.meta); @@ -677,10 +679,10 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected removeMetadata( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, ): void { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); valueDB.setMetadata(valueId, undefined); } @@ -691,11 +693,11 @@ export class CommandClass implements CCId { * @param meta Will be used in place of the predefined metadata when given */ protected setMetadata( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, meta?: ValueMetadata, ): void { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); valueDB.setMetadata(valueId, meta ?? ccValue.meta); } @@ -705,10 +707,10 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected getMetadata( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, ): T | undefined { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); return valueDB.getMetadata(valueId) as any; } @@ -718,11 +720,11 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected setValue( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, value: unknown, ): void { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); valueDB.setValue(valueId, value); } @@ -732,10 +734,10 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected removeValue( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, ): void { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); valueDB.removeValue(valueId); } @@ -745,10 +747,10 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected getValue( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, ): T | undefined { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); return valueDB.getValue(valueId); } @@ -758,10 +760,10 @@ export class CommandClass implements CCId { * The endpoint index of the current CC instance is automatically taken into account. */ protected getValueTimestamp( - host: GetValueDB, + ctx: GetValueDB, ccValue: CCValue, ): number | undefined { - const valueDB = this.getValueDB(host); + const valueDB = this.getValueDB(ctx); const valueId = ccValue.endpoint(this.endpointIndex); return valueDB.getTimestamp(valueId); } @@ -799,14 +801,14 @@ export class CommandClass implements CCId { } private shouldAutoCreateValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, value: StaticCCValue, ): boolean { return ( value.options.autoCreate === true || (typeof value.options.autoCreate === "function" && value.options.autoCreate( - applHost, + ctx, { virtual: false, nodeId: this.nodeId as number, @@ -818,7 +820,7 @@ export class CommandClass implements CCId { /** Returns a list of all value names that are defined for this CommandClass */ public getDefinedValueIDs( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetSupportedCCVersion & GetDeviceConfig, includeInternal: boolean = false, ): ValueID[] { // In order to compare value ids, we need them to be strings @@ -839,7 +841,7 @@ export class CommandClass implements CCId { }; // Return all value IDs for this CC... - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); // ...which either have metadata or a value const existingValueIds: ValueID[] = [ ...valueDB.getValues(this.ccId), @@ -852,7 +854,7 @@ export class CommandClass implements CCId { && this.nodeId !== NODE_ID_BROADCAST && this.nodeId !== NODE_ID_BROADCAST_LR // On singlecast CCs, use the version the node reported support for, - ? applHost.getSupportedCCVersion( + ? ctx.getSupportedCCVersion( this.ccId, this.nodeId, this.endpointIndex, @@ -877,7 +879,7 @@ export class CommandClass implements CCId { if (value.options.internal && !includeInternal) continue; // And determine if this value should be automatically "created" - if (!this.shouldAutoCreateValue(applHost, value)) continue; + if (!this.shouldAutoCreateValue(ctx, value)) continue; existingValueIds.push(value.endpoint(this.endpointIndex)); } diff --git a/packages/cc/src/lib/Values.ts b/packages/cc/src/lib/Values.ts index a276a8bdc543..ae4f074093b9 100644 --- a/packages/cc/src/lib/Values.ts +++ b/packages/cc/src/lib/Values.ts @@ -4,7 +4,7 @@ import { type ValueID, ValueMetadata, } from "@zwave-js/core"; -import type { ZWaveApplicationHost } from "@zwave-js/host"; +import type { GetDeviceConfig, GetValueDB } from "@zwave-js/host"; import { type FnOrStatic, type ReturnTypeOrStatic, @@ -48,7 +48,7 @@ export interface CCValueOptions { autoCreate?: | boolean | (( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, endpoint: EndpointId, ) => boolean); } diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 799723e85fd0..1211ba1647e0 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -35,7 +35,7 @@ export interface GetNextCallbackId { /** Allows querying device configuration for a node */ export interface GetDeviceConfig { - getDeviceConfig?: (nodeId: number) => DeviceConfig | undefined; + getDeviceConfig(nodeId: number): DeviceConfig | undefined; } export interface GetSupportedCCVersion { @@ -178,8 +178,7 @@ export interface ZWaveApplicationHost GetUserPreferences, GetCommunicationTimeouts, LogNode -{ -} +{} /** Allows scheduling a value refresh (poll) for a later time */ export interface SchedulePoll { diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 28086c85aadf..c646d51bfe0a 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -55,7 +55,7 @@ export function createTestingHost< securityManager: undefined, securityManager2: undefined, securityManagerLR: undefined, - getDeviceConfig: undefined, + getDeviceConfig: () => undefined, lookupManufacturer: () => undefined, logNode: () => {}, // options: { diff --git a/packages/maintenance/src/codeshifts/refactorGetXCached.ts b/packages/maintenance/src/codeshifts/refactorGetXCached.ts new file mode 100644 index 000000000000..558d063d94ab --- /dev/null +++ b/packages/maintenance/src/codeshifts/refactorGetXCached.ts @@ -0,0 +1,113 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { + type API, + type FileInfo, + type Identifier, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + {}: Options, +) => { + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + const ccImplementations = root.find(j.ClassDeclaration, { + superClass: { + name: "CommandClass", + }, + }); + + const methods = ccImplementations.find(j.ClassMethod, { + kind: "method", + static: true, + }).filter(({ node }) => { + return node.key.type === "Identifier" + && node.key.name.endsWith("Cached") + && node.params.length >= 1 + && node.params[0].type === "Identifier" + && node.params[0].name === "applHost" + && node.params[0].typeAnnotation?.type === "TSTypeAnnotation" + && node.params[0].typeAnnotation.typeAnnotation.type + === "TSTypeReference" + && node.params[0].typeAnnotation.typeAnnotation.typeName.type + === "Identifier" + && node.params[0].typeAnnotation.typeAnnotation.typeName.name + === "ZWaveApplicationHost"; + }); + + methods.replaceWith(({ node }) => { + const ident = node.params[0] as Identifier; + ident.name = "ctx"; + // @ts-expect-error + ident.typeAnnotation.typeAnnotation.typeName.name = "GetValueDB"; + return node; + }); + + const memberExprs = methods.find(j.MemberExpression, { + object: { + type: "Identifier", + name: "applHost", + }, + }); + + memberExprs.replaceWith(({ node }) => { + node.object = j.identifier("ctx"); + return node; + }); + + return root.toSource(); + + // const imp = root + // .find( + // j.ImportDeclaration, + // { importKind: typeOnly ? "type" : undefined }, + // ) + // .find(j.ImportSpecifier, { + // imported: { + // name: from, + // }, + // }); + + // return imp.replaceWith(({ node }) => { + // node.imported.name = to; + // return node; + // }).toSource(); + + // return ( + // j(file.source) + // .find(j.FunctionDeclaration) + // // Target a particular function declaration + // .filter(({ node: functionDeclaration }) => functionDeclaration.id.name === functionName) + // .replaceWith(({ node: functionDeclaration }) => { + // // Create a function call expression statement + // const functionCallExpressionStatement = j.expressionStatement( + // j.callExpression(j.identifier(functionNameToCall), []) + // ); + + // // Create a comment and add it as a leading comment to the function call expression + // const commentLine = j.commentLine(comment); + // functionCallExpressionStatement.comments = [commentLine]; + + // // Append the function call expression to the function declaration's existing body + // functionDeclaration.body.body = [...functionDeclaration.body.body, functionCallExpressionStatement]; + // return functionDeclaration; + // }) + // .toSource() + // ); +}; + +export default transform; +export const parser = "ts"; diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 41d3f1304e18..b17658198654 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -95,7 +95,11 @@ export type MessageOptions = | MessageDeserializationOptions; export interface MessageEncodingContext - extends Readonly, HostIDs, GetSupportedCCVersion + extends + Readonly, + HostIDs, + GetSupportedCCVersion, + GetDeviceConfig { /** How many bytes a node ID occupies in serial API commands */ nodeIdType: NodeIDType; diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 030558af5013..092278b31e6c 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -115,9 +115,11 @@ export class MockController { const endpoint = node.endpoints.get(endpointIndex); return (endpoint ?? node).implementedCCs.get(cc)?.version ?? 0; }, + getDeviceConfig: () => undefined, }; this.parsingContext = { ...this.encodingContext, + getDeviceConfig: () => undefined, }; void this.execute(); diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 8e9874ec50a5..3d25d03b3eb2 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -187,6 +187,8 @@ export class MockNode { const endpoint = this.endpoints.get(endpointIndex); return (endpoint ?? this).implementedCCs.get(cc)?.version ?? 0; }, + // Mock nodes don't care about device configuration files + getDeviceConfig: () => undefined, }; } diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index adf403794e64..b860f3cefb08 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -666,6 +666,7 @@ export class Driver extends TypedEventEmitter this.hasSecurityClass(nodeId, securityClass), setSecurityClass: (nodeId, securityClass, granted) => this.setSecurityClass(nodeId, securityClass, granted), + getDeviceConfig: (nodeId) => this.getDeviceConfig(nodeId), }; this.messageEncodingContext = { getHighestSecurityClass: (nodeId) => @@ -676,6 +677,7 @@ export class Driver extends TypedEventEmitter this.setSecurityClass(nodeId, securityClass, granted), getSupportedCCVersion: (cc, nodeId, endpointIndex) => this.getSupportedCCVersion(cc, nodeId, endpointIndex), + getDeviceConfig: (nodeId) => this.getDeviceConfig(nodeId), }; this.immediateQueue = new TransactionQueue({ From f98c05a89079847ac0fd6b25a0b16a67766e1d3c Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 11:31:38 +0200 Subject: [PATCH 44/60] refactor: rename CCAPI.applHost to just host --- packages/cc/src/cc/AlarmSensorCC.ts | 4 +- packages/cc/src/cc/AssociationCC.ts | 16 +++--- packages/cc/src/cc/AssociationGroupInfoCC.ts | 12 ++-- packages/cc/src/cc/BarrierOperatorCC.ts | 12 ++-- packages/cc/src/cc/BasicCC.ts | 6 +- packages/cc/src/cc/BatteryCC.ts | 4 +- packages/cc/src/cc/BinarySensorCC.ts | 8 +-- packages/cc/src/cc/BinarySwitchCC.ts | 6 +- packages/cc/src/cc/CRC16CC.ts | 2 +- packages/cc/src/cc/CentralSceneCC.ts | 6 +- .../cc/src/cc/ClimateControlScheduleCC.ts | 10 ++-- packages/cc/src/cc/ClockCC.ts | 4 +- packages/cc/src/cc/ColorSwitchCC.ts | 12 ++-- packages/cc/src/cc/ConfigurationCC.ts | 52 ++++++++--------- packages/cc/src/cc/DeviceResetLocallyCC.ts | 2 +- packages/cc/src/cc/DoorLockCC.ts | 10 ++-- packages/cc/src/cc/DoorLockLoggingCC.ts | 4 +- packages/cc/src/cc/EnergyProductionCC.ts | 2 +- packages/cc/src/cc/EntryControlCC.ts | 8 +-- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 10 ++-- packages/cc/src/cc/HumidityControlModeCC.ts | 6 +- .../src/cc/HumidityControlOperatingStateCC.ts | 2 +- .../cc/src/cc/HumidityControlSetpointCC.ts | 10 ++-- packages/cc/src/cc/InclusionControllerCC.ts | 4 +- packages/cc/src/cc/IndicatorCC.ts | 16 +++--- packages/cc/src/cc/IrrigationCC.ts | 26 ++++----- packages/cc/src/cc/LanguageCC.ts | 4 +- packages/cc/src/cc/LockCC.ts | 4 +- .../cc/src/cc/ManufacturerProprietaryCC.ts | 4 +- packages/cc/src/cc/ManufacturerSpecificCC.ts | 6 +- packages/cc/src/cc/MeterCC.ts | 10 ++-- .../cc/src/cc/MultiChannelAssociationCC.ts | 16 +++--- packages/cc/src/cc/MultiChannelCC.ts | 14 ++--- packages/cc/src/cc/MultiCommandCC.ts | 2 +- packages/cc/src/cc/MultilevelSensorCC.ts | 10 ++-- packages/cc/src/cc/MultilevelSwitchCC.ts | 12 ++-- packages/cc/src/cc/NoOperationCC.ts | 2 +- packages/cc/src/cc/NodeNamingCC.ts | 8 +-- packages/cc/src/cc/NotificationCC.ts | 10 ++-- packages/cc/src/cc/PowerlevelCC.ts | 16 +++--- packages/cc/src/cc/ProtectionCC.ts | 14 ++--- packages/cc/src/cc/SceneActivationCC.ts | 2 +- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 6 +- .../src/cc/SceneControllerConfigurationCC.ts | 8 +-- packages/cc/src/cc/ScheduleEntryLockCC.ts | 48 ++++++++-------- packages/cc/src/cc/Security2CC.ts | 56 +++++++++---------- packages/cc/src/cc/SecurityCC.ts | 44 +++++++-------- packages/cc/src/cc/SoundSwitchCC.ts | 14 ++--- packages/cc/src/cc/SupervisionCC.ts | 2 +- packages/cc/src/cc/ThermostatFanModeCC.ts | 6 +- packages/cc/src/cc/ThermostatFanStateCC.ts | 2 +- packages/cc/src/cc/ThermostatModeCC.ts | 6 +- .../cc/src/cc/ThermostatOperatingStateCC.ts | 2 +- packages/cc/src/cc/ThermostatSetbackCC.ts | 4 +- packages/cc/src/cc/ThermostatSetpointCC.ts | 8 +-- packages/cc/src/cc/TimeCC.ts | 14 ++--- packages/cc/src/cc/TimeParametersCC.ts | 6 +- packages/cc/src/cc/UserCodeCC.ts | 42 +++++++------- packages/cc/src/cc/VersionCC.ts | 14 ++--- packages/cc/src/cc/WakeUpCC.ts | 10 ++-- packages/cc/src/cc/WindowCoveringCC.ts | 12 ++-- packages/cc/src/cc/ZWavePlusCC.ts | 4 +- .../cc/manufacturerProprietary/FibaroCC.ts | 6 +- packages/cc/src/lib/API.ts | 44 +++++++-------- packages/cc/src/lib/CommandClass.ts | 12 ++-- 65 files changed, 379 insertions(+), 379 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 8cd720a2d5b4..11071aaad5b2 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -135,7 +135,7 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, sensorType, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -153,7 +153,7 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< AlarmSensorCCSupportedReport >( cc, diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 7da51e3bde0e..5628f3c9f03a 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -110,7 +110,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< AssociationCCSupportedGroupingsReport >( cc, @@ -131,7 +131,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, groupCount, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -147,7 +147,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, groupId, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -173,7 +173,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -192,7 +192,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { groupId, nodeIds, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -227,7 +227,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -273,7 +273,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< AssociationCCSpecificGroupReport >( cc, @@ -299,7 +299,7 @@ export class AssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, group, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 524a9dc51332..ca1545633148 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -116,7 +116,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, groupId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< AssociationGroupInfoCCNameReport >( cc, @@ -139,7 +139,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { name, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -156,7 +156,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { groupId, refreshCache, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< AssociationGroupInfoCCInfoReport >( cc, @@ -189,7 +189,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -210,7 +210,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { groupId, allowCache, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< AssociationGroupInfoCCCommandListReport >( cc, @@ -236,7 +236,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI { commands, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 67461983206c..5c1da4f8c4ce 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -151,7 +151,7 @@ export class BarrierOperatorCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< BarrierOperatorCCReport >( cc, @@ -176,7 +176,7 @@ export class BarrierOperatorCCAPI extends CCAPI { endpoint: this.endpoint.index, targetState, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -192,7 +192,7 @@ export class BarrierOperatorCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< BarrierOperatorCCSignalingCapabilitiesReport >( cc, @@ -215,7 +215,7 @@ export class BarrierOperatorCCAPI extends CCAPI { endpoint: this.endpoint.index, subsystemType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< BarrierOperatorCCEventSignalingReport >( cc, @@ -241,7 +241,7 @@ export class BarrierOperatorCCAPI extends CCAPI { subsystemState, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { @@ -351,7 +351,7 @@ export class BarrierOperatorCCAPI extends CCAPI { ); // and optimistically update the currentValue for (const node of affectedNodes) { - this.applHost + this.host .tryGetValueDB(node.id) ?.setValue(currentStateValueId, targetValue); } diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index fef4b9fa2463..0d5ec4517f95 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -169,7 +169,7 @@ export class BasicCCAPI extends CCAPI { ); // and optimistically update the currentValue for (const node of affectedNodes) { - this.applHost + this.host .tryGetValueDB(node.id) ?.setValue(currentValueValueId, value); } @@ -219,7 +219,7 @@ export class BasicCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -243,7 +243,7 @@ export class BasicCCAPI extends CCAPI { endpoint: this.endpoint.index, targetValue, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 5790c3421032..89b72d0766bc 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -233,7 +233,7 @@ export class BatteryCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -261,7 +261,7 @@ export class BatteryCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index e97fcdab6ea7..c2b2ff7bb073 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -117,7 +117,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, sensorType, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -141,7 +141,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { value, type: sensorType, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getSupportedSensorTypes(): Promise< @@ -156,7 +156,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< BinarySensorCCSupportedReport >( cc, @@ -180,7 +180,7 @@ export class BinarySensorCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, supportedSensorTypes: supported, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 8b12eb50f730..8668f2669654 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -106,7 +106,7 @@ export class BinarySwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -141,7 +141,7 @@ export class BinarySwitchCCAPI extends CCAPI { targetValue, duration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { @@ -196,7 +196,7 @@ export class BinarySwitchCCAPI extends CCAPI { ); // and optimistically update the currentValue for (const node of affectedNodes) { - this.applHost + this.host .tryGetValueDB(node.id) ?.setValue(currentValueValueId, value); } diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index 0fe5349e4066..399b63136bd1 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -51,7 +51,7 @@ export class CRC16CCAPI extends CCAPI { endpoint: this.endpoint.index, encapsulated: encapsulatedCC, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index ac476a27385b..b32183840bdc 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -118,7 +118,7 @@ export class CentralSceneCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< CentralSceneCCSupportedReport >( cc, @@ -144,7 +144,7 @@ export class CentralSceneCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< CentralSceneCCConfigurationReport >( cc, @@ -169,7 +169,7 @@ export class CentralSceneCCAPI extends CCAPI { endpoint: this.endpoint.index, slowRefresh, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index 3a94ac2a7b83..2db729c63426 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -116,7 +116,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { weekday, switchPoints, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs({ strictEnums: true }) @@ -133,7 +133,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { endpoint: this.endpoint.index, weekday, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ClimateControlScheduleCCReport >( cc, @@ -152,7 +152,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ClimateControlScheduleCCChangedReport >( cc, @@ -172,7 +172,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ClimateControlScheduleCCOverrideReport >( cc, @@ -202,7 +202,7 @@ export class ClimateControlScheduleCCAPI extends CCAPI { overrideType: type, overrideState: state, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 92e932b8b9cb..7e8b7d3dafd9 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -58,7 +58,7 @@ export class ClockCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -82,7 +82,7 @@ export class ClockCCAPI extends CCAPI { minute, weekday: weekday ?? Weekday.Unknown, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 7f079d3206d6..66930f37d01e 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -213,7 +213,7 @@ export class ColorSwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ColorSwitchCCSupportedReport >( cc, @@ -232,7 +232,7 @@ export class ColorSwitchCCAPI extends CCAPI { endpoint: this.endpoint.index, colorComponent: component, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -253,7 +253,7 @@ export class ColorSwitchCCAPI extends CCAPI { ...options, }); - const result = await this.applHost.sendCommand(cc, this.commandOptions); + const result = await this.host.sendCommand(cc, this.commandOptions); if (isUnsupervisedOrSucceeded(result)) { // If the command did not fail, assume that it succeeded and update the values accordingly @@ -272,7 +272,7 @@ export class ColorSwitchCCAPI extends CCAPI { ); // and optimistically update the currentColor for (const node of affectedNodes) { - const valueDB = this.applHost.tryGetValueDB(node.id); + const valueDB = this.host.tryGetValueDB(node.id); if (valueDB) { this.updateCurrentColor(valueDB, cc.colorTable); } @@ -371,7 +371,7 @@ export class ColorSwitchCCAPI extends CCAPI { ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs({ strictEnums: true }) @@ -389,7 +389,7 @@ export class ColorSwitchCCAPI extends CCAPI { colorComponent, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 8c2253b43b80..e4cf1299437d 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -340,7 +340,7 @@ export class ConfigurationCCAPI extends CCAPI { } let ccInstance: ConfigurationCC; - const applHost = this.applHost; + const applHost = this.host; if (this.isSinglecast()) { ccInstance = createConfigurationCCInstance(this.endpoint); @@ -365,7 +365,7 @@ export class ConfigurationCCAPI extends CCAPI { createConfigurationCCInstance( node.getEndpoint(this.endpoint.index)!, ).getParamInformation( - this.applHost, + this.host, property, propertyKey, ), @@ -531,7 +531,7 @@ export class ConfigurationCCAPI extends CCAPI { parameter, allowUnexpectedResponse, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -542,7 +542,7 @@ export class ConfigurationCCAPI extends CCAPI { if (!valueBitMask) return response.value; // If a partial parameter was requested, extract that value const paramInfo = cc.getParamInformation( - this.applHost, + this.host, response.parameter, valueBitMask, ); @@ -552,7 +552,7 @@ export class ConfigurationCCAPI extends CCAPI { isSignedPartial(valueBitMask, paramInfo.format), ); } - this.applHost.logNode(this.endpoint.nodeId, { + this.host.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: `Received unexpected ConfigurationReport (param = ${response.parameter}, value = ${response.value.toString()})`, @@ -599,7 +599,7 @@ export class ConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, parameters: distinctParameters, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ConfigurationCCBulkReport >( cc, @@ -619,7 +619,7 @@ export class ConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, parameter, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ConfigurationCCReport >( cc, @@ -638,7 +638,7 @@ export class ConfigurationCCAPI extends CCAPI { let value = values?.get(o.parameter); if (typeof value === "number" && o.bitMask) { const paramInfo = cc.getParamInformation( - this.applHost, + this.host, o.parameter, o.bitMask, ); @@ -670,7 +670,7 @@ export class ConfigurationCCAPI extends CCAPI { ); const normalized = normalizeConfigurationCCAPISetOptions( - this.applHost, + this.host, this.endpoint, options, ); @@ -678,7 +678,7 @@ export class ConfigurationCCAPI extends CCAPI { if (normalized.bitMask) { const ccc = createConfigurationCCInstance(this.endpoint); value = ccc.composePartialParamValue( - this.applHost, + this.host, normalized.parameter, normalized.bitMask, normalized.value, @@ -694,7 +694,7 @@ export class ConfigurationCCAPI extends CCAPI { valueFormat: normalized.valueFormat, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -707,14 +707,14 @@ export class ConfigurationCCAPI extends CCAPI { // Normalize the values so we can better work with them const normalized = values.map((v) => normalizeConfigurationCCAPISetOptions( - this.applHost, + this.host, this.endpoint, v, ) ); // And merge multiple partials that belong the same "full" value const allParams = bulkMergePartialParamValues( - this.applHost, + this.host, this.endpoint, normalized, ); @@ -738,7 +738,7 @@ export class ConfigurationCCAPI extends CCAPI { handshake: true, }); // The handshake flag is set, so we expect a BulkReport in response - const result = await this.applHost.sendCommand< + const result = await this.host.sendCommand< ConfigurationCCBulkReport >( cc, @@ -785,7 +785,7 @@ export class ConfigurationCCAPI extends CCAPI { valueFormat, }); supervisionResults.push( - await this.applHost.sendCommand(cc, this.commandOptions), + await this.host.sendCommand(cc, this.commandOptions), ); } return mergeSupervisionResults(supervisionResults); @@ -828,7 +828,7 @@ export class ConfigurationCCAPI extends CCAPI { parameter, resetToDefault: true, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -850,7 +850,7 @@ export class ConfigurationCCAPI extends CCAPI { parameters, resetToDefault: true, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } else { this.assertSupportsCommand( ConfigurationCommand, @@ -866,7 +866,7 @@ export class ConfigurationCCAPI extends CCAPI { }), ); for (const cc of CCs) { - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } } @@ -885,7 +885,7 @@ export class ConfigurationCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -899,7 +899,7 @@ export class ConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, parameter, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ConfigurationCCPropertiesReport >( cc, @@ -932,7 +932,7 @@ export class ConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, parameter, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ConfigurationCCNameReport >( cc, @@ -952,7 +952,7 @@ export class ConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, parameter, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ConfigurationCCInfoReport >( cc, @@ -984,7 +984,7 @@ export class ConfigurationCCAPI extends CCAPI { this.assertPhysicalEndpoint(this.endpoint); // TODO: Reduce the priority of the messages - this.applHost.logNode(this.endpoint.nodeId, { + this.host.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: `Scanning available parameters...`, }); @@ -992,7 +992,7 @@ export class ConfigurationCCAPI extends CCAPI { for (let param = 1; param <= 255; param++) { // Check if the parameter is readable let originalValue: ConfigValue | undefined; - this.applHost.logNode(this.endpoint.nodeId, { + this.host.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: ` trying param ${param}...`, direction: "outbound", @@ -1008,11 +1008,11 @@ export class ConfigurationCCAPI extends CCAPI { const logMessage = ` Param ${param}: readable = true valueSize = ${ - ccInstance.getParamInformation(this.applHost, param) + ccInstance.getParamInformation(this.host, param) .valueSize } value = ${originalValue.toString()}`; - this.applHost.logNode(this.endpoint.nodeId, { + this.host.logNode(this.endpoint.nodeId, { endpoint: this.endpoint.index, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/DeviceResetLocallyCC.ts b/packages/cc/src/cc/DeviceResetLocallyCC.ts index 9927ddff1922..105ac53672e5 100644 --- a/packages/cc/src/cc/DeviceResetLocallyCC.ts +++ b/packages/cc/src/cc/DeviceResetLocallyCC.ts @@ -46,7 +46,7 @@ export class DeviceResetLocallyCCAPI extends CCAPI { try { // This command is sent immediately before a hard reset of the controller. // If we don't wait for a callback (ack), the controller locks up when hard-resetting. - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Do not fall back to explorer frames transmitOptions: TransmitOptions.ACK diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index 4b84767ac026..d2c081fde99f 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -468,7 +468,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< DoorLockCCCapabilitiesReport >( cc, @@ -502,7 +502,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< DoorLockCCOperationReport >( cc, @@ -537,7 +537,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, mode, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -554,7 +554,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...configuration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -568,7 +568,7 @@ export class DoorLockCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< DoorLockCCConfigurationReport >( cc, diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index ae08542c8750..16f864899a86 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -131,7 +131,7 @@ export class DoorLockLoggingCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< DoorLockLoggingCCRecordsSupportedReport >( cc, @@ -155,7 +155,7 @@ export class DoorLockLoggingCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, recordNumber, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< DoorLockLoggingCCRecordReport >( cc, diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index 77f4680faf63..59256c42541b 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -115,7 +115,7 @@ export class EnergyProductionCCAPI extends CCAPI { endpoint: this.endpoint.index, parameter, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< EnergyProductionCCReport >( cc, diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index e766342f20e0..8f44c7ae42a0 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -118,7 +118,7 @@ export class EntryControlCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< EntryControlCCKeySupportedReport >( cc, @@ -138,7 +138,7 @@ export class EntryControlCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< EntryControlCCEventSupportedReport >( cc, @@ -167,7 +167,7 @@ export class EntryControlCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< EntryControlCCConfigurationReport >( cc, @@ -194,7 +194,7 @@ export class EntryControlCCAPI extends CCAPI { keyCacheSize, keyCacheTimeout, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index b593662d28dd..a0569956f641 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -118,7 +118,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< FirmwareUpdateMetaDataCCMetaDataReport >( cc, @@ -155,7 +155,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -177,7 +177,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { ...options, }); - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Do not wait for Nonce Reports s2VerifyDelivery: false, @@ -205,7 +205,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { isLast: isLastFragment, firmwareData: data, }); - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Do not wait for Nonce Reports s2VerifyDelivery: false, @@ -227,7 +227,7 @@ export class FirmwareUpdateMetaDataCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< FirmwareUpdateMetaDataCCActivationReport >( cc, diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index cfa1ca604c01..056fcafb7e7e 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -130,7 +130,7 @@ export class HumidityControlModeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlModeCCReport >( cc, @@ -155,7 +155,7 @@ export class HumidityControlModeCCAPI extends CCAPI { endpoint: this.endpoint.index, mode, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getSupportedModes(): Promise< @@ -170,7 +170,7 @@ export class HumidityControlModeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlModeCCSupportedReport >( cc, diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index d99c311f5a9e..a6295a3da7fd 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -90,7 +90,7 @@ export class HumidityControlOperatingStateCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlOperatingStateCCReport >( cc, diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index a5ffc60b36b2..ee3f33d60ace 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -212,7 +212,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { endpoint: this.endpoint.index, setpointType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlSetpointCCReport >( cc, @@ -247,7 +247,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { value, scale, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -264,7 +264,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { endpoint: this.endpoint.index, setpointType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlSetpointCCCapabilitiesReport >( cc, @@ -292,7 +292,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlSetpointCCSupportedReport >( cc, @@ -315,7 +315,7 @@ export class HumidityControlSetpointCCAPI extends CCAPI { endpoint: this.endpoint.index, setpointType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< HumidityControlSetpointCCScaleSupportedReport >( cc, diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index 515b6d04fb53..b7fc8117c63d 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -63,7 +63,7 @@ export class InclusionControllerCCAPI extends CCAPI { includedNodeId: nodeId, step, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** Indicate to the other node that the given inclusion step has been completed */ @@ -82,7 +82,7 @@ export class InclusionControllerCCAPI extends CCAPI { step, status, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 0ceaa3d379c2..de6230a5a90e 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -363,7 +363,7 @@ export class IndicatorCCAPI extends CCAPI { endpoint: this.endpoint.index, indicatorId, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -400,7 +400,7 @@ export class IndicatorCCAPI extends CCAPI { endpoint: this.endpoint.index, ...(typeof value === "number" ? { value } : { values: value }), }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -418,7 +418,7 @@ export class IndicatorCCAPI extends CCAPI { ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -440,7 +440,7 @@ export class IndicatorCCAPI extends CCAPI { endpoint: this.endpoint.index, indicatorId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IndicatorCCSupportedReport >( cc, @@ -477,7 +477,7 @@ export class IndicatorCCAPI extends CCAPI { nextIndicatorId, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -497,7 +497,7 @@ export class IndicatorCCAPI extends CCAPI { description, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -566,7 +566,7 @@ export class IndicatorCCAPI extends CCAPI { } const supportedPropertyIDs = IndicatorCC.getSupportedPropertyIDsCached( - this.applHost, + this.host, this.endpoint, indicatorId, ); @@ -675,7 +675,7 @@ export class IndicatorCCAPI extends CCAPI { endpoint: this.endpoint.index, indicatorId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IndicatorCCDescriptionReport >( cc, diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 1f396a39dee9..fd627f92fec4 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -607,7 +607,7 @@ export class IrrigationCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IrrigationCCSystemInfoReport >( cc, @@ -634,7 +634,7 @@ export class IrrigationCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IrrigationCCSystemStatusReport >( cc, @@ -672,7 +672,7 @@ export class IrrigationCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IrrigationCCSystemConfigReport >( cc, @@ -704,7 +704,7 @@ export class IrrigationCCAPI extends CCAPI { ...config, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -720,7 +720,7 @@ export class IrrigationCCAPI extends CCAPI { endpoint: this.endpoint.index, valveId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IrrigationCCValveInfoReport >( cc, @@ -755,7 +755,7 @@ export class IrrigationCCAPI extends CCAPI { ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -771,7 +771,7 @@ export class IrrigationCCAPI extends CCAPI { endpoint: this.endpoint.index, valveId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IrrigationCCValveConfigReport >( cc, @@ -807,7 +807,7 @@ export class IrrigationCCAPI extends CCAPI { duration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -829,7 +829,7 @@ export class IrrigationCCAPI extends CCAPI { if (!this.endpoint.virtual) { const maxValveTableSize = IrrigationCC.getMaxValveTableSizeCached( - this.applHost, + this.host, this.endpoint, ); if ( @@ -850,7 +850,7 @@ export class IrrigationCCAPI extends CCAPI { entries, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -867,7 +867,7 @@ export class IrrigationCCAPI extends CCAPI { endpoint: this.endpoint.index, tableId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< IrrigationCCValveTableReport >( cc, @@ -893,7 +893,7 @@ export class IrrigationCCAPI extends CCAPI { tableIDs, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -915,7 +915,7 @@ export class IrrigationCCAPI extends CCAPI { duration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** Shuts off the entire system permanently and prevents schedules from running */ diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index a44eda9c5e95..5cb555bf6308 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -82,7 +82,7 @@ export class LanguageCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -104,7 +104,7 @@ export class LanguageCCAPI extends CCAPI { language, country, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 254eecc19012..dafa12b5faad 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -77,7 +77,7 @@ export class LockCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -97,7 +97,7 @@ export class LockCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, locked, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index 13b2c88aedeb..a214f19ffc0c 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -77,7 +77,7 @@ export class ManufacturerProprietaryCCAPI extends CCAPI { }); cc.payload = data ?? Buffer.allocUnsafe(0); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -91,7 +91,7 @@ export class ManufacturerProprietaryCCAPI extends CCAPI { }); cc.payload = data ?? Buffer.allocUnsafe(0); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ManufacturerProprietaryCC >( cc, diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 9260a1d66ba5..64ea4768a97a 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -112,7 +112,7 @@ export class ManufacturerSpecificCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ManufacturerSpecificCCReport >( cc, @@ -141,7 +141,7 @@ export class ManufacturerSpecificCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, deviceIdType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ManufacturerSpecificCCDeviceSpecificReport >( cc, @@ -164,7 +164,7 @@ export class ManufacturerSpecificCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 285b82a8c265..b346f5b9d6fc 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -360,7 +360,7 @@ export class MeterCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -390,7 +390,7 @@ export class MeterCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -450,7 +450,7 @@ export class MeterCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MeterCCSupportedReport >( cc, @@ -477,7 +477,7 @@ export class MeterCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -491,7 +491,7 @@ export class MeterCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index a78d2724a097..a43b78b82c4d 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -208,7 +208,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelAssociationCCSupportedGroupingsReport >( cc, @@ -229,7 +229,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, groupCount, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -248,7 +248,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, groupId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelAssociationCCReport >( cc, @@ -273,7 +273,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -293,7 +293,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -313,7 +313,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { // We don't want to do too much work, so find out which groups the destination is in const currentDestinations = MultiChannelAssociationCC .getAllDestinationsCached( - this.applHost, + this.host, this.endpoint, ); for (const [group, destinations] of currentDestinations) { @@ -330,7 +330,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { ), }); // TODO: evaluate intermediate supervision results - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } else if (options.groupId && options.groupId < 0) { throw new ZWaveError( @@ -343,7 +343,7 @@ export class MultiChannelAssociationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } } diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 2bc42821c8fc..fc3ee33bc27d 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -220,7 +220,7 @@ export class MultiChannelCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelCCEndPointReport >( cc, @@ -250,7 +250,7 @@ export class MultiChannelCCAPI extends CCAPI { endpoint: this.endpoint.index, requestedEndpoint: endpoint, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelCCCapabilityReport >( cc, @@ -290,7 +290,7 @@ export class MultiChannelCCAPI extends CCAPI { genericClass, specificClass, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelCCEndPointFindReport >( cc, @@ -313,7 +313,7 @@ export class MultiChannelCCAPI extends CCAPI { endpoint: this.endpoint.index, requestedEndpoint: endpoint, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelCCAggregatedMembersReport >( cc, @@ -340,7 +340,7 @@ export class MultiChannelCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -356,7 +356,7 @@ export class MultiChannelCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, requestedCC: ccId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultiChannelCCV1Report >( cc, @@ -378,7 +378,7 @@ export class MultiChannelCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, encapsulated, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index da005011abc1..fc6e9f0f692b 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -50,7 +50,7 @@ export class MultiCommandCCAPI extends CCAPI { encapsulated: commands, }); cc.endpointIndex = this.endpoint.index; - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 268303f5c0bc..5a78e664737f 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -272,7 +272,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { }) ?? []; preferredScale = getPreferredSensorScale( - this.applHost, + this.host, this.endpoint.nodeId, this.endpoint.index, sensorType, @@ -286,7 +286,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { sensorType, scale: scale ?? preferredScale, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultilevelSensorCCReport >( cc, @@ -327,7 +327,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultilevelSensorCCSupportedSensorReport >( cc, @@ -350,7 +350,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, sensorType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultilevelSensorCCSupportedScaleReport >( cc, @@ -377,7 +377,7 @@ export class MultilevelSensorCCAPI extends PhysicalCCAPI { scale, value, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index fe9993acbbe8..391d8c1a4a40 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -234,7 +234,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultilevelSwitchCCReport >( cc, @@ -267,7 +267,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { targetValue, duration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -285,7 +285,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async stopLevelChange(): Promise { @@ -299,7 +299,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { endpoint: this.endpoint.index, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getSupported(): Promise> { @@ -312,7 +312,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< MultilevelSwitchCCSupportedReport >( cc, @@ -470,7 +470,7 @@ export class MultilevelSwitchCCAPI extends CCAPI { ); // and optimistically update the currentValue for (const node of affectedNodes) { - this.applHost + this.host .tryGetValueDB(node.id) ?.setValue(currentValueValueId, value); } diff --git a/packages/cc/src/cc/NoOperationCC.ts b/packages/cc/src/cc/NoOperationCC.ts index 79ae57ff5e9c..c81d89f72737 100644 --- a/packages/cc/src/cc/NoOperationCC.ts +++ b/packages/cc/src/cc/NoOperationCC.ts @@ -15,7 +15,7 @@ import { isCommandClassContainer } from "../lib/ICommandClassContainer"; @API(CommandClasses["No Operation"]) export class NoOperationCCAPI extends PhysicalCCAPI { public async send(): Promise { - await this.applHost.sendCommand( + await this.host.sendCommand( new NoOperationCC({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index b41531eac120..2b783df18b50 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -138,7 +138,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< NodeNamingAndLocationCCNameReport >( cc, @@ -159,7 +159,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, name, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getLocation(): Promise> { @@ -172,7 +172,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< NodeNamingAndLocationCCLocationReport >( cc, @@ -195,7 +195,7 @@ export class NodeNamingAndLocationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, location, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index d490a444a72d..001f22631455 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -297,7 +297,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand( + return this.host.sendCommand( cc, this.commandOptions, ); @@ -317,7 +317,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -351,7 +351,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { notificationType, notificationStatus, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -365,7 +365,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< NotificationCCSupportedReport >( cc, @@ -393,7 +393,7 @@ export class NotificationCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, notificationType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< NotificationCCEventSupportedReport >( cc, diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index ab8c30824532..287c3871c24f 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -58,7 +58,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, powerlevel: Powerlevel["Normal Power"], }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs({ strictEnums: true }) @@ -74,7 +74,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { powerlevel, timeout, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getPowerlevel(): Promise< @@ -86,7 +86,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -106,7 +106,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs({ strictEnums: true }) @@ -126,7 +126,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { ZWaveErrorCodes.Argument_Invalid, ); } - const testNode = this.applHost.getNodeOrThrow(testNodeId); + const testNode = this.host.getNodeOrThrow(testNodeId); if (testNode.isFrequentListening) { throw new ZWaveError( `Node ${testNodeId} is FLiRS and therefore cannot be used for a powerlevel test.`, @@ -147,7 +147,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { powerlevel, testFrameCount, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getNodeTestStatus(): Promise< @@ -167,7 +167,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< PowerlevelCCTestNodeReport >( cc, @@ -196,7 +196,7 @@ export class PowerlevelCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 8604f7900a36..50af8fd848f0 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -226,7 +226,7 @@ export class ProtectionCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -248,7 +248,7 @@ export class ProtectionCCAPI extends CCAPI { local, rf, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -262,7 +262,7 @@ export class ProtectionCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ProtectionCCSupportedReport >( cc, @@ -288,7 +288,7 @@ export class ProtectionCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ProtectionCCExclusiveControlReport >( cc, @@ -311,7 +311,7 @@ export class ProtectionCCAPI extends CCAPI { endpoint: this.endpoint.index, exclusiveControlNodeId: nodeId, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getTimeout(): Promise> { @@ -324,7 +324,7 @@ export class ProtectionCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ProtectionCCTimeoutReport >( cc, @@ -347,7 +347,7 @@ export class ProtectionCCAPI extends CCAPI { endpoint: this.endpoint.index, timeout, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index 469069b312cf..d9ea442a15da 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -114,7 +114,7 @@ export class SceneActivationCCAPI extends CCAPI { sceneId, dimmingDuration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index c482f6f8e454..b49ac975dbd3 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -217,7 +217,7 @@ export class SceneActuatorConfigurationCCAPI extends CCAPI { level, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getActive(): Promise< @@ -238,7 +238,7 @@ export class SceneActuatorConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, sceneId: 0, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SceneActuatorConfigurationCCReport >( cc, @@ -278,7 +278,7 @@ export class SceneActuatorConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, sceneId: sceneId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SceneActuatorConfigurationCCReport >( cc, diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 0e651bf7a625..3fe089fbde1c 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -247,7 +247,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { if (!this.endpoint.virtual) { const groupCount = SceneControllerConfigurationCC .getGroupCountCached( - this.applHost, + this.host, this.endpoint, ); @@ -275,7 +275,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { dimmingDuration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getLastActivated(): Promise< @@ -296,7 +296,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, groupId: 0, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SceneControllerConfigurationCCReport >( cc, @@ -344,7 +344,7 @@ export class SceneControllerConfigurationCCAPI extends CCAPI { endpoint: this.endpoint.index, groupId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SceneControllerConfigurationCCReport >( cc, diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 671656a54a68..898220cce405 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -238,7 +238,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { enabled, }); - result = await this.applHost.sendCommand(cc, this.commandOptions); + result = await this.host.sendCommand(cc, this.commandOptions); } else { this.assertSupportsCommand( ScheduleEntryLockCommand, @@ -251,13 +251,13 @@ export class ScheduleEntryLockCCAPI extends CCAPI { enabled, }); - result = await this.applHost.sendCommand(cc, this.commandOptions); + result = await this.host.sendCommand(cc, this.commandOptions); } if (this.isSinglecast() && isUnsupervisedOrSucceeded(result)) { // Remember the new state in the cache setUserCodeScheduleEnabledCached( - this.applHost, + this.host, this.endpoint, userId, enabled, @@ -279,7 +279,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { endpoint: this.endpoint.index, }); - const result = await this.applHost.sendCommand< + const result = await this.host.sendCommand< ScheduleEntryLockCCSupportedReport >( cc, @@ -307,7 +307,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { if (this.isSinglecast()) { const numSlots = ScheduleEntryLockCC.getNumWeekDaySlotsCached( - this.applHost, + this.host, this.endpoint, ); @@ -346,20 +346,20 @@ export class ScheduleEntryLockCCAPI extends CCAPI { }), }); - const result = await this.applHost.sendCommand(cc, this.commandOptions); + const result = await this.host.sendCommand(cc, this.commandOptions); if (this.isSinglecast() && isUnsupervisedOrSucceeded(result)) { // Editing (but not erasing) a schedule will enable scheduling for that user // and switch it to the current scheduling kind if (!!schedule) { setUserCodeScheduleEnabledCached( - this.applHost, + this.host, this.endpoint, slot.userId, true, ); setUserCodeScheduleKindCached( - this.applHost, + this.host, this.endpoint, slot.userId, ScheduleEntryLockScheduleKind.WeekDay, @@ -369,7 +369,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { // And cache the schedule persistSchedule.call( cc, - this.applHost, + this.host, ScheduleEntryLockScheduleKind.WeekDay, slot.userId, slot.slotId, @@ -394,7 +394,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { endpoint: this.endpoint.index, ...slot, }); - const result = await this.applHost.sendCommand< + const result = await this.host.sendCommand< ScheduleEntryLockCCWeekDayScheduleReport >( cc, @@ -424,7 +424,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { if (this.isSinglecast()) { const numSlots = ScheduleEntryLockCC.getNumYearDaySlotsCached( - this.applHost, + this.host, this.endpoint, ); @@ -473,20 +473,20 @@ export class ScheduleEntryLockCCAPI extends CCAPI { }), }); - const result = await this.applHost.sendCommand(cc, this.commandOptions); + const result = await this.host.sendCommand(cc, this.commandOptions); if (this.isSinglecast() && isUnsupervisedOrSucceeded(result)) { // Editing (but not erasing) a schedule will enable scheduling for that user // and switch it to the current scheduling kind if (!!schedule) { setUserCodeScheduleEnabledCached( - this.applHost, + this.host, this.endpoint, slot.userId, true, ); setUserCodeScheduleKindCached( - this.applHost, + this.host, this.endpoint, slot.userId, ScheduleEntryLockScheduleKind.YearDay, @@ -496,7 +496,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { // And cache the schedule persistSchedule.call( cc, - this.applHost, + this.host, ScheduleEntryLockScheduleKind.YearDay, slot.userId, slot.slotId, @@ -521,7 +521,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { endpoint: this.endpoint.index, ...slot, }); - const result = await this.applHost.sendCommand< + const result = await this.host.sendCommand< ScheduleEntryLockCCYearDayScheduleReport >( cc, @@ -557,7 +557,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { if (this.isSinglecast()) { const numSlots = ScheduleEntryLockCC .getNumDailyRepeatingSlotsCached( - this.applHost, + this.host, this.endpoint, ); @@ -583,20 +583,20 @@ export class ScheduleEntryLockCCAPI extends CCAPI { }), }); - const result = await this.applHost.sendCommand(cc, this.commandOptions); + const result = await this.host.sendCommand(cc, this.commandOptions); if (this.isSinglecast() && isUnsupervisedOrSucceeded(result)) { // Editing (but not erasing) a schedule will enable scheduling for that user // and switch it to the current scheduling kind if (!!schedule) { setUserCodeScheduleEnabledCached( - this.applHost, + this.host, this.endpoint, slot.userId, true, ); setUserCodeScheduleKindCached( - this.applHost, + this.host, this.endpoint, slot.userId, ScheduleEntryLockScheduleKind.DailyRepeating, @@ -606,7 +606,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { // And cache the schedule persistSchedule.call( cc, - this.applHost, + this.host, ScheduleEntryLockScheduleKind.DailyRepeating, slot.userId, slot.slotId, @@ -631,7 +631,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { endpoint: this.endpoint.index, ...slot, }); - const result = await this.applHost.sendCommand< + const result = await this.host.sendCommand< ScheduleEntryLockCCDailyRepeatingScheduleReport >( cc, @@ -659,7 +659,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const result = await this.applHost.sendCommand< + const result = await this.host.sendCommand< ScheduleEntryLockCCTimeOffsetReport >( cc, @@ -686,7 +686,7 @@ export class ScheduleEntryLockCCAPI extends CCAPI { ...timezone, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 139f9e27cbdb..2aeb8e7ee040 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -193,8 +193,8 @@ export class Security2CCAPI extends CCAPI { this.assertPhysicalEndpoint(this.endpoint); const securityManager = getSecurityManager( - this.applHost.ownNodeId, - this.applHost, + this.host.ownNodeId, + this.host, this.endpoint.nodeId, ); @@ -211,16 +211,16 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCNonceReport({ nodeId: this.endpoint.nodeId, - ownNodeId: this.applHost.ownNodeId, + ownNodeId: this.host.ownNodeId, endpoint: this.endpoint.index, - securityManagers: this.applHost, + securityManagers: this.host, SOS: true, MOS: false, receiverEI, }); try { - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Seems we need these options or some nodes won't accept the nonce transmitOptions: TransmitOptions.ACK @@ -259,15 +259,15 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCNonceReport({ nodeId: this.endpoint.nodeId, - ownNodeId: this.applHost.ownNodeId, + ownNodeId: this.host.ownNodeId, endpoint: this.endpoint.index, - securityManagers: this.applHost, + securityManagers: this.host, SOS: false, MOS: true, }); try { - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Seems we need these options or some nodes won't accept the nonce transmitOptions: TransmitOptions.ACK @@ -304,9 +304,9 @@ export class Security2CCAPI extends CCAPI { const cc = new Security2CCMessageEncapsulation({ nodeId: this.endpoint.nodeId, - ownNodeId: this.applHost.ownNodeId, + ownNodeId: this.host.ownNodeId, endpoint: this.endpoint.index, - securityManagers: this.applHost, + securityManagers: this.host, extensions: [ new MPANExtension({ groupId, @@ -316,7 +316,7 @@ export class Security2CCAPI extends CCAPI { }); try { - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Seems we need these options or some nodes won't accept the nonce transmitOptions: TransmitOptions.ACK @@ -362,7 +362,7 @@ export class Security2CCAPI extends CCAPI { // encapsulation because it would use a different security class. Therefore the entire possible stack // of encapsulation needs to be done here if (MultiChannelCC.requiresEncapsulation(cc)) { - const multiChannelCCVersion = this.applHost.getSupportedCCVersion( + const multiChannelCCVersion = this.host.getSupportedCCVersion( CommandClasses["Multi Channel"], this.endpoint.nodeId as number, ); @@ -373,12 +373,12 @@ export class Security2CCAPI extends CCAPI { } cc = Security2CC.encapsulate( cc, - this.applHost.ownNodeId, - this.applHost, + this.host.ownNodeId, + this.host, { securityClass }, ); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< Security2CCCommandsSupportedReport >( cc, @@ -403,7 +403,7 @@ export class Security2CCAPI extends CCAPI { endpoint: this.endpoint.index, supportedCCs, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -414,7 +414,7 @@ export class Security2CCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -445,7 +445,7 @@ export class Security2CCAPI extends CCAPI { ...params, echo: false, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** Grants the joining node the given keys */ @@ -460,7 +460,7 @@ export class Security2CCAPI extends CCAPI { ...params, echo: false, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** Confirms the keys that were requested by a node */ @@ -478,7 +478,7 @@ export class Security2CCAPI extends CCAPI { ...params, echo: true, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** Confirms the keys that were granted by the including node */ @@ -496,7 +496,7 @@ export class Security2CCAPI extends CCAPI { ...params, echo: true, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** Notifies the other node that the ongoing key exchange was aborted */ @@ -508,7 +508,7 @@ export class Security2CCAPI extends CCAPI { endpoint: this.endpoint.index, failType, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async sendPublicKey( @@ -526,7 +526,7 @@ export class Security2CCAPI extends CCAPI { includingNode, publicKey, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async requestNetworkKey( @@ -542,7 +542,7 @@ export class Security2CCAPI extends CCAPI { endpoint: this.endpoint.index, requestedKey: securityClass, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async sendNetworkKey( @@ -560,7 +560,7 @@ export class Security2CCAPI extends CCAPI { grantedKey: securityClass, networkKey, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async verifyNetworkKey(): Promise { @@ -573,7 +573,7 @@ export class Security2CCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async confirmKeyVerification(): Promise { @@ -588,7 +588,7 @@ export class Security2CCAPI extends CCAPI { keyVerified: true, keyRequestComplete: false, }); - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Don't wait for an ACK from the node transmitOptions: TransmitOptions.DEFAULT & ~TransmitOptions.ACK, @@ -607,7 +607,7 @@ export class Security2CCAPI extends CCAPI { keyVerified: false, keyRequestComplete: true, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index cc65c79a597d..813e948af1ed 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -116,11 +116,11 @@ export class SecurityCCAPI extends PhysicalCCAPI { : SecurityCCCommandEncapsulation )({ nodeId: this.endpoint.nodeId, - ownNodeId: this.applHost.ownNodeId, - securityManager: this.applHost.securityManager!, + ownNodeId: this.host.ownNodeId, + securityManager: this.host.securityManager!, encapsulated, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } /** @@ -133,7 +133,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, { ...this.commandOptions, @@ -144,13 +144,13 @@ export class SecurityCCAPI extends PhysicalCCAPI { if (!response) return; const nonce = response.nonce; - const secMan = this.applHost.securityManager!; + const secMan = this.host.securityManager!; secMan.setNonce( { issuer: this.endpoint.nodeId, nonceId: secMan.getNonceId(nonce), }, - { nonce, receiver: this.applHost.ownNodeId }, + { nonce, receiver: this.host.ownNodeId }, { free: true }, ); return nonce; @@ -166,18 +166,18 @@ export class SecurityCCAPI extends PhysicalCCAPI { SecurityCommand.NonceReport, ); - if (!this.applHost.securityManager) { + if (!this.host.securityManager) { throw new ZWaveError( `Nonces can only be sent if secure communication is set up!`, ZWaveErrorCodes.Driver_NoSecurity, ); } - const nonce = this.applHost.securityManager.generateNonce( + const nonce = this.host.securityManager.generateNonce( this.endpoint.nodeId, HALF_NONCE_SIZE, ); - const nonceId = this.applHost.securityManager.getNonceId(nonce); + const nonceId = this.host.securityManager.getNonceId(nonce); const cc = new SecurityCCNonceReport({ nodeId: this.endpoint.nodeId, @@ -186,7 +186,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { }); try { - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Seems we need these options or some nodes won't accept the nonce transmitOptions: TransmitOptions.ACK @@ -201,7 +201,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { } catch (e) { if (isTransmissionError(e)) { // The nonce could not be sent, invalidate it - this.applHost.securityManager.deleteNonce(nonceId); + this.host.securityManager.deleteNonce(nonceId); return false; } else { // Pass other errors through @@ -218,7 +218,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); // There is only one scheme, so we hardcode it return [0]; } @@ -237,12 +237,12 @@ export class SecurityCCAPI extends PhysicalCCAPI { cc = new SecurityCCCommandEncapsulation({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, - ownNodeId: this.applHost.ownNodeId, - securityManager: this.applHost.securityManager!, + ownNodeId: this.host.ownNodeId, + securityManager: this.host.securityManager!, encapsulated: cc, }); } - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async inheritSecurityScheme(): Promise { @@ -255,7 +255,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); // There is only one scheme, so we don't return anything here } @@ -273,12 +273,12 @@ export class SecurityCCAPI extends PhysicalCCAPI { const cc = new SecurityCCCommandEncapsulation({ nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, - ownNodeId: this.applHost.ownNodeId, - securityManager: this.applHost.securityManager!, + ownNodeId: this.host.ownNodeId, + securityManager: this.host.securityManager!, encapsulated: keySet, alternativeNetworkKey: Buffer.alloc(16, 0), }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } public async verifyNetworkKey(): Promise { @@ -291,7 +291,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -305,7 +305,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SecurityCCCommandsSupportedReport >( cc, @@ -331,7 +331,7 @@ export class SecurityCCAPI extends PhysicalCCAPI { supportedCCs, controlledCCs, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index f242965f03bb..99d447bbc1ba 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -124,7 +124,7 @@ export class SoundSwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SoundSwitchCCTonesNumberReport >( cc, @@ -146,7 +146,7 @@ export class SoundSwitchCCAPI extends CCAPI { endpoint: this.endpoint.index, toneId, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SoundSwitchCCToneInfoReport >( cc, @@ -171,7 +171,7 @@ export class SoundSwitchCCAPI extends CCAPI { defaultToneId, defaultVolume, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -185,7 +185,7 @@ export class SoundSwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SoundSwitchCCConfigurationReport >( cc, @@ -219,7 +219,7 @@ export class SoundSwitchCCAPI extends CCAPI { toneId, volume, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async stopPlaying(): Promise { @@ -234,7 +234,7 @@ export class SoundSwitchCCAPI extends CCAPI { toneId: 0x00, volume: 0x00, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -248,7 +248,7 @@ export class SoundSwitchCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< SoundSwitchCCTonePlayReport >( cc, diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 42753c9364fa..cddbef952c9e 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -101,7 +101,7 @@ export class SupervisionCCAPI extends PhysicalCCAPI { cc.encapsulationFlags = encapsulationFlags; try { - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // Supervision Reports must be prioritized over normal messages priority: lowPriority diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index b9228cac83c6..9f8bf1a6cbd0 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -180,7 +180,7 @@ export class ThermostatFanModeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatFanModeCCReport >( cc, @@ -207,7 +207,7 @@ export class ThermostatFanModeCCAPI extends CCAPI { mode, off, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getSupportedModes(): Promise< @@ -222,7 +222,7 @@ export class ThermostatFanModeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatFanModeCCSupportedReport >( cc, diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index 583a9cc60316..f485ebdcacf0 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -82,7 +82,7 @@ export class ThermostatFanStateCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatFanStateCCReport >( cc, diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index b7c4b41430ee..cd30871c7d02 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -136,7 +136,7 @@ export class ThermostatModeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatModeCCReport >( cc, @@ -188,7 +188,7 @@ export class ThermostatModeCCAPI extends CCAPI { mode, manufacturerData: manufacturerData as any, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getSupportedModes(): Promise< @@ -203,7 +203,7 @@ export class ThermostatModeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatModeCCSupportedReport >( cc, diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index e857e40229ce..4636d048c0ae 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -88,7 +88,7 @@ export class ThermostatOperatingStateCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatOperatingStateCCReport >( cc, diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 444e56cc30f7..c607ad865288 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -82,7 +82,7 @@ export class ThermostatSetbackCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatSetbackCCReport >( cc, @@ -109,7 +109,7 @@ export class ThermostatSetbackCCAPI extends CCAPI { setbackType, setbackState, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index 179aeb7e5123..baf1e33f61a1 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -225,7 +225,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { endpoint: this.endpoint.index, setpointType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatSetpointCCReport >( cc, @@ -260,7 +260,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { value, scale, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -276,7 +276,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { endpoint: this.endpoint.index, setpointType, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatSetpointCCCapabilitiesReport >( cc, @@ -309,7 +309,7 @@ export class ThermostatSetpointCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< ThermostatSetpointCCSupportedReport >( cc, diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 81a6a3142a67..7586776ca02f 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -67,7 +67,7 @@ export class TimeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -91,7 +91,7 @@ export class TimeCCAPI extends CCAPI { minute, second, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -102,7 +102,7 @@ export class TimeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -126,7 +126,7 @@ export class TimeCCAPI extends CCAPI { month, day, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -143,7 +143,7 @@ export class TimeCCAPI extends CCAPI { dstStart: timezone.startDate, dstEnd: timezone.endDate, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getTimezone(): Promise> { @@ -153,7 +153,7 @@ export class TimeCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< TimeCCTimeOffsetReport >( cc, @@ -183,7 +183,7 @@ export class TimeCCAPI extends CCAPI { dstStart: timezone.startDate, dstEnd: timezone.endDate, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 0bf088c7e139..74b05e4dfa4a 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -181,7 +181,7 @@ export class TimeParametersCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< TimeParametersCCReport >( cc, @@ -205,7 +205,7 @@ export class TimeParametersCCAPI extends CCAPI { )! : this.endpoint; - const useLocalTime = shouldUseLocalTime(this.applHost, endpointToCheck); + const useLocalTime = shouldUseLocalTime(this.host, endpointToCheck); const cc = new TimeParametersCCSet({ nodeId: this.endpoint.nodeId, @@ -213,7 +213,7 @@ export class TimeParametersCCAPI extends CCAPI { dateAndTime, useLocalTime, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 50659e711315..549f8d1153b9 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -452,7 +452,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< UserCodeCCUsersNumberReport >( cc, @@ -487,7 +487,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { userId, reportMore: multiple, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< UserCodeCCExtendedUserCodeReport >( cc, @@ -511,7 +511,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, userId, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -536,7 +536,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { this.assertSupportsCommand(UserCodeCommand, UserCodeCommand.Set); const numUsers = UserCodeCC.getSupportedUsersCached( - this.applHost, + this.host, this.endpoint, ); if (numUsers != undefined && userId > numUsers) { @@ -554,7 +554,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { userCode, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** Configures multiple user codes */ @@ -568,20 +568,20 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); const numUsers = UserCodeCC.getSupportedUsersCached( - this.applHost, + this.host, this.endpoint, ); const supportedStatuses = UserCodeCC.getSupportedUserIDStatusesCached( - this.applHost, + this.host, this.endpoint, ); const supportedASCIIChars = UserCodeCC.getSupportedASCIICharsCached( - this.applHost, + this.host, this.endpoint, ); const supportsMultipleUserCodeSet = UserCodeCC.supportsMultipleUserCodeSetCached( - this.applHost, + this.host, this.endpoint, ) ?? false; @@ -662,7 +662,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, userCodes: codes, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } /** @@ -681,7 +681,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { this.assertSupportsCommand(UserCodeCommand, UserCodeCommand.Set); const numUsers = UserCodeCC.getSupportedUsersCached( - this.applHost, + this.host, this.endpoint, ); if (numUsers != undefined && userId > numUsers) { @@ -697,7 +697,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { userId, userIdStatus: UserIDStatus.Available, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } @@ -712,7 +712,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< UserCodeCCCapabilitiesReport >( cc, @@ -742,7 +742,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< UserCodeCCKeypadModeReport >( cc, @@ -761,7 +761,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); const supportedModes = UserCodeCC.getSupportedKeypadModesCached( - this.applHost, + this.host, this.endpoint, ); @@ -788,7 +788,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { keypadMode, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getAdminCode(): Promise> { @@ -801,7 +801,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< UserCodeCCAdminCodeReport >( cc, @@ -820,7 +820,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { ); const supportedASCIIChars = UserCodeCC.getSupportedASCIICharsCached( - this.applHost, + this.host, this.endpoint, ); if (!supportedASCIIChars) { @@ -834,7 +834,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { if (!adminCode) { const supportsDeactivation = UserCodeCC .supportsAdminCodeDeactivationCached( - this.applHost, + this.host, this.endpoint, ); if (!supportsDeactivation) { @@ -856,7 +856,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { adminCode, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async getUserCodeChecksum(): Promise> { @@ -869,7 +869,7 @@ export class UserCodeCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< UserCodeCCUserCodeChecksumReport >( cc, diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 23261fe79206..04b1ae3764be 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -248,7 +248,7 @@ export class VersionCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -271,7 +271,7 @@ export class VersionCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -288,7 +288,7 @@ export class VersionCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, requestedCC, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< VersionCCCommandClassReport >( cc, @@ -330,7 +330,7 @@ export class VersionCCAPI extends PhysicalCCAPI { requestedCC, ccVersion, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -344,7 +344,7 @@ export class VersionCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< VersionCCCapabilitiesReport >( cc, @@ -367,7 +367,7 @@ export class VersionCCAPI extends PhysicalCCAPI { // At this time, we do not support responding to Z-Wave Software Get supportsZWaveSoftwareGet: false, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -381,7 +381,7 @@ export class VersionCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< VersionCCZWaveSoftwareReport >( cc, diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 4111a6465269..42b6ed353228 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -108,7 +108,7 @@ export class WakeUpCCAPI extends CCAPI { } const result = await this.setInterval( value, - this.applHost.ownNodeId ?? 1, + this.host.ownNodeId ?? 1, ); // Verify the change after a short delay, unless the command was supervised and successful @@ -139,7 +139,7 @@ export class WakeUpCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< WakeUpCCIntervalReport >( cc, @@ -161,7 +161,7 @@ export class WakeUpCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< WakeUpCCIntervalCapabilitiesReport >( cc, @@ -191,7 +191,7 @@ export class WakeUpCCAPI extends CCAPI { wakeUpInterval, controllerNodeId, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } public async sendNoMoreInformation(): Promise { @@ -204,7 +204,7 @@ export class WakeUpCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - await this.applHost.sendCommand(cc, { + await this.host.sendCommand(cc, { ...this.commandOptions, // This command must be sent as part of the wake up queue priority: MessagePriority.WakeUp, diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 9fbd42469a9f..9723f8b7f3fe 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -419,7 +419,7 @@ export class WindowCoveringCCAPI extends CCAPI { ); // and optimistically update the currentValue for (const node of affectedNodes) { - this.applHost + this.host .tryGetValueDB(node.id) ?.setValue(currentValueValueId, value); } @@ -478,7 +478,7 @@ export class WindowCoveringCCAPI extends CCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< WindowCoveringCCSupportedReport >( cc, @@ -500,7 +500,7 @@ export class WindowCoveringCCAPI extends CCAPI { endpoint: this.endpoint.index, parameter, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< WindowCoveringCCReport >( cc, @@ -531,7 +531,7 @@ export class WindowCoveringCCAPI extends CCAPI { duration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs({ strictEnums: true }) @@ -553,7 +553,7 @@ export class WindowCoveringCCAPI extends CCAPI { duration, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } @validateArgs({ strictEnums: true }) @@ -571,7 +571,7 @@ export class WindowCoveringCCAPI extends CCAPI { parameter, }); - return this.applHost.sendCommand(cc, this.commandOptions); + return this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index 1f1d82892fcc..f952423ef562 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -88,7 +88,7 @@ export class ZWavePlusCCAPI extends PhysicalCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand( + const response = await this.host.sendCommand( cc, this.commandOptions, ); @@ -112,7 +112,7 @@ export class ZWavePlusCCAPI extends PhysicalCCAPI { endpoint: this.endpoint.index, ...options, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } } diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index e814b2a5914b..313a6c694fb9 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -116,7 +116,7 @@ export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { nodeId: this.endpoint.nodeId, endpoint: this.endpoint.index, }); - const response = await this.applHost.sendCommand< + const response = await this.host.sendCommand< FibaroVenetianBlindCCReport >( cc, @@ -134,7 +134,7 @@ export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { endpoint: this.endpoint.index, position: value, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } @validateArgs() @@ -144,7 +144,7 @@ export class FibaroCCAPI extends ManufacturerProprietaryCCAPI { endpoint: this.endpoint.index, tilt: value, }); - await this.applHost.sendCommand(cc, this.commandOptions); + await this.host.sendCommand(cc, this.commandOptions); } protected override get [SET_VALUE](): SetValueImplementation { diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index ed325ca58a80..5d6b9104b211 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -216,7 +216,7 @@ export type VirtualCCAPIEndpoint = CCAPIEndpoint & VirtualEndpointId; */ export class CCAPI { public constructor( - protected readonly applHost: CCAPIHost, + protected readonly host: CCAPIHost, protected readonly endpoint: CCAPIEndpoint, ) { this.ccId = getCommandClass(this); @@ -224,7 +224,7 @@ export class CCAPI { public static create( ccId: T, - applHost: CCAPIHost, + host: CCAPIHost, endpoint: CCAPIEndpoint, requireSupport?: boolean, ): CommandClasses extends T ? CCAPI : CCToAPI { @@ -240,7 +240,7 @@ export class CCAPI { ZWaveErrorCodes.CC_NoAPI, ); } - const apiInstance = new APIConstructor(applHost, endpoint); + const apiInstance = new APIConstructor(host, endpoint); // Only require support for physical endpoints by default requireSupport ??= !endpoint.virtual; @@ -289,12 +289,12 @@ export class CCAPI { && !endpoint.virtual && typeof fallback === "function" ) { - const overrides = applHost.getDeviceConfig?.( + const overrides = host.getDeviceConfig?.( endpoint.nodeId, )?.compat?.overrideQueries; if (overrides?.hasOverride(ccId)) { return overrideQueriesWrapper( - applHost, + host, endpoint, ccId, property, @@ -368,17 +368,17 @@ export class CCAPI { // Figure out the delay. If a non-zero duration was given or this is a "fast" transition, // use/add the short delay. Otherwise, default to the long delay. const durationMs = duration?.toMilliseconds() ?? 0; - const timeouts = this.applHost.getCommunicationTimeouts(); + const timeouts = this.host.getCommunicationTimeouts(); const additionalDelay = !!durationMs || transition === "fast" ? timeouts.refreshValueAfterTransition : timeouts.refreshValue; const timeoutMs = durationMs + additionalDelay; if (this.isSinglecast()) { - const node = this.applHost.getNode(this.endpoint.nodeId); + const node = this.host.getNode(this.endpoint.nodeId); if (!node) return false; - return this.applHost.schedulePoll( + return this.host.schedulePoll( node.id, { commandClass: this.ccId, @@ -398,7 +398,7 @@ export class CCAPI { ); let ret = false; for (const node of supportingNodes) { - ret ||= this.applHost.schedulePoll( + ret ||= this.host.schedulePoll( node.id, { commandClass: this.ccId, @@ -421,7 +421,7 @@ export class CCAPI { */ public get version(): number { if (this.isSinglecast()) { - return this.applHost.getSafeCCVersion( + return this.host.getSafeCCVersion( this.ccId, this.endpoint.nodeId, this.endpoint.index, @@ -614,7 +614,7 @@ export class CCAPI { protected tryGetValueDB(): ValueDB | undefined { if (!this.isSinglecast()) return; try { - return this.applHost.getValueDB(this.endpoint.nodeId); + return this.host.getValueDB(this.endpoint.nodeId); } catch { return; } @@ -624,7 +624,7 @@ export class CCAPI { protected getValueDB(): ValueDB { if (this.isSinglecast()) { try { - return this.applHost.getValueDB(this.endpoint.nodeId); + return this.host.getValueDB(this.endpoint.nodeId); } catch { throw new ZWaveError( "The node for this CC does not exist or the driver is not ready yet", @@ -640,7 +640,7 @@ export class CCAPI { } function overrideQueriesWrapper( - applHost: GetValueDB & LogNode, + ctx: GetValueDB & LogNode, endpoint: PhysicalCCAPIEndpoint, ccId: CommandClasses, method: string, @@ -657,7 +657,7 @@ function overrideQueriesWrapper( ); if (!match) return fallback.call(this, ...args); - applHost.logNode(endpoint.nodeId, { + ctx.logNode(endpoint.nodeId, { message: `API call ${method} for ${ getCCName( ccId, @@ -669,7 +669,7 @@ function overrideQueriesWrapper( const ccValues = getCCValues(ccId); if (ccValues) { - const valueDB = applHost.getValueDB(endpoint.nodeId); + const valueDB = ctx.getValueDB(endpoint.nodeId); const prop2value = (prop: string): CCValue | undefined => { // We use a simplistic parser to support dynamic value IDs: @@ -709,7 +709,7 @@ function overrideQueriesWrapper( value, ); } else { - applHost.logNode(endpoint.nodeId, { + ctx.logNode(endpoint.nodeId, { message: `Failed to persist value ${prop} during overridden API call: value does not exist`, level: "error", @@ -717,7 +717,7 @@ function overrideQueriesWrapper( }); } } catch (e) { - applHost.logNode(endpoint.nodeId, { + ctx.logNode(endpoint.nodeId, { message: `Failed to persist value ${prop} during overridden API call: ${ getErrorMessage( @@ -749,7 +749,7 @@ function overrideQueriesWrapper( }, ); } else { - applHost.logNode(endpoint.nodeId, { + ctx.logNode(endpoint.nodeId, { message: `Failed to extend value metadata ${prop} during overridden API call: value does not exist`, level: "error", @@ -757,7 +757,7 @@ function overrideQueriesWrapper( }); } } catch (e) { - applHost.logNode(endpoint.nodeId, { + ctx.logNode(endpoint.nodeId, { message: `Failed to extend value metadata ${prop} during overridden API call: ${ getErrorMessage( @@ -780,10 +780,10 @@ function overrideQueriesWrapper( /** A CC API that is only available for physical endpoints */ export class PhysicalCCAPI extends CCAPI { public constructor( - applHost: CCAPIHost, + host: CCAPIHost, endpoint: CCAPIEndpoint, ) { - super(applHost, endpoint); + super(host, endpoint); this.assertPhysicalEndpoint(endpoint); } @@ -791,7 +791,7 @@ export class PhysicalCCAPI extends CCAPI { } export type APIConstructor = new ( - applHost: CCAPIHost, + host: CCAPIHost, endpoint: CCAPIEndpoint, ) => T; diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index b459ac38c746..be394d8ebfff 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -607,10 +607,10 @@ export class CommandClass implements CCId { * Returns the node this CC is linked to. Throws if the controller is not yet ready. */ public getNode( - applHost: GetNode, + ctx: GetNode, ): T | undefined { if (this.isSinglecast()) { - return applHost.getNode(this.nodeId); + return ctx.getNode(this.nodeId); } } @@ -619,10 +619,10 @@ export class CommandClass implements CCId { * Returns the node this CC is linked to (or undefined if the node doesn't exist) */ public getNodeUnsafe( - applHost: GetNode, + ctx: GetNode, ): T | undefined { try { - return this.getNode(applHost); + return this.getNode(ctx); } catch (e) { // This was expected if (isZWaveError(e) && e.code === ZWaveErrorCodes.Driver_NotReady) { @@ -634,9 +634,9 @@ export class CommandClass implements CCId { } public getEndpoint( - applHost: GetNode>, + ctx: GetNode>, ): T | undefined { - return this.getNode(applHost)?.getEndpoint(this.endpointIndex); + return this.getNode(ctx)?.getEndpoint(this.endpointIndex); } /** Returns the value DB for this CC's node */ From a33ed082bf263fcbd3a59d41d849e55489a0c25c Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 12:35:05 +0200 Subject: [PATCH 45/60] fix: make security managers required in contexts --- packages/cc/src/cc/AssociationGroupInfoCC.ts | 6 +- packages/cc/src/lib/API.ts | 4 +- packages/cc/src/lib/utils.ts | 228 ++++++++++-------- .../core/src/abstractions/ICommandClass.ts | 6 +- packages/serial/src/message/Message.ts | 4 +- packages/testing/src/MockController.ts | 7 +- packages/testing/src/MockNode.ts | 16 +- packages/zwave-js/src/lib/driver/Driver.ts | 24 +- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 3 +- 9 files changed, 163 insertions(+), 135 deletions(-) diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index ca1545633148..f97fd22c7fd3 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -302,20 +302,20 @@ export class AssociationGroupInfoCC extends CommandClass { } public static findGroupsForIssuedCommand( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId & SupportsCC, ccId: CommandClasses, command: number, ): number[] { const ret: number[] = []; const associationGroupCount = this.getAssociationGroupCountCached( - applHost, + ctx, endpoint, ); for (let groupId = 1; groupId <= associationGroupCount; groupId++) { // Scan the issued commands of all groups if there's a match const issuedCommands = this.getIssuedCommandsCached( - applHost, + ctx, endpoint, groupId, ); diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index 5d6b9104b211..0797477b29e1 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -167,9 +167,9 @@ export interface SchedulePollOptions { } // Defines the necessary traits the host passed to a CC API must have -export type CCAPIHost = +export type CCAPIHost = & HostIDs - & GetNode + & GetNode & GetValueDB & GetSupportedCCVersion & GetSafeCCVersion diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index 52cc58fd5785..8c5f0fecb2ce 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -5,11 +5,9 @@ import { type EndpointId, type GetAllEndpoints, type GetEndpoint, - type ListenBehavior, type MaybeNotKnown, NOT_KNOWN, type NodeId, - type QueryNodeStatus, type QuerySecurityClasses, SecurityClass, type SupportsCC, @@ -21,7 +19,12 @@ import { isLongRangeNodeId, isSensorCC, } from "@zwave-js/core/safe"; -import type { ZWaveApplicationHost } from "@zwave-js/host/safe"; +import { + type GetDeviceConfig, + type GetNode, + type GetValueDB, + type HostIDs, +} from "@zwave-js/host"; import { ObjectKeyMap, type ReadonlyObjectKeyMap, @@ -31,8 +34,7 @@ import { distinct } from "alcalzone-shared/arrays"; import { AssociationCC, AssociationCCValues } from "../cc/AssociationCC"; import { AssociationGroupInfoCC } from "../cc/AssociationGroupInfoCC"; import { MultiChannelAssociationCC } from "../cc/MultiChannelAssociationCC"; -import { CCAPI } from "./API"; -import { type CCNode } from "./CommandClass"; +import { CCAPI, type CCAPIHost, type CCAPINode } from "./API"; import { type AssociationAddress, AssociationCheckResult, @@ -42,14 +44,14 @@ import { } from "./_Types"; export function getAssociations( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId & SupportsCC, ): ReadonlyMap { const ret = new Map(); if (endpoint.supportsCC(CommandClasses.Association)) { const destinations = AssociationCC.getAllDestinationsCached( - applHost, + ctx, endpoint, ); for (const [groupId, assocs] of destinations) { @@ -67,7 +69,7 @@ export function getAssociations( // Merge the "normal" destinations with multi channel destinations if (endpoint.supportsCC(CommandClasses["Multi Channel Association"])) { const destinations = MultiChannelAssociationCC.getAllDestinationsCached( - applHost, + ctx, endpoint, ); for (const [groupId, assocs] of destinations) { @@ -95,7 +97,7 @@ export function getAssociations( } export function getAllAssociations( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, node: NodeId & GetAllEndpoints, ): ReadonlyObjectKeyMap< AssociationAddress, @@ -111,26 +113,29 @@ export function getAllAssociations( endpoint: endpoint.index, }; if (endpoint.supportsCC(CommandClasses.Association)) { - ret.set(address, getAssociations(applHost, endpoint)); + ret.set(address, getAssociations(ctx, endpoint)); } } return ret; } export function checkAssociation( - applHost: ZWaveApplicationHost< - & NodeId - & SupportsCC - & GetEndpoint - & QuerySecurityClasses - >, + ctx: + & HostIDs + & GetValueDB + & GetNode< + & NodeId + & SupportsCC + & GetEndpoint + & QuerySecurityClasses + >, endpoint: EndpointId & SupportsCC & ControlsCC, group: number, destination: AssociationAddress, ): AssociationCheckResult { // Check that the target endpoint exists except when adding an association to the controller - const targetNode = applHost.getNodeOrThrow(destination.nodeId); - const targetEndpoint = destination.nodeId === applHost.ownNodeId + const targetNode = ctx.getNodeOrThrow(destination.nodeId); + const targetEndpoint = destination.nodeId === ctx.ownNodeId ? targetNode : targetNode.getEndpointOrThrow(destination.endpoint ?? 0); @@ -151,13 +156,13 @@ export function checkAssociation( return AssociationCheckResult.Forbidden_DestinationIsLongRange; } else if (isLongRangeNodeId(endpoint.nodeId)) { // Except the lifeline back to the host - if (group !== 1 || destination.nodeId !== applHost.ownNodeId) { + if (group !== 1 || destination.nodeId !== ctx.ownNodeId) { return AssociationCheckResult.Forbidden_SourceIsLongRange; } } // The following checks don't apply to Lifeline associations - if (destination.nodeId === applHost.ownNodeId) { + if (destination.nodeId === ctx.ownNodeId) { return AssociationCheckResult.OK; } @@ -173,7 +178,7 @@ export function checkAssociation( // A controlling node MUST NOT associate Node A to a Node B destination // if Node A was not granted Node B’s highest Security Class. - const sourceNode = applHost.getNode(endpoint.nodeId)!; + const sourceNode = ctx.getNode(endpoint.nodeId)!; let securityClassMustMatch: boolean; if (destination.endpoint == undefined) { // "normal" association @@ -222,7 +227,7 @@ export function checkAssociation( } const groupCommandList = AssociationGroupInfoCC.getIssuedCommandsCached( - applHost, + ctx, endpoint, group, ); @@ -250,7 +255,7 @@ export function checkAssociation( } export function getAssociationGroups( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, endpoint: EndpointId & SupportsCC, ): ReadonlyMap { // Check whether we have multi channel support or not @@ -270,13 +275,13 @@ export function getAssociationGroups( mcInstance = MultiChannelAssociationCC; } - const assocGroupCount = - assocInstance.getGroupCountCached(applHost, endpoint) ?? 0; - const mcGroupCount = mcInstance?.getGroupCountCached(applHost, endpoint) + const assocGroupCount = assocInstance.getGroupCountCached(ctx, endpoint) + ?? 0; + const mcGroupCount = mcInstance?.getGroupCountCached(ctx, endpoint) ?? 0; const groupCount = Math.max(assocGroupCount, mcGroupCount); - const deviceConfig = applHost.getDeviceConfig?.(endpoint.nodeId); + const deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId); const ret = new Map(); @@ -293,7 +298,7 @@ export function getAssociationGroups( maxNodes: (multiChannel ? mcInstance! : assocInstance).getMaxNodesCached( - applHost, + ctx, endpoint, group, ) || 1, @@ -304,7 +309,7 @@ export function getAssociationGroups( assocConfig?.label // the ones reported by AGI are sometimes pretty bad ?? agiInstance.getGroupNameCached( - applHost, + ctx, endpoint, group, ) @@ -312,12 +317,12 @@ export function getAssociationGroups( ?? `Unnamed group ${group}`, multiChannel, profile: agiInstance.getGroupProfileCached( - applHost, + ctx, endpoint, group, ), issuedCommands: agiInstance.getIssuedCommandsCached( - applHost, + ctx, endpoint, group, ), @@ -335,7 +340,7 @@ export function getAssociationGroups( maxNodes: (multiChannel ? mcInstance! : assocInstance).getMaxNodesCached( - applHost, + ctx, endpoint, group, ) @@ -351,20 +356,25 @@ export function getAssociationGroups( } export function getAllAssociationGroups( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, node: NodeId & GetAllEndpoints, ): ReadonlyMap> { const ret = new Map>(); for (const endpoint of node.getAllEndpoints()) { if (endpoint.supportsCC(CommandClasses.Association)) { - ret.set(endpoint.index, getAssociationGroups(applHost, endpoint)); + ret.set(endpoint.index, getAssociationGroups(ctx, endpoint)); } } return ret; } export async function addAssociations( - applHost: ZWaveApplicationHost, + ctx: CCAPIHost< + & CCAPINode + & SupportsCC + & GetEndpoint + & QuerySecurityClasses + >, endpoint: EndpointId & SupportsCC & ControlsCC, group: number, destinations: AssociationAddress[], @@ -419,9 +429,9 @@ export async function addAssociations( ); } - const assocGroupCount = - assocInstance?.getGroupCountCached(applHost, endpoint) ?? 0; - const mcGroupCount = mcInstance?.getGroupCountCached(applHost, endpoint) + const assocGroupCount = assocInstance?.getGroupCountCached(ctx, endpoint) + ?? 0; + const mcGroupCount = mcInstance?.getGroupCountCached(ctx, endpoint) ?? 0; const groupCount = Math.max(assocGroupCount, mcGroupCount); if (group > groupCount) { @@ -431,7 +441,7 @@ export async function addAssociations( ); } - const deviceConfig = applHost.getDeviceConfig?.(endpoint.nodeId); + const deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId); const groupIsMultiChannel = !!mcInstance && group <= mcGroupCount @@ -442,7 +452,7 @@ export async function addAssociations( const disallowedAssociations = destinations.map( (a) => ({ ...a, - checkResult: checkAssociation(applHost, endpoint, group, a), + checkResult: checkAssociation(ctx, endpoint, group, a), }), ).filter(({ checkResult }) => checkResult !== AssociationCheckResult.OK @@ -472,7 +482,7 @@ export async function addAssociations( // And add them const api = CCAPI.create( CommandClasses["Multi Channel Association"], - applHost, + ctx, endpoint, ); await api.addDestinations({ @@ -495,7 +505,7 @@ export async function addAssociations( const disallowedAssociations = destinations.map( (a) => ({ ...a, - checkResult: checkAssociation(applHost, endpoint, group, a), + checkResult: checkAssociation(ctx, endpoint, group, a), }), ).filter(({ checkResult }) => checkResult !== AssociationCheckResult.OK @@ -524,7 +534,7 @@ export async function addAssociations( const api = CCAPI.create( CommandClasses.Association, - applHost, + ctx, endpoint, ); await api.addNodeIds(group, ...destinations.map((a) => a.nodeId)); @@ -534,7 +544,7 @@ export async function addAssociations( } export async function removeAssociations( - applHost: ZWaveApplicationHost, + ctx: CCAPIHost, endpoint: EndpointId & SupportsCC & ControlsCC, group: number, destinations: AssociationAddress[], @@ -567,7 +577,7 @@ export async function removeAssociations( // and the node supports multi channel associations if (endpoint.supportsCC(CommandClasses["Multi Channel Association"])) { mcInstance = MultiChannelAssociationCC; - if (group <= mcInstance.getGroupCountCached(applHost, endpoint)) { + if (group <= mcInstance.getGroupCountCached(ctx, endpoint)) { groupExistsAsMultiChannel = true; } } else if (endpointAssociations.length > 0) { @@ -581,7 +591,7 @@ export async function removeAssociations( // or as a multi channel association if (endpoint.supportsCC(CommandClasses.Association)) { assocInstance = AssociationCC; - if (group <= assocInstance.getGroupCountCached(applHost, endpoint)) { + if (group <= assocInstance.getGroupCountCached(ctx, endpoint)) { groupExistsAsNodeAssociation = true; } } @@ -616,7 +626,7 @@ export async function removeAssociations( ) { const api = CCAPI.create( CommandClasses.Association, - applHost, + ctx, endpoint, ); await api.removeNodeIds({ @@ -630,7 +640,7 @@ export async function removeAssociations( if (mcInstance && groupExistsAsMultiChannel) { const api = CCAPI.create( CommandClasses["Multi Channel Association"], - applHost, + ctx, endpoint, ); await api.removeDestinations({ @@ -644,7 +654,7 @@ export async function removeAssociations( } export function getLifelineGroupIds( - applHost: ZWaveApplicationHost, + applHost: GetValueDB & GetDeviceConfig, endpoint: EndpointId & SupportsCC, ): number[] { // For now only support this for the root endpoint - i.e. node @@ -685,21 +695,19 @@ export function getLifelineGroupIds( } export async function configureLifelineAssociations( - applHost: ZWaveApplicationHost< - & NodeId + ctx: CCAPIHost< + & CCAPINode & SupportsCC & ControlsCC - & ListenBehavior - & QueryNodeStatus - & GetAllEndpoints + & GetAllEndpoints >, endpoint: EndpointId & SupportsCC & ControlsCC, ): Promise { // Assign the controller to all lifeline groups - const ownNodeId = applHost.ownNodeId; - const node = applHost.getNodeOrThrow(endpoint.nodeId); - const valueDB = applHost.getValueDB(node.id); - const deviceConfig = applHost.getDeviceConfig?.(node.id); + const ownNodeId = ctx.ownNodeId; + const node = ctx.getNodeOrThrow(endpoint.nodeId); + const valueDB = ctx.getValueDB(node.id); + const deviceConfig = ctx.getDeviceConfig?.(node.id); // We check if a node supports Multi Channel CC before creating Multi Channel Lifeline Associations (#1109) const nodeSupportsMultiChannel = node.supportsCC( @@ -709,7 +717,7 @@ export async function configureLifelineAssociations( let assocInstance: typeof AssociationCC | undefined; const assocAPI = CCAPI.create( CommandClasses.Association, - applHost, + ctx, endpoint, ); if (endpoint.supportsCC(CommandClasses.Association)) { @@ -720,15 +728,15 @@ export async function configureLifelineAssociations( let mcGroupCount = 0; const mcAPI = CCAPI.create( CommandClasses["Multi Channel Association"], - applHost, + ctx, endpoint, ); if (endpoint.supportsCC(CommandClasses["Multi Channel Association"])) { mcInstance = MultiChannelAssociationCC; - mcGroupCount = mcInstance.getGroupCountCached(applHost, endpoint) ?? 0; + mcGroupCount = mcInstance.getGroupCountCached(ctx, endpoint) ?? 0; } - const lifelineGroups = getLifelineGroupIds(applHost, node); + const lifelineGroups = getLifelineGroupIds(ctx, node); if (lifelineGroups.length === 0) { // We can look for the General Lifeline AGI profile as a last resort if ( @@ -736,7 +744,7 @@ export async function configureLifelineAssociations( ) { const agiAPI = CCAPI.create( CommandClasses["Association Group Information"], - applHost, + ctx, endpoint, ); @@ -754,7 +762,7 @@ export async function configureLifelineAssociations( } if (lifelineGroups.length === 0) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: "No information about Lifeline associations, cannot assign ourselves!", @@ -768,7 +776,7 @@ export async function configureLifelineAssociations( return; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Checking/assigning lifeline groups: ${ lifelineGroups.join( @@ -815,7 +823,7 @@ supports multi channel associations: ${!!mcInstance}`, } } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Configuring lifeline group #${group}: group supports multi channel: ${groupSupportsMultiChannelAssociation} @@ -831,10 +839,10 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (groupSupportsMultiChannelAssociation && mcInstance) { if ( // Only consider a group if it doesn't share its associations with the root endpoint - mcInstance.getMaxNodesCached(applHost, endpoint, group) + mcInstance.getMaxNodesCached(ctx, endpoint, group) > 0 && !!mcInstance - .getAllDestinationsCached(applHost, endpoint) + .getAllDestinationsCached(ctx, endpoint) .get(group) ?.some( (addr) => @@ -848,10 +856,10 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (assocInstance) { if ( // Only consider a group if it doesn't share its associations with the root endpoint - assocInstance.getMaxNodesCached(applHost, endpoint, group) + assocInstance.getMaxNodesCached(ctx, endpoint, group) > 0 && !!assocInstance - .getAllDestinationsCached(applHost, endpoint) + .getAllDestinationsCached(ctx, endpoint) .get(group) ?.some((addr) => addr.nodeId === ownNodeId) ) { @@ -868,10 +876,10 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (mcInstance) { if ( // Only consider a group if it doesn't share its associations with the root endpoint - mcInstance.getMaxNodesCached(applHost, endpoint, group) + mcInstance.getMaxNodesCached(ctx, endpoint, group) > 0 && mcInstance - .getAllDestinationsCached(applHost, endpoint) + .getAllDestinationsCached(ctx, endpoint) .get(group) ?.some( (addr) => @@ -888,7 +896,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, // If the node was used with other controller software, there might be // invalid lifeline associations which cause reporting problems const invalidEndpointAssociations: EndpointAddress[] = mcInstance - ?.getAllDestinationsCached(applHost, endpoint) + ?.getAllDestinationsCached(ctx, endpoint) .get(group) ?.filter( (addr): addr is AssociationAddress & EndpointAddress => @@ -903,7 +911,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, && mcAPI.isSupported() && groupSupportsMultiChannelAssociation ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Found invalid lifeline associations in group #${group}, removing them...`, @@ -935,7 +943,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (isAssignedAsNodeAssociation(endpoint)) { // We already have the correct association hasLifeline = true; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} is already assigned with a node association`, @@ -944,11 +952,11 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, } else if ( assocAPI.isSupported() // Some endpoint groups don't support having any destinations because they are shared with the root - && assocInstance!.getMaxNodesCached(applHost, endpoint, group) + && assocInstance!.getMaxNodesCached(ctx, endpoint, group) > 0 ) { // We can use a node association, but first remove any possible endpoint associations - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Association CC...`, @@ -972,14 +980,14 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, hasLifeline = !!groupReport?.nodeIds.includes(ownNodeId); if (hasLifeline) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} was assigned with a node association via Association CC`, direction: "none", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Association CC did not work`, @@ -992,10 +1000,10 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if ( !hasLifeline && mcAPI.isSupported() - && mcInstance!.getMaxNodesCached(applHost, endpoint, group) > 0 + && mcInstance!.getMaxNodesCached(ctx, endpoint, group) > 0 ) { // We can use a node association, but first remove any possible endpoint associations - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Multi Channel Association CC...`, @@ -1017,14 +1025,14 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, hasLifeline = !!groupReport?.nodeIds.includes(ownNodeId); if (hasLifeline) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} was assigned with a node association via Multi Channel Association CC`, direction: "none", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a node association via Multi Channel Association CC did not work`, @@ -1040,7 +1048,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, if (isAssignedAsEndpointAssociation(endpoint)) { // We already have the correct association hasLifeline = true; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} is already assigned with an endpoint association`, @@ -1049,10 +1057,10 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, } else if ( mcAPI.isSupported() && mcAPI.version >= 3 - && mcInstance!.getMaxNodesCached(applHost, endpoint, group) > 0 + && mcInstance!.getMaxNodesCached(ctx, endpoint, group) > 0 ) { // We can use a multi channel association, but first remove any possible node associations - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a multi channel association...`, @@ -1086,14 +1094,14 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, ); if (hasLifeline) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} was assigned with a multi channel association`, direction: "none", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a multi channel association did not work`, @@ -1118,7 +1126,7 @@ must use endpoint association: ${mustUseMultiChannelAssociation}`, const rootMustUseNodeAssociation = !nodeSupportsMultiChannel || rootAssocConfig?.multiChannel === false; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Checking root device for fallback assignment of lifeline group #${group}: @@ -1131,7 +1139,7 @@ must use node association: ${rootMustUseNodeAssociation}`, if (isAssignedAsEndpointAssociation(node)) { // We already have the correct association hasLifeline = true; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Lifeline group #${group} is already assigned with a multi channel association on the root device`, @@ -1140,16 +1148,16 @@ must use node association: ${rootMustUseNodeAssociation}`, } else { const rootMCAPI = CCAPI.create( CommandClasses["Multi Channel Association"], - applHost, + ctx, node, ); const rootAssocAPI = CCAPI.create( CommandClasses.Association, - applHost, + ctx, node, ); if (rootMCAPI.isSupported()) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Assigning lifeline group #${group} with a multi channel association on the root device...`, @@ -1187,7 +1195,7 @@ must use node association: ${rootMustUseNodeAssociation}`, } if (!hasLifeline) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `All attempts to assign lifeline group #${group} failed, skipping...`, @@ -1205,12 +1213,18 @@ must use node association: ${rootMustUseNodeAssociation}`, } export async function assignLifelineIssueingCommand( - applHost: ZWaveApplicationHost, + ctx: CCAPIHost< + & CCAPINode + & SupportsCC + & ControlsCC + & GetEndpoint + & QuerySecurityClasses + >, endpoint: EndpointId, ccId: CommandClasses, ccCommand: number, ): Promise { - const node = applHost.getNodeOrThrow(endpoint.nodeId); + const node = ctx.getNodeOrThrow(endpoint.nodeId); if ( node.supportsCC(CommandClasses["Association Group Information"]) && (node.supportsCC(CommandClasses.Association) @@ -1218,7 +1232,7 @@ export async function assignLifelineIssueingCommand( ) { const groupsIssueingNotifications = AssociationGroupInfoCC .findGroupsForIssuedCommand( - applHost, + ctx, node, ccId, ccCommand, @@ -1226,15 +1240,15 @@ export async function assignLifelineIssueingCommand( if (groupsIssueingNotifications.length > 0) { // We always grab the first group - usually it should be the lifeline const groupId = groupsIssueingNotifications[0]; - const existingAssociations = - getAssociations(applHost, node).get(groupId) ?? []; + const existingAssociations = getAssociations(ctx, node).get(groupId) + ?? []; if ( !existingAssociations.some( - (a) => a.nodeId === applHost.ownNodeId, + (a) => a.nodeId === ctx.ownNodeId, ) ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -1243,8 +1257,8 @@ export async function assignLifelineIssueingCommand( } commands...`, direction: "outbound", }); - await addAssociations(applHost, node, groupId, [ - { nodeId: applHost.ownNodeId }, + await addAssociations(ctx, node, groupId, [ + { nodeId: ctx.ownNodeId }, ]); } } @@ -1252,7 +1266,7 @@ export async function assignLifelineIssueingCommand( } export function doesAnyLifelineSendActuatorOrSensorReports( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, node: NodeId & SupportsCC, ): MaybeNotKnown { // No association support means no unsolicited reports @@ -1269,13 +1283,13 @@ export function doesAnyLifelineSendActuatorOrSensorReports( } // Lifeline group IDs include the ones we added via a config file, so they may not be considered true lifelines - const lifelineGroupIds = getLifelineGroupIds(applHost, node); + const lifelineGroupIds = getLifelineGroupIds(ctx, node); // If any potential lifeline group has the "General: Lifeline" profile, the node MUST send unsolicited reports that way if ( lifelineGroupIds.some( (id) => AssociationGroupInfoCC.getGroupProfileCached( - applHost, + ctx, node, id, ) === AssociationGroupInfoProfile["General: Lifeline"], @@ -1287,7 +1301,7 @@ export function doesAnyLifelineSendActuatorOrSensorReports( // Otherwise check if any of the groups sends any actuator or sensor commands. We'll assume that those are reports for (const groupId of lifelineGroupIds) { const issuedCommands = AssociationGroupInfoCC.getIssuedCommandsCached( - applHost, + ctx, node, groupId, ); diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts index 98b7a08ce799..867c409c1e59 100644 --- a/packages/core/src/abstractions/ICommandClass.ts +++ b/packages/core/src/abstractions/ICommandClass.ts @@ -10,11 +10,11 @@ import { type SecurityManager2 } from "../security/Manager2"; /** Allows accessing the security manager instances */ export interface SecurityManagers { /** Management of Security S0 keys and nonces */ - securityManager?: SecurityManager; + securityManager: SecurityManager | undefined; /** Management of Security S2 keys and nonces (Z-Wave Classic) */ - securityManager2?: SecurityManager2; + securityManager2: SecurityManager2 | undefined; /** Management of Security S2 keys and nonces (Z-Wave Long Range) */ - securityManagerLR?: SecurityManager2; + securityManagerLR: SecurityManager2 | undefined; } /** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index b17658198654..18c5a8d062f4 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -38,7 +38,9 @@ export enum MessageOrigin { Host, } -export interface MessageParsingContext extends GetDeviceConfig, HostIDs { +export interface MessageParsingContext + extends Readonly, HostIDs, GetDeviceConfig +{ /** How many bytes a node ID occupies in serial API commands */ nodeIdType: NodeIDType; diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 092278b31e6c..74ad80fd4b48 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -4,7 +4,6 @@ import { NOT_KNOWN, NodeIDType, SecurityClass, - type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; import { @@ -74,6 +73,9 @@ export class MockController { ownNodeId: this.ownNodeId, // TODO: LR is not supported in mocks nodeIdType: NodeIDType.Short, + securityManager: undefined, + securityManager2: undefined, + securityManagerLR: undefined, hasSecurityClass( nodeId: number, securityClass: SecurityClass, @@ -119,7 +121,6 @@ export class MockController { }; this.parsingContext = { ...this.encodingContext, - getDeviceConfig: () => undefined, }; void this.execute(); @@ -128,8 +129,6 @@ export class MockController { public homeId: number; public ownNodeId: number; - public securityManagers: SecurityManagers = {}; - public encodingContext: MessageEncodingContext; public parsingContext: MessageParsingContext; diff --git a/packages/testing/src/MockNode.ts b/packages/testing/src/MockNode.ts index 3d25d03b3eb2..5b26aecf214a 100644 --- a/packages/testing/src/MockNode.ts +++ b/packages/testing/src/MockNode.ts @@ -146,6 +146,7 @@ export class MockNode { ); } + const self = this; this.encodingContext = { homeId: this.controller.homeId, ownNodeId: this.id, @@ -189,6 +190,15 @@ export class MockNode { }, // Mock nodes don't care about device configuration files getDeviceConfig: () => undefined, + get securityManager() { + return self.securityManagers.securityManager; + }, + get securityManager2() { + return self.securityManagers.securityManager2; + }, + get securityManagerLR() { + return self.securityManagers.securityManagerLR; + }, }; } @@ -196,7 +206,11 @@ export class MockNode { public readonly controller: MockController; public readonly capabilities: MockNodeCapabilities; - public securityManagers: SecurityManagers = {}; + public securityManagers: SecurityManagers = { + securityManager: undefined, + securityManager2: undefined, + securityManagerLR: undefined, + }; public encodingContext: CCEncodingContext; diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index b860f3cefb08..2b777909a584 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -659,6 +659,7 @@ export class Driver extends TypedEventEmitter this._options.storage.deviceConfigPriorityDir, }); + const self = this; this.messageParsingContext = { getHighestSecurityClass: (nodeId) => this.getHighestSecurityClass(nodeId), @@ -667,17 +668,20 @@ export class Driver extends TypedEventEmitter setSecurityClass: (nodeId, securityClass, granted) => this.setSecurityClass(nodeId, securityClass, granted), getDeviceConfig: (nodeId) => this.getDeviceConfig(nodeId), + get securityManager() { + return self.securityManager; + }, + get securityManager2() { + return self.securityManager2; + }, + get securityManagerLR() { + return self.securityManagerLR; + }, }; this.messageEncodingContext = { - getHighestSecurityClass: (nodeId) => - this.getHighestSecurityClass(nodeId), - hasSecurityClass: (nodeId, securityClass) => - this.hasSecurityClass(nodeId, securityClass), - setSecurityClass: (nodeId, securityClass, granted) => - this.setSecurityClass(nodeId, securityClass, granted), + ...this.messageParsingContext, getSupportedCCVersion: (cc, nodeId, endpointIndex) => this.getSupportedCCVersion(cc, nodeId, endpointIndex), - getDeviceConfig: (nodeId) => this.getDeviceConfig(nodeId), }; this.immediateQueue = new TransactionQueue({ @@ -731,9 +735,6 @@ export class Driver extends TypedEventEmitter ownNodeId: this.controller.ownNodeId!, homeId: this.controller.homeId!, nodeIdType: this._controller?.nodeIdType ?? NodeIDType.Short, - securityManager: this.securityManager, - securityManager2: this.securityManager2, - securityManagerLR: this.securityManagerLR, }; } @@ -745,9 +746,6 @@ export class Driver extends TypedEventEmitter ownNodeId: this.controller.ownNodeId!, homeId: this.controller.homeId!, nodeIdType: this._controller?.nodeIdType ?? NodeIDType.Short, - securityManager: this.securityManager, - securityManager2: this.securityManager2, - securityManagerLR: this.securityManagerLR, }; } diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 2dda6357f7fe..f20dd64a0f1e 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -16,6 +16,7 @@ import { SecurityClass, SecurityManager, SecurityManager2, + type SecurityManagers, type UnknownZWaveChipType, ZWaveError, ZWaveErrorCodes, @@ -264,7 +265,7 @@ export class Zniffer extends TypedEventEmitter { private serial: ZnifferSerialPortBase | undefined; private parsingContext: Omit< CCParsingContext, - keyof HostIDs | "sourceNodeId" + keyof HostIDs | "sourceNodeId" | keyof SecurityManagers >; private _destroyPromise: DeferredPromise | undefined; From e933ef2a81c33373ed0684f18650547748867f2e Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 12:46:31 +0200 Subject: [PATCH 46/60] fix: tests --- packages/testing/src/MockController.ts | 21 ++++++++++++++++--- .../test/compliance/decodeLowerS2Keys.test.ts | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index 74ad80fd4b48..7aef7607df75 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -4,6 +4,7 @@ import { NOT_KNOWN, NodeIDType, SecurityClass, + type SecurityManagers, securityClassOrder, } from "@zwave-js/core"; import { @@ -68,14 +69,13 @@ export class MockController { }; const securityClasses = new Map>(); + + const self = this; this.encodingContext = { homeId: this.homeId, ownNodeId: this.ownNodeId, // TODO: LR is not supported in mocks nodeIdType: NodeIDType.Short, - securityManager: undefined, - securityManager2: undefined, - securityManagerLR: undefined, hasSecurityClass( nodeId: number, securityClass: SecurityClass, @@ -118,6 +118,15 @@ export class MockController { return (endpoint ?? node).implementedCCs.get(cc)?.version ?? 0; }, getDeviceConfig: () => undefined, + get securityManager() { + return self.securityManagers.securityManager; + }, + get securityManager2() { + return self.securityManagers.securityManager2; + }, + get securityManagerLR() { + return self.securityManagers.securityManagerLR; + }, }; this.parsingContext = { ...this.encodingContext, @@ -129,6 +138,12 @@ export class MockController { public homeId: number; public ownNodeId: number; + public securityManagers: SecurityManagers = { + securityManager: undefined, + securityManager2: undefined, + securityManagerLR: undefined, + }; + public encodingContext: MessageEncodingContext; public parsingContext: MessageParsingContext; diff --git a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts index 5ea59f9ac67a..a59b1b455a24 100644 --- a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts @@ -48,7 +48,7 @@ integrationTest( driver.options.securityKeys!.S2_Unauthenticated!, ); mockNode.securityManagers.securityManager2 = sm2Node; - // The fixtures define Access Control as granted, but we want the node to send commands using Unauthenticated + // The fixtures define Access Control as granted, but we want the prode to send commands using Unauthenticated mockNode.encodingContext.getHighestSecurityClass = () => SecurityClass.S2_Unauthenticated; From 8d896670504b246b9c826f8b32cd1fb465a7d25e Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 14:04:07 +0200 Subject: [PATCH 47/60] refactor: reorganize traits --- .../core/src/abstractions/ICommandClass.ts | 38 ------- .../core/src/abstractions/IZWaveEndpoint.ts | 69 ------------ packages/core/src/consts/Transmission.ts | 2 +- packages/core/src/index.ts | 7 +- packages/core/src/index_safe.ts | 8 +- packages/core/src/traits/CommandClasses.ts | 56 ++++++++++ packages/core/src/traits/Endpoints.ts | 21 ++++ .../IZWaveNode.ts => traits/Nodes.ts} | 48 ++------ packages/core/src/traits/SecurityManagers.ts | 12 ++ .../maintenance/src/codeshifts/moveImport.ts | 104 ++++++++++++++++++ packages/zwave-js/src/lib/node/Endpoint.ts | 4 +- packages/zwave-js/src/lib/node/Node.ts | 5 +- .../zwave-js/src/lib/node/VirtualEndpoint.ts | 8 +- packages/zwave-js/src/lib/node/VirtualNode.ts | 5 +- .../src/lib/node/mixins/50_Endpoints.ts | 7 +- 15 files changed, 217 insertions(+), 177 deletions(-) delete mode 100644 packages/core/src/abstractions/ICommandClass.ts delete mode 100644 packages/core/src/abstractions/IZWaveEndpoint.ts create mode 100644 packages/core/src/traits/CommandClasses.ts create mode 100644 packages/core/src/traits/Endpoints.ts rename packages/core/src/{abstractions/IZWaveNode.ts => traits/Nodes.ts} (60%) create mode 100644 packages/core/src/traits/SecurityManagers.ts create mode 100644 packages/maintenance/src/codeshifts/moveImport.ts diff --git a/packages/core/src/abstractions/ICommandClass.ts b/packages/core/src/abstractions/ICommandClass.ts deleted file mode 100644 index 867c409c1e59..000000000000 --- a/packages/core/src/abstractions/ICommandClass.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { CommandClasses } from "../capabilities/CommandClasses"; -import type { - MulticastDestination, - NODE_ID_BROADCAST, - NODE_ID_BROADCAST_LR, -} from "../consts"; -import { type SecurityManager } from "../security/Manager"; -import { type SecurityManager2 } from "../security/Manager2"; - -/** Allows accessing the security manager instances */ -export interface SecurityManagers { - /** Management of Security S0 keys and nonces */ - securityManager: SecurityManager | undefined; - /** Management of Security S2 keys and nonces (Z-Wave Classic) */ - securityManager2: SecurityManager2 | undefined; - /** Management of Security S2 keys and nonces (Z-Wave Long Range) */ - securityManagerLR: SecurityManager2 | undefined; -} - -/** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ -export interface CCId { - nodeId: number | MulticastDestination; - endpointIndex?: number; - ccId: CommandClasses; - ccCommand?: number; -} - -export type SinglecastCC = T & { - nodeId: number; -}; - -export type MulticastCC = T & { - nodeId: MulticastDestination; -}; - -export type BroadcastCC = T & { - nodeId: typeof NODE_ID_BROADCAST | typeof NODE_ID_BROADCAST_LR; -}; diff --git a/packages/core/src/abstractions/IZWaveEndpoint.ts b/packages/core/src/abstractions/IZWaveEndpoint.ts deleted file mode 100644 index d54716695d4f..000000000000 --- a/packages/core/src/abstractions/IZWaveEndpoint.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { - CommandClassInfo, - CommandClasses, -} from "../capabilities/CommandClasses"; -import type { MulticastDestination } from "../consts"; -import type { IVirtualNode, NodeId } from "./IZWaveNode"; - -/** Identifies an endpoint */ -export interface EndpointId { - readonly virtual: false; - readonly nodeId: number; - readonly index: number; -} - -/** Allows querying if a CC is supported and in which version */ -export interface SupportsCC { - supportsCC(cc: CommandClasses): boolean; - getCCVersion(cc: CommandClasses): number; -} - -/** Allows querying if a CC is controlled */ -export interface ControlsCC { - controlsCC(cc: CommandClasses): boolean; -} - -/** Allows querying if a CC is supported or controlled only securely */ -export interface IsCCSecure { - isCCSecure(cc: CommandClasses): boolean; -} - -/** Allows querying all implemented CCs and their information */ -export interface GetCCs { - getCCs(): Iterable<[ccId: CommandClasses, info: CommandClassInfo]>; -} - -/** Allows modifying the list of supported/controlled CCs */ -export interface ModifyCCs { - addCC(cc: CommandClasses, info: Partial): void; - removeCC(cc: CommandClasses): void; -} - -/** Allows accessing the parent node of the endpoint, if it exists */ -export interface GetEndpointNode { - tryGetNode(): T | undefined; -} - -/** A basic abstraction of a Z-Wave endpoint providing access to the relevant functionality */ -export interface IZWaveEndpoint - extends - EndpointId, - SupportsCC, - ControlsCC, - IsCCSecure, - ModifyCCs, - GetCCs, - GetEndpointNode -{} - -/** Identifies a virtual endpoint */ -export interface VirtualEndpointId { - readonly virtual: true; - readonly nodeId: number | MulticastDestination; - readonly index: number; -} - -/** A basic abstraction of an endpoint of a virtual node (multicast or broadcast) providing access to the relevant functionality */ -export interface IVirtualEndpoint extends VirtualEndpointId, SupportsCC { - readonly node: IVirtualNode; -} diff --git a/packages/core/src/consts/Transmission.ts b/packages/core/src/consts/Transmission.ts index fe6863fd625c..006dab8e9cab 100644 --- a/packages/core/src/consts/Transmission.ts +++ b/packages/core/src/consts/Transmission.ts @@ -1,8 +1,8 @@ import { num2hex } from "@zwave-js/shared/safe"; import { isObject } from "alcalzone-shared/typeguards"; -import type { CCId } from "../abstractions/ICommandClass"; import type { ProtocolDataRate } from "../capabilities/Protocols"; import { type SecurityClass } from "../security/SecurityClass"; +import type { CCId } from "../traits/CommandClasses"; import { Duration } from "../values/Duration"; /** The priority of messages, sorted from high (0) to low (>0) */ diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 6afee8722c97..4fe19cbc112e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,7 +1,4 @@ /* eslint-disable @typescript-eslint/consistent-type-exports */ -export * from "./abstractions/ICommandClass"; -export * from "./abstractions/IZWaveEndpoint"; -export * from "./abstractions/IZWaveNode"; export * from "./capabilities/CommandClasses"; export * from "./capabilities/ControllerCapabilities"; export * from "./capabilities/LibraryTypes"; @@ -30,6 +27,10 @@ export * from "./security/crypto"; export * from "./security/ctr_drbg"; export * from "./security/shared_safe"; export * from "./test/assertZWaveError"; +export * from "./traits/CommandClasses"; +export * from "./traits/Endpoints"; +export * from "./traits/Nodes"; +export * from "./traits/SecurityManagers"; export * from "./util/_Types"; export * from "./util/config"; export * from "./util/crc"; diff --git a/packages/core/src/index_safe.ts b/packages/core/src/index_safe.ts index c241edf8958f..7c15660e1ae8 100644 --- a/packages/core/src/index_safe.ts +++ b/packages/core/src/index_safe.ts @@ -1,9 +1,6 @@ /* eslint-disable @typescript-eslint/consistent-type-exports */ /* @forbiddenImports external */ -export * from "./abstractions/ICommandClass"; -export * from "./abstractions/IZWaveEndpoint"; -export * from "./abstractions/IZWaveNode"; export * from "./capabilities/CommandClasses"; export * from "./capabilities/ControllerCapabilities"; export * from "./capabilities/LibraryTypes"; @@ -24,6 +21,11 @@ export * from "./registries/Sensors"; export * from "./security/DSK"; export * from "./security/SecurityClass"; export * from "./security/shared_safe"; +export * from "./traits/CommandClasses"; +export * from "./traits/Endpoints"; +export * from "./traits/Endpoints"; +export * from "./traits/Nodes"; +export * from "./traits/SecurityManagers"; export * from "./util/_Types"; export * from "./util/config"; export * from "./util/crc"; diff --git a/packages/core/src/traits/CommandClasses.ts b/packages/core/src/traits/CommandClasses.ts new file mode 100644 index 000000000000..759567a2d7dc --- /dev/null +++ b/packages/core/src/traits/CommandClasses.ts @@ -0,0 +1,56 @@ +import type { + CommandClassInfo, + CommandClasses, +} from "../capabilities/CommandClasses"; +import type { + MulticastDestination, + NODE_ID_BROADCAST, + NODE_ID_BROADCAST_LR, +} from "../consts"; + +/** A basic abstraction of a Z-Wave Command Class providing access to the relevant functionality */ +export interface CCId { + nodeId: number | MulticastDestination; + endpointIndex?: number; + ccId: CommandClasses; + ccCommand?: number; +} + +export type SinglecastCC = T & { + nodeId: number; +}; + +export type MulticastCC = T & { + nodeId: MulticastDestination; +}; + +export type BroadcastCC = T & { + nodeId: typeof NODE_ID_BROADCAST | typeof NODE_ID_BROADCAST_LR; +}; + +/** Allows querying if a CC is supported and in which version */ +export interface SupportsCC { + supportsCC(cc: CommandClasses): boolean; + getCCVersion(cc: CommandClasses): number; +} + +/** Allows querying if a CC is controlled */ +export interface ControlsCC { + controlsCC(cc: CommandClasses): boolean; +} + +/** Allows querying if a CC is supported or controlled only securely */ +export interface IsCCSecure { + isCCSecure(cc: CommandClasses): boolean; +} + +/** Allows querying all implemented CCs and their information */ +export interface GetCCs { + getCCs(): Iterable<[ccId: CommandClasses, info: CommandClassInfo]>; +} + +/** Allows modifying the list of supported/controlled CCs */ +export interface ModifyCCs { + addCC(cc: CommandClasses, info: Partial): void; + removeCC(cc: CommandClasses): void; +} diff --git a/packages/core/src/traits/Endpoints.ts b/packages/core/src/traits/Endpoints.ts new file mode 100644 index 000000000000..0e42d1353b2a --- /dev/null +++ b/packages/core/src/traits/Endpoints.ts @@ -0,0 +1,21 @@ +import { type MulticastDestination } from "../consts/Transmission"; +import { type NodeId } from "./Nodes"; + +/** Identifies an endpoint */ +export interface EndpointId { + readonly virtual: false; + readonly nodeId: number; + readonly index: number; +} + +/** Identifies a virtual endpoint */ +export interface VirtualEndpointId { + readonly virtual: true; + readonly nodeId: number | MulticastDestination; + readonly index: number; +} + +/** Allows accessing the parent node of the endpoint, if it exists */ +export interface GetEndpointNode { + tryGetNode(): T | undefined; +} diff --git a/packages/core/src/abstractions/IZWaveNode.ts b/packages/core/src/traits/Nodes.ts similarity index 60% rename from packages/core/src/abstractions/IZWaveNode.ts rename to packages/core/src/traits/Nodes.ts index 70c393ab18c5..80b6fbbac7c3 100644 --- a/packages/core/src/abstractions/IZWaveNode.ts +++ b/packages/core/src/traits/Nodes.ts @@ -1,16 +1,7 @@ -import type { FLiRS } from "../capabilities/NodeInfo"; -import type { InterviewStage, NodeStatus } from "../consts"; -import type { - QuerySecurityClasses, - SetSecurityClass, -} from "../security/SecurityClass"; +import { type FLiRS } from "../capabilities/NodeInfo"; +import { type NodeStatus } from "../consts/NodeStatus"; import { type MaybeNotKnown } from "../values/Primitive"; -import type { - EndpointId, - IVirtualEndpoint, - IZWaveEndpoint, - VirtualEndpointId, -} from "./IZWaveEndpoint"; +import { type EndpointId, type VirtualEndpointId } from "./Endpoints"; /** Identifies a node */ export interface NodeId extends EndpointId { @@ -19,6 +10,10 @@ export interface NodeId extends EndpointId { // readonly index: number; } +export interface VirtualNodeId extends VirtualEndpointId { + readonly id: number | undefined; +} + /** Allows accessing a specific endpoint */ export interface GetEndpoint { getEndpoint(index: 0): T; @@ -51,35 +46,6 @@ export interface QueryNodeStatus { readonly status: NodeStatus; } -/** A basic abstraction of a Z-Wave node providing access to the relevant functionality */ -export interface IZWaveNode - extends - IZWaveEndpoint, - NodeId, - ListenBehavior, - QueryNodeStatus, - GetEndpoint, - GetAllEndpoints, - QuerySecurityClasses, - SetSecurityClass -{ - interviewStage: InterviewStage; -} - -export interface VirtualNodeId extends VirtualEndpointId { - readonly id: number | undefined; -} - export interface PhysicalNodes { readonly physicalNodes: readonly T[]; } - -/** A basic abstraction of a virtual node (multicast or broadcast) providing access to the relevant functionality */ -export interface IVirtualNode - extends - IVirtualEndpoint, - VirtualNodeId, - GetEndpoint, - PhysicalNodes -{ -} diff --git a/packages/core/src/traits/SecurityManagers.ts b/packages/core/src/traits/SecurityManagers.ts new file mode 100644 index 000000000000..c366240633e5 --- /dev/null +++ b/packages/core/src/traits/SecurityManagers.ts @@ -0,0 +1,12 @@ +import { type SecurityManager } from "../security/Manager"; +import { type SecurityManager2 } from "../security/Manager2"; + +/** Allows accessing the security manager instances */ +export interface SecurityManagers { + /** Management of Security S0 keys and nonces */ + securityManager: SecurityManager | undefined; + /** Management of Security S2 keys and nonces (Z-Wave Classic) */ + securityManager2: SecurityManager2 | undefined; + /** Management of Security S2 keys and nonces (Z-Wave Long Range) */ + securityManagerLR: SecurityManager2 | undefined; +} diff --git a/packages/maintenance/src/codeshifts/moveImport.ts b/packages/maintenance/src/codeshifts/moveImport.ts new file mode 100644 index 000000000000..5bfc1da315ca --- /dev/null +++ b/packages/maintenance/src/codeshifts/moveImport.ts @@ -0,0 +1,104 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { + type API, + type FileInfo, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + { + name, + from, + to, + }: Options, +) => { + if (!name || !to) { + throw new Error("Both 'name' and 'to' are required options"); + } + + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + const imp = root + .find( + j.ImportDeclaration, + from && { + source: { + type: "StringLiteral", + value: from, + }, + }, + ) + .find(j.ImportSpecifier, { + imported: { + name: name, + }, + }); + + if (imp.length !== 1) return file.source; + + const decl = imp.closest(j.ImportDeclaration); + + const isTypeOnly = (imp.at(0).nodes()[0] as any).importKind === "type" + || decl.at(0).nodes()[0].importKind === "type"; + + // Remove the found import from its parent + imp.remove(); + // And remove all empty imports + root + .find( + j.ImportDeclaration, + from && { + source: { + type: "StringLiteral", + value: from, + }, + }, + ).filter((path) => !path.value.specifiers?.length) + .remove(); + + // Try to find an existing import for the new specifier + const targetDecl = root + .find( + j.ImportDeclaration, + { + source: { + type: "StringLiteral", + value: to, + }, + ...(isTypeOnly ? { importKind: "type" } : {}), + }, + ); + + if (targetDecl.length === 1) { + targetDecl.at(0).get().node.specifiers.push( + j.importSpecifier(j.identifier(name)), + ); + } else { + // Create the new import specifier + root.find(j.Program).at(0).nodes()[0].body.unshift( + j.importDeclaration( + [j.importSpecifier(j.identifier(name))], + j.stringLiteral(to), + isTypeOnly ? "type" : "value", + ), + ); + } + + return root.toSource(); +}; + +export default transform; +export const parser = "ts"; diff --git a/packages/zwave-js/src/lib/node/Endpoint.ts b/packages/zwave-js/src/lib/node/Endpoint.ts index c9a052c7eb25..042c0c3910ef 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.ts @@ -15,7 +15,6 @@ import type { EndpointId, GetCCs, GetEndpointNode, - IZWaveEndpoint, IsCCSecure, MaybeNotKnown, ModifyCCs, @@ -54,8 +53,7 @@ export class Endpoint IsCCSecure, ModifyCCs, GetCCs, - GetEndpointNode, - IZWaveEndpoint + GetEndpointNode { public constructor( /** The id of the node this endpoint belongs to */ diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index c57a36aa8609..b23bf7b15cec 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -145,7 +145,6 @@ import { CommandClasses, Duration, EncapsulationFlags, - type IZWaveNode, type MaybeNotKnown, MessagePriority, NOT_KNOWN, @@ -287,9 +286,7 @@ export interface ZWaveNode * of its root endpoint (index 0) */ @Mixin([EventEmitter, NodeStatisticsHost]) -export class ZWaveNode extends ZWaveNodeMixins - implements QuerySecurityClasses, IZWaveNode -{ +export class ZWaveNode extends ZWaveNodeMixins implements QuerySecurityClasses { public constructor( id: number, driver: Driver, diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts index bbb9aacc70ad..b965df0d6571 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts @@ -10,7 +10,6 @@ import { } from "@zwave-js/cc"; import { type CommandClasses, - type IVirtualEndpoint, type MulticastDestination, type SecurityClass, type SupportsCC, @@ -32,11 +31,9 @@ import { VirtualNode } from "./VirtualNode"; * * The endpoint's capabilities are determined by the capabilities of the individual nodes' endpoints. */ -export class VirtualEndpoint - implements VirtualEndpointId, SupportsCC, IVirtualEndpoint -{ +export class VirtualEndpoint implements VirtualEndpointId, SupportsCC { public constructor( - /** The virtual node this endpoint belongs to (or undefined if it set later) */ + /** The virtual node this endpoint belongs to */ node: VirtualNode | undefined, /** The driver instance this endpoint belongs to */ protected readonly driver: Driver, @@ -54,7 +51,6 @@ export class VirtualEndpoint public get node(): VirtualNode { return this._node; } - /** @internal */ protected setNode(node: VirtualNode): void { this._node = node; } diff --git a/packages/zwave-js/src/lib/node/VirtualNode.ts b/packages/zwave-js/src/lib/node/VirtualNode.ts index 65cf9ce86349..0a26c4590ae2 100644 --- a/packages/zwave-js/src/lib/node/VirtualNode.ts +++ b/packages/zwave-js/src/lib/node/VirtualNode.ts @@ -10,7 +10,6 @@ import { supervisionResultToSetValueResult, } from "@zwave-js/cc/safe"; import { - type IVirtualNode, SecurityClass, SupervisionStatus, type TranslatedValueID, @@ -59,7 +58,7 @@ function groupNodesBySecurityClass( return ret; } -export class VirtualNode extends VirtualEndpoint implements IVirtualNode { +export class VirtualNode extends VirtualEndpoint { public constructor( public readonly id: number | undefined, driver: Driver, @@ -179,7 +178,7 @@ export class VirtualNode extends VirtualEndpoint implements IVirtualNode { if (api.isSetValueOptimistic(valueId)) { // If the call did not throw, assume that the call was successful and remember the new value // for each node that was affected by this command - const affectedNodes = endpointInstance.node.physicalNodes + const affectedNodes = this.physicalNodes .filter((node) => node .getEndpoint(endpointInstance.index) diff --git a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts index 0e29fe4716b4..1e0985293f26 100644 --- a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts +++ b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts @@ -3,7 +3,6 @@ import { type CommandClasses, type GetAllEndpoints, type GetEndpoint, - type IZWaveNode, type MaybeNotKnown, ZWaveError, ZWaveErrorCodes, @@ -42,11 +41,7 @@ export interface Endpoints { } export abstract class EndpointsMixin extends NodeValuesMixin - implements - Endpoints, - GetEndpoint, - GetAllEndpoints, - IZWaveNode + implements Endpoints, GetEndpoint, GetAllEndpoints { public get endpointCountIsDynamic(): MaybeNotKnown { return nodeUtils.endpointCountIsDynamic(this.driver, this.id); From d902697fb30d74b965643e8a33d948c6b65835f2 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 14:19:11 +0200 Subject: [PATCH 48/60] refactor: remove GetEndpointNode trait --- ZWaveHost properties.txt | 16 ---------------- packages/core/src/traits/Endpoints.ts | 6 ------ packages/zwave-js/src/lib/node/Endpoint.ts | 10 +--------- 3 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 ZWaveHost properties.txt diff --git a/ZWaveHost properties.txt b/ZWaveHost properties.txt deleted file mode 100644 index 22d51fa65bc9..000000000000 --- a/ZWaveHost properties.txt +++ /dev/null @@ -1,16 +0,0 @@ -ZWaveHost, properties used: - -getDeviceConfig -ownNodeId -homeId -nodeIdType -securityManager -__internalIsMockNode -getSafeCCVersion -getSupportedCCVersion -isCCSecure - -getNextCallbackId -> how did zwave-rs do this? - -for a specific node: getHighestSecurityClass, hasSecurityClass, setSecurityClass --> GetNode<...> ? -for a specific endpoint: isCCSecure ? diff --git a/packages/core/src/traits/Endpoints.ts b/packages/core/src/traits/Endpoints.ts index 0e42d1353b2a..cfc505f789e7 100644 --- a/packages/core/src/traits/Endpoints.ts +++ b/packages/core/src/traits/Endpoints.ts @@ -1,5 +1,4 @@ import { type MulticastDestination } from "../consts/Transmission"; -import { type NodeId } from "./Nodes"; /** Identifies an endpoint */ export interface EndpointId { @@ -14,8 +13,3 @@ export interface VirtualEndpointId { readonly nodeId: number | MulticastDestination; readonly index: number; } - -/** Allows accessing the parent node of the endpoint, if it exists */ -export interface GetEndpointNode { - tryGetNode(): T | undefined; -} diff --git a/packages/zwave-js/src/lib/node/Endpoint.ts b/packages/zwave-js/src/lib/node/Endpoint.ts index 042c0c3910ef..3c11901c3b47 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.ts @@ -14,7 +14,6 @@ import type { ControlsCC, EndpointId, GetCCs, - GetEndpointNode, IsCCSecure, MaybeNotKnown, ModifyCCs, @@ -46,14 +45,7 @@ import type { ZWaveNode } from "./Node"; * Each endpoint may have different capabilities (device class/supported CCs) */ export class Endpoint - implements - EndpointId, - SupportsCC, - ControlsCC, - IsCCSecure, - ModifyCCs, - GetCCs, - GetEndpointNode + implements EndpointId, SupportsCC, ControlsCC, IsCCSecure, ModifyCCs, GetCCs { public constructor( /** The id of the node this endpoint belongs to */ From 838723c9b6ec80308e9b45bf27ce522da8594c5f Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 14:25:14 +0200 Subject: [PATCH 49/60] refactor: rename getNodeUnsafe to tryGetNode --- docs/api/endpoint.md | 4 +-- packages/cc/src/lib/API.ts | 2 +- packages/cc/src/lib/CommandClass.ts | 2 +- packages/serial/src/message/Message.test.ts | 36 ++++++++++--------- packages/serial/src/message/Message.ts | 8 ++--- packages/zwave-js/src/lib/driver/Driver.ts | 28 +++++++-------- .../src/lib/driver/MessageGenerators.ts | 2 +- .../zwave-js/src/lib/driver/Transaction.ts | 8 ++--- packages/zwave-js/src/lib/log/Driver.ts | 2 +- .../src/lib/node/MultiCCAPIWrapper.ts | 6 ++-- packages/zwave-js/src/lib/test/messages.ts | 2 +- packages/zwave-js/src/lib/test/mocks.ts | 2 +- 12 files changed, 53 insertions(+), 49 deletions(-) diff --git a/docs/api/endpoint.md b/docs/api/endpoint.md index 27876ce8d137..100479635005 100644 --- a/docs/api/endpoint.md +++ b/docs/api/endpoint.md @@ -56,10 +56,10 @@ createCCInstanceUnsafe(cc: CommandClasses): T | undefined Like [`createCCInstance`](#createCCInstance) but returns `undefined` instead of throwing when a CC is not supported. -### `getNodeUnsafe` +### `tryGetNode` ```ts -getNodeUnsafe(): ZWaveNode | undefined +tryGetNode(): ZWaveNode | undefined ``` Returns the node this endpoint belongs to (or undefined if the node doesn't exist). diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index 0797477b29e1..29bde3de01aa 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -888,7 +888,7 @@ export type APIMethodsOf = Omit< OnlyMethods>, | "ccId" | "getNode" - | "getNodeUnsafe" + | "tryGetNode" | "isSetValueOptimistic" | "isSupported" | "pollValue" diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index be394d8ebfff..69c049b994e4 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -618,7 +618,7 @@ export class CommandClass implements CCId { * @internal * Returns the node this CC is linked to (or undefined if the node doesn't exist) */ - public getNodeUnsafe( + public tryGetNode( ctx: GetNode, ): T | undefined { try { diff --git a/packages/serial/src/message/Message.test.ts b/packages/serial/src/message/Message.test.ts index 664245187419..a052fcc78983 100644 --- a/packages/serial/src/message/Message.test.ts +++ b/packages/serial/src/message/Message.test.ts @@ -40,8 +40,8 @@ test("should deserialize and serialize correctly", (t) => { ]), ]; for (const original of okayMessages) { - const parsed = new Message({ data: original }); - t.deepEqual(parsed.serialize(), original); + const parsed = new Message({ data: original, ctx: {} as any }); + t.deepEqual(parsed.serialize({} as any), original); } }); @@ -53,7 +53,7 @@ test("should serialize correctly when the payload is null", (t) => { type: MessageType.Request, functionType: 0xff as any, }); - t.deepEqual(message.serialize(), expected); + t.deepEqual(message.serialize({} as any), expected); }); test("should throw the correct error when parsing a faulty message", (t) => { @@ -92,10 +92,14 @@ test("should throw the correct error when parsing a faulty message", (t) => { ], ]; for (const [message, msg, code] of brokenMessages) { - assertZWaveError(t, () => new Message({ data: message }), { - messageMatches: msg, - errorCode: code, - }); + assertZWaveError( + t, + () => new Message({ data: message, ctx: {} as any }), + { + messageMatches: msg, + errorCode: code, + }, + ); } }); @@ -321,7 +325,7 @@ test(`the constructor should throw when no message type is specified`, (t) => { @messageTypes(undefined as any, 0xff as any) class FakeMessageWithoutMessageType extends Message {} - assertZWaveError(t, () => new FakeMessageWithoutMessageType(host), { + assertZWaveError(t, () => new FakeMessageWithoutMessageType(), { errorCode: ZWaveErrorCodes.Argument_Invalid, messageMatches: /message type/i, }); @@ -341,31 +345,31 @@ test(`the constructor should throw when no function type is specified`, (t) => { @messageTypes(MessageType.Request, undefined as any) class FakeMessageWithoutFunctionType extends Message {} - assertZWaveError(t, () => new FakeMessageWithoutFunctionType(host), { + assertZWaveError(t, () => new FakeMessageWithoutFunctionType(), { errorCode: ZWaveErrorCodes.Argument_Invalid, messageMatches: /function type/i, }); }); -test("getNodeUnsafe() returns undefined when the controller is not initialized yet", (t) => { +test("tryGetNode() returns undefined when the controller is not initialized yet", (t) => { const host = createTestingHost(); const msg = new Message({ type: MessageType.Request, functionType: 0xff as any, }); - t.is(msg.getNodeUnsafe(host), undefined); + t.is(msg.tryGetNode(host), undefined); }); -test("getNodeUnsafe() returns undefined when the message is no node query", (t) => { +test("tryGetNode() returns undefined when the message is no node query", (t) => { const host = createTestingHost(); const msg = new Message({ type: MessageType.Request, functionType: 0xff as any, }); - t.is(msg.getNodeUnsafe(host), undefined); + t.is(msg.tryGetNode(host), undefined); }); -test("getNodeUnsafe() returns the associated node otherwise", (t) => { +test("tryGetNode() returns the associated node otherwise", (t) => { const host = createTestingHost(); host.setNode(1, {} as any); @@ -376,9 +380,9 @@ test("getNodeUnsafe() returns the associated node otherwise", (t) => { // This node exists (msg as any as INodeQuery).nodeId = 1; - t.is(msg.getNodeUnsafe(host), host.getNode(1)); + t.is(msg.tryGetNode(host), host.getNode(1)); // This one does (msg as any as INodeQuery).nodeId = 2; - t.is(msg.getNodeUnsafe(host), undefined); + t.is(msg.tryGetNode(host), undefined); }); diff --git a/packages/serial/src/message/Message.ts b/packages/serial/src/message/Message.ts index 18c5a8d062f4..4bf25cbafcd7 100644 --- a/packages/serial/src/message/Message.ts +++ b/packages/serial/src/message/Message.ts @@ -14,9 +14,9 @@ import { } from "@zwave-js/core"; import type { GetDeviceConfig, + GetNode, GetSupportedCCVersion, HostIDs, - ZWaveApplicationHost, } from "@zwave-js/host"; import type { JSONObject, TypedClassDecorator } from "@zwave-js/shared/safe"; import { num2hex, staticExtends } from "@zwave-js/shared/safe"; @@ -453,11 +453,11 @@ export class Message { /** * Returns the node this message is linked to or undefined */ - public getNodeUnsafe( - applHost: ZWaveApplicationHost, + public tryGetNode( + ctx: GetNode, ): T | undefined { const nodeId = this.getNodeId(); - if (nodeId != undefined) return applHost.getNode(nodeId); + if (nodeId != undefined) return ctx.getNode(nodeId); } private _transmissionTimestamp: number | undefined; diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 2b777909a584..2bab99cfc38c 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -1007,7 +1007,7 @@ export class Driver extends TypedEventEmitter return [...this.controller.nodes.values()]; } - public getNodeUnsafe(msg: Message): ZWaveNode | undefined { + public tryGetNode(msg: Message): ZWaveNode | undefined { const nodeId = msg.getNodeId(); if (nodeId != undefined) return this.controller.nodes.get(nodeId); } @@ -3501,7 +3501,7 @@ export class Driver extends TypedEventEmitter }, this._requestContext); if (isCommandClassContainer(msg)) { // Whether successful or not, a message from a node should update last seen - const node = this.getNodeUnsafe(msg); + const node = this.tryGetNode(msg); if (node) node.lastSeen = new Date(); // Ensure there are no errors @@ -3510,7 +3510,7 @@ export class Driver extends TypedEventEmitter // And update statistics if (!!this._controller) { if (isCommandClassContainer(msg)) { - this.getNodeUnsafe(msg)?.incrementStatistics("commandsRX"); + this.tryGetNode(msg)?.incrementStatistics("commandsRX"); } else { this._controller.incrementStatistics("messagesRX"); } @@ -3526,7 +3526,7 @@ export class Driver extends TypedEventEmitter if (response) await this.writeHeader(response); if (!!this._controller) { if (isCommandClassContainer(msg)) { - this.getNodeUnsafe(msg)?.incrementStatistics( + this.tryGetNode(msg)?.incrementStatistics( "commandsDroppedRX", ); @@ -3538,7 +3538,7 @@ export class Driver extends TypedEventEmitter && msg.command instanceof InvalidCC ) { // If it was, we need to notify the sender that we couldn't decode the command - const node = this.getNodeUnsafe(msg); + const node = this.tryGetNode(msg); if (node) { const endpoint = node.getEndpoint( msg.command.endpointIndex, @@ -3606,7 +3606,7 @@ export class Driver extends TypedEventEmitter msg.command instanceof SecurityCCCommandEncapsulationNonceGet ) { - void this.getNodeUnsafe(msg)?.handleSecurityNonceGet(); + void this.tryGetNode(msg)?.handleSecurityNonceGet(); } // Transport Service commands must be handled before assembling partial CCs @@ -3822,7 +3822,7 @@ export class Driver extends TypedEventEmitter if (!encapS2) return false; // With the MGRP extension present - const node = this.getNodeUnsafe(msg); + const node = this.tryGetNode(msg); if (!node) return false; const groupId = encapS2.getMulticastGroupId(); if (groupId == undefined) return false; @@ -4007,7 +4007,7 @@ export class Driver extends TypedEventEmitter }, error: ZWaveError, ): boolean { - const node = this.getNodeUnsafe(transaction.message); + const node = this.tryGetNode(transaction.message); if (!node) return false; // This should never happen, but whatever const messagePart1 = isSendData(transaction.message) @@ -4172,7 +4172,7 @@ export class Driver extends TypedEventEmitter || this._recoveryPhase === ControllerRecoveryPhase.CallbackTimeoutAfterReset ) { - const node = this.getNodeUnsafe(transaction.message); + const node = this.tryGetNode(transaction.message); if (!node) return false; // This should never happen, but whatever // The controller is still timing out transmitting after a soft reset, don't try again. @@ -4980,7 +4980,7 @@ ${handlers.length} left`, let handlers: RequestHandlerEntry[] | undefined; if (isNodeQuery(msg) || isCommandClassContainer(msg)) { - const node = this.getNodeUnsafe(msg); + const node = this.tryGetNode(msg); if (node) { // We have received an unsolicited message from a dead node, bring it back to life if (node.status === NodeStatus.Dead) { @@ -5427,7 +5427,7 @@ ${handlers.length} left`, result: Message | undefined, ): void { // Update statistics - const node = this.getNodeUnsafe(msg); + const node = this.tryGetNode(msg); let success = true; if (isSendData(msg) || isNodeQuery(msg)) { // This shouldn't happen, but just in case @@ -5528,7 +5528,7 @@ ${handlers.length} left`, } const message = transaction.message; - const targetNode = message.getNodeUnsafe(this); + const targetNode = message.tryGetNode(this); // Messages to the controller may always be sent... if (!targetNode) return true; @@ -5949,7 +5949,7 @@ ${handlers.length} left`, let node: ZWaveNode | undefined; if (isNodeQuery(msg) || isCommandClassContainer(msg)) { - node = this.getNodeUnsafe(msg); + node = this.tryGetNode(msg); } if (options.priority == undefined) { @@ -7073,7 +7073,7 @@ ${handlers.length} left`, /** Determines time in milliseconds to wait for a report from a node */ public getReportTimeout(msg: Message): number { - const node = this.getNodeUnsafe(msg); + const node = this.tryGetNode(msg); return ( // If there's a message-specific timeout, use that diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index 15b8ee124bde..aafa8eceab71 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -230,7 +230,7 @@ export const maybeTransportServiceGenerator: MessageGeneratorImplementation = ); } - const node = msg.getNodeUnsafe(driver); + const node = msg.tryGetNode(driver); const mayUseTransportService = node?.supportsCC(CommandClasses["Transport Service"]) && node.getCCVersion(CommandClasses["Transport Service"]) >= 2; diff --git a/packages/zwave-js/src/lib/driver/Transaction.ts b/packages/zwave-js/src/lib/driver/Transaction.ts index 46c7cd8bcceb..a2064e7ecc2d 100644 --- a/packages/zwave-js/src/lib/driver/Transaction.ts +++ b/packages/zwave-js/src/lib/driver/Transaction.ts @@ -194,8 +194,8 @@ export class Transaction implements Comparable { _this: Transaction, _other: Transaction, ): CompareResult | undefined => { - const thisNode = _this.message.getNodeUnsafe(this.driver); - const otherNode = _other.message.getNodeUnsafe(this.driver); + const thisNode = _this.message.tryGetNode(this.driver); + const otherNode = _other.message.tryGetNode(this.driver); // We don't require existence of the node object // If any transaction is not for a node, it targets the controller @@ -222,8 +222,8 @@ export class Transaction implements Comparable { _this: Transaction, _other: Transaction, ): CompareResult | undefined => { - const thisNode = _this.message.getNodeUnsafe(this.driver); - const otherNode = _other.message.getNodeUnsafe(this.driver); + const thisNode = _this.message.tryGetNode(this.driver); + const otherNode = _other.message.tryGetNode(this.driver); if (thisNode && otherNode) { // Both nodes exist const thisListening = thisNode.isListening diff --git a/packages/zwave-js/src/lib/log/Driver.ts b/packages/zwave-js/src/lib/log/Driver.ts index 2be109c6dfe6..332e381f60ad 100644 --- a/packages/zwave-js/src/lib/log/Driver.ts +++ b/packages/zwave-js/src/lib/log/Driver.ts @@ -197,7 +197,7 @@ export class DriverLogger extends ZWaveLoggerBase { if (queue.length > 0) { for (const trns of queue.transactions) { // TODO: This formatting should be shared with the other logging methods - const node = trns.message.getNodeUnsafe(this.driver); + const node = trns.message.tryGetNode(this.driver); const prefix = trns.message.type === MessageType.Request ? "[REQ]" : "[RES]"; diff --git a/packages/zwave-js/src/lib/node/MultiCCAPIWrapper.ts b/packages/zwave-js/src/lib/node/MultiCCAPIWrapper.ts index 9bdeda6d99a1..c6993ccc2bc5 100644 --- a/packages/zwave-js/src/lib/node/MultiCCAPIWrapper.ts +++ b/packages/zwave-js/src/lib/node/MultiCCAPIWrapper.ts @@ -57,7 +57,7 @@ export function createMultiCCAPIWrapper(apiInstances: T[]): T { // This wrapper is by definition for multiple nodes, so we cannot return one const getNode = () => undefined; - const getNodeUnsafe = () => undefined; + const tryGetNode = () => undefined; return new Proxy({} as T, { get(target, prop) { @@ -81,8 +81,8 @@ export function createMultiCCAPIWrapper(apiInstances: T[]): T { return isSupported; case "getNode": return getNode; - case "getNodeUnsafe": - return getNodeUnsafe; + case "tryGetNode": + return tryGetNode; case "isSetValueOptimistic": return isSetValueOptimistic; case "supportsCommand": diff --git a/packages/zwave-js/src/lib/test/messages.ts b/packages/zwave-js/src/lib/test/messages.ts index 48ed82c9b7e7..d37819af6ce2 100644 --- a/packages/zwave-js/src/lib/test/messages.ts +++ b/packages/zwave-js/src/lib/test/messages.ts @@ -3,7 +3,7 @@ import { MessageType } from "@zwave-js/serial"; const defaultImplementations = { serialize: () => Buffer.from([1, 2, 3]), - getNodeUnsafe: () => undefined, + tryGetNode: () => undefined, getNodeId: () => undefined, toLogEntry: () => ({ tags: [] }), needsCallbackId: () => true, diff --git a/packages/zwave-js/src/lib/test/mocks.ts b/packages/zwave-js/src/lib/test/mocks.ts index 9e15f4923e3c..e43c06b0e68a 100644 --- a/packages/zwave-js/src/lib/test/mocks.ts +++ b/packages/zwave-js/src/lib/test/mocks.ts @@ -389,7 +389,7 @@ export function createTestEndpoint( > { throw new Error("Function not implemented."); }, - getNodeUnsafe: function(): IZWaveNode | undefined { + tryGetNode: function(): IZWaveNode | undefined { return host.nodes.get(options.nodeId); }, }; From 89d795ed86c52e7d46345cea4e385d988594a907 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 14:53:36 +0200 Subject: [PATCH 50/60] refactor: translateProperty[Key] takes context --- packages/cc/src/cc/ColorSwitchCC.ts | 4 +- packages/cc/src/cc/ConfigurationCC.ts | 10 +- .../cc/src/cc/HumidityControlSetpointCC.ts | 4 +- packages/cc/src/cc/IndicatorCC.ts | 8 +- packages/cc/src/cc/IrrigationCC.ts | 4 +- packages/cc/src/cc/MeterCC.ts | 4 +- packages/cc/src/cc/MultilevelSensorCC.ts | 4 +- packages/cc/src/cc/ThermostatSetpointCC.ts | 4 +- packages/cc/src/cc/index.ts | 1 + packages/cc/src/lib/CommandClass.ts | 4 +- packages/host/src/mocks.ts | 15 ++- .../codeshifts/refactorTranslateProperty.ts | 111 ++++++++++++++++++ packages/zwave-js/src/lib/node/utils.ts | 94 ++++++++------- packages/zwave-js/src/lib/test/mocks.ts | 86 ++++++-------- 14 files changed, 236 insertions(+), 117 deletions(-) create mode 100644 packages/maintenance/src/codeshifts/refactorTranslateProperty.ts diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 66930f37d01e..4adf6d0aa99c 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -663,7 +663,7 @@ export class ColorSwitchCC extends CommandClass { } public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey: string | number, ): string | undefined { @@ -674,7 +674,7 @@ export class ColorSwitchCC extends CommandClass { const translated = ColorComponent[propertyKey]; if (translated) return translated; } - return super.translatePropertyKey(applHost, property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index e4cf1299437d..26135e1b9392 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -1547,7 +1547,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; } public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey?: string | number, ): string | undefined { @@ -1559,11 +1559,11 @@ alters capabilities: ${!!properties.altersCapabilities}`; // so no name for the property key is required return undefined; } - return super.translateProperty(applHost, property, propertyKey); + return super.translateProperty(ctx, property, propertyKey); } public translateProperty( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey?: string | number, ): string { @@ -1573,7 +1573,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; && (propertyKey == undefined || typeof propertyKey === "number") ) { const paramInfo = this.getParamInformation( - applHost, + ctx, property, propertyKey, ); @@ -1585,7 +1585,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; } return ret; } - return super.translateProperty(applHost, property, propertyKey); + return super.translateProperty(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index ee3f33d60ace..f4c1013f5ed7 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -334,7 +334,7 @@ export class HumidityControlSetpointCC extends CommandClass { declare ccCommand: HumidityControlSetpointCommand; public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey: string | number, ): string | undefined { @@ -344,7 +344,7 @@ export class HumidityControlSetpointCC extends CommandClass { propertyKey as any, ); } else { - return super.translatePropertyKey(applHost, property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index de6230a5a90e..eb31b18d8ce5 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -820,7 +820,7 @@ export class IndicatorCC extends CommandClass { } public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey: string | number, ): string | undefined { @@ -835,11 +835,11 @@ export class IndicatorCC extends CommandClass { const prop = getIndicatorProperty(propertyKey); if (prop) return prop.label; } - return super.translatePropertyKey(applHost, property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } public translateProperty( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey?: string | number, ): string { @@ -847,7 +847,7 @@ export class IndicatorCC extends CommandClass { // The indicator corresponds to our property if (property in Indicator) return Indicator[property]; } - return super.translateProperty(applHost, property, propertyKey); + return super.translateProperty(ctx, property, propertyKey); } protected supportsV2Indicators(applHost: ZWaveApplicationHost): boolean { diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index fd627f92fec4..0ec68f43c74b 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1333,7 +1333,7 @@ moisture sensor polarity: ${ } public translateProperty( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey?: string | number, ): string { @@ -1342,7 +1342,7 @@ moisture sensor polarity: ${ } else if (typeof property === "number") { return `Valve ${padStart(property.toString(), 3, "0")}`; } - return super.translateProperty(applHost, property, propertyKey); + return super.translateProperty(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index b346f5b9d6fc..6efccc28a836 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -837,7 +837,7 @@ supports reset: ${suppResp.supportsReset}`; } public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey: string | number, ): string | undefined { @@ -861,7 +861,7 @@ supports reset: ${suppResp.supportsReset}`; } else if (property === "reset" && typeof propertyKey === "number") { return getMeterName(propertyKey); } - return super.translatePropertyKey(applHost, property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 5a78e664737f..30852c170c1f 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -607,7 +607,7 @@ value: ${mlsResponse.value}${ } public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey: string | number, ): string | undefined { @@ -616,7 +616,7 @@ value: ${mlsResponse.value}${ const sensor = getSensor(propertyKey); if (sensor) return sensor.label; } - return super.translatePropertyKey(applHost, property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index baf1e33f61a1..d509a4641dfd 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -326,7 +326,7 @@ export class ThermostatSetpointCC extends CommandClass { declare ccCommand: ThermostatSetpointCommand; public translatePropertyKey( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, property: string | number, propertyKey: string | number, ): string | undefined { @@ -336,7 +336,7 @@ export class ThermostatSetpointCC extends CommandClass { propertyKey as any, ); } else { - return super.translatePropertyKey(applHost, property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/index.ts b/packages/cc/src/cc/index.ts index 1499572ca55b..11af0556c837 100644 --- a/packages/cc/src/cc/index.ts +++ b/packages/cc/src/cc/index.ts @@ -628,6 +628,7 @@ export type { Security2CCMessageEncapsulationOptions, Security2CCNetworkKeyGetOptions, Security2CCNetworkKeyReportOptions, + Security2CCNonceGetOptions, Security2CCNonceReportOptions, Security2CCPublicKeyReportOptions, Security2CCTransferEndOptions, diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 69c049b994e4..8003be18d4c9 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -1094,7 +1094,7 @@ export class CommandClass implements CCId { * @param _propertyKey The (optional) property key the translated name may depend on */ public translateProperty( - _applHost: ZWaveApplicationHost, + _ctx: GetValueDB, property: string | number, _propertyKey?: string | number, ): string { @@ -1108,7 +1108,7 @@ export class CommandClass implements CCId { * @param propertyKey The property key for which the speaking name should be retrieved */ public translatePropertyKey( - _applHost: ZWaveApplicationHost, + _ctx: GetValueDB, _property: string | number, propertyKey: string | number, ): string | undefined { diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index c646d51bfe0a..6adff03f356c 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -1,11 +1,14 @@ /* eslint-disable @typescript-eslint/require-await */ import { + type ControlsCC, type EndpointId, type GetEndpoint, type IsCCSecure, + type ListenBehavior, type NodeId, type QuerySecurityClasses, type SetSecurityClass, + type SupportsCC, ValueDB, ZWaveError, ZWaveErrorCodes, @@ -18,12 +21,22 @@ export interface CreateTestingHostOptions extends HostIDs { getSupportedCCVersion?: ZWaveApplicationHost["getSupportedCCVersion"]; } +export type BaseTestEndpoint = + & EndpointId + & SupportsCC + & ControlsCC + & IsCCSecure; + export type BaseTestNode = + & BaseTestEndpoint & NodeId + & ListenBehavior & QuerySecurityClasses & SetSecurityClass + & SupportsCC + & ControlsCC & IsCCSecure - & GetEndpoint; + & GetEndpoint; export type TestingHost< TNode extends BaseTestNode, diff --git a/packages/maintenance/src/codeshifts/refactorTranslateProperty.ts b/packages/maintenance/src/codeshifts/refactorTranslateProperty.ts new file mode 100644 index 000000000000..3d5ba16f5015 --- /dev/null +++ b/packages/maintenance/src/codeshifts/refactorTranslateProperty.ts @@ -0,0 +1,111 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { + type API, + type FileInfo, + type Identifier, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + {}: Options, +) => { + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + const ccImplementations = root.find(j.ClassDeclaration, { + superClass: { + name: "CommandClass", + }, + }); + + const methods = ccImplementations.find(j.ClassMethod, { + kind: "method", + }).filter(({ node }) => { + return node.key.type === "Identifier" + && (node.key.name === "translateProperty" + || node.key.name === "translatePropertyKey") + && node.params.length >= 1 + && node.params[0].type === "Identifier" + && node.params[0].name === "applHost" + && node.params[0].typeAnnotation?.type === "TSTypeAnnotation" + && node.params[0].typeAnnotation.typeAnnotation.type + === "TSTypeReference" + && node.params[0].typeAnnotation.typeAnnotation.typeName.type + === "Identifier" + && node.params[0].typeAnnotation.typeAnnotation.typeName.name + === "ZWaveApplicationHost"; + }); + + if (!methods.length) return file.source; + + methods.replaceWith(({ node }) => { + const ident = node.params[0] as Identifier; + ident.name = "ctx"; + // @ts-expect-error + ident.typeAnnotation.typeAnnotation.typeName.name = "GetValueDB"; + return node; + }); + + const paramUsages = methods.find(j.Identifier, { + name: "applHost", + }); + paramUsages.replaceWith(({ node }) => { + node.name = "ctx"; + return node; + }); + + return root.toSource(); + + // const imp = root + // .find( + // j.ImportDeclaration, + // { importKind: typeOnly ? "type" : undefined }, + // ) + // .find(j.ImportSpecifier, { + // imported: { + // name: from, + // }, + // }); + + // return imp.replaceWith(({ node }) => { + // node.imported.name = to; + // return node; + // }).toSource(); + + // return ( + // j(file.source) + // .find(j.FunctionDeclaration) + // // Target a particular function declaration + // .filter(({ node: functionDeclaration }) => functionDeclaration.id.name === functionName) + // .replaceWith(({ node: functionDeclaration }) => { + // // Create a function call expression statement + // const functionCallExpressionStatement = j.expressionStatement( + // j.callExpression(j.identifier(functionNameToCall), []) + // ); + + // // Create a comment and add it as a leading comment to the function call expression + // const commentLine = j.commentLine(comment); + // functionCallExpressionStatement.comments = [commentLine]; + + // // Append the function call expression to the function declaration's existing body + // functionDeclaration.body.body = [...functionDeclaration.body.body, functionCallExpressionStatement]; + // return functionDeclaration; + // }) + // .toSource() + // ); +}; + +export default transform; +export const parser = "ts"; diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index 15ba32c92139..3a2a2c3a12ec 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -17,87 +17,93 @@ import { applicationCCs, getCCName, } from "@zwave-js/core"; -import type { ZWaveApplicationHost } from "@zwave-js/host"; +import type { + GetDeviceConfig, + GetSupportedCCVersion, + GetValueDB, + HostIDs, + ZWaveApplicationHost, +} from "@zwave-js/host"; function getValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, valueId: ValueID, ): T | undefined { - return applHost.getValueDB(nodeId).getValue(valueId); + return ctx.getValueDB(nodeId).getValue(valueId); } function setValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, valueId: ValueID, value: unknown, options?: SetValueOptions, ): void { - return applHost.getValueDB(nodeId).setValue(valueId, value, options); + return ctx.getValueDB(nodeId).setValue(valueId, value, options); } export function endpointCountIsDynamic( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): MaybeNotKnown { return getValue( - applHost, + ctx, nodeId, MultiChannelCCValues.endpointCountIsDynamic.id, ); } export function endpointsHaveIdenticalCapabilities( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): MaybeNotKnown { return getValue( - applHost, + ctx, nodeId, MultiChannelCCValues.endpointsHaveIdenticalCapabilities.id, ); } export function getIndividualEndpointCount( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): MaybeNotKnown { return getValue( - applHost, + ctx, nodeId, MultiChannelCCValues.individualEndpointCount.id, ); } export function getAggregatedEndpointCount( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): MaybeNotKnown { return getValue( - applHost, + ctx, nodeId, MultiChannelCCValues.aggregatedEndpointCount.id, ); } export function getEndpointCount( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): number { return ( - (getIndividualEndpointCount(applHost, nodeId) || 0) - + (getAggregatedEndpointCount(applHost, nodeId) || 0) + (getIndividualEndpointCount(ctx, nodeId) || 0) + + (getAggregatedEndpointCount(ctx, nodeId) || 0) ); } export function setIndividualEndpointCount( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, count: number, ): void { setValue( - applHost, + ctx, nodeId, MultiChannelCCValues.individualEndpointCount.id, count, @@ -105,12 +111,12 @@ export function setIndividualEndpointCount( } export function setAggregatedEndpointCount( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, count: number, ): void { setValue( - applHost, + ctx, nodeId, MultiChannelCCValues.aggregatedEndpointCount.id, count, @@ -118,18 +124,18 @@ export function setAggregatedEndpointCount( } export function getEndpointIndizes( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): number[] { let ret = getValue( - applHost, + ctx, nodeId, MultiChannelCCValues.endpointIndizes.id, ); if (!ret) { // Endpoint indizes not stored, assume sequential endpoints ret = []; - for (let i = 1; i <= getEndpointCount(applHost, nodeId); i++) { + for (let i = 1; i <= getEndpointCount(ctx, nodeId); i++) { ret.push(i); } } @@ -137,12 +143,12 @@ export function getEndpointIndizes( } export function setEndpointIndizes( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, indizes: number[], ): void { setValue( - applHost, + ctx, nodeId, MultiChannelCCValues.endpointIndizes.id, indizes, @@ -150,10 +156,10 @@ export function setEndpointIndizes( } export function isMultiChannelInterviewComplete( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, ): boolean { - return !!getValue(applHost, nodeId, { + return !!getValue(ctx, nodeId, { commandClass: CommandClasses["Multi Channel"], endpoint: 0, property: "interviewComplete", @@ -161,12 +167,12 @@ export function isMultiChannelInterviewComplete( } export function setMultiChannelInterviewComplete( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, complete: boolean, ): void { setValue( - applHost, + ctx, nodeId, { commandClass: CommandClasses["Multi Channel"], @@ -178,14 +184,14 @@ export function setMultiChannelInterviewComplete( } export function getAllEndpoints( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, node: T & GetEndpoint, ): T[] { const ret: T[] = [node]; // Check if the Multi Channel CC interview for this node is completed, // because we don't have all the endpoint information before that - if (isMultiChannelInterviewComplete(applHost, node.nodeId)) { - for (const i of getEndpointIndizes(applHost, node.nodeId)) { + if (isMultiChannelInterviewComplete(ctx, node.nodeId)) { + for (const i of getEndpointIndizes(ctx, node.nodeId)) { const endpoint = node.getEndpoint(i); if (endpoint) ret.push(endpoint); } @@ -195,15 +201,15 @@ export function getAllEndpoints( /** Determines whether the root application CC values should be hidden in favor of endpoint values */ export function shouldHideRootApplicationCCValues( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, nodeId: number, ): boolean { // This is not the case when the root values should explicitly be preserved - const compatConfig = applHost.getDeviceConfig?.(nodeId)?.compat; + const compatConfig = ctx.getDeviceConfig?.(nodeId)?.compat; if (compatConfig?.preserveRootApplicationCCValueIDs) return false; // This is not the case when there are no endpoints - const endpointIndizes = getEndpointIndizes(applHost, nodeId); + const endpointIndizes = getEndpointIndizes(ctx, nodeId); if (endpointIndizes.length === 0) return false; // This is not the case when only individual endpoints should be preserved in addition to the root @@ -224,7 +230,7 @@ export function shouldHideRootApplicationCCValues( * Enhances a value id so it can be consumed better by applications */ export function translateValueID( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, valueId: T, ): T & TranslatedValueID { @@ -251,14 +257,14 @@ export function translateValueID( // Retrieve the speaking property name ret.propertyName = ccInstance.translateProperty( - applHost, + ctx, valueId.property, valueId.propertyKey, ); // Try to retrieve the speaking property key if (valueId.propertyKey != undefined) { const propertyKey = ccInstance.translatePropertyKey( - applHost, + ctx, valueId.property, valueId.propertyKey, ); @@ -318,7 +324,7 @@ export function getDefinedValueIDs( * Returns a list of all value names that are defined on all endpoints of this node */ export function getDefinedValueIDsInternal( - applHost: ZWaveApplicationHost, + ctx: HostIDs & GetValueDB & GetDeviceConfig & GetSupportedCCVersion, node: & NodeId & SupportsCC @@ -327,7 +333,7 @@ export function getDefinedValueIDsInternal( includeInternal: boolean = false, ): TranslatedValueID[] { // The controller has no values. Even if some ended up in the cache somehow, do not return any. - if (node.id === applHost.ownNodeId) return []; + if (node.id === ctx.ownNodeId) return []; let ret: ValueID[] = []; const allowControlled: CommandClasses[] = [ @@ -335,7 +341,7 @@ export function getDefinedValueIDsInternal( ]; for ( const endpoint of getAllEndpoints( - applHost, + ctx, node, ) ) { @@ -356,7 +362,7 @@ export function getDefinedValueIDsInternal( if (ccInstance) { ret.push( ...ccInstance.getDefinedValueIDs( - applHost, + ctx, includeInternal, ), ); @@ -370,10 +376,10 @@ export function getDefinedValueIDsInternal( // via service discovery mechanisms like mDNS or to users in a GUI. // We do this when there are endpoints that were explicitly preserved - if (shouldHideRootApplicationCCValues(applHost, node.id)) { + if (shouldHideRootApplicationCCValues(ctx, node.id)) { ret = filterRootApplicationCCValueIDs(ret); } // Translate the remaining value IDs before exposing them to applications - return ret.map((id) => translateValueID(applHost, node, id)); + return ret.map((id) => translateValueID(ctx, node, id)); } diff --git a/packages/zwave-js/src/lib/test/mocks.ts b/packages/zwave-js/src/lib/test/mocks.ts index e43c06b0e68a..b7542df9fbb5 100644 --- a/packages/zwave-js/src/lib/test/mocks.ts +++ b/packages/zwave-js/src/lib/test/mocks.ts @@ -1,23 +1,24 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import { getImplementedVersion } from "@zwave-js/cc"; import { ConfigManager } from "@zwave-js/config"; import { - type CommandClassInfo, type CommandClasses, type FLiRS, - type IZWaveEndpoint, - type IZWaveNode, - InterviewStage, + type InterviewStage, type MaybeNotKnown, MessagePriority, NOT_KNOWN, - NodeStatus, + type NodeStatus, SecurityClass, ZWaveError, ZWaveErrorCodes, securityClassOrder, } from "@zwave-js/core"; -import type { BaseTestNode, TestingHost } from "@zwave-js/host"; +import type { + BaseTestEndpoint, + BaseTestNode, + GetSafeCCVersion, + GetValueDB, +} from "@zwave-js/host"; import { type FunctionType, Message, @@ -220,14 +221,14 @@ export type TestNode = T & { setEndpoint(endpoint: CreateTestEndpointOptions): void; }; -export function createTestNode( - host: TestingHost, +export function createTestNode( + host: GetValueDB & GetSafeCCVersion, options: CreateTestNodeOptions, -): TestNode { - const endpointCache = new Map(); +): TestNode { + const endpointCache = new Map(); const securityClasses = new Map(); - const ret: TestNode = { + const ret: TestNode = { id: options.id, ...createTestEndpoint(host, { nodeId: options.id, @@ -246,9 +247,9 @@ export function createTestNode( return !ret.isListening && !ret.isFrequentListening; }, - status: options.status - ?? (options.isListening ? NodeStatus.Alive : NodeStatus.Asleep), - interviewStage: options.interviewStage ?? InterviewStage.Complete, + // status: options.status + // ?? (options.isListening ? NodeStatus.Alive : NodeStatus.Asleep), + // interviewStage: options.interviewStage ?? InterviewStage.Complete, setEndpoint: (endpoint) => { endpointCache.set( @@ -286,7 +287,7 @@ export function createTestNode( ); } return endpointCache.get(index); - }) as IZWaveNode["getEndpoint"], + }) as BaseTestNode["getEndpoint"], getEndpointOrThrow(index) { const ep = ret.getEndpoint(index); @@ -299,15 +300,15 @@ export function createTestNode( return ep; }, - getAllEndpoints() { - if (!options.numEndpoints) return [...endpointCache.values()]; - const eps: IZWaveEndpoint[] = []; - for (let i = 0; i <= options.numEndpoints; i++) { - const ep = ret.getEndpoint(i); - if (ep) eps.push(ep); - } - return eps; - }, + // getAllEndpoints() { + // if (!options.numEndpoints) return [...endpointCache.values()]; + // const eps: IZWaveEndpoint[] = []; + // for (let i = 0; i <= options.numEndpoints; i++) { + // const ep = ret.getEndpoint(i); + // if (ep) eps.push(ep); + // } + // return eps; + // }, // These are copied from Node.ts getHighestSecurityClass(): SecurityClass | undefined { @@ -362,36 +363,23 @@ export interface CreateTestEndpointOptions { } export function createTestEndpoint( - host: TestingHost, + host: GetSafeCCVersion, options: CreateTestEndpointOptions, -): IZWaveEndpoint { - const ret: IZWaveEndpoint = { +): BaseTestEndpoint { + const ret: BaseTestEndpoint = { + virtual: false, nodeId: options.nodeId, index: options.index, supportsCC: options.supportsCC ?? (() => true), controlsCC: options.controlsCC ?? (() => false), isCCSecure: options.isCCSecure ?? (() => false), - getCCVersion: options.getCCVersion - ?? ((cc) => - host.getSafeCCVersion(cc, options.nodeId, options.index)), - virtual: false, - addCC: function( - cc: CommandClasses, - info: Partial, - ): void { - throw new Error("Function not implemented."); - }, - removeCC: function(cc: CommandClasses): void { - throw new Error("Function not implemented."); - }, - getCCs: function(): Iterable< - [ccId: CommandClasses, info: CommandClassInfo] - > { - throw new Error("Function not implemented."); - }, - tryGetNode: function(): IZWaveNode | undefined { - return host.nodes.get(options.nodeId); - }, + getCCVersion: (cc) => + options.getCCVersion?.(cc) + ?? host.getSafeCCVersion(cc, options.nodeId, options.index) + ?? 0, + // tryGetNode: function(): IZWaveNode | undefined { + // return host.nodes.get(options.nodeId); + // }, }; return ret; From ea549c4ac9e14b69ce85e0ad984ab3fa4e6ddc17 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 15:27:31 +0200 Subject: [PATCH 51/60] refactor: rename toLogEntry parameter to ctx --- packages/cc/src/cc/AlarmSensorCC.ts | 12 ++-- packages/cc/src/cc/AssociationCC.ts | 24 ++++---- packages/cc/src/cc/AssociationGroupInfoCC.ts | 24 ++++---- packages/cc/src/cc/BarrierOperatorCC.ts | 24 ++++---- packages/cc/src/cc/BasicCC.ts | 8 +-- packages/cc/src/cc/BatteryCC.ts | 8 +-- packages/cc/src/cc/BinarySensorCC.ts | 12 ++-- packages/cc/src/cc/BinarySwitchCC.ts | 8 +-- packages/cc/src/cc/CRC16CC.ts | 4 +- packages/cc/src/cc/CentralSceneCC.ts | 16 ++--- .../cc/src/cc/ClimateControlScheduleCC.ts | 24 ++++---- packages/cc/src/cc/ClockCC.ts | 8 +-- packages/cc/src/cc/ColorSwitchCC.ts | 24 ++++---- packages/cc/src/cc/ConfigurationCC.ts | 48 +++++++-------- packages/cc/src/cc/DoorLockCC.ts | 20 +++---- packages/cc/src/cc/DoorLockLoggingCC.ts | 12 ++-- packages/cc/src/cc/EnergyProductionCC.ts | 8 +-- packages/cc/src/cc/EntryControlCC.ts | 20 +++---- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 40 ++++++------- packages/cc/src/cc/HumidityControlModeCC.ts | 12 ++-- .../src/cc/HumidityControlOperatingStateCC.ts | 4 +- .../cc/src/cc/HumidityControlSetpointCC.ts | 32 +++++----- packages/cc/src/cc/InclusionControllerCC.ts | 8 +-- packages/cc/src/cc/IndicatorCC.ts | 28 ++++----- packages/cc/src/cc/IrrigationCC.ts | 60 +++++++++---------- packages/cc/src/cc/LanguageCC.ts | 8 +-- packages/cc/src/cc/LockCC.ts | 8 +-- packages/cc/src/cc/ManufacturerSpecificCC.ts | 12 ++-- packages/cc/src/cc/MeterCC.ts | 20 +++---- .../cc/src/cc/MultiChannelAssociationCC.ts | 20 +++---- packages/cc/src/cc/MultiChannelCC.ts | 44 +++++++------- packages/cc/src/cc/MultiCommandCC.ts | 4 +- packages/cc/src/cc/MultilevelSensorCC.ts | 20 +++---- packages/cc/src/cc/MultilevelSwitchCC.ts | 16 ++--- packages/cc/src/cc/NodeNamingCC.ts | 16 ++--- packages/cc/src/cc/NotificationCC.ts | 24 ++++---- packages/cc/src/cc/PowerlevelCC.ts | 16 ++--- packages/cc/src/cc/ProtectionCC.ts | 28 ++++----- packages/cc/src/cc/SceneActivationCC.ts | 4 +- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 12 ++-- .../src/cc/SceneControllerConfigurationCC.ts | 12 ++-- packages/cc/src/cc/ScheduleEntryLockCC.ts | 56 ++++++++--------- packages/cc/src/cc/Security2CC.ts | 44 +++++++------- packages/cc/src/cc/SecurityCC.ts | 28 ++++----- packages/cc/src/cc/SoundSwitchCC.ts | 28 ++++----- packages/cc/src/cc/SupervisionCC.ts | 8 +-- packages/cc/src/cc/ThermostatFanModeCC.ts | 12 ++-- packages/cc/src/cc/ThermostatFanStateCC.ts | 4 +- packages/cc/src/cc/ThermostatModeCC.ts | 12 ++-- .../cc/src/cc/ThermostatOperatingStateCC.ts | 4 +- packages/cc/src/cc/ThermostatSetbackCC.ts | 8 +-- packages/cc/src/cc/ThermostatSetpointCC.ts | 24 ++++---- packages/cc/src/cc/TimeCC.ts | 16 ++--- packages/cc/src/cc/TimeParametersCC.ts | 8 +-- packages/cc/src/cc/TransportServiceCC.ts | 20 +++---- packages/cc/src/cc/UserCodeCC.ts | 52 ++++++++-------- packages/cc/src/cc/VersionCC.ts | 20 +++---- packages/cc/src/cc/WakeUpCC.ts | 12 ++-- packages/cc/src/cc/WindowCoveringCC.ts | 24 ++++---- packages/cc/src/cc/ZWavePlusCC.ts | 4 +- .../cc/manufacturerProprietary/FibaroCC.ts | 8 +-- 61 files changed, 572 insertions(+), 572 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 11071aaad5b2..7fe5e270a97d 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -349,7 +349,7 @@ export class AlarmSensorCCReport extends AlarmSensorCC { public readonly severity: number | undefined; public readonly duration: number | undefined; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sensor type": getEnumMemberName(AlarmSensorType, this.sensorType), "alarm state": this.state, @@ -361,7 +361,7 @@ export class AlarmSensorCCReport extends AlarmSensorCC { message.duration = `${this.duration} seconds`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -424,9 +424,9 @@ export class AlarmSensorCCGet extends AlarmSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "sensor type": getEnumMemberName( AlarmSensorType, @@ -467,9 +467,9 @@ export class AlarmSensorCCSupportedReport extends AlarmSensorCC { return true; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported sensor types": this._supportedSensorTypes .map((t) => getEnumMemberName(AlarmSensorType, t)) diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 5628f3c9f03a..4f3fbe4275ca 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -539,7 +539,7 @@ export class AssociationCCSet extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "group id": this.groupId || "all groups", "node ids": this.nodeIds.length @@ -547,7 +547,7 @@ export class AssociationCCSet extends AssociationCC { : "all nodes", }; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -595,7 +595,7 @@ export class AssociationCCRemove extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "group id": this.groupId || "all groups", "node ids": this.nodeIds && this.nodeIds.length @@ -603,7 +603,7 @@ export class AssociationCCRemove extends AssociationCC { : "all nodes", }; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -686,9 +686,9 @@ export class AssociationCCReport extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, "max # of nodes": this.maxNodes, @@ -732,9 +732,9 @@ export class AssociationCCGet extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId }, }; } @@ -772,9 +772,9 @@ export class AssociationCCSupportedGroupingsReport extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group count": this.groupCount }, }; } @@ -813,9 +813,9 @@ export class AssociationCCSpecificGroupReport extends AssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { group: this.group }, }; } diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index f97fd22c7fd3..33bd881c053d 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -520,9 +520,9 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, name: this.name, @@ -560,9 +560,9 @@ export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId }, }; } @@ -663,9 +663,9 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "is list mode": this.isListMode, "has dynamic info": this.hasDynamicInfo, @@ -739,7 +739,7 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.groupId != undefined) { message["group id"] = this.groupId; @@ -749,7 +749,7 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC { } message["refresh cache"] = this.refreshCache; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -825,9 +825,9 @@ export class AssociationGroupInfoCCCommandListReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, commands: `${ @@ -886,9 +886,9 @@ export class AssociationGroupInfoCCCommandListGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, "allow cache": this.allowCache, diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 5c1da4f8c4ce..452a3a4b621d 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -570,9 +570,9 @@ export class BarrierOperatorCCSet extends BarrierOperatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "target state": this.targetState }, }; } @@ -621,9 +621,9 @@ export class BarrierOperatorCCReport extends BarrierOperatorCC { @ccValue(BarrierOperatorCCValues.position) public readonly position: MaybeUnknown; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "barrier position": maybeUnknownToString(this.position), "barrier state": this.currentState != undefined @@ -656,9 +656,9 @@ export class BarrierOperatorCCSignalingCapabilitiesReport @ccValue(BarrierOperatorCCValues.supportedSubsystemTypes) public readonly supportedSubsystemTypes: readonly SubsystemType[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported types": this.supportedSubsystemTypes .map((t) => `\n· ${getEnumMemberName(SubsystemType, t)}`) @@ -710,9 +710,9 @@ export class BarrierOperatorCCEventSignalingSet extends BarrierOperatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "subsystem type": getEnumMemberName( SubsystemType, @@ -755,9 +755,9 @@ export class BarrierOperatorCCEventSignalingReport extends BarrierOperatorCC { public readonly subsystemType: SubsystemType; public readonly subsystemState: SubsystemState; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "subsystem type": getEnumMemberName( SubsystemType, @@ -806,9 +806,9 @@ export class BarrierOperatorCCEventSignalingGet extends BarrierOperatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "subsystem type": getEnumMemberName( SubsystemType, diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 0d5ec4517f95..3dea123b5dae 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -381,9 +381,9 @@ export class BasicCCSet extends BasicCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "target value": this.targetValue }, }; } @@ -504,7 +504,7 @@ export class BasicCCReport extends BasicCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current value": maybeUnknownToString(this.currentValue), }; @@ -515,7 +515,7 @@ export class BasicCCReport extends BasicCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 89b72d0766bc..659e026b1143 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -551,7 +551,7 @@ export class BatteryCCReport extends BatteryCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { level: this.level, "is low": this.isLow, @@ -587,7 +587,7 @@ export class BatteryCCReport extends BatteryCC { message.disconnected = this.disconnected; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -639,9 +639,9 @@ export class BatteryCCHealthReport extends BatteryCC { private readonly temperatureScale: number | undefined; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { temperature: this.temperature != undefined ? this.temperature diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index c2b2ff7bb073..3b1b536f97cd 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -395,9 +395,9 @@ export class BinarySensorCCReport extends BinarySensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { type: getEnumMemberName(BinarySensorType, this.type), value: this.value, @@ -448,9 +448,9 @@ export class BinarySensorCCGet extends BinarySensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { type: getEnumMemberName( BinarySensorType, @@ -499,9 +499,9 @@ export class BinarySensorCCSupportedReport extends BinarySensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported types": this.supportedSensorTypes .map((type) => getEnumMemberName(BinarySensorType, type)) diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 8668f2669654..a84ec85fcf0c 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -351,7 +351,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "target value": this.targetValue, }; @@ -359,7 +359,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -425,7 +425,7 @@ export class BinarySwitchCCReport extends BinarySwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current value": maybeUnknownToString(this.currentValue), }; @@ -436,7 +436,7 @@ export class BinarySwitchCCReport extends BinarySwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/CRC16CC.ts b/packages/cc/src/cc/CRC16CC.ts index 399b63136bd1..fe0a30c8437e 100644 --- a/packages/cc/src/cc/CRC16CC.ts +++ b/packages/cc/src/cc/CRC16CC.ts @@ -159,9 +159,9 @@ export class CRC16CCCommandEncapsulation extends CRC16CC { return super.computeEncapsulationOverhead() + 2; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), // Hide the default payload line message: undefined, }; diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index b32183840bdc..57c906de773c 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -336,7 +336,7 @@ export class CentralSceneCCNotification extends CentralSceneCC { public readonly sceneNumber: number; public readonly slowRefresh: boolean | undefined; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, "key attribute": getEnumMemberName( @@ -349,7 +349,7 @@ export class CentralSceneCCNotification extends CentralSceneCC { message["slow refresh"] = this.slowRefresh; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -429,7 +429,7 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC { return this._supportedKeyAttributes; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "scene count": this.sceneCount, "supports slow refresh": maybeUnknownToString( @@ -442,7 +442,7 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC { .join(""); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -466,9 +466,9 @@ export class CentralSceneCCConfigurationReport extends CentralSceneCC { @ccValue(CentralSceneCCValues.slowRefresh) public readonly slowRefresh: boolean; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "slow refresh": this.slowRefresh }, }; } @@ -511,9 +511,9 @@ export class CentralSceneCCConfigurationSet extends CentralSceneCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "slow refresh": this.slowRefresh }, }; } diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index 2db729c63426..d02d8fd8ab95 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -259,9 +259,9 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { weekday: getEnumMemberName(Weekday, this.weekday), switchpoints: `${ @@ -309,9 +309,9 @@ export class ClimateControlScheduleCCReport extends ClimateControlScheduleCC { ) public readonly schedule: readonly Switchpoint[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { weekday: getEnumMemberName(Weekday, this.weekday), schedule: `${ @@ -364,9 +364,9 @@ export class ClimateControlScheduleCCGet extends ClimateControlScheduleCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { weekday: getEnumMemberName(Weekday, this.weekday) }, }; } @@ -387,9 +387,9 @@ export class ClimateControlScheduleCCChangedReport public readonly changeCounter: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "change counter": this.changeCounter }, }; } @@ -422,9 +422,9 @@ export class ClimateControlScheduleCCOverrideReport @ccValue(ClimateControlScheduleCCValues.overrideState) public readonly overrideState: SetbackState; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "override type": getEnumMemberName( ScheduleOverrideType, @@ -483,9 +483,9 @@ export class ClimateControlScheduleCCOverrideSet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "override type": getEnumMemberName( ScheduleOverrideType, diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 7e8b7d3dafd9..7c9a629d65b8 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -181,9 +181,9 @@ export class ClockCCSet extends ClockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "clock setting": `${ getEnumMemberName( @@ -224,9 +224,9 @@ export class ClockCCReport extends ClockCC { public readonly hour: number; public readonly minute: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "clock setting": `${ getEnumMemberName( diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index 4adf6d0aa99c..e56e41bfc568 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -717,9 +717,9 @@ export class ColorSwitchCCSupportedReport extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported color components": this.supportedColorComponents .map((c) => `\n· ${getEnumMemberName(ColorComponent, c)}`) @@ -865,7 +865,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "color component": getEnumMemberName( ColorComponent, @@ -880,7 +880,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -932,9 +932,9 @@ export class ColorSwitchCCGet extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "color component": getEnumMemberName( ColorComponent, @@ -1032,7 +1032,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const [key, value] of Object.entries(this.colorTable)) { const realKey: string = key in ColorComponentMap @@ -1044,7 +1044,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1131,7 +1131,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "color component": getEnumMemberName( ColorComponent, @@ -1146,7 +1146,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1181,9 +1181,9 @@ export class ColorSwitchCCStopLevelChange extends ColorSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "color component": getEnumMemberName( ColorComponent, diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 26135e1b9392..97efff691d25 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -1748,9 +1748,9 @@ export class ConfigurationCCReport extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter, "value size": this.valueSize, @@ -1806,9 +1806,9 @@ export class ConfigurationCCGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter }, }; } @@ -1919,7 +1919,7 @@ export class ConfigurationCCSet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "parameter #": this.parameter, "reset to default": this.resetToDefault, @@ -1937,7 +1937,7 @@ export class ConfigurationCCSet extends ConfigurationCC { message.value = configValueToString(this.value); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2082,7 +2082,7 @@ export class ConfigurationCCBulkSet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { handshake: this.handshake, "reset to default": this.resetToDefault, @@ -2101,7 +2101,7 @@ export class ConfigurationCCBulkSet extends ConfigurationCC { .join(""); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2209,7 +2209,7 @@ export class ConfigurationCCBulkReport extends ConfigurationCC { return this._values; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "handshake response": this._isHandshakeResponse, "default values": this._defaultValues, @@ -2225,7 +2225,7 @@ export class ConfigurationCCBulkReport extends ConfigurationCC { .join(""); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2274,9 +2274,9 @@ export class ConfigurationCCBulkGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { parameters: this.parameters.join(", ") }, }; } @@ -2385,9 +2385,9 @@ export class ConfigurationCCNameReport extends ConfigurationCC { .reduce((prev, cur) => prev + cur, ""); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter, name: this.name, @@ -2420,9 +2420,9 @@ export class ConfigurationCCNameGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter }, }; } @@ -2544,9 +2544,9 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { .reduce((prev, cur) => prev + cur, ""); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter, info: this.info, @@ -2579,9 +2579,9 @@ export class ConfigurationCCInfoGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter }, }; } @@ -2840,7 +2840,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "parameter #": this.parameter, "next param #": this.nextParameter, @@ -2872,7 +2872,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { message["bulk support"] = !this.noBulkSupport; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2901,9 +2901,9 @@ export class ConfigurationCCPropertiesGet extends ConfigurationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "parameter #": this.parameter }, }; } diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index d2c081fde99f..c8450216fa03 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -857,9 +857,9 @@ export class DoorLockCCOperationSet extends DoorLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "target mode": getEnumMemberName(DoorLockMode, this.mode), }, @@ -969,7 +969,7 @@ export class DoorLockCCOperationReport extends DoorLockCC { @ccValue(DoorLockCCValues.lockTimeout) public readonly lockTimeout?: number; // in seconds - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current mode": getEnumMemberName(DoorLockMode, this.currentMode), "active outside handles": this.outsideHandlesCanOpenDoor.join(", "), @@ -999,7 +999,7 @@ export class DoorLockCCOperationReport extends DoorLockCC { message["lock timeout"] = `${this.lockTimeout} seconds`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1119,7 +1119,7 @@ export class DoorLockCCConfigurationReport extends DoorLockCC { return true; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "operation type": getEnumMemberName( DoorLockOperationType, @@ -1150,7 +1150,7 @@ export class DoorLockCCConfigurationReport extends DoorLockCC { message["block-to-block enabled"] = this.blockToBlock; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1273,7 +1273,7 @@ export class DoorLockCCConfigurationSet extends DoorLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const insideHandles = isArray( this.insideHandlesCanOpenDoorConfiguration, ) @@ -1312,7 +1312,7 @@ export class DoorLockCCConfigurationSet extends DoorLockCC { message["enable block-to-block"] = this.blockToBlock; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1396,9 +1396,9 @@ export class DoorLockCCCapabilitiesReport extends DoorLockCC { @ccValue(DoorLockCCValues.blockToBlockSupported) public readonly blockToBlockSupported: boolean; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { door: this.doorSupported, bolt: this.boltSupported, diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index 16f864899a86..c25d7b8d9a5c 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -243,9 +243,9 @@ export class DoorLockLoggingCCRecordsSupportedReport extends DoorLockLoggingCC { @ccValue(DoorLockLoggingCCValues.recordsCount) public readonly recordsCount: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported no. of records": this.recordsCount, }, @@ -318,7 +318,7 @@ export class DoorLockLoggingCCRecordReport extends DoorLockLoggingCC { public readonly recordNumber: number; public readonly record?: DoorLockLoggingRecord; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (!this.record) { @@ -341,7 +341,7 @@ export class DoorLockLoggingCCRecordReport extends DoorLockLoggingCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -391,9 +391,9 @@ export class DoorLockLoggingCCRecordGet extends DoorLockLoggingCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "record number": this.recordNumber }, }; } diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index 59256c42541b..14bbb926edff 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -247,9 +247,9 @@ export class EnergyProductionCCReport extends EnergyProductionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { [ getEnumMemberName( @@ -301,9 +301,9 @@ export class EnergyProductionCCGet extends EnergyProductionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { parameter: getEnumMemberName( EnergyProductionParameter, diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index 8f44c7ae42a0..21f980ad1cea 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -467,7 +467,7 @@ export class EntryControlCCNotification extends EntryControlCC { public readonly eventType: EntryControlEventTypes; public readonly eventData?: Buffer | string; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, "data type": this.dataType, @@ -488,7 +488,7 @@ export class EntryControlCCNotification extends EntryControlCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -513,9 +513,9 @@ export class EntryControlCCKeySupportedReport extends EntryControlCC { @ccValue(EntryControlCCValues.supportedKeys) public readonly supportedKeys: readonly number[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported keys": this.supportedKeys.toString() }, }; } @@ -600,9 +600,9 @@ export class EntryControlCCEventSupportedReport extends EntryControlCC { public readonly minKeyCacheTimeout: number; public readonly maxKeyCacheTimeout: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported data types": this.supportedDataTypes .map((dt) => EntryControlDataTypes[dt]) @@ -643,9 +643,9 @@ export class EntryControlCCConfigurationReport extends EntryControlCC { @ccValue(EntryControlCCValues.keyCacheTimeout) public readonly keyCacheTimeout: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "key cache size": this.keyCacheSize, "key cache timeout": this.keyCacheTimeout, @@ -695,9 +695,9 @@ export class EntryControlCCConfigurationSet extends EntryControlCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "key cache size": this.keyCacheSize, "key cache timeout": this.keyCacheTimeout, diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index a0569956f641..0152a7c9ae11 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -441,7 +441,7 @@ export class FirmwareUpdateMetaDataCCMetaDataReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": this.manufacturerId, "firmware id": this.firmwareId, @@ -474,7 +474,7 @@ export class FirmwareUpdateMetaDataCCMetaDataReport } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -506,7 +506,7 @@ export class FirmwareUpdateMetaDataCCRequestReport public resume?: boolean; public nonSecureTransfer?: boolean; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { status: getEnumMemberName( FirmwareUpdateRequestStatus, @@ -520,7 +520,7 @@ export class FirmwareUpdateMetaDataCCRequestReport message["non-secure transfer"] = this.nonSecureTransfer; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -606,7 +606,7 @@ export class FirmwareUpdateMetaDataCCRequestGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), @@ -631,7 +631,7 @@ export class FirmwareUpdateMetaDataCCRequestGet message["hardware version"] = this.hardwareVersion; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -652,9 +652,9 @@ export class FirmwareUpdateMetaDataCCGet extends FirmwareUpdateMetaDataCC { public readonly numReports: number; public readonly reportNumber: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "total # of reports": this.numReports, "report number": this.reportNumber, @@ -728,9 +728,9 @@ export class FirmwareUpdateMetaDataCCReport extends FirmwareUpdateMetaDataCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "report #": this.reportNumber, "is last": this.isLast, @@ -758,7 +758,7 @@ export class FirmwareUpdateMetaDataCCStatusReport /** The wait time in seconds before the node becomes available for communication after the update */ public readonly waitTime?: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { status: getEnumMemberName(FirmwareUpdateStatus, this.status), }; @@ -766,7 +766,7 @@ export class FirmwareUpdateMetaDataCCStatusReport message["wait time"] = `${this.waitTime} seconds`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -799,7 +799,7 @@ export class FirmwareUpdateMetaDataCCActivationReport public readonly activationStatus: FirmwareUpdateActivationStatus; public readonly hardwareVersion?: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), @@ -814,7 +814,7 @@ export class FirmwareUpdateMetaDataCCActivationReport message.hardwareVersion = this.hardwareVersion; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -872,7 +872,7 @@ export class FirmwareUpdateMetaDataCCActivationSet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), @@ -883,7 +883,7 @@ export class FirmwareUpdateMetaDataCCActivationSet message["hardware version"] = this.hardwareVersion; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -905,9 +905,9 @@ export class FirmwareUpdateMetaDataCCPrepareReport public readonly status: FirmwareDownloadStatus; public readonly checksum: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { status: getEnumMemberName(FirmwareDownloadStatus, this.status), checksum: num2hex(this.checksum), @@ -969,9 +969,9 @@ export class FirmwareUpdateMetaDataCCPrepareGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "manufacturer id": num2hex(this.manufacturerId), "firmware id": num2hex(this.firmwareId), diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index 056fcafb7e7e..de971c71f308 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -308,9 +308,9 @@ export class HumidityControlModeCCSet extends HumidityControlModeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { mode: getEnumMemberName(HumidityControlMode, this.mode), }, @@ -332,9 +332,9 @@ export class HumidityControlModeCCReport extends HumidityControlModeCC { @ccValue(HumidityControlModeCCValues.mode) public readonly mode: HumidityControlMode; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { mode: getEnumMemberName(HumidityControlMode, this.mode), }, @@ -388,9 +388,9 @@ export class HumidityControlModeCCSupportedReport return this._supportedModes; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported modes": this.supportedModes .map( diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index a6295a3da7fd..067c57b17ec4 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -175,9 +175,9 @@ export class HumidityControlOperatingStateCCReport @ccValue(HumidityControlOperatingStateCCValues.state) public readonly state: HumidityControlOperatingState; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { state: getEnumMemberName( HumidityControlOperatingState, diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index f4c1013f5ed7..510448d21efa 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -553,10 +553,10 @@ export class HumidityControlSetpointCCSet extends HumidityControlSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( HumidityControlSetpointType, @@ -634,10 +634,10 @@ export class HumidityControlSetpointCCReport extends HumidityControlSetpointCC { return this._value; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( HumidityControlSetpointType, @@ -692,9 +692,9 @@ export class HumidityControlSetpointCCGet extends HumidityControlSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( HumidityControlSetpointType, @@ -725,9 +725,9 @@ export class HumidityControlSetpointCCSupportedReport public readonly supportedSetpointTypes: readonly HumidityControlSetpointType[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported setpoint types": this.supportedSetpointTypes .map( @@ -770,12 +770,12 @@ export class HumidityControlSetpointCCScaleSupportedReport public readonly supportedScales: readonly number[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const supportedScales = this.supportedScales.map((scale) => getScale(scale) ); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "scale supported": supportedScales .map((t) => `\n· ${t.key} ${t.unit} - ${t.label}`) @@ -821,9 +821,9 @@ export class HumidityControlSetpointCCScaleSupportedGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( HumidityControlSetpointType, @@ -899,11 +899,11 @@ export class HumidityControlSetpointCCCapabilitiesReport return this._maxValueScale; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const minValueScale = getScale(this.minValueScale); const maxValueScale = getScale(this.maxValueScale); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( HumidityControlSetpointType, @@ -952,9 +952,9 @@ export class HumidityControlSetpointCCCapabilitiesGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( HumidityControlSetpointType, diff --git a/packages/cc/src/cc/InclusionControllerCC.ts b/packages/cc/src/cc/InclusionControllerCC.ts index b7fc8117c63d..ba26ef111bcc 100644 --- a/packages/cc/src/cc/InclusionControllerCC.ts +++ b/packages/cc/src/cc/InclusionControllerCC.ts @@ -121,9 +121,9 @@ export class InclusionControllerCCComplete extends InclusionControllerCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { step: getEnumMemberName(InclusionControllerStep, this.step), status: getEnumMemberName( @@ -170,9 +170,9 @@ export class InclusionControllerCCInitiate extends InclusionControllerCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "included node id": this.includedNodeId, step: getEnumMemberName(InclusionControllerStep, this.step), diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index eb31b18d8ce5..0179432368e1 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -964,7 +964,7 @@ export class IndicatorCCSet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.indicator0Value != undefined) { message["indicator 0 value"] = this.indicator0Value; @@ -982,7 +982,7 @@ export class IndicatorCCSet extends IndicatorCC { }`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1176,7 +1176,7 @@ export class IndicatorCCReport extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.indicator0Value != undefined) { message["indicator 0 value"] = this.indicator0Value; @@ -1194,7 +1194,7 @@ export class IndicatorCCReport extends IndicatorCC { }`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1230,9 +1230,9 @@ export class IndicatorCCGet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { indicator: getIndicatorName(this.indicatorId), }, @@ -1312,9 +1312,9 @@ export class IndicatorCCSupportedReport extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { indicator: getIndicatorName(this.indicatorId), "supported properties": `${ @@ -1371,9 +1371,9 @@ export class IndicatorCCSupportedGet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { indicator: getIndicatorName(this.indicatorId), }, @@ -1436,9 +1436,9 @@ export class IndicatorCCDescriptionReport extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "indicator ID": this.indicatorId, description: this.description || "(none)", @@ -1492,9 +1492,9 @@ export class IndicatorCCDescriptionGet extends IndicatorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "indicator ID": this.indicatorId, }, diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 0ec68f43c74b..2e3dafc85673 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -1371,9 +1371,9 @@ export class IrrigationCCSystemInfoReport extends IrrigationCC { @ccValue(IrrigationCCValues.maxValveTableSize) public readonly maxValveTableSize: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supports master valve": this.supportsMasterValve, "no. of valves": this.numValves, @@ -1477,7 +1477,7 @@ export class IrrigationCCSystemStatusReport extends IrrigationCC { @ccValue(IrrigationCCValues.firstOpenZoneId) public firstOpenZoneId?: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "system voltage": `${this.systemVoltage} V`, "active sensors": [ @@ -1518,7 +1518,7 @@ export class IrrigationCCSystemStatusReport extends IrrigationCC { } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1587,7 +1587,7 @@ export class IrrigationCCSystemConfigSet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "master valve delay": `${this.masterValveDelay} s`, "high pressure threshold": `${this.highPressureThreshold} kPa`, @@ -1606,7 +1606,7 @@ export class IrrigationCCSystemConfigSet extends IrrigationCC { ); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1661,7 +1661,7 @@ export class IrrigationCCSystemConfigReport extends IrrigationCC { @ccValue(IrrigationCCValues.moistureSensorPolarity) public readonly moistureSensorPolarity?: IrrigationSensorPolarity; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "master valve delay": `${this.masterValveDelay} s`, "high pressure threshold": `${this.highPressureThreshold} kPa`, @@ -1680,7 +1680,7 @@ export class IrrigationCCSystemConfigReport extends IrrigationCC { ); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1795,7 +1795,7 @@ export class IrrigationCCValveInfoReport extends IrrigationCC { return true; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "valve ID": this.valveId, connected: this.connected, @@ -1813,7 +1813,7 @@ export class IrrigationCCValveInfoReport extends IrrigationCC { message.errors = errors.map((e) => `\n· ${e}`).join(""); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1868,9 +1868,9 @@ export class IrrigationCCValveInfoGet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "valve ID": this.valveId, }, @@ -1947,9 +1947,9 @@ export class IrrigationCCValveConfigSet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "valve ID": this.valveId, "nominal current high threshold": @@ -2079,9 +2079,9 @@ export class IrrigationCCValveConfigReport extends IrrigationCC { public useRainSensor: boolean; public useMoistureSensor: boolean; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "valve ID": this.valveId, "nominal current high threshold": @@ -2136,9 +2136,9 @@ export class IrrigationCCValveConfigGet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "valve ID": this.valveId, }, @@ -2187,7 +2187,7 @@ export class IrrigationCCValveRun extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "valve ID": this.valveId, }; @@ -2197,7 +2197,7 @@ export class IrrigationCCValveRun extends IrrigationCC { message.action = "turn off"; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2245,7 +2245,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "table ID": this.tableId, }; @@ -2259,7 +2259,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2285,7 +2285,7 @@ export class IrrigationCCValveTableReport extends IrrigationCC { public readonly tableId: number; public readonly entries: ValveTableEntry[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "table ID": this.tableId, }; @@ -2299,7 +2299,7 @@ export class IrrigationCCValveTableReport extends IrrigationCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2347,9 +2347,9 @@ export class IrrigationCCValveTableGet extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "table ID": this.tableId, }, @@ -2395,9 +2395,9 @@ export class IrrigationCCValveTableRun extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "table IDs": this.tableIDs .map((id) => padStart(id.toString(), 3, "0")) @@ -2443,9 +2443,9 @@ export class IrrigationCCSystemShutoff extends IrrigationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { duration: this.duration === 0 ? "temporarily" diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 5cb555bf6308..d481c41ebaec 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -226,13 +226,13 @@ export class LanguageCCSet extends LanguageCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { language: this.language }; if (this._country != undefined) { message.country = this._country; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -259,13 +259,13 @@ export class LanguageCCReport extends LanguageCC { @ccValue(LanguageCCValues.country) public readonly country: MaybeNotKnown; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { language: this.language }; if (this.country != undefined) { message.country = this.country; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index dafa12b5faad..3d7d77284bf3 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -211,9 +211,9 @@ export class LockCCSet extends LockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { locked: this.locked }, }; } @@ -232,9 +232,9 @@ export class LockCCReport extends LockCC { @ccValue(LockCCValues.locked) public readonly locked: boolean; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { locked: this.locked }, }; } diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 64ea4768a97a..3e57ee01132c 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -272,9 +272,9 @@ export class ManufacturerSpecificCCReport extends ManufacturerSpecificCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "manufacturer id": num2hex(this.manufacturerId), "product type": num2hex(this.productType), @@ -318,9 +318,9 @@ export class ManufacturerSpecificCCDeviceSpecificReport ) public readonly deviceId: string; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "device id type": getEnumMemberName(DeviceIdType, this.type), "device id": this.deviceId, @@ -364,9 +364,9 @@ export class ManufacturerSpecificCCDeviceSpecificGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "device id type": getEnumMemberName( DeviceIdType, diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 6efccc28a836..c45ed14b8092 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -1060,7 +1060,7 @@ export class MeterCCReport extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const scale = getMeterScale(this.type, this.scale) ?? getUnknownMeterScale(this.scale); @@ -1077,7 +1077,7 @@ export class MeterCCReport extends MeterCC { message["prev. value"] = this.previousValue; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1160,15 +1160,15 @@ export class MeterCCGet extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.rateType != undefined) { message["rate type"] = getEnumMemberName(RateType, this.rateType); } if (this.scale != undefined) { - if (host) { + if (ctx) { // Try to lookup the meter type to translate the scale - const type = this.getValue(host, MeterCCValues.type); + const type = this.getValue(ctx, MeterCCValues.type); if (type != undefined) { message.scale = (getMeterScale(type, this.scale) ?? getUnknownMeterScale(this.scale)).label; @@ -1178,7 +1178,7 @@ export class MeterCCGet extends MeterCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1323,7 +1323,7 @@ export class MeterCCSupportedReport extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "meter type": getMeterName(this.type), "supports reset": this.supportsReset, @@ -1340,7 +1340,7 @@ export class MeterCCSupportedReport extends MeterCC { .join(", "), }; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1420,7 +1420,7 @@ export class MeterCCReset extends MeterCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.type != undefined) { message.type = getMeterName(this.type); @@ -1436,7 +1436,7 @@ export class MeterCCReset extends MeterCC { message["target value"] = this.targetValue; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index a43b78b82c4d..6e315b466bc2 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -670,9 +670,9 @@ export class MultiChannelAssociationCCSet extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, "node ids": this.nodeIds.join(", "), @@ -732,7 +732,7 @@ export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "group id": this.groupId || "(all groups)", }; @@ -743,7 +743,7 @@ export class MultiChannelAssociationCCRemove extends MultiChannelAssociationCC { message.endpoints = endpointAddressesToString(this.endpoints); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -847,9 +847,9 @@ export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, "maximum # of nodes": this.maxNodes, @@ -895,9 +895,9 @@ export class MultiChannelAssociationCCGet extends MultiChannelAssociationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId }, }; } @@ -937,9 +937,9 @@ export class MultiChannelAssociationCCSupportedGroupingsReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group count": this.groupCount }, }; } diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index fc3ee33bc27d..634519163229 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -864,7 +864,7 @@ export class MultiChannelCCEndPointReport extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "endpoint count (individual)": this.individualCount, "count is dynamic": this.countIsDynamic, @@ -874,7 +874,7 @@ export class MultiChannelCCEndPointReport extends MultiChannelCC { message["endpoint count (aggregated)"] = this.aggregatedCount; } const ret = { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; return ret; @@ -973,9 +973,9 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "endpoint index": this.endpointIndex, "generic device class": getGenericDeviceClass( @@ -1033,9 +1033,9 @@ export class MultiChannelCCCapabilityGet extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { endpoint: this.requestedEndpoint }, }; } @@ -1119,9 +1119,9 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC { .reduce((prev, cur) => prev.concat(...cur), []); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "generic device class": getGenericDeviceClass( this.genericClass, @@ -1170,9 +1170,9 @@ export class MultiChannelCCEndPointFind extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "generic device class": getGenericDeviceClass(this.genericClass).label, @@ -1209,9 +1209,9 @@ export class MultiChannelCCAggregatedMembersReport extends MultiChannelCC { ) public readonly members: readonly number[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "aggregated endpoint": this.aggregatedEndpointIndex, members: this.members.join(", "), @@ -1254,9 +1254,9 @@ export class MultiChannelCCAggregatedMembersGet extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { endpoint: this.requestedEndpoint }, }; } @@ -1385,9 +1385,9 @@ export class MultiChannelCCCommandEncapsulation extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { source: this.endpointIndex, destination: typeof this.destination === "number" @@ -1418,9 +1418,9 @@ export class MultiChannelCCV1Report extends MultiChannelCC { public readonly requestedCC: CommandClasses; public readonly endpointCount: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { CC: getCCName(this.requestedCC), "# of endpoints": this.endpointCount, @@ -1468,9 +1468,9 @@ export class MultiChannelCCV1Get extends MultiChannelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { CC: getCCName(this.requestedCC) }, }; } @@ -1552,9 +1552,9 @@ export class MultiChannelCCV1CommandEncapsulation extends MultiChannelCC { return super.computeEncapsulationOverhead() + 1; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { source: this.endpointIndex }, }; } diff --git a/packages/cc/src/cc/MultiCommandCC.ts b/packages/cc/src/cc/MultiCommandCC.ts index fc6e9f0f692b..5d620e0737e3 100644 --- a/packages/cc/src/cc/MultiCommandCC.ts +++ b/packages/cc/src/cc/MultiCommandCC.ts @@ -154,9 +154,9 @@ export class MultiCommandCCCommandEncapsulation extends MultiCommandCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), // Hide the default payload line message: undefined, }; diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 30852c170c1f..7fcb8074f590 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -739,9 +739,9 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "sensor type": getSensorName(this.type), scale: (getSensorScale(this.type, this.scale) @@ -811,7 +811,7 @@ export class MultilevelSensorCCGet extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord = {}; if ( this.sensorType != undefined @@ -828,7 +828,7 @@ export class MultilevelSensorCCGet extends MultilevelSensorCC { }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -869,9 +869,9 @@ export class MultilevelSensorCCSupportedSensorReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported sensor types": this.supportedSensorTypes .map((t) => `\n· ${getSensorName(t)}`) @@ -932,9 +932,9 @@ export class MultilevelSensorCCSupportedScaleReport extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "sensor type": getSensorName(this.sensorType), "supported scales": this.supportedScales @@ -982,9 +982,9 @@ export class MultilevelSensorCCGetSupportedScale extends MultilevelSensorCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "sensor type": getSensorName(this.sensorType), }, diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 391d8c1a4a40..a96696c780d4 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -667,7 +667,7 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "target value": this.targetValue, }; @@ -675,7 +675,7 @@ export class MultilevelSwitchCCSet extends MultilevelSwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -733,7 +733,7 @@ export class MultilevelSwitchCCReport extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "current value": maybeUnknownToString(this.currentValue), }; @@ -742,7 +742,7 @@ export class MultilevelSwitchCCReport extends MultilevelSwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -828,7 +828,7 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { startLevel: `${this.startLevel}${ this.ignoreStartLevel ? " (ignored)" : "" @@ -839,7 +839,7 @@ export class MultilevelSwitchCCStartLevelChange extends MultilevelSwitchCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -887,9 +887,9 @@ export class MultilevelSwitchCCSupportedReport extends MultilevelSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "switch type": getEnumMemberName(SwitchType, this.switchType), }, diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 2b783df18b50..4443556af714 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -316,9 +316,9 @@ export class NodeNamingAndLocationCCNameSet extends NodeNamingAndLocationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { name: this.name }, }; } @@ -343,9 +343,9 @@ export class NodeNamingAndLocationCCNameReport extends NodeNamingAndLocationCC { @ccValue(NodeNamingAndLocationCCValues.name) public readonly name: string; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { name: this.name }, }; } @@ -407,9 +407,9 @@ export class NodeNamingAndLocationCCLocationSet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { location: this.location }, }; } @@ -436,9 +436,9 @@ export class NodeNamingAndLocationCCLocationReport @ccValue(NodeNamingAndLocationCCValues.location) public readonly location: string; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { location: this.location }, }; } diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index 001f22631455..20d756d97628 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -939,9 +939,9 @@ export class NotificationCCSet extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "notification type": getNotificationName(this.notificationType), status: this.notificationStatus, @@ -1134,7 +1134,7 @@ export class NotificationCCReport extends NotificationCC { public sequenceNumber: number | undefined; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord = {}; if (this.alarmType) { message = { @@ -1221,7 +1221,7 @@ export class NotificationCCReport extends NotificationCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1478,7 +1478,7 @@ export class NotificationCCGet extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.alarmType != undefined) { message["V1 alarm type"] = this.alarmType; @@ -1495,7 +1495,7 @@ export class NotificationCCGet extends NotificationCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1561,9 +1561,9 @@ export class NotificationCCSupportedReport extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supports V1 alarm": this.supportsV1Alarm, "supported notification types": this.supportedNotificationTypes @@ -1693,9 +1693,9 @@ export class NotificationCCEventSupportedReport extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "notification type": getNotificationName(this.notificationType), "supported events": this.supportedEvents @@ -1745,9 +1745,9 @@ export class NotificationCCEventSupportedGet extends NotificationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "notification type": getNotificationName(this.notificationType), }, diff --git a/packages/cc/src/cc/PowerlevelCC.ts b/packages/cc/src/cc/PowerlevelCC.ts index 287c3871c24f..49e461caa8d7 100644 --- a/packages/cc/src/cc/PowerlevelCC.ts +++ b/packages/cc/src/cc/PowerlevelCC.ts @@ -255,7 +255,7 @@ export class PowerlevelCCSet extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "power level": getEnumMemberName(Powerlevel, this.powerlevel), }; @@ -263,7 +263,7 @@ export class PowerlevelCCSet extends PowerlevelCC { message.timeout = `${this.timeout} s`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -306,7 +306,7 @@ export class PowerlevelCCReport extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "power level": getEnumMemberName(Powerlevel, this.powerlevel), }; @@ -314,7 +314,7 @@ export class PowerlevelCCReport extends PowerlevelCC { message.timeout = `${this.timeout} s`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -362,9 +362,9 @@ export class PowerlevelCCTestNodeSet extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "test node id": this.testNodeId, "power level": getEnumMemberName(Powerlevel, this.powerlevel), @@ -418,9 +418,9 @@ export class PowerlevelCCTestNodeReport extends PowerlevelCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "test node id": this.testNodeId, status: getEnumMemberName(PowerlevelTestStatus, this.status), diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index 50af8fd848f0..d3e771bfe405 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -544,7 +544,7 @@ export class ProtectionCCSet extends ProtectionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { local: getEnumMemberName(LocalProtectionState, this.local), }; @@ -552,7 +552,7 @@ export class ProtectionCCSet extends ProtectionCC { message.rf = getEnumMemberName(RFProtectionState, this.rf); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -577,7 +577,7 @@ export class ProtectionCCReport extends ProtectionCC { @ccValue(ProtectionCCValues.rfProtectionState) public readonly rf?: RFProtectionState; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { local: getEnumMemberName(LocalProtectionState, this.local), }; @@ -585,7 +585,7 @@ export class ProtectionCCReport extends ProtectionCC { message.rf = getEnumMemberName(RFProtectionState, this.rf); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -651,9 +651,9 @@ export class ProtectionCCSupportedReport extends ProtectionCC { @ccValue(ProtectionCCValues.supportedRFStates) public readonly supportedRFStates: RFProtectionState[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supports exclusive control": this.supportsExclusiveControl, "supports timeout": this.supportsTimeout, @@ -689,9 +689,9 @@ export class ProtectionCCExclusiveControlReport extends ProtectionCC { @ccValue(ProtectionCCValues.exclusiveControlNodeId) public readonly exclusiveControlNodeId: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "exclusive control node id": this.exclusiveControlNodeId, }, @@ -738,9 +738,9 @@ export class ProtectionCCExclusiveControlSet extends ProtectionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "exclusive control node id": this.exclusiveControlNodeId, }, @@ -761,9 +761,9 @@ export class ProtectionCCTimeoutReport extends ProtectionCC { @ccValue(ProtectionCCValues.timeout) public readonly timeout: Timeout; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { timeout: this.timeout.toString() }, }; } @@ -806,9 +806,9 @@ export class ProtectionCCTimeoutSet extends ProtectionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { timeout: this.timeout.toString() }, }; } diff --git a/packages/cc/src/cc/SceneActivationCC.ts b/packages/cc/src/cc/SceneActivationCC.ts index d9ea442a15da..0793bd8204ad 100644 --- a/packages/cc/src/cc/SceneActivationCC.ts +++ b/packages/cc/src/cc/SceneActivationCC.ts @@ -169,13 +169,13 @@ export class SceneActivationCCSet extends SceneActivationCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "scene id": this.sceneId }; if (this.dimmingDuration != undefined) { message["dimming duration"] = this.dimmingDuration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index b49ac975dbd3..bca070f34964 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -397,7 +397,7 @@ export class SceneActuatorConfigurationCCSet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { sceneId: this.sceneId, dimmingDuration: this.dimmingDuration.toString(), @@ -407,7 +407,7 @@ export class SceneActuatorConfigurationCCSet } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -462,7 +462,7 @@ export class SceneActuatorConfigurationCCReport return true; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { sceneId: this.sceneId, }; @@ -474,7 +474,7 @@ export class SceneActuatorConfigurationCCReport } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -528,9 +528,9 @@ export class SceneActuatorConfigurationCCGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "scene id": this.sceneId }, }; } diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 3fe089fbde1c..44abb7bbfe77 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -528,9 +528,9 @@ export class SceneControllerConfigurationCCSet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, "scene id": this.sceneId, @@ -579,9 +579,9 @@ export class SceneControllerConfigurationCCReport return true; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId, "scene id": this.sceneId, @@ -639,9 +639,9 @@ export class SceneControllerConfigurationCCGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "group id": this.groupId }, }; } diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 898220cce405..351bce154700 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -954,9 +954,9 @@ export class ScheduleEntryLockCCEnableSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user ID": this.userId, action: this.enabled ? "enable" : "disable", @@ -996,9 +996,9 @@ export class ScheduleEntryLockCCEnableAllSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { action: this.enabled ? "enable all" : "disable all", }, @@ -1053,7 +1053,7 @@ export class ScheduleEntryLockCCSupportedReport extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "no. of weekday schedule slots": this.numWeekDaySlots, "no. of day-of-year schedule slots": this.numYearDaySlots, @@ -1063,7 +1063,7 @@ export class ScheduleEntryLockCCSupportedReport extends ScheduleEntryLockCC { this.numDailyRepeatingSlots; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1154,7 +1154,7 @@ export class ScheduleEntryLockCCWeekDayScheduleSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.action === ScheduleEntryLockSetAction.Erase) { message = { @@ -1182,7 +1182,7 @@ export class ScheduleEntryLockCCWeekDayScheduleSet extends ScheduleEntryLockCC { }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1280,7 +1280,7 @@ export class ScheduleEntryLockCCWeekDayScheduleReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.weekday == undefined) { message = { @@ -1307,7 +1307,7 @@ export class ScheduleEntryLockCCWeekDayScheduleReport }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1345,9 +1345,9 @@ export class ScheduleEntryLockCCWeekDayScheduleGet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user ID": this.userId, "slot #": this.slotId, @@ -1457,7 +1457,7 @@ export class ScheduleEntryLockCCYearDayScheduleSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.action === ScheduleEntryLockSetAction.Erase) { message = { @@ -1487,7 +1487,7 @@ export class ScheduleEntryLockCCYearDayScheduleSet extends ScheduleEntryLockCC { }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1620,7 +1620,7 @@ export class ScheduleEntryLockCCYearDayScheduleReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.startYear !== undefined) { message = { @@ -1650,7 +1650,7 @@ export class ScheduleEntryLockCCYearDayScheduleReport }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1688,9 +1688,9 @@ export class ScheduleEntryLockCCYearDayScheduleGet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user ID": this.userId, "slot #": this.slotId, @@ -1737,9 +1737,9 @@ export class ScheduleEntryLockCCTimeOffsetSet extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "standard time offset": `${this.standardOffset} minutes`, "DST offset": `${this.dstOffset} minutes`, @@ -1785,9 +1785,9 @@ export class ScheduleEntryLockCCTimeOffsetReport extends ScheduleEntryLockCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "standard time offset": `${this.standardOffset} minutes`, "DST offset": `${this.dstOffset} minutes`, @@ -1894,7 +1894,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleSet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (this.action === ScheduleEntryLockSetAction.Erase) { message = { @@ -1921,7 +1921,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleSet }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2028,7 +2028,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { let message: MessageRecord; if (!this.weekdays) { message = { @@ -2055,7 +2055,7 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport }; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2095,9 +2095,9 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleGet return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user ID": this.userId, "slot #": this.slotId, diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 2aeb8e7ee040..24d055c1e084 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -1712,7 +1712,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { ); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, }; @@ -1766,7 +1766,7 @@ export class Security2CCMessageEncapsulation extends Security2CC { } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2061,7 +2061,7 @@ export class Security2CCNonceReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "sequence number": this.sequenceNumber, SOS: this.SOS, @@ -2071,7 +2071,7 @@ export class Security2CCNonceReport extends Security2CC { message["receiver entropy"] = buffer2hex(this.receiverEI); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2136,9 +2136,9 @@ export class Security2CCNonceGet extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "sequence number": this.sequenceNumber }, }; } @@ -2221,9 +2221,9 @@ export class Security2CCKEXReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { echo: this.echo, "supported schemes": this.supportedKEXSchemes @@ -2350,9 +2350,9 @@ export class Security2CCKEXSet extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { echo: this.echo, "selected scheme": getEnumMemberName( @@ -2398,9 +2398,9 @@ export class Security2CCKEXFail extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { reason: getEnumMemberName(KEXFailType, this.failType) }, }; } @@ -2441,9 +2441,9 @@ export class Security2CCPublicKeyReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "is including node": this.includingNode, "public key": buffer2hex(this.publicKey), @@ -2487,9 +2487,9 @@ export class Security2CCNetworkKeyReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "security class": getEnumMemberName( SecurityClass, @@ -2532,9 +2532,9 @@ export class Security2CCNetworkKeyGet extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "security class": getEnumMemberName( SecurityClass, @@ -2582,9 +2582,9 @@ export class Security2CCTransferEnd extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "key verified": this.keyVerified, "request complete": this.keyRequestComplete, @@ -2627,9 +2627,9 @@ export class Security2CCCommandsSupportedReport extends Security2CC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported CCs": this.supportedCCs .map((cc) => getCCName(cc)) diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 813e948af1ed..421d9ef15241 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -592,9 +592,9 @@ export class SecurityCCNonceReport extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { nonce: buffer2hex(this.nonce) }, }; } @@ -819,7 +819,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { return super.computeEncapsulationOverhead() + 18; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.nonceId != undefined) { message["nonce id"] = this.nonceId; @@ -856,7 +856,7 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { } } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -886,9 +886,9 @@ export class SecurityCCSchemeReport extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), // Hide the default payload line message: undefined, }; @@ -911,9 +911,9 @@ export class SecurityCCSchemeGet extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), // Hide the default payload line message: undefined, }; @@ -936,9 +936,9 @@ export class SecurityCCSchemeInherit extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), // Hide the default payload line message: undefined, }; @@ -983,9 +983,9 @@ export class SecurityCCNetworkKeySet extends SecurityCC { return super.serialize(ctx); } - public toLogEntry(applHost: ZWaveApplicationHost): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { // The network key shouldn't be logged, so users can safely post their logs online - const { message, ...log } = super.toLogEntry(applHost); + const { message, ...log } = super.toLogEntry(ctx); return log; } } @@ -1056,9 +1056,9 @@ export class SecurityCCCommandsSupportedReport extends SecurityCC { .reduce((prev, cur) => prev.concat(...cur), []); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { reportsToFollow: this.reportsToFollow, supportedCCs: this.supportedCCs diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index 99d447bbc1ba..f23888eea97c 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -500,9 +500,9 @@ export class SoundSwitchCCTonesNumberReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "# of tones": this.toneCount }, }; } @@ -556,9 +556,9 @@ export class SoundSwitchCCToneInfoReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "tone id": this.toneId, duration: `${this.duration} seconds`, @@ -607,9 +607,9 @@ export class SoundSwitchCCToneInfoGet extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "tone id": this.toneId }, }; } @@ -648,9 +648,9 @@ export class SoundSwitchCCConfigurationSet extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "default volume": `${this.defaultVolume} %`, "default tone id": this.defaultToneId, @@ -694,9 +694,9 @@ export class SoundSwitchCCConfigurationReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "default volume": `${this.defaultVolume} %`, "default tone id": this.defaultToneId, @@ -745,7 +745,7 @@ export class SoundSwitchCCTonePlaySet extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "tone id": this.toneId, }; @@ -753,7 +753,7 @@ export class SoundSwitchCCTonePlaySet extends SoundSwitchCC { message.volume = this.volume === 0 ? "default" : `${this.volume} %`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -797,7 +797,7 @@ export class SoundSwitchCCTonePlayReport extends SoundSwitchCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "tone id": this.toneId, }; @@ -805,7 +805,7 @@ export class SoundSwitchCCTonePlayReport extends SoundSwitchCC { message.volume = this.volume === 0 ? "default" : `${this.volume} %`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index cddbef952c9e..337bfc379b8b 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -340,7 +340,7 @@ export class SupervisionCCReport extends SupervisionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "session id": this.sessionId, "more updates follow": this.moreUpdatesFollow, @@ -350,7 +350,7 @@ export class SupervisionCCReport extends SupervisionCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -432,9 +432,9 @@ export class SupervisionCCGet extends SupervisionCC { return super.computeEncapsulationOverhead() + 2; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "session id": this.sessionId, "request updates": this.requestStatusUpdates, diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index 9f8bf1a6cbd0..2df5dd29b052 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -371,12 +371,12 @@ export class ThermostatFanModeCCSet extends ThermostatFanModeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatFanMode, this.mode), }; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -402,7 +402,7 @@ export class ThermostatFanModeCCReport extends ThermostatFanModeCC { @ccValue(ThermostatFanModeCCValues.turnedOff) public readonly off: boolean | undefined; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatFanMode, this.mode), }; @@ -410,7 +410,7 @@ export class ThermostatFanModeCCReport extends ThermostatFanModeCC { message.off = this.off; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -451,9 +451,9 @@ export class ThermostatFanModeCCSupportedReport extends ThermostatFanModeCC { @ccValue(ThermostatFanModeCCValues.supportedFanModes) public readonly supportedModes: ThermostatFanMode[]; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported modes": this.supportedModes .map( diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index f485ebdcacf0..1093c67651ea 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -162,12 +162,12 @@ export class ThermostatFanStateCCReport extends ThermostatFanStateCC { @ccValue(ThermostatFanStateCCValues.fanState) public readonly state: ThermostatFanState; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { state: getEnumMemberName(ThermostatFanState, this.state), }; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index cd30871c7d02..d33e09fc818d 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -371,7 +371,7 @@ export class ThermostatModeCCSet extends ThermostatModeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatMode, this.mode), }; @@ -379,7 +379,7 @@ export class ThermostatModeCCSet extends ThermostatModeCC { message["manufacturer data"] = buffer2hex(this.manufacturerData); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -490,7 +490,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { mode: getEnumMemberName(ThermostatMode, this.mode), }; @@ -498,7 +498,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { message["manufacturer data"] = buffer2hex(this.manufacturerData); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -561,9 +561,9 @@ export class ThermostatModeCCSupportedReport extends ThermostatModeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported modes": this.supportedModes .map( diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index 4636d048c0ae..82700511fd8e 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -173,9 +173,9 @@ export class ThermostatOperatingStateCCReport @ccValue(ThermostatOperatingStateCCValues.operatingState) public readonly state: ThermostatOperatingState; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { state: getEnumMemberName(ThermostatOperatingState, this.state), }, diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index c607ad865288..345073ac18ec 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -208,9 +208,9 @@ export class ThermostatSetbackCCSet extends ThermostatSetbackCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setback type": getEnumMemberName( SetbackType, @@ -264,9 +264,9 @@ export class ThermostatSetbackCCReport extends ThermostatSetbackCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setback type": getEnumMemberName( SetbackType, diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index d509a4641dfd..d79857cf761e 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -588,10 +588,10 @@ export class ThermostatSetpointCCSet extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( ThermostatSetpointType, @@ -683,10 +683,10 @@ export class ThermostatSetpointCCReport extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const scale = getScale(this.scale); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( ThermostatSetpointType, @@ -738,9 +738,9 @@ export class ThermostatSetpointCCGet extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( ThermostatSetpointType, @@ -823,11 +823,11 @@ export class ThermostatSetpointCCCapabilitiesReport return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const minValueScale = getScale(this.minValueScale); const maxValueScale = getScale(this.maxValueScale); return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( ThermostatSetpointType, @@ -871,9 +871,9 @@ export class ThermostatSetpointCCCapabilitiesGet extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "setpoint type": getEnumMemberName( ThermostatSetpointType, @@ -938,9 +938,9 @@ export class ThermostatSetpointCCSupportedReport extends ThermostatSetpointCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported setpoint types": this.supportedSetpointTypes .map( diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 7586776ca02f..52dd4e1894af 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -269,9 +269,9 @@ export class TimeCCTimeReport extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { time: `${padStart(this.hour.toString(), 2, "0")}:${ padStart( @@ -330,9 +330,9 @@ export class TimeCCDateReport extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { date: `${padStart(this.year.toString(), 4, "0")}-${ padStart( @@ -404,9 +404,9 @@ export class TimeCCTimeOffsetSet extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "standard time offset": `${this.standardOffset} minutes`, "DST offset": `${this.dstOffset} minutes`, @@ -487,9 +487,9 @@ export class TimeCCTimeOffsetReport extends TimeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "standard time offset": `${this.standardOffset} minutes`, "DST offset": `${this.dstOffset} minutes`, diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 74b05e4dfa4a..6e1ab0a64e6b 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -295,9 +295,9 @@ export class TimeParametersCCReport extends TimeParametersCC { return this._dateAndTime; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "date and time": formatDate( this.dateAndTime, @@ -391,9 +391,9 @@ export class TimeParametersCCSet extends TimeParametersCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "date and time": formatDate( this.dateAndTime, diff --git a/packages/cc/src/cc/TransportServiceCC.ts b/packages/cc/src/cc/TransportServiceCC.ts index ad951c0678c1..80c6809adc50 100644 --- a/packages/cc/src/cc/TransportServiceCC.ts +++ b/packages/cc/src/cc/TransportServiceCC.ts @@ -222,9 +222,9 @@ export class TransportServiceCCFirstSegment extends TransportServiceCC { ); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "session ID": this.sessionId, "datagram size": this.datagramSize, @@ -423,9 +423,9 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { ); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "session ID": this.sessionId, "datagram size": this.datagramSize, @@ -493,9 +493,9 @@ export class TransportServiceCCSegmentRequest extends TransportServiceCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "session ID": this.sessionId, offset: this.datagramOffset, @@ -534,9 +534,9 @@ export class TransportServiceCCSegmentComplete extends TransportServiceCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "session ID": this.sessionId }, }; } @@ -570,9 +570,9 @@ export class TransportServiceCCSegmentWait extends TransportServiceCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "pending segments": this.pendingSegments }, }; } diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 549f8d1153b9..8006928e3d93 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -1300,9 +1300,9 @@ export class UserCodeCCSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user id": this.userId, "id status": getEnumMemberName(UserIDStatus, this.userIdStatus), @@ -1400,9 +1400,9 @@ export class UserCodeCCReport extends UserCodeCC return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user id": this.userId, "id status": getEnumMemberName(UserIDStatus, this.userIdStatus), @@ -1444,9 +1444,9 @@ export class UserCodeCCGet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user id": this.userId }, }; } @@ -1491,9 +1491,9 @@ export class UserCodeCCUsersNumberReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported users": this.supportedUsers }, }; } @@ -1654,9 +1654,9 @@ export class UserCodeCCCapabilitiesReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supports admin code": this.supportsAdminCode, "supports admin code deactivation": @@ -1714,9 +1714,9 @@ export class UserCodeCCKeypadModeSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { mode: getEnumMemberName(KeypadMode, this.keypadMode) }, }; } @@ -1772,9 +1772,9 @@ export class UserCodeCCKeypadModeReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { keypadMode: getEnumMemberName(KeypadMode, this.keypadMode), }, @@ -1822,9 +1822,9 @@ export class UserCodeCCAdminCodeSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "admin code": userCodeToLogString(this.adminCode) }, }; } @@ -1866,9 +1866,9 @@ export class UserCodeCCAdminCodeReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "admin code": userCodeToLogString(this.adminCode) }, }; } @@ -1910,9 +1910,9 @@ export class UserCodeCCUserCodeChecksumReport extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user code checksum": num2hex(this.userCodeChecksum) }, }; } @@ -1978,7 +1978,7 @@ export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const { userId, userIdStatus, userCode } of this.userCodes) { message[`code #${userId}`] = `${ @@ -1988,7 +1988,7 @@ export class UserCodeCCExtendedUserCodeSet extends UserCodeCC { } (status: ${getEnumMemberName(UserIDStatus, userIdStatus)})`; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2036,7 +2036,7 @@ export class UserCodeCCExtendedUserCodeReport extends UserCodeCC { public readonly userCodes: readonly UserCode[]; public readonly nextUserId: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const { userId, userIdStatus, userCode } of this.userCodes) { message[`code #${userId}`] = `${ @@ -2047,7 +2047,7 @@ export class UserCodeCCExtendedUserCodeReport extends UserCodeCC { } message["next user id"] = this.nextUserId; return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -2089,9 +2089,9 @@ export class UserCodeCCExtendedUserCodeGet extends UserCodeCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "user id": this.userId, "report more": this.reportMore, diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 04b1ae3764be..0295b33c97f8 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -749,7 +749,7 @@ export class VersionCCReport extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "library type": getEnumMemberName( ZWaveLibraryTypes, @@ -762,7 +762,7 @@ export class VersionCCReport extends VersionCC { message["hardware version"] = this.hardwareVersion; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -804,9 +804,9 @@ export class VersionCCCommandClassReport extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { CC: getCCName(this.requestedCC), version: this.ccVersion, @@ -855,9 +855,9 @@ export class VersionCCCommandClassGet extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { CC: getCCName(this.requestedCC) }, }; } @@ -896,9 +896,9 @@ export class VersionCCCapabilitiesReport extends VersionCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supports Z-Wave Software Get command": this.supportsZWaveSoftwareGet, @@ -975,7 +975,7 @@ export class VersionCCZWaveSoftwareReport extends VersionCC { @ccValue(VersionCCValues.applicationBuildNumber) public readonly applicationBuildNumber: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { "SDK version": this.sdkVersion, }; @@ -1000,7 +1000,7 @@ export class VersionCCZWaveSoftwareReport extends VersionCC { message["application build number"] = this.applicationBuildNumber; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 42b6ed353228..43b24d54dd07 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -392,9 +392,9 @@ export class WakeUpCCIntervalSet extends WakeUpCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "wake-up interval": `${this.wakeUpInterval} seconds`, "controller node id": this.controllerNodeId, @@ -421,9 +421,9 @@ export class WakeUpCCIntervalReport extends WakeUpCC { @ccValue(WakeUpCCValues.controllerNodeId) public readonly controllerNodeId: number; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "wake-up interval": `${this.wakeUpInterval} seconds`, "controller node id": this.controllerNodeId, @@ -496,9 +496,9 @@ export class WakeUpCCIntervalCapabilitiesReport extends WakeUpCC { @ccValue(WakeUpCCValues.wakeUpOnDemandSupported) public readonly wakeUpOnDemandSupported: boolean; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "default interval": `${this.defaultWakeUpInterval} seconds`, "minimum interval": `${this.minWakeUpInterval} seconds`, diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 9723f8b7f3fe..f8876925abb4 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -730,9 +730,9 @@ export class WindowCoveringCCSupportedReport extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { "supported parameters": this.supportedParameters .map( @@ -786,9 +786,9 @@ export class WindowCoveringCCReport extends WindowCoveringCC { ) public readonly duration: Duration; - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { parameter: getEnumMemberName( WindowCoveringParameter, @@ -838,9 +838,9 @@ export class WindowCoveringCCGet extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { parameter: getEnumMemberName( WindowCoveringParameter, @@ -917,7 +917,7 @@ export class WindowCoveringCCSet extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; for (const { parameter, value } of this.targetValues) { message[getEnumMemberName(WindowCoveringParameter, parameter)] = @@ -927,7 +927,7 @@ export class WindowCoveringCCSet extends WindowCoveringCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -978,7 +978,7 @@ export class WindowCoveringCCStartLevelChange extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = { parameter: getEnumMemberName( WindowCoveringParameter, @@ -990,7 +990,7 @@ export class WindowCoveringCCStartLevelChange extends WindowCoveringCC { message.duration = this.duration.toString(); } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -1027,9 +1027,9 @@ export class WindowCoveringCCStopLevelChange extends WindowCoveringCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { parameter: getEnumMemberName( WindowCoveringParameter, diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index f952423ef562..f5760ac1c687 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -231,9 +231,9 @@ export class ZWavePlusCCReport extends ZWavePlusCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message: { version: this.zwavePlusVersion, "node type": getEnumMemberName( diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 313a6c694fb9..0a3aa1b16961 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -418,7 +418,7 @@ export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { return super.serialize(ctx); } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.position != undefined) { message.position = this.position; @@ -427,7 +427,7 @@ export class FibaroVenetianBlindCCSet extends FibaroVenetianBlindCC { message.tilt = this.tilt; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } @@ -491,7 +491,7 @@ export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { return this._tilt; } - public toLogEntry(host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(ctx?: GetValueDB): MessageOrCCLogEntry { const message: MessageRecord = {}; if (this.position != undefined) { message.position = this.position; @@ -500,7 +500,7 @@ export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { message.tilt = this.tilt; } return { - ...super.toLogEntry(host), + ...super.toLogEntry(ctx), message, }; } From f467c5aa8b035dab608c55c7679b73d7339fbfe7 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 16:16:16 +0200 Subject: [PATCH 52/60] refactor: remove ZWaveApplicationHost from more methods --- packages/cc/src/cc/AlarmSensorCC.ts | 8 ++-- packages/cc/src/cc/BasicCC.ts | 22 +++++++++-- packages/cc/src/cc/BatteryCC.ts | 18 ++++++++- packages/cc/src/cc/BinarySensorCC.ts | 4 +- packages/cc/src/cc/BinarySwitchCC.ts | 4 +- packages/cc/src/cc/ConfigurationCC.ts | 38 ++++++++++++------- packages/cc/src/cc/IndicatorCC.ts | 14 +++---- .../cc/src/cc/ManufacturerProprietaryCC.ts | 6 +-- packages/cc/src/cc/MeterCC.ts | 19 ++++++++-- packages/cc/src/cc/MultilevelSensorCC.ts | 19 ++++++++-- packages/cc/src/cc/MultilevelSwitchCC.ts | 10 ++--- packages/cc/src/cc/NotificationCC.ts | 37 ++++++++++++------ packages/cc/src/cc/ScheduleEntryLockCC.ts | 8 ++-- packages/cc/src/cc/SupervisionCC.ts | 24 ++++++------ packages/cc/src/cc/UserCodeCC.ts | 29 +++++++------- packages/cc/src/cc/WindowCoveringCC.ts | 6 +-- .../cc/manufacturerProprietary/FibaroCC.ts | 5 ++- packages/cc/src/lib/CommandClass.ts | 18 +++++++-- .../cc/src/lib/EncapsulatingCommandClass.ts | 32 +--------------- packages/cc/src/lib/utils.ts | 4 +- packages/zwave-js/src/lib/node/utils.ts | 22 +++++++++-- 21 files changed, 213 insertions(+), 134 deletions(-) diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 7fe5e270a97d..2206e0ce4120 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -306,7 +306,7 @@ duration: ${currentValue.duration}`; } protected createMetadataForSensorType( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, sensorType: AlarmSensorType, ): void { const stateValue = AlarmSensorCCValues.state(sensorType); @@ -314,9 +314,9 @@ duration: ${currentValue.duration}`; const durationValue = AlarmSensorCCValues.duration(sensorType); // Always create metadata if it does not exist - this.ensureMetadata(applHost, stateValue); - this.ensureMetadata(applHost, severityValue); - this.ensureMetadata(applHost, durationValue); + this.ensureMetadata(ctx, stateValue); + this.ensureMetadata(ctx, severityValue); + this.ensureMetadata(ctx, durationValue); } } diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 3dea123b5dae..2d2f840e7a42 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -1,12 +1,17 @@ import { CommandClasses, + type ControlsCC, Duration, + type EndpointId, + type GetEndpoint, type MaybeNotKnown, type MaybeUnknown, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type NodeId, type SupervisionResult, + type SupportsCC, type ValueID, ValueMetadata, maybeUnknownToString, @@ -15,6 +20,9 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, + GetNode, + GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -330,12 +338,18 @@ remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; } public override getDefinedValueIDs( - applHost: ZWaveApplicationHost, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): ValueID[] { const ret: ValueID[] = []; - const endpoint = this.getEndpoint(applHost)!; + const endpoint = this.getEndpoint(ctx)!; - const compat = applHost.getDeviceConfig?.(endpoint.nodeId)?.compat; + const compat = ctx.getDeviceConfig?.(endpoint.nodeId)?.compat; if (compat?.mapBasicSet === "event") { // Add the compat event value if it should be exposed ret.push(BasicCCValues.compatEvent.endpoint(endpoint.index)); @@ -344,7 +358,7 @@ remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; if (endpoint.supportsCC(this.ccId)) { // Defer to the base implementation if Basic CC is supported. // This implies that no other actuator CC is supported. - ret.push(...super.getDefinedValueIDs(applHost)); + ret.push(...super.getDefinedValueIDs(ctx)); } else if (endpoint.controlsCC(CommandClasses.Basic)) { // During the interview, we mark Basic CC as controlled only if we want to expose currentValue ret.push(BasicCCValues.currentValue.endpoint(endpoint.index)); diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 659e026b1143..59758631af1e 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -1,8 +1,13 @@ import { timespan } from "@zwave-js/core"; import type { + ControlsCC, + EndpointId, + GetEndpoint, MessageOrCCLogEntry, MessageRecord, + NodeId, SinglecastCC, + SupportsCC, } from "@zwave-js/core/safe"; import { CommandClasses, @@ -15,6 +20,9 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, + GetNode, + GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -366,10 +374,16 @@ temperature: ${batteryHealth.temperature} °C`; public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): boolean { // Check when the battery state was last updated - const valueDB = applHost.tryGetValueDB(this.nodeId); + const valueDB = ctx.tryGetValueDB(this.nodeId); if (!valueDB) return true; const lastUpdated = valueDB.getTimestamp( diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 3b1b536f97cd..5bd2ed9396d1 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -325,11 +325,11 @@ export class BinarySensorCC extends CommandClass { } public setMappedBasicValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, value: number, ): boolean { this.setValue( - applHost, + ctx, BinarySensorCCValues.state(BinarySensorType.Any), value > 0, ); diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index a84ec85fcf0c..1232f6a61af2 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -296,10 +296,10 @@ remaining duration: ${resp.duration?.toString() ?? "undefined"}`; } public setMappedBasicValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, value: number, ): boolean { - this.setValue(applHost, BinarySwitchCCValues.currentValue, value > 0); + this.setValue(ctx, BinarySwitchCCValues.currentValue, value > 0); return true; } } diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 97efff691d25..c4934b81004f 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -3,12 +3,17 @@ import { CommandClasses, ConfigValueFormat, type ConfigurationMetadata, + type ControlsCC, + type EndpointId, + type GetEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type NodeId, type SupervisionResult, SupervisionStatus, + type SupportsCC, type ValueID, ValueMetadata, ZWaveError, @@ -28,6 +33,7 @@ import type { CCEncodingContext, CCParsingContext, GetDeviceConfig, + GetNode, GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, @@ -1299,20 +1305,20 @@ alters capabilities: ${!!properties.altersCapabilities}`; * If this is true, we don't trust what the node reports */ protected paramExistsInConfigFile( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, parameter: number, valueBitMask?: number, ): boolean { if ( this.getValue( - applHost, + ctx, ConfigurationCCValues.isParamInformationFromConfig, ) !== true ) { return false; } const paramInformation = getParamInformationFromConfigFile( - applHost, + ctx, this.nodeId as number, this.endpointIndex, ); @@ -1336,7 +1342,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; * Stores config parameter metadata for this CC's node */ public extendParamInformation( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, parameter: number, valueBitMask: number | undefined, info: Partial, @@ -1344,14 +1350,14 @@ alters capabilities: ${!!properties.altersCapabilities}`; // Don't trust param information that a node reports if we have already loaded it from a config file if ( valueBitMask === undefined - && this.paramExistsInConfigFile(applHost, parameter) + && this.paramExistsInConfigFile(ctx, parameter) ) { return; } // Retrieve the base metadata const metadata = this.getParamInformation( - applHost, + ctx, parameter, valueBitMask, ); @@ -1359,7 +1365,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; Object.assign(metadata, info); // And store it back this.setMetadata( - applHost, + ctx, ConfigurationCCValues.paramInformation(parameter, valueBitMask), metadata, ); @@ -1389,7 +1395,13 @@ alters capabilities: ${!!properties.altersCapabilities}`; * and does not include partial parameters. */ public getQueriedParamInfos( - ctx: GetValueDB & GetSupportedCCVersion & GetDeviceConfig, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): Record { const parameters = distinct( this.getDefinedValueIDs(ctx) @@ -1473,10 +1485,10 @@ alters capabilities: ${!!properties.altersCapabilities}`; /** Deserializes the config parameter info from a config file */ public deserializeParamInformationFromConfig( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetDeviceConfig, config: ParamInfoMap, ): void { - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); // Clear old param information for (const meta of valueDB.getAllMetadata(this.ccId)) { @@ -1496,7 +1508,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; // Allow overwriting the param info (mark it as unloaded) this.setValue( - applHost, + ctx, ConfigurationCCValues.isParamInformationFromConfig, false, ); @@ -1531,7 +1543,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; isFromConfig: true, }); this.extendParamInformation( - applHost, + ctx, param.parameter, param.valueBitMask, paramInfo, @@ -1540,7 +1552,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; // Remember that we loaded the param information from a config file this.setValue( - applHost, + ctx, ConfigurationCCValues.isParamInformationFromConfig, true, ); diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index 0179432368e1..e1fe2ce5e2cf 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -850,10 +850,10 @@ export class IndicatorCC extends CommandClass { return super.translateProperty(ctx, property, propertyKey); } - protected supportsV2Indicators(applHost: ZWaveApplicationHost): boolean { + protected supportsV2Indicators(ctx: GetValueDB): boolean { // First test if there are any indicator ids defined const supportedIndicatorIds = this.getValue( - applHost, + ctx, IndicatorCCValues.supportedIndicatorIds, ); if (!supportedIndicatorIds?.length) return false; @@ -861,7 +861,7 @@ export class IndicatorCC extends CommandClass { return supportedIndicatorIds.some( (indicatorId) => !!this.getValue( - applHost, + ctx, IndicatorCCValues.supportedPropertyIDs(indicatorId), )?.length, ); @@ -1119,7 +1119,7 @@ export class IndicatorCCReport extends IndicatorCC { public readonly values: IndicatorObject[] | undefined; private setIndicatorValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, value: IndicatorObject, ): void { // Manufacturer-defined indicators may need a custom label @@ -1127,7 +1127,7 @@ export class IndicatorCCReport extends IndicatorCC { value.indicatorId, ) ? this.getValue( - applHost, + ctx, IndicatorCCValues.indicatorDescription(value.indicatorId), ) : undefined; @@ -1147,8 +1147,8 @@ export class IndicatorCCReport extends IndicatorCC { value.indicatorId, value.propertyId, ); - this.setMetadata(applHost, valueV2, metadata); - this.setValue(applHost, valueV2, value.value); + this.setMetadata(ctx, valueV2, metadata); + this.setValue(ctx, valueV2, value.value); } public serialize(ctx: CCEncodingContext): Buffer { diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index a214f19ffc0c..86c1a7de91eb 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -42,10 +42,10 @@ export type ManufacturerProprietaryCCConstructor< @API(CommandClasses["Manufacturer Proprietary"]) export class ManufacturerProprietaryCCAPI extends CCAPI { public constructor( - applHost: CCAPIHost, + host: CCAPIHost, endpoint: CCAPIEndpoint, ) { - super(applHost, endpoint); + super(host, endpoint); // Read the manufacturer ID from Manufacturer Specific CC const manufacturerId = this.getValueDB().getValue( @@ -60,7 +60,7 @@ export class ManufacturerProprietaryCCAPI extends CCAPI { SpecificAPIConstructor != undefined && new.target !== SpecificAPIConstructor ) { - return new SpecificAPIConstructor(applHost, endpoint); + return new SpecificAPIConstructor(host, endpoint); } } } diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index c45ed14b8092..ed82d2df44c5 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -12,13 +12,17 @@ import { } from "@zwave-js/core"; import { CommandClasses, + type ControlsCC, type EndpointId, + type GetEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, type MessageRecord, + type NodeId, type SinglecastCC, type SupervisionResult, + type SupportsCC, UNKNOWN_STATE, ValueMetadata, parseBitMask, @@ -27,6 +31,9 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, + GetNode, + GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -762,15 +769,21 @@ supports reset: ${suppResp.supportsReset}`; public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): boolean { // Poll the device when all of the supported values were last updated longer than 6 hours ago. // This may lead to some values not being updated, but the user may have disabled some unnecessary // reports to reduce traffic. - const valueDB = applHost.tryGetValueDB(this.nodeId); + const valueDB = ctx.tryGetValueDB(this.nodeId); if (!valueDB) return true; - const values = this.getDefinedValueIDs(applHost).filter((v) => + const values = this.getDefinedValueIDs(ctx).filter((v) => MeterCCValues.value.is(v) ); return values.every((v) => { diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 7fcb8074f590..776eff4246f6 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -7,12 +7,16 @@ import { timespan, } from "@zwave-js/core"; import type { + ControlsCC, EndpointId, + GetEndpoint, MessageOrCCLogEntry, MessageRecord, + NodeId, Scale, SinglecastCC, SupervisionResult, + SupportsCC, ValueID, } from "@zwave-js/core/safe"; import { @@ -27,6 +31,9 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, + GetNode, + GetSupportedCCVersion, GetUserPreferences, GetValueDB, LogNode, @@ -551,15 +558,21 @@ value: ${mlsResponse.value}${ public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): boolean { // Poll the device when all of the supported values were last updated longer than 6 hours ago. // This may lead to some values not being updated, but the user may have disabled some unnecessary // reports to reduce traffic. - const valueDB = applHost.tryGetValueDB(this.nodeId); + const valueDB = ctx.tryGetValueDB(this.nodeId); if (!valueDB) return true; - const values = this.getDefinedValueIDs(applHost).filter((v) => + const values = this.getDefinedValueIDs(ctx).filter((v) => MultilevelSensorCCValues.value.is(v) ); return values.every((v) => { diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index a96696c780d4..95afbbe73d48 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -593,24 +593,24 @@ export class MultilevelSwitchCC extends CommandClass { } public setMappedBasicValue( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, value: number, ): boolean { - this.setValue(applHost, MultilevelSwitchCCValues.currentValue, value); + this.setValue(ctx, MultilevelSwitchCCValues.currentValue, value); return true; } protected createMetadataForLevelChangeActions( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, // SDS13781: The Primary Switch Type SHOULD be 0x02 (Up/Down) switchType: SwitchType = SwitchType["Down/Up"], ): void { this.ensureMetadata( - applHost, + ctx, MultilevelSwitchCCValues.levelChangeUp(switchType), ); this.ensureMetadata( - applHost, + ctx, MultilevelSwitchCCValues.levelChangeDown(switchType), ); } diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index 20d756d97628..eab3b0e84798 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -11,8 +11,10 @@ import { } from "@zwave-js/core"; import { CommandClasses, + type ControlsCC, Duration, type EndpointId, + type GetEndpoint, type MaybeNotKnown, type MessageOrCCLogEntry, MessagePriority, @@ -20,6 +22,7 @@ import { type NodeId, type SinglecastCC, type SupervisionResult, + type SupportsCC, type ValueID, ValueMetadata, type ValueMetadataNumeric, @@ -33,7 +36,11 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, + GetNode, + GetSupportedCCVersion, GetValueDB, + LogNode, ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; @@ -491,11 +498,11 @@ export class NotificationCC extends CommandClass { } private async determineNotificationMode( - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetNode & LogNode, api: NotificationCCAPI, supportedNotificationEvents: ReadonlyMap, ): Promise<"push" | "pull"> { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; // SDS14223: If the supporting node does not support the Association Command Class, // it may be concluded that the supporting node implements Pull Mode and discovery may be aborted. @@ -505,7 +512,7 @@ export class NotificationCC extends CommandClass { try { const groupsIssueingNotifications = AssociationGroupInfoCC .findGroupsForIssuedCommand( - applHost, + ctx, node, this.ccId, NotificationCommand.Report, @@ -516,7 +523,7 @@ export class NotificationCC extends CommandClass { } } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `determining whether this node is pull or push...`, direction: "outbound", @@ -552,10 +559,10 @@ export class NotificationCC extends CommandClass { /** Whether the node implements push or pull notifications */ public static getNotificationMode( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, node: NodeId, ): MaybeNotKnown<"push" | "pull"> { - return applHost + return ctx .getValueDB(node.id) .getValue(NotificationCCValues.notificationMode.id); } @@ -884,18 +891,24 @@ export class NotificationCC extends CommandClass { public shouldRefreshValues( this: SinglecastCC, - applHost: ZWaveApplicationHost, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): boolean { // Pull-mode nodes must be polled regularly const isPullMode = NotificationCC.getNotificationMode( - applHost, - this.getNode(applHost)!, + ctx, + this.getNode(ctx)!, ) === "pull"; if (!isPullMode) return false; const lastUpdated = this.getValue( - applHost, + ctx, NotificationCCValues.lastRefresh, ); @@ -1226,7 +1239,7 @@ export class NotificationCCReport extends NotificationCC { }; } - private parseEventParameters(applHost: ZWaveApplicationHost): void { + private parseEventParameters(ctx: LogNode): void { // This only makes sense for V2+ notifications if ( this.notificationType == undefined @@ -1323,7 +1336,7 @@ export class NotificationCCReport extends NotificationCC { userId: this.eventParameters[2], }; } else { - applHost.logNode( + ctx.logNode( this.nodeId as number, `Failed to parse Notification CC event parameters, ignoring them...`, "error", diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 351bce154700..0d7360a14586 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -852,7 +852,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; } public static getScheduleCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind.WeekDay, userId: number, @@ -860,7 +860,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; ): MaybeNotKnown; public static getScheduleCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind.YearDay, userId: number, @@ -868,7 +868,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; ): MaybeNotKnown; public static getScheduleCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind.DailyRepeating, userId: number, @@ -877,7 +877,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; // Catch-all overload for applications which haven't narrowed `scheduleKind` public static getScheduleCached( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, scheduleKind: ScheduleEntryLockScheduleKind, userId: number, diff --git a/packages/cc/src/cc/SupervisionCC.ts b/packages/cc/src/cc/SupervisionCC.ts index 337bfc379b8b..4faea6a5614f 100644 --- a/packages/cc/src/cc/SupervisionCC.ts +++ b/packages/cc/src/cc/SupervisionCC.ts @@ -21,8 +21,8 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetNode, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { PhysicalCCAPI } from "../lib/API"; @@ -199,13 +199,13 @@ export class SupervisionCC extends CommandClass { * Returns whether a node supports the given CC with Supervision encapsulation. */ public static getCCSupportedWithSupervision( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ccId: CommandClasses, ): boolean { // By default assume supervision is supported for all CCs, unless we've remembered one not to be return ( - applHost + ctx .getValueDB(endpoint.nodeId) .getValue( SupervisionCCValues.ccSupported(ccId).endpoint( @@ -219,12 +219,12 @@ export class SupervisionCC extends CommandClass { * Remembers whether a node supports the given CC with Supervision encapsulation. */ public static setCCSupportedWithSupervision( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, endpoint: EndpointId, ccId: CommandClasses, supported: boolean, ): void { - applHost + ctx .getValueDB(endpoint.nodeId) .setValue( SupervisionCCValues.ccSupported(ccId).endpoint(endpoint.index), @@ -234,9 +234,11 @@ export class SupervisionCC extends CommandClass { /** Returns whether this is a valid command to send supervised */ public static mayUseSupervision( - applHost: ZWaveApplicationHost< - NodeId & SupportsCC & GetEndpoint - >, + ctx: + & GetValueDB + & GetNode< + NodeId & SupportsCC & GetEndpoint + >, command: T, ): command is SinglecastCC { // Supervision may only be used for singlecast CCs that expect no response @@ -245,9 +247,9 @@ export class SupervisionCC extends CommandClass { if (command.expectsCCResponse()) return false; // with a valid node and endpoint - const node = command.getNode(applHost); + const node = command.getNode(ctx); if (!node) return false; - const endpoint = command.getEndpoint(applHost); + const endpoint = command.getEndpoint(ctx); if (!endpoint) return false; // and only if ... @@ -258,7 +260,7 @@ export class SupervisionCC extends CommandClass { && shouldUseSupervision(command) // ... and we haven't previously determined that the node doesn't properly support it && SupervisionCC.getCCSupportedWithSupervision( - applHost, + ctx, endpoint, command.ccId, ) diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 8006928e3d93..45e74c1229e9 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -17,6 +17,7 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetSupportedCCVersion, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -186,17 +187,17 @@ function validateCode(code: string, supportedChars: string): boolean { function setUserCodeMetadata( this: UserCodeCC, - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetSupportedCCVersion, userId: number, userCode?: string | Buffer, ) { const statusValue = UserCodeCCValues.userIdStatus(userId); const codeValue = UserCodeCCValues.userCode(userId); - const ccVersion = getEffectiveCCVersion(applHost, this); + const ccVersion = getEffectiveCCVersion(ctx, this); const supportedUserIDStatuses: UserIDStatus[] = - this.getValue(applHost, UserCodeCCValues.supportedUserIDStatuses) + this.getValue(ctx, UserCodeCCValues.supportedUserIDStatuses) ?? (ccVersion === 1 ? [ UserIDStatus.Available, @@ -211,7 +212,7 @@ function setUserCodeMetadata( UserIDStatus.PassageMode, ]); - this.ensureMetadata(applHost, statusValue, { + this.ensureMetadata(ctx, statusValue, { ...statusValue.meta, states: enumValuesToMetadataStates( UserIDStatus, @@ -227,14 +228,14 @@ function setUserCodeMetadata( maxLength: 10, label: `User Code (${userId})`, }; - if (this.getMetadata(applHost, codeValue)?.type !== codeMetadata.type) { - this.setMetadata(applHost, codeValue, codeMetadata); + if (this.getMetadata(ctx, codeValue)?.type !== codeMetadata.type) { + this.setMetadata(ctx, codeValue, codeMetadata); } } function persistUserCode( this: UserCodeCC, - applHost: ZWaveApplicationHost, + ctx: GetValueDB & GetSupportedCCVersion, userId: number, userIdStatus: UserIDStatus, userCode: string | Buffer, @@ -245,15 +246,15 @@ function persistUserCode( // Check if this code is supported if (userIdStatus === UserIDStatus.StatusNotAvailable) { // It is not, remove all values if any exist - this.removeValue(applHost, statusValue); - this.removeValue(applHost, codeValue); - this.removeMetadata(applHost, statusValue); - this.removeMetadata(applHost, codeValue); + this.removeValue(ctx, statusValue); + this.removeValue(ctx, codeValue); + this.removeMetadata(ctx, statusValue); + this.removeMetadata(ctx, codeValue); } else { // Always create metadata in case it does not exist - setUserCodeMetadata.call(this, applHost, userId, userCode); - this.setValue(applHost, statusValue, userIdStatus); - this.setValue(applHost, codeValue, userCode); + setUserCodeMetadata.call(this, ctx, userId, userCode); + this.setValue(ctx, statusValue, userIdStatus); + this.setValue(ctx, codeValue, userCode); } return true; diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index f8876925abb4..175c3cd92734 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -669,14 +669,14 @@ ${ } public translatePropertyKey( - _applHost: ZWaveApplicationHost, - _property: string | number, + ctx: GetValueDB, + property: string | number, propertyKey: string | number, ): string | undefined { if (typeof propertyKey === "number") { return getEnumMemberName(WindowCoveringParameter, propertyKey); } - return super.translatePropertyKey(_applHost, _property, propertyKey); + return super.translatePropertyKey(ctx, property, propertyKey); } } diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 0a3aa1b16961..4c7939b6932a 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -12,6 +12,7 @@ import { } from "@zwave-js/core/safe"; import type { CCEncodingContext, + GetDeviceConfig, GetValueDB, ZWaveApplicationHost, } from "@zwave-js/host/safe"; @@ -91,10 +92,10 @@ export function getFibaroVenetianBlindTiltMetadata(): ValueMetadata { } function getSupportedFibaroCCIDs( - applHost: ZWaveApplicationHost, + ctx: GetDeviceConfig, nodeId: number, ): FibaroCCIDs[] { - const proprietaryConfig = applHost.getDeviceConfig?.( + const proprietaryConfig = ctx.getDeviceConfig?.( nodeId, )?.proprietary; if (proprietaryConfig && isArray(proprietaryConfig.fibaroCCs)) { diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 8003be18d4c9..a86c5db61c9c 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -532,7 +532,13 @@ export class CommandClass implements CCId { */ public shouldRefreshValues( this: SinglecastCC, - _applHost: ZWaveApplicationHost, + _ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, ): boolean { // This needs to be overwritten per command class. // In the default implementation, don't require a refresh @@ -564,7 +570,7 @@ export class CommandClass implements CCId { * @param _value The value of the received BasicCC */ public setMappedBasicValue( - _applHost: ZWaveApplicationHost, + _ctx: GetValueDB, _value: number, ): boolean { // By default, don't map @@ -820,7 +826,13 @@ export class CommandClass implements CCId { /** Returns a list of all value names that are defined for this CommandClass */ public getDefinedValueIDs( - ctx: GetValueDB & GetSupportedCCVersion & GetDeviceConfig, + ctx: + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + >, includeInternal: boolean = false, ): ValueID[] { // In order to compare value ids, we need them to be strings diff --git a/packages/cc/src/lib/EncapsulatingCommandClass.ts b/packages/cc/src/lib/EncapsulatingCommandClass.ts index 246a4f980069..5f9103e47682 100644 --- a/packages/cc/src/lib/EncapsulatingCommandClass.ts +++ b/packages/cc/src/lib/EncapsulatingCommandClass.ts @@ -1,26 +1,11 @@ -import type { ZWaveApplicationHost } from "@zwave-js/host"; import { isArray } from "alcalzone-shared/typeguards"; -import { CommandClass, type CommandClassOptions } from "./CommandClass"; - -/** Defines the static side of an encapsulating command class */ -export interface EncapsulatingCommandClassStatic { - new ( - applHost: ZWaveApplicationHost, - options: CommandClassOptions, - ): EncapsulatingCommandClass; - - encapsulate( - applHost: ZWaveApplicationHost, - cc: CommandClass, - ): EncapsulatingCommandClass; -} +import { CommandClass } from "./CommandClass"; export type EncapsulatedCommandClass = CommandClass & { encapsulatingCC: EncapsulatingCommandClass; }; export type EncapsulatingCommandClass = CommandClass & { - constructor: EncapsulatingCommandClassStatic; encapsulated: EncapsulatedCommandClass; }; @@ -57,22 +42,7 @@ export function getInnermostCommandClass(cc: CommandClass): CommandClass { } } -/** Defines the static side of an encapsulating command class */ -export interface MultiEncapsulatingCommandClassStatic { - new ( - applHost: ZWaveApplicationHost, - options: CommandClassOptions, - ): MultiEncapsulatingCommandClass; - - requiresEncapsulation(cc: CommandClass): boolean; - encapsulate( - applHost: ZWaveApplicationHost, - CCs: CommandClass[], - ): MultiEncapsulatingCommandClass; -} - export interface MultiEncapsulatingCommandClass { - constructor: MultiEncapsulatingCommandClassStatic; encapsulated: EncapsulatedCommandClass[]; } diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index 8c5f0fecb2ce..6a5d7d617db4 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -654,7 +654,7 @@ export async function removeAssociations( } export function getLifelineGroupIds( - applHost: GetValueDB & GetDeviceConfig, + ctx: GetValueDB & GetDeviceConfig, endpoint: EndpointId & SupportsCC, ): number[] { // For now only support this for the root endpoint - i.e. node @@ -671,7 +671,7 @@ export function getLifelineGroupIds( // We have a device config file that tells us which (additional) association to assign let associations: ReadonlyMap | undefined; - const deviceConfig = applHost.getDeviceConfig?.(endpoint.nodeId); + const deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId); if (endpoint.index === 0) { // The root endpoint's associations may be configured separately or as part of "endpoints" associations = deviceConfig?.associations diff --git a/packages/zwave-js/src/lib/node/utils.ts b/packages/zwave-js/src/lib/node/utils.ts index 3a2a2c3a12ec..65e84820bd7a 100644 --- a/packages/zwave-js/src/lib/node/utils.ts +++ b/packages/zwave-js/src/lib/node/utils.ts @@ -19,10 +19,10 @@ import { } from "@zwave-js/core"; import type { GetDeviceConfig, + GetNode, GetSupportedCCVersion, GetValueDB, HostIDs, - ZWaveApplicationHost, } from "@zwave-js/host"; function getValue( @@ -309,14 +309,21 @@ export function filterRootApplicationCCValueIDs( /** Returns a list of all value names that are defined on all endpoints of this node */ export function getDefinedValueIDs( - applHost: ZWaveApplicationHost, + ctx: + & HostIDs + & GetValueDB + & GetDeviceConfig + & GetSupportedCCVersion + & GetNode< + NodeId & GetEndpoint + >, node: & NodeId & SupportsCC & ControlsCC & GetEndpoint, ): TranslatedValueID[] { - return getDefinedValueIDsInternal(applHost, node, false); + return getDefinedValueIDsInternal(ctx, node, false); } /** @@ -324,7 +331,14 @@ export function getDefinedValueIDs( * Returns a list of all value names that are defined on all endpoints of this node */ export function getDefinedValueIDsInternal( - ctx: HostIDs & GetValueDB & GetDeviceConfig & GetSupportedCCVersion, + ctx: + & HostIDs + & GetValueDB + & GetDeviceConfig + & GetSupportedCCVersion + & GetNode< + NodeId & GetEndpoint + >, node: & NodeId & SupportsCC From 2c5f84d0212377b17bbabc36807a44e44409b450 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 16:27:27 +0200 Subject: [PATCH 53/60] refactor: one more --- packages/cc/src/cc/MultiChannelCC.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 634519163229..06cf85a588f1 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -131,7 +131,7 @@ export const MultiChannelCCValues = Object.freeze({ * This function gives an estimate if this is the case (i.e. all endpoints have a different device class) */ function areEndpointsUnnecessary( - applHost: ZWaveApplicationHost, + ctx: GetValueDB, nodeId: number, endpointIndizes: number[], ): boolean { @@ -146,7 +146,7 @@ function areEndpointsUnnecessary( for (const endpoint of endpointIndizes) { const devClassValueId = MultiChannelCCValues.endpointDeviceClass .endpoint(endpoint); - const deviceClass = applHost.getValueDB(nodeId).getValue<{ + const deviceClass = ctx.getValueDB(nodeId).getValue<{ generic: number; specific: number; }>(devClassValueId); From c645f87d2a8a4482dcf623cd47b8856d2bcaaf39 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 16 Oct 2024 23:34:43 +0200 Subject: [PATCH 54/60] refactor: replace ZWaveApplicationHost in interview/refreshValues --- packages/cc/src/cc/AlarmSensorCC.ts | 40 +++--- packages/cc/src/cc/AssociationCC.ts | 42 +++--- packages/cc/src/cc/AssociationGroupInfoCC.ts | 46 ++++--- packages/cc/src/cc/BarrierOperatorCC.ts | 40 +++--- packages/cc/src/cc/BasicCC.ts | 30 +++-- packages/cc/src/cc/BatteryCC.ts | 28 ++-- packages/cc/src/cc/BinarySensorCC.ts | 40 +++--- packages/cc/src/cc/BinarySwitchCC.ts | 30 ++--- packages/cc/src/cc/CentralSceneCC.ts | 25 ++-- packages/cc/src/cc/ClockCC.ts | 30 ++--- packages/cc/src/cc/ColorSwitchCC.ts | 46 ++++--- packages/cc/src/cc/ConfigurationCC.ts | 62 ++++----- packages/cc/src/cc/DoorLockCC.ts | 52 ++++---- packages/cc/src/cc/DoorLockLoggingCC.ts | 32 +++-- packages/cc/src/cc/EnergyProductionCC.ts | 22 +-- packages/cc/src/cc/EntryControlCC.ts | 40 +++--- .../cc/src/cc/FirmwareUpdateMetaDataCC.ts | 26 ++-- packages/cc/src/cc/HumidityControlModeCC.ts | 34 ++--- .../src/cc/HumidityControlOperatingStateCC.ts | 26 ++-- .../cc/src/cc/HumidityControlSetpointCC.ts | 44 +++--- packages/cc/src/cc/IndicatorCC.ts | 40 +++--- packages/cc/src/cc/IrrigationCC.ts | 54 ++++---- packages/cc/src/cc/LanguageCC.ts | 30 ++--- packages/cc/src/cc/LockCC.ts | 30 ++--- .../cc/src/cc/ManufacturerProprietaryCC.ts | 29 ++-- packages/cc/src/cc/ManufacturerSpecificCC.ts | 28 ++-- packages/cc/src/cc/MeterCC.ts | 58 ++++---- .../cc/src/cc/MultiChannelAssociationCC.ts | 48 +++---- packages/cc/src/cc/MultiChannelCC.ts | 89 ++++++------- packages/cc/src/cc/MultilevelSensorCC.ts | 46 ++++--- packages/cc/src/cc/MultilevelSwitchCC.ts | 32 ++--- packages/cc/src/cc/NodeNamingCC.ts | 34 +++-- packages/cc/src/cc/NotificationCC.ts | 76 +++++------ packages/cc/src/cc/ProtectionCC.ts | 44 +++--- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 13 +- .../src/cc/SceneControllerConfigurationCC.ts | 36 ++--- packages/cc/src/cc/ScheduleEntryLockCC.ts | 19 +-- packages/cc/src/cc/Security2CC.ts | 35 +++-- packages/cc/src/cc/SecurityCC.ts | 24 ++-- packages/cc/src/cc/SoundSwitchCC.ts | 38 +++--- packages/cc/src/cc/ThermostatFanModeCC.ts | 34 ++--- packages/cc/src/cc/ThermostatFanStateCC.ts | 27 ++-- packages/cc/src/cc/ThermostatModeCC.ts | 34 ++--- .../cc/src/cc/ThermostatOperatingStateCC.ts | 26 ++-- packages/cc/src/cc/ThermostatSetbackCC.ts | 30 ++--- packages/cc/src/cc/ThermostatSetpointCC.ts | 46 ++++--- packages/cc/src/cc/TimeCC.ts | 22 ++- packages/cc/src/cc/TimeParametersCC.ts | 15 ++- packages/cc/src/cc/UserCodeCC.ts | 60 +++++---- packages/cc/src/cc/VersionCC.ts | 42 +++--- packages/cc/src/cc/WakeUpCC.ts | 35 ++--- packages/cc/src/cc/WindowCoveringCC.ts | 36 +++-- packages/cc/src/cc/ZWavePlusCC.ts | 24 ++-- packages/cc/src/lib/CommandClass.ts | 26 +++- .../src/codeshifts/refactorInterview.ts | 124 +++++++++++++++++ .../src/codeshifts/refactorRefreshValues.ts | 125 ++++++++++++++++++ 56 files changed, 1269 insertions(+), 975 deletions(-) create mode 100644 packages/maintenance/src/codeshifts/refactorInterview.ts create mode 100644 packages/maintenance/src/codeshifts/refactorRefreshValues.ts diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 2206e0ce4120..4d633aad7acf 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -24,6 +24,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -170,39 +172,39 @@ export class AlarmSensorCC extends CommandClass { declare ccCommand: AlarmSensorCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; // Skip the interview in favor of Notification CC if possible if (endpoint.supportsCC(CommandClasses.Notification)) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: skipping interview because Notification CC is supported...`, direction: "none", }); - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); return; } const api = CCAPI.create( CommandClasses["Alarm Sensor"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Find out which sensor types this sensor supports - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported sensor types...", direction: "outbound", @@ -215,13 +217,13 @@ export class AlarmSensorCC extends CommandClass { .map((name) => `\n· ${name}`) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported sensor types timed out, skipping interview...", @@ -231,27 +233,27 @@ export class AlarmSensorCC extends CommandClass { } // Query (all of) the sensor's current value(s) - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Alarm Sensor"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const supportedSensorTypes: readonly AlarmSensorType[] = - this.getValue(applHost, AlarmSensorCCValues.supportedSensorTypes) + this.getValue(ctx, AlarmSensorCCValues.supportedSensorTypes) ?? []; // Always query (all of) the sensor's current value(s) @@ -262,7 +264,7 @@ export class AlarmSensorCC extends CommandClass { const sensorName = getEnumMemberName(AlarmSensorType, type); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value for ${sensorName}...`, direction: "outbound", @@ -279,7 +281,7 @@ severity: ${currentValue.severity}`; message += ` duration: ${currentValue.duration}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message, direction: "inbound", diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 4f3fbe4275ca..90aec0e87c1a 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -28,6 +28,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -388,19 +390,19 @@ export class AssociationCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Association, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -411,20 +413,20 @@ export class AssociationCC extends CommandClass { // multi channel association groups // Find out how many groups are supported - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying number of association groups...", direction: "outbound", }); const groupCount = await api.getGroupCount(); if (groupCount != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `supports ${groupCount} association groups`, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying association groups timed out, skipping interview...", @@ -434,48 +436,48 @@ export class AssociationCC extends CommandClass { } // Query each association group for its members - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Skip the remaining Association CC interview in favor of Multi Channel Association if possible if (endpoint.supportsCC(CommandClasses["Multi Channel Association"])) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: delaying configuration of lifeline associations until after Multi Channel Association interview...`, direction: "none", }); - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); return; } // And set up lifeline associations - await ccUtils.configureLifelineAssociations(applHost, endpoint); + await ccUtils.configureLifelineAssociations(ctx, endpoint); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Association, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const groupCount = AssociationCC.getGroupCountCached( - applHost, + ctx, endpoint, ); // Query each association group for (let groupId = 1; groupId <= groupCount; groupId++) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying association group #${groupId}...`, direction: "outbound", @@ -486,7 +488,7 @@ export class AssociationCC extends CommandClass { `received information for association group #${groupId}: maximum # of nodes: ${group.maxNodes} currently assigned nodes: ${group.nodeIds.map(String).join(", ")}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 33bd881c053d..7fc55741bc2d 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -24,6 +24,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -340,7 +342,10 @@ export class AssociationGroupInfoCC extends CommandClass { return ( // First query the Multi Channel Association CC - (endpoint.supportsCC(CommandClasses["Multi Channel Association"]) + // And fall back to 0 + (endpoint.supportsCC( + CommandClasses["Multi Channel Association"], + ) && MultiChannelAssociationCC.getGroupCountCached( ctx, endpoint, @@ -348,23 +353,22 @@ export class AssociationGroupInfoCC extends CommandClass { // Then the Association CC || (endpoint.supportsCC(CommandClasses.Association) && AssociationCC.getGroupCountCached(ctx, endpoint)) - // And fall back to 0 || 0 ); } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Association Group Information"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -372,13 +376,13 @@ export class AssociationGroupInfoCC extends CommandClass { const associationGroupCount = AssociationGroupInfoCC .getAssociationGroupCountCached( - applHost, + ctx, endpoint, ); for (let groupId = 1; groupId <= associationGroupCount; groupId++) { // First get the group's name - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Association group #${groupId}: Querying name...`, direction: "outbound", @@ -387,7 +391,7 @@ export class AssociationGroupInfoCC extends CommandClass { if (name) { const logMessage = `Association group #${groupId} has name "${name}"`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -395,7 +399,7 @@ export class AssociationGroupInfoCC extends CommandClass { } // Then the command list - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Association group #${groupId}: Querying command list...`, @@ -406,37 +410,37 @@ export class AssociationGroupInfoCC extends CommandClass { } // Finally query each group for its information - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Association Group Information"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery }); // Query the information for each group (this is the only thing that could be dynamic) const associationGroupCount = AssociationGroupInfoCC .getAssociationGroupCountCached( - applHost, + ctx, endpoint, ); const hasDynamicInfo = this.getValue( - applHost, + ctx, AssociationGroupInfoCCValues.hasDynamicInfo, ); for (let groupId = 1; groupId <= associationGroupCount; groupId++) { // Then its information - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Association group #${groupId}: Querying info...`, direction: "outbound", @@ -452,7 +456,7 @@ profile: ${ info.profile, ) }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 452a3a4b621d..456a3ca8275f 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -44,6 +44,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -421,34 +423,34 @@ export class BarrierOperatorCC extends CommandClass { declare ccCommand: BarrierOperatorCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Barrier Operator"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Create targetState value if it does not exist - this.ensureMetadata(applHost, BarrierOperatorCCValues.targetState); + this.ensureMetadata(ctx, BarrierOperatorCCValues.targetState); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "Querying signaling capabilities...", direction: "outbound", }); const resp = await api.getSignalingCapabilities(); if (resp) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Received supported subsystem types: ${ resp .map((t) => @@ -465,7 +467,7 @@ export class BarrierOperatorCC extends CommandClass { // for valid values and throws otherwise. if (!isEnumMember(SubsystemType, subsystemType)) continue; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Enabling subsystem ${ getEnumMemberName( SubsystemType, @@ -479,27 +481,27 @@ export class BarrierOperatorCC extends CommandClass { } } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Barrier Operator"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const supportedSubsystems: SubsystemType[] = this.getValue( - applHost, + ctx, BarrierOperatorCCValues.supportedSubsystemTypes, ) ?? []; @@ -508,7 +510,7 @@ export class BarrierOperatorCC extends CommandClass { // for valid values and throws otherwise. if (!isEnumMember(SubsystemType, subsystemType)) continue; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Querying event signaling state for subsystem ${ getEnumMemberName( SubsystemType, @@ -519,7 +521,7 @@ export class BarrierOperatorCC extends CommandClass { }); const state = await api.getEventSignaling(subsystemType); if (state != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Subsystem ${ getEnumMemberName( SubsystemType, @@ -531,7 +533,7 @@ export class BarrierOperatorCC extends CommandClass { } } - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying current barrier state...", direction: "outbound", }); diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 2d2f840e7a42..35ec874704e5 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -44,6 +44,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -262,12 +264,12 @@ export class BasicCC extends CommandClass { declare ccCommand: BasicCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -277,13 +279,13 @@ export class BasicCC extends CommandClass { endpoint.addCC(CommandClasses.Basic, { isSupported: true }); // try to query the current state - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remove Basic CC support again when there was no response if ( - this.getValue(applHost, BasicCCValues.currentValue) == undefined + this.getValue(ctx, BasicCCValues.currentValue) == undefined ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "No response to Basic Get command, assuming Basic CC is unsupported...", @@ -297,24 +299,24 @@ export class BasicCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Basic, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // try to query the current state - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Basic CC state...", direction: "outbound", @@ -329,7 +331,7 @@ current value: ${basicResponse.currentValue}`; target value: ${basicResponse.targetValue} remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index 59758631af1e..f7dda93d85ee 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -39,6 +39,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -286,37 +288,37 @@ export class BatteryCC extends CommandClass { declare ccCommand: BatteryCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Query the Battery status - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Battery, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying battery status...", direction: "outbound", @@ -343,7 +345,7 @@ needs to be replaced or charged: ${ is low temperature ${batteryStatus.lowTemperatureStatus} is disconnected: ${batteryStatus.disconnected}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -352,7 +354,7 @@ is disconnected: ${batteryStatus.disconnected}`; if (api.version >= 2) { // always query the health - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying battery health...", direction: "outbound", @@ -363,7 +365,7 @@ is disconnected: ${batteryStatus.disconnected}`; const logMessage = `received response for battery health: max. capacity: ${batteryHealth.maximumCapacity} % temperature: ${batteryHealth.temperature} °C`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 5bd2ed9396d1..3847eddf68b8 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -29,6 +29,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -191,19 +193,19 @@ export class BinarySensorCC extends CommandClass { declare ccCommand: BinarySensorCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Binary Sensor"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -211,7 +213,7 @@ export class BinarySensorCC extends CommandClass { // Find out which sensor types this sensor supports if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported sensor types...", direction: "outbound", @@ -226,13 +228,13 @@ export class BinarySensorCC extends CommandClass { .map((name) => `\n· ${name}`) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported sensor types timed out, skipping interview...", @@ -242,20 +244,20 @@ export class BinarySensorCC extends CommandClass { } } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Binary Sensor"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, @@ -263,14 +265,14 @@ export class BinarySensorCC extends CommandClass { // Query (all of) the sensor's current value(s) if (api.version === 1) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current value...", direction: "outbound", }); const currentValue = await api.get(); if (currentValue != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received current value: ${currentValue}`, direction: "inbound", @@ -279,7 +281,7 @@ export class BinarySensorCC extends CommandClass { } else { const supportedSensorTypes: readonly BinarySensorType[] = this.getValue( - applHost, + ctx, BinarySensorCCValues.supportedSensorTypes, ) ?? []; @@ -289,14 +291,14 @@ export class BinarySensorCC extends CommandClass { if (!isEnumMember(BinarySensorType, type)) continue; const sensorName = getEnumMemberName(BinarySensorType, type); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value for ${sensorName}...`, direction: "outbound", }); const currentValue = await api.get(type); if (currentValue != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received current value for ${sensorName}: ${currentValue}`, diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index 1232f6a61af2..ad47337b4b41 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -14,11 +14,7 @@ import { parseMaybeBoolean, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import type { AllOrNone } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -37,6 +33,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -242,37 +240,37 @@ export class BinarySwitchCC extends CommandClass { declare ccCommand: BinarySwitchCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Binary Switch"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current state - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Binary Switch state...", direction: "outbound", @@ -287,7 +285,7 @@ current value: ${resp.currentValue}`; target value: ${resp.targetValue} remaining duration: ${resp.duration?.toString() ?? "undefined"}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 57c906de773c..12d6981dd36b 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -36,6 +36,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -220,19 +221,19 @@ export class CentralSceneCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Central Scene"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -242,13 +243,13 @@ export class CentralSceneCC extends CommandClass { // we must associate ourselves with that channel try { await ccUtils.assignLifelineIssueingCommand( - applHost, + ctx, endpoint, this.ccId, CentralSceneCommand.Notification, ); } catch { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -259,7 +260,7 @@ export class CentralSceneCC extends CommandClass { }); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported scenes...", direction: "outbound", @@ -269,13 +270,13 @@ export class CentralSceneCC extends CommandClass { const logMessage = `received supported scenes: # of scenes: ${ccSupported.sceneCount} supports slow refresh: ${ccSupported.supportsSlowRefresh}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported scenes timed out, skipping interview...", @@ -286,7 +287,7 @@ supports slow refresh: ${ccSupported.supportsSlowRefresh}`; // The slow refresh capability should be enabled whenever possible if (api.version >= 3 && ccSupported?.supportsSlowRefresh) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Enabling slow refresh capability...", direction: "outbound", @@ -295,7 +296,7 @@ supports slow refresh: ${ccSupported.supportsSlowRefresh}`; } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 7c9a629d65b8..ac5256d64031 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -10,11 +10,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; @@ -24,6 +20,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -92,36 +90,36 @@ export class ClockCC extends CommandClass { declare ccCommand: ClockCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Clock, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "requesting current clock setting...", direction: "outbound", }); @@ -134,7 +132,7 @@ export class ClockCC extends CommandClass { }${response.hour < 10 ? "0" : ""}${response.hour}:${ response.minute < 10 ? "0" : "" }${response.minute}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index e56e41bfc568..a09334e8ea90 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -47,6 +47,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -546,32 +548,32 @@ export class ColorSwitchCC extends CommandClass { declare ccCommand: ColorSwitchCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Color Switch"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported colors...", direction: "outbound", }); const supportedColors = await api.getSupported(); if (!supportedColors) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported colors timed out, skipping interview...", @@ -580,7 +582,7 @@ export class ColorSwitchCC extends CommandClass { return; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received supported colors:${ supportedColors @@ -594,17 +596,17 @@ export class ColorSwitchCC extends CommandClass { for (const color of supportedColors) { const currentColorChannelValue = ColorSwitchCCValues .currentColorChannel(color); - this.setMetadata(applHost, currentColorChannelValue); + this.setMetadata(ctx, currentColorChannelValue); const targetColorChannelValue = ColorSwitchCCValues .targetColorChannel(color); - this.setMetadata(applHost, targetColorChannelValue); + this.setMetadata(ctx, targetColorChannelValue); } // And the compound one const currentColorValue = ColorSwitchCCValues.currentColor; - this.setMetadata(applHost, currentColorValue); + this.setMetadata(ctx, currentColorValue); const targetColorValue = ColorSwitchCCValues.targetColor; - this.setMetadata(applHost, targetColorValue); + this.setMetadata(ctx, targetColorValue); // Create the collective HEX color values const supportsHex = [ @@ -613,37 +615,37 @@ export class ColorSwitchCC extends CommandClass { ColorComponent.Blue, ].every((c) => supportedColors.includes(c)); this.setValue( - applHost, + ctx, ColorSwitchCCValues.supportsHexColor, supportsHex, ); if (supportsHex) { const hexColorValue = ColorSwitchCCValues.hexColor; - this.setMetadata(applHost, hexColorValue); + this.setMetadata(ctx, hexColorValue); } // Query all color components - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Color Switch"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const supportedColors: readonly ColorComponent[] = this.getValue( - applHost, + ctx, ColorSwitchCCValues.supportedColorComponents, ) ?? []; @@ -653,7 +655,7 @@ export class ColorSwitchCC extends CommandClass { if (!isEnumMember(ColorComponent, color)) continue; const colorName = getEnumMemberName(ColorComponent, color); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current color state (${colorName})`, direction: "outbound", diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index c4934b81004f..da9c76b4bd4a 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -59,6 +59,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -1047,45 +1049,45 @@ export class ConfigurationCC extends CommandClass { declare ccCommand: ConfigurationCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Configuration, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - const deviceConfig = applHost.getDeviceConfig?.(node.id); + const deviceConfig = ctx.getDeviceConfig?.(node.id); const paramInfo = getParamInformationFromConfigFile( - applHost, + ctx, node.id, this.endpointIndex, ); if (paramInfo) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: Loading configuration parameters from device config`, direction: "none", }); - this.deserializeParamInformationFromConfig(applHost, paramInfo); + this.deserializeParamInformationFromConfig(ctx, paramInfo); } const documentedParamNumbers = new Set( Array.from(paramInfo?.keys() ?? []).map((k) => k.parameter), ); if (api.version >= 3) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "finding first configuration parameter...", direction: "outbound", @@ -1095,7 +1097,7 @@ export class ConfigurationCC extends CommandClass { if (param0props) { param = param0props.nextParameter; if (param === 0) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `didn't report any config params, trying #1 just to be sure...`, @@ -1104,7 +1106,7 @@ export class ConfigurationCC extends CommandClass { param = 1; } } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Finding first configuration parameter timed out, skipping interview...", @@ -1114,7 +1116,7 @@ export class ConfigurationCC extends CommandClass { } while (param > 0) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying parameter #${param} information...`, direction: "outbound", @@ -1126,7 +1128,7 @@ export class ConfigurationCC extends CommandClass { () => undefined, ); if (!props) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying parameter #${param} information timed out, skipping scan...`, @@ -1183,7 +1185,7 @@ is advanced (UI): ${!!properties.isAdvanced} has bulk support: ${!properties.noBulkSupport} alters capabilities: ${!!properties.altersCapabilities}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -1200,20 +1202,20 @@ alters capabilities: ${!!properties.altersCapabilities}`; } } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Configuration, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, @@ -1222,7 +1224,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; if (api.version < 3) { // V1/V2: Query all values defined in the config file const paramInfo = getParamInformationFromConfigFile( - applHost, + ctx, node.id, this.endpointIndex, ); @@ -1238,7 +1240,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; alreadyQueried.add(param.parameter); // Query the current value - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying parameter #${param.parameter} value...`, @@ -1247,14 +1249,14 @@ alters capabilities: ${!!properties.altersCapabilities}`; // ... at least try to const paramValue = await api.get(param.parameter); if (typeof paramValue === "number") { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `parameter #${param.parameter} has value: ${paramValue}`, direction: "inbound", }); } else if (!paramValue) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received no value for parameter #${param.parameter}`, @@ -1264,7 +1266,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; } } } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `${this.constructor.name}: skipping interview because CC version is < 3 and there is no config file`, @@ -1274,22 +1276,22 @@ alters capabilities: ${!!properties.altersCapabilities}`; } else { // V3+: Query the values of discovered parameters const parameters = distinct( - this.getDefinedValueIDs(applHost) + this.getDefinedValueIDs(ctx) .map((v) => v.property) .filter((p) => typeof p === "number"), ); for (const param of parameters) { if ( - this.getParamInformation(applHost, param).readable !== false + this.getParamInformation(ctx, param).readable !== false ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying parameter #${param} value...`, direction: "outbound", }); await api.get(param); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `not querying parameter #${param} value, because it is writeonly`, diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index c8450216fa03..acc50c37bead 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -38,6 +38,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -596,19 +598,19 @@ export class DoorLockCC extends CommandClass { declare ccCommand: DoorLockCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Door Lock"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -624,7 +626,7 @@ export class DoorLockCC extends CommandClass { let latchSupported = true; if (api.version >= 4) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting lock capabilities...", direction: "outbound", @@ -656,7 +658,7 @@ supports auto-relock: ${resp.autoRelockSupported} supports hold-and-release: ${resp.holdAndReleaseSupported} supports twist assist: ${resp.twistAssistSupported} supports block to block: ${resp.blockToBlockSupported}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -668,7 +670,7 @@ supports block to block: ${resp.blockToBlockSupported}`; // Update metadata of settable states const targetModeValue = DoorLockCCValues.targetMode; - this.setMetadata(applHost, targetModeValue, { + this.setMetadata(ctx, targetModeValue, { ...targetModeValue.meta, states: enumValuesToMetadataStates( DoorLockMode, @@ -677,7 +679,7 @@ supports block to block: ${resp.blockToBlockSupported}`; }); const operationTypeValue = DoorLockCCValues.operationType; - this.setMetadata(applHost, operationTypeValue, { + this.setMetadata(ctx, operationTypeValue, { ...operationTypeValue.meta, states: enumValuesToMetadataStates( DoorLockOperationType, @@ -692,50 +694,50 @@ supports block to block: ${resp.blockToBlockSupported}`; if (!hadCriticalTimeout) { // Save support information for the status values const doorStatusValue = DoorLockCCValues.doorStatus; - if (doorSupported) this.setMetadata(applHost, doorStatusValue); + if (doorSupported) this.setMetadata(ctx, doorStatusValue); this.setValue( - applHost, + ctx, DoorLockCCValues.doorSupported, doorSupported, ); const latchStatusValue = DoorLockCCValues.latchStatus; - if (latchSupported) this.setMetadata(applHost, latchStatusValue); + if (latchSupported) this.setMetadata(ctx, latchStatusValue); this.setValue( - applHost, + ctx, DoorLockCCValues.latchSupported, latchSupported, ); const boltStatusValue = DoorLockCCValues.boltStatus; - if (boltSupported) this.setMetadata(applHost, boltStatusValue); + if (boltSupported) this.setMetadata(ctx, boltStatusValue); this.setValue( - applHost, + ctx, DoorLockCCValues.boltSupported, boltSupported, ); } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - if (!hadCriticalTimeout) this.setInterviewComplete(applHost, true); + if (!hadCriticalTimeout) this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Door Lock"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting lock configuration...", direction: "outbound", @@ -773,14 +775,14 @@ twist assist ${!!config.twistAssist} block to block ${!!config.blockToBlock}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current lock status...", direction: "outbound", @@ -810,7 +812,7 @@ bolt status: ${status.boltStatus}`; logMessage += ` latch status: ${status.latchStatus}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index c25d7b8d9a5c..503d4d802d14 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -8,11 +8,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { isPrintableASCII, num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; @@ -21,6 +17,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -172,36 +170,36 @@ export class DoorLockLoggingCC extends CommandClass { declare ccCommand: DoorLockLoggingCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Door Lock Logging"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported number of records...", direction: "outbound", @@ -209,7 +207,7 @@ export class DoorLockLoggingCC extends CommandClass { const recordsCount = await api.getRecordsCount(); if (!recordsCount) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Door Lock Logging records count query timed out, skipping interview...", @@ -221,7 +219,7 @@ export class DoorLockLoggingCC extends CommandClass { const recordsCountLogMessage = `supports ${recordsCount} record${ recordsCount === 1 ? "" : "s" }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: recordsCountLogMessage, direction: "inbound", diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index 14bbb926edff..fc063e5c9f3b 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -26,6 +26,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -134,31 +136,31 @@ export class EnergyProductionCC extends CommandClass { declare ccCommand: EnergyProductionCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Query current values - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Energy Production"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, @@ -172,7 +174,7 @@ export class EnergyProductionCC extends CommandClass { EnergyProductionParameter["Total Time"], ] as const ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying energy production (${ getEnumMemberName( diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index 21f980ad1cea..c86971821171 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -34,6 +34,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -271,19 +273,19 @@ export class EntryControlCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Entry Control"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -293,13 +295,13 @@ export class EntryControlCC extends CommandClass { // we must associate ourselves with that channel try { await ccUtils.assignLifelineIssueingCommand( - applHost, + ctx, endpoint, this.ccId, EntryControlCommand.Notification, ); } catch { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -310,7 +312,7 @@ export class EntryControlCC extends CommandClass { }); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting entry control supported keys...", direction: "outbound", @@ -318,7 +320,7 @@ export class EntryControlCC extends CommandClass { const supportedKeys = await api.getSupportedKeys(); if (supportedKeys) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received entry control supported keys: ${supportedKeys.toString()}`, @@ -326,7 +328,7 @@ export class EntryControlCC extends CommandClass { }); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting entry control supported events...", direction: "outbound", @@ -334,7 +336,7 @@ export class EntryControlCC extends CommandClass { const eventCapabilities = await api.getEventCapabilities(); if (eventCapabilities) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received entry control supported keys: data types: ${ @@ -355,26 +357,26 @@ max key cache timeout: ${eventCapabilities.maxKeyCacheTimeout} seconds`, }); } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Entry Control"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting entry control configuration...", direction: "outbound", @@ -382,7 +384,7 @@ max key cache timeout: ${eventCapabilities.maxKeyCacheTimeout} seconds`, const conf = await api.getConfiguration(); if (conf) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received entry control configuration: key cache size: ${conf.keyCacheSize} diff --git a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts index 0152a7c9ae11..0d1ad2a74cec 100644 --- a/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts +++ b/packages/cc/src/cc/FirmwareUpdateMetaDataCC.ts @@ -9,11 +9,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { type AllOrNone, getEnumMemberName, @@ -24,9 +20,9 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -248,25 +244,25 @@ export class FirmwareUpdateMetaDataCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Firmware Update Meta Data"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying firmware update capabilities...", direction: "outbound", @@ -291,13 +287,13 @@ export class FirmwareUpdateMetaDataCC extends CommandClass { } else { logMessage += `\nfirmware upgradeable: false`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Firmware update capability query timed out", direction: "inbound", @@ -305,7 +301,7 @@ export class FirmwareUpdateMetaDataCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index de971c71f308..ccb47e362b7f 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -33,6 +33,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -187,26 +189,26 @@ export class HumidityControlModeCC extends CommandClass { declare ccCommand: HumidityControlModeCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Humidity Control Mode"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First query the possible modes to set the metadata - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported humidity control modes...", direction: "outbound", @@ -224,13 +226,13 @@ export class HumidityControlModeCC extends CommandClass { ) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported humidity control modes timed out, skipping interview...", @@ -239,34 +241,34 @@ export class HumidityControlModeCC extends CommandClass { return; } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Humidity Control Mode"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current status - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current humidity control mode...", direction: "outbound", }); const currentMode = await api.get(); if (currentMode) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "received current humidity control mode: " + getEnumMemberName(HumidityControlMode, currentMode), diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index 067c57b17ec4..de807772c6b5 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -7,7 +7,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { GetValueDB, ZWaveApplicationHost } from "@zwave-js/host/safe"; +import type { GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { CCAPI, @@ -19,6 +19,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, } from "../lib/CommandClass"; import { API, @@ -109,44 +111,44 @@ export class HumidityControlOperatingStateCC extends CommandClass { declare ccCommand: HumidityControlOperatingStateCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Humidity Control Operating State"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current status - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current humidity control operating state...", direction: "outbound", }); const currentStatus = await api.get(); if (currentStatus) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "received current humidity control operating state: " + getEnumMemberName( diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 510448d21efa..9cbfdc5c78e3 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -38,6 +38,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -349,19 +351,19 @@ export class HumidityControlSetpointCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Humidity Control Setpoint"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -369,7 +371,7 @@ export class HumidityControlSetpointCC extends CommandClass { // Query the supported setpoint types let setpointTypes: HumidityControlSetpointType[] = []; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving supported setpoint types...", direction: "outbound", @@ -385,13 +387,13 @@ export class HumidityControlSetpointCC extends CommandClass { .map((name) => `· ${name}`) .join("\n"); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported setpoint types timed out, skipping interview...", @@ -406,7 +408,7 @@ export class HumidityControlSetpointCC extends CommandClass { type, ); // Find out the capabilities of this setpoint - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `retrieving capabilities for setpoint ${setpointName}...`, @@ -421,7 +423,7 @@ ${ .map((t) => `\n· ${t.key} ${t.unit} - ${t.label}`) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -433,7 +435,7 @@ ${ for (const scale of setpointScaleSupported) { if (scale.unit) states[scale.key] = scale.unit; } - this.setMetadata(applHost, scaleValue, { + this.setMetadata(ctx, scaleValue, { ...scaleValue.meta, states, }); @@ -450,7 +452,7 @@ ${ `received capabilities for setpoint ${setpointName}: minimum value: ${setpointCaps.minValue} ${minValueUnit} maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -459,27 +461,27 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; } // Query the current value for all setpoint types - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Humidity Control Setpoint"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const setpointTypes: HumidityControlSetpointType[] = this.getValue( - applHost, + ctx, HumidityControlSetpointCCValues.supportedSetpointTypes, ) ?? []; @@ -490,7 +492,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; type, ); // Every time, query the current value - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value of setpoint ${setpointName}...`, @@ -502,7 +504,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; `received current value of setpoint ${setpointName}: ${setpoint.value} ${ getScale(setpoint.scale).unit ?? "" }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index e1fe2ce5e2cf..d76af831f932 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -38,6 +38,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -692,26 +694,26 @@ export class IndicatorCC extends CommandClass { declare ccCommand: IndicatorCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Indicator, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); if (api.version > 1) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "scanning supported indicator IDs...", direction: "outbound", @@ -722,7 +724,7 @@ export class IndicatorCC extends CommandClass { do { const supportedResponse = await api.getSupported(curId); if (!supportedResponse) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Time out while scanning supported indicator IDs, skipping interview...", @@ -739,7 +741,7 @@ export class IndicatorCC extends CommandClass { // The IDs are not stored by the report CCs so store them here once we have all of them this.setValue( - applHost, + ctx, IndicatorCCValues.supportedIndicatorIds, supportedIndicatorIds, ); @@ -748,7 +750,7 @@ export class IndicatorCC extends CommandClass { ", ", ) }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -758,7 +760,7 @@ export class IndicatorCC extends CommandClass { const manufacturerDefinedIndicatorIds = supportedIndicatorIds .filter((id) => isManufacturerDefinedIndicator(id)); if (manufacturerDefinedIndicatorIds.length > 0) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving description for manufacturer-defined indicator IDs...", @@ -773,27 +775,27 @@ export class IndicatorCC extends CommandClass { } // Query current values - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Indicator, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); if (api.version === 1) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current indicator value...", direction: "outbound", @@ -801,11 +803,11 @@ export class IndicatorCC extends CommandClass { await api.get(); } else { const supportedIndicatorIds: number[] = this.getValue( - applHost, + ctx, IndicatorCCValues.supportedIndicatorIds, ) ?? []; for (const indicatorId of supportedIndicatorIds) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `requesting current indicator value (id = ${ num2hex( diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 2e3dafc85673..9eb93b56f9ff 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -39,6 +39,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -1158,32 +1160,32 @@ export class IrrigationCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Irrigation, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying irrigation system info...", direction: "outbound", }); const systemInfo = await api.getSystemInfo(); if (!systemInfo) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Time out while querying irrigation system info, skipping interview...", @@ -1196,7 +1198,7 @@ supports master valve: ${systemInfo.supportsMasterValve} no. of valves: ${systemInfo.numValves} no. of valve tables: ${systemInfo.numValveTables} max. valve table size: ${systemInfo.maxValveTableSize}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -1205,39 +1207,39 @@ max. valve table size: ${systemInfo.maxValveTableSize}`; // For each valve, create the values to start/stop a run for (let i = 1; i <= systemInfo.numValves; i++) { this.ensureMetadata( - applHost, + ctx, IrrigationCCValues.valveRunDuration(i), ); this.ensureMetadata( - applHost, + ctx, IrrigationCCValues.valveRunStartStop(i), ); } // And create a shutoff value - this.ensureMetadata(applHost, IrrigationCCValues.shutoffSystem); + this.ensureMetadata(ctx, IrrigationCCValues.shutoffSystem); // Query current values - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Irrigation, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current system config - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying irrigation system configuration...", direction: "outbound", @@ -1266,7 +1268,7 @@ moisture sensor polarity: ${ ) }`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -1275,7 +1277,7 @@ moisture sensor polarity: ${ // and status // Query the current system config - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying irrigation system status...", direction: "outbound", @@ -1283,15 +1285,15 @@ moisture sensor polarity: ${ await api.getSystemStatus(); // for each valve, query the current status and configuration - if (IrrigationCC.supportsMasterValveCached(applHost, endpoint)) { - applHost.logNode(node.id, { + if (IrrigationCC.supportsMasterValveCached(ctx, endpoint)) { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying master valve configuration...", direction: "outbound", }); await api.getValveConfig("master"); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying master valve status...", direction: "outbound", @@ -1301,10 +1303,10 @@ moisture sensor polarity: ${ for ( let i = 1; - i <= (IrrigationCC.getNumValvesCached(applHost, endpoint) ?? 0); + i <= (IrrigationCC.getNumValvesCached(ctx, endpoint) ?? 0); i++ ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying configuration for valve ${ padStart( @@ -1317,7 +1319,7 @@ moisture sensor polarity: ${ }); await api.getValveConfig(i); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying status for valve ${ padStart( diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index d481c41ebaec..61c3ff329897 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -12,11 +12,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; @@ -25,6 +21,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -115,36 +113,36 @@ export class LanguageCC extends CommandClass { declare ccCommand: LanguageCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Language, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "requesting language setting...", direction: "outbound", }); @@ -154,7 +152,7 @@ export class LanguageCC extends CommandClass { const logMessage = `received current language setting: ${language}${ country != undefined ? `-${country}` : "" }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 3d7d77284bf3..24e0bb73bdae 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -10,11 +10,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, @@ -31,6 +27,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -139,42 +137,42 @@ export class LockCC extends CommandClass { declare ccCommand: LockCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Lock, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "requesting current lock state...", direction: "outbound", }); const locked = await api.get(); const logMessage = `the lock is ${locked ? "locked" : "unlocked"}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index 86c1a7de91eb..bdb222a7470f 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -4,10 +4,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext } from "@zwave-js/host/safe"; import { staticExtends } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, type CCAPIEndpoint, type CCAPIHost } from "../lib/API"; @@ -16,6 +13,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -225,20 +224,20 @@ export class ManufacturerProprietaryCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; // Read the manufacturer ID from Manufacturer Specific CC this.manufacturerId = this.getValue( - applHost, + ctx, ManufacturerSpecificCCValues.manufacturerId, )!; const pcInstance = this.createSpecificInstance(); if (pcInstance) { - await pcInstance.interview(applHost); + await pcInstance.interview(ctx); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `${this.constructor.name}: skipping interview refresh because the matching proprietary CC is not implemented...`, direction: "none", @@ -246,26 +245,26 @@ export class ManufacturerProprietaryCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; if (this.manufacturerId == undefined) { // Read the manufacturer ID from Manufacturer Specific CC this.manufacturerId = this.getValue( - applHost, + ctx, ManufacturerSpecificCCValues.manufacturerId, )!; } const pcInstance = this.createSpecificInstance(); if (pcInstance) { - await pcInstance.refreshValues(applHost); + await pcInstance.refreshValues(ctx); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `${this.constructor.name}: skipping value refresh because the matching proprietary CC is not implemented...`, direction: "none", diff --git a/packages/cc/src/cc/ManufacturerSpecificCC.ts b/packages/cc/src/cc/ManufacturerSpecificCC.ts index 3e57ee01132c..9f993fab4418 100644 --- a/packages/cc/src/cc/ManufacturerSpecificCC.ts +++ b/packages/cc/src/cc/ManufacturerSpecificCC.ts @@ -8,19 +8,15 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -180,24 +176,24 @@ export class ManufacturerSpecificCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Manufacturer Specific"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery }); - if (node.id !== applHost.ownNodeId) { - applHost.logNode(node.id, { + if (node.id !== ctx.ownNodeId) { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying manufacturer information...", direction: "outbound", @@ -207,14 +203,14 @@ export class ManufacturerSpecificCC extends CommandClass { const logMessage = `received response for manufacturer information: manufacturer: ${ - applHost.lookupManufacturer( + ctx.lookupManufacturer( mfResp.manufacturerId, ) || "unknown" } (${num2hex(mfResp.manufacturerId)}) product type: ${num2hex(mfResp.productType)} product id: ${num2hex(mfResp.productId)}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -223,7 +219,7 @@ export class ManufacturerSpecificCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index ed82d2df44c5..630976aab876 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -63,6 +63,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -278,23 +280,29 @@ export function isAccumulatedValue( switch (meterType) { case 0x01: // Electric return ( + // kVarh + // Pulse count scale === 0x00 // kWh || scale === 0x01 // kVAh - || scale === 0x03 // Pulse count - || scale === 0x08 // kVarh + || scale === 0x03 + || scale === 0x08 ); case 0x02: // Gas return ( + // Pulse count + // ft³ scale === 0x00 // m³ - || scale === 0x01 // ft³ - || scale === 0x03 // Pulse count + || scale === 0x01 + || scale === 0x03 ); case 0x03: // Water return ( + // Pulse count + // US gallons scale === 0x00 // m³ || scale === 0x01 // ft³ - || scale === 0x02 // US gallons - || scale === 0x03 // Pulse count + || scale === 0x02 + || scale === 0x03 ); case 0x04: // Heating return scale === 0x00; // kWh @@ -638,26 +646,26 @@ export class MeterCC extends CommandClass { declare ccCommand: MeterCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Meter, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying meter support...", direction: "outbound", @@ -684,13 +692,13 @@ supported rate types: ${ .join("") } supports reset: ${suppResp.supportsReset}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying meter support timed out, skipping interview...", @@ -701,48 +709,48 @@ supports reset: ${suppResp.supportsReset}`; } // Query current meter values - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Meter, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); if (api.version === 1) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying default meter value...`, direction: "outbound", }); await api.get(); } else { - const type: number = this.getValue(applHost, MeterCCValues.type) + const type: number = this.getValue(ctx, MeterCCValues.type) ?? 0; const supportedScales: readonly number[] = - this.getValue(applHost, MeterCCValues.supportedScales) ?? []; + this.getValue(ctx, MeterCCValues.supportedScales) ?? []; const supportedRateTypes: readonly RateType[] = - this.getValue(applHost, MeterCCValues.supportedRateTypes) ?? []; + this.getValue(ctx, MeterCCValues.supportedRateTypes) ?? []; const rateTypes = supportedRateTypes.length ? supportedRateTypes : [undefined]; for (const rateType of rateTypes) { for (const scale of supportedScales) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying meter value (type = ${ getMeterName(type) diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 6e315b466bc2..568ab030f9b8 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -29,6 +29,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -460,38 +462,38 @@ export class MultiChannelAssociationCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const mcAPI = CCAPI.create( CommandClasses["Multi Channel Association"], - applHost, + ctx, endpoint, ); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First find out how many groups are supported as multi channel - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying number of multi channel association groups...", direction: "outbound", }); const mcGroupCount = await mcAPI.getGroupCount(); if (mcGroupCount != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `supports ${mcGroupCount} multi channel association groups`, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying multi channel association groups timed out, skipping interview...", @@ -501,48 +503,48 @@ export class MultiChannelAssociationCC extends CommandClass { } // Query each association group for its members - await this.refreshValues(applHost); + await this.refreshValues(ctx); // And set up lifeline associations - await ccUtils.configureLifelineAssociations(applHost, endpoint); + await ccUtils.configureLifelineAssociations(ctx, endpoint); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const mcAPI = CCAPI.create( CommandClasses["Multi Channel Association"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const assocAPI = CCAPI.create( CommandClasses.Association, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const mcGroupCount: number = this.getValue( - applHost, + ctx, MultiChannelAssociationCCValues.groupCount, ) ?? 0; // Some devices report more association groups than multi channel association groups, so we need this info here const assocGroupCount: number = - this.getValue(applHost, AssociationCCValues.groupCount) + this.getValue(ctx, AssociationCCValues.groupCount) || mcGroupCount; // Then query each multi channel association group for (let groupId = 1; groupId <= mcGroupCount; groupId++) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying multi channel association group #${groupId}...`, @@ -567,7 +569,7 @@ currently assigned endpoints: ${ }) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -576,7 +578,7 @@ currently assigned endpoints: ${ // Check if there are more non-multi-channel association groups we haven't queried yet if (assocAPI.isSupported() && assocGroupCount > mcGroupCount) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying additional non-multi-channel association groups...`, @@ -587,7 +589,7 @@ currently assigned endpoints: ${ groupId <= assocGroupCount; groupId++ ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying association group #${groupId}...`, direction: "outbound", @@ -598,7 +600,7 @@ currently assigned endpoints: ${ `received information for association group #${groupId}: maximum # of nodes: ${group.maxNodes} currently assigned nodes: ${group.nodeIds.map(String).join(", ")}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 06cf85a588f1..83fea4b43d3f 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -32,6 +32,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -441,15 +442,13 @@ export class MultiChannelCC extends CommandClass { return true; } - public async interview( - applHost: ZWaveApplicationHost, - ): Promise { - const node = this.getNode(applHost)!; + public async interview(ctx: InterviewContext): Promise { + const node = this.getNode(ctx)!; - const removeEndpoints = applHost.getDeviceConfig?.(node.id)?.compat + const removeEndpoints = ctx.getDeviceConfig?.(node.id)?.compat ?.removeEndpoints; if (removeEndpoints === "*") { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Skipping ${this.ccName} interview b/c all endpoints are ignored by the device config file...`, @@ -458,35 +457,35 @@ export class MultiChannelCC extends CommandClass { return; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Special interview procedure for legacy nodes - const ccVersion = getEffectiveCCVersion(applHost, this); - if (ccVersion === 1) return this.interviewV1(applHost); + const ccVersion = getEffectiveCCVersion(ctx, this); + if (ccVersion === 1) return this.interviewV1(ctx); const endpoint = node.getEndpoint(this.endpointIndex)!; const api = CCAPI.create( CommandClasses["Multi Channel"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); // Step 1: Retrieve general information about end points - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying device endpoint information...", direction: "outbound", }); const multiResponse = await api.getEndpoints(); if (!multiResponse) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying device endpoint information timed out, aborting interview...", @@ -503,7 +502,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; logMessage += `\nendpoint count (aggregated): ${multiResponse.aggregatedEndpointCount}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -523,7 +522,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; }; if (api.supportsCommand(MultiChannelCommand.EndPointFind)) { // Step 2a: Find all endpoints - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying all endpoints...", direction: "outbound", @@ -533,7 +532,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; if (foundEndpoints) allEndpoints.push(...foundEndpoints); if (!allEndpoints.length) { // Create a sequential list of endpoints - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Endpoint query returned no results, assuming that endpoints are sequential`, @@ -541,7 +540,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; }); addSequentialEndpoints(); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received endpoints: ${ allEndpoints @@ -553,7 +552,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; } } else { // Step 2b: Assume that the endpoints are in sequential order - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `does not support EndPointFind, assuming that endpoints are sequential`, @@ -564,7 +563,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; // Step 2.5: remove ignored endpoints if (removeEndpoints?.length) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `The following endpoints are ignored through the config file: ${ @@ -587,7 +586,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; && ccVersion >= 4 ) { // Find members of aggregated end point - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying members of aggregated endpoint #${endpoint}...`, @@ -595,7 +594,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; }); const members = await api.getAggregatedMembers(endpoint); if (members) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `aggregated endpoint #${endpoint} has members ${ @@ -611,7 +610,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; // When the device reports identical capabilities for all endpoints, // we don't need to query them all if (multiResponse.identicalCapabilities && hasQueriedCapabilities) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `all endpoints identical, skipping capability query for endpoint #${endpoint}...`, @@ -639,7 +638,7 @@ identical capabilities: ${multiResponse.identicalCapabilities}`; continue; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying capabilities for endpoint #${endpoint}...`, direction: "outbound", @@ -656,13 +655,13 @@ supported CCs:`; for (const cc of caps.supportedCCs) { logMessage += `\n · ${getCCName(cc)}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying endpoint #${endpoint} capabilities timed out, aborting interview...`, @@ -676,19 +675,19 @@ supported CCs:`; // But first figure out if they seem unnecessary and if they do, which ones should be preserved if ( !multiResponse.identicalCapabilities - && areEndpointsUnnecessary(applHost, node.id, allEndpoints) + && areEndpointsUnnecessary(ctx, node.id, allEndpoints) ) { - const preserve = applHost.getDeviceConfig?.(node.id)?.compat + const preserve = ctx.getDeviceConfig?.(node.id)?.compat ?.preserveEndpoints; if (!preserve) { allEndpoints = []; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Endpoints seem unnecessary b/c they have different device classes, ignoring all...`, }); } else if (preserve === "*") { // preserve all endpoints, do nothing - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Endpoints seem unnecessary, but are configured to be preserved.`, }); @@ -696,7 +695,7 @@ supported CCs:`; allEndpoints = allEndpoints.filter((ep) => preserve.includes(ep) ); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Endpoints seem unnecessary, but endpoints ${ allEndpoints.join( ", ", @@ -706,26 +705,24 @@ supported CCs:`; } } this.setValue( - applHost, + ctx, MultiChannelCCValues.endpointIndizes, allEndpoints, ); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } - private async interviewV1( - applHost: ZWaveApplicationHost, - ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + private async interviewV1(ctx: InterviewContext): Promise { + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Multi Channel"], - applHost, + ctx, endpoint, ); - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); // V1 works the opposite way - we scan all CCs and remember how many // endpoints they have @@ -743,7 +740,7 @@ supported CCs:`; ); const endpointCounts = new Map(); for (const ccId of supportedCCs) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `Querying endpoint count for CommandClass ${ getCCName( ccId, @@ -755,7 +752,7 @@ supported CCs:`; if (endpointCount != undefined) { endpointCounts.set(ccId, endpointCount); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `CommandClass ${ getCCName( ccId, @@ -770,24 +767,24 @@ supported CCs:`; // We have only individual and no dynamic and no aggregated endpoints const numEndpoints = Math.max(...endpointCounts.values()); this.setValue( - applHost, + ctx, MultiChannelCCValues.endpointCountIsDynamic, false, ); this.setValue( - applHost, + ctx, MultiChannelCCValues.aggregatedEndpointCount, 0, ); this.setValue( - applHost, + ctx, MultiChannelCCValues.individualEndpointCount, numEndpoints, ); // Since we queried all CCs separately, we can assume that all // endpoints have different capabilities this.setValue( - applHost, + ctx, MultiChannelCCValues.endpointsHaveIdenticalCapabilities, false, ); @@ -805,7 +802,7 @@ supported CCs:`; } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 776eff4246f6..02a464946962 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -54,6 +54,8 @@ import { type CCResponsePredicate, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -395,19 +397,19 @@ export class MultilevelSensorCC extends CommandClass { declare ccCommand: MultilevelSensorCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Multilevel Sensor"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -415,7 +417,7 @@ export class MultilevelSensorCC extends CommandClass { if (api.version >= 5) { // Query the supported sensor types - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving supported sensor types...", direction: "outbound", @@ -427,13 +429,13 @@ export class MultilevelSensorCC extends CommandClass { .map((t) => getSensorName(t)) .map((name) => `· ${name}`) .join("\n"); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported sensor types timed out, skipping interview...", @@ -445,7 +447,7 @@ export class MultilevelSensorCC extends CommandClass { // As well as the supported scales for each sensor for (const type of sensorTypes) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying supported scales for ${ getSensorName(type) @@ -463,13 +465,13 @@ export class MultilevelSensorCC extends CommandClass { ) .map((name) => `· ${name}`) .join("\n"); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported scales timed out, skipping interview...", @@ -480,29 +482,29 @@ export class MultilevelSensorCC extends CommandClass { } } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Multilevel Sensor"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - const valueDB = this.getValueDB(applHost); + const valueDB = this.getValueDB(ctx); if (api.version <= 4) { // Sensors up to V4 only support a single value - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current sensor reading...", direction: "outbound", @@ -518,7 +520,7 @@ sensor type: ${getSensorName(mlsResponse.type)} value: ${mlsResponse.value}${ sensorScale?.unit ? ` ${sensorScale.unit}` : "" }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -533,7 +535,7 @@ value: ${mlsResponse.value}${ }) || []; for (const type of sensorTypes) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying ${ getSensorName(type) @@ -546,7 +548,7 @@ value: ${mlsResponse.value}${ const logMessage = `received current ${ getSensorName(type) } sensor reading: ${value.value} ${value.scale.unit || ""}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index 95afbbe73d48..bc14ee53e3bb 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -36,6 +36,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -521,19 +523,19 @@ export class MultilevelSwitchCC extends CommandClass { declare ccCommand: MultilevelSwitchCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Multilevel Switch"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -541,14 +543,14 @@ export class MultilevelSwitchCC extends CommandClass { if (api.version >= 3) { // Find out which kind of switch this is - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting switch type...", direction: "outbound", }); const switchType = await api.getSupported(); if (switchType != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `has switch type ${ getEnumMemberName( @@ -562,29 +564,29 @@ export class MultilevelSwitchCC extends CommandClass { } else { // requesting the switch type automatically creates the up/down actions // We need to do this manually for V1 and V2 - this.createMetadataForLevelChangeActions(applHost); + this.createMetadataForLevelChangeActions(ctx); } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Multilevel Switch"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "requesting current switch state...", direction: "outbound", diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index 4443556af714..c524e776957a 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -9,11 +9,7 @@ import { ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, @@ -30,6 +26,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -211,54 +209,54 @@ export class NodeNamingAndLocationCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Node Naming and Location"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "retrieving node name...", direction: "outbound", }); const name = await api.getName(); if (name != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `is named "${name}"`, direction: "inbound", }); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "retrieving node location...", direction: "outbound", }); const location = await api.getLocation(); if (location != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `received location: ${location}`, direction: "inbound", }); diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index eab3b0e84798..d50201f0e5fe 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -58,7 +58,9 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, InvalidCC, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -568,19 +570,19 @@ export class NotificationCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Notification, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -590,13 +592,13 @@ export class NotificationCC extends CommandClass { // we must associate ourselves with that channel try { await ccUtils.assignLifelineIssueingCommand( - applHost, + ctx, endpoint, this.ccId, NotificationCommand.Report, ); } catch { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Configuring associations to receive ${ getCCName( @@ -609,7 +611,7 @@ export class NotificationCC extends CommandClass { let supportsV1Alarm = false; if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported notification types...", direction: "outbound", @@ -617,7 +619,7 @@ export class NotificationCC extends CommandClass { const suppResponse = await api.getSupported(); if (!suppResponse) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported notification types timed out, skipping interview...", @@ -641,7 +643,7 @@ export class NotificationCC extends CommandClass { .map((name) => `\n· ${name}`) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -653,7 +655,7 @@ export class NotificationCC extends CommandClass { const type = supportedNotificationTypes[i]; const name = supportedNotificationNames[i]; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying supported notification events for ${name}...`, @@ -662,7 +664,7 @@ export class NotificationCC extends CommandClass { const supportedEvents = await api.getSupportedEvents(type); if (supportedEvents) { supportedNotificationEvents.set(type, supportedEvents); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received supported notification events for ${name}: ${ @@ -678,24 +680,24 @@ export class NotificationCC extends CommandClass { // Determine whether the node is a push or pull node let notificationMode = this.getValue<"push" | "pull">( - applHost, + ctx, NotificationCCValues.notificationMode, ); if (notificationMode !== "push" && notificationMode !== "pull") { notificationMode = await this.determineNotificationMode( - applHost, + ctx, api, supportedNotificationEvents, ); this.setValue( - applHost, + ctx, NotificationCCValues.notificationMode, notificationMode, ); } if (notificationMode === "pull") { - await this.refreshValues(applHost); + await this.refreshValues(ctx); } /* if (notificationMode === "push") */ else { for (let i = 0; i < supportedNotificationTypes.length; i++) { const type = supportedNotificationTypes[i]; @@ -703,7 +705,7 @@ export class NotificationCC extends CommandClass { const notification = getNotification(type); // Enable reports for each notification type - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `enabling notifications for ${name}...`, direction: "outbound", @@ -735,11 +737,11 @@ export class NotificationCC extends CommandClass { // * do this only if the last update was more than 5 minutes ago // * schedule an auto-idle if the last update was less than 5 minutes ago but before the current applHost start if ( - this.getValue(applHost, value) + this.getValue(ctx, value) == undefined ) { this.setValue( - applHost, + ctx, value, 0, /* idle */ ); @@ -754,12 +756,12 @@ export class NotificationCC extends CommandClass { // Only create metadata for V1 values if necessary if (api.version === 1 || supportsV1Alarm) { - this.ensureMetadata(applHost, NotificationCCValues.alarmType); - this.ensureMetadata(applHost, NotificationCCValues.alarmLevel); + this.ensureMetadata(ctx, NotificationCCValues.alarmType); + this.ensureMetadata(ctx, NotificationCCValues.alarmLevel); } // Also create metadata for values mapped through compat config - const mappings = applHost.getDeviceConfig?.(this.nodeId as number) + const mappings = ctx.getDeviceConfig?.(this.nodeId as number) ?.compat?.alarmMapping; if (mappings) { // Find all mappings to a valid notification variable @@ -793,11 +795,11 @@ export class NotificationCC extends CommandClass { // Create or update the metadata const metadata = getNotificationValueMetadata( - this.getMetadata(applHost, notificationValue), + this.getMetadata(ctx, notificationValue), notification, valueConfig, ); - this.setMetadata(applHost, notificationValue, metadata); + this.setMetadata(ctx, notificationValue, metadata); // Set the value to idle if it has no value yet if (valueConfig.idle) { @@ -805,10 +807,10 @@ export class NotificationCC extends CommandClass { // * do this only if the last update was more than 5 minutes ago // * schedule an auto-idle if the last update was less than 5 minutes ago but before the current applHost start if ( - this.getValue(applHost, notificationValue) == undefined + this.getValue(ctx, notificationValue) == undefined ) { this.setValue( - applHost, + ctx, notificationValue, 0, /* idle */ ); @@ -818,13 +820,13 @@ export class NotificationCC extends CommandClass { // Remember supported notification types and events in the cache this.setValue( - applHost, + ctx, NotificationCCValues.supportedNotificationTypes, [...supportedNotifications.keys()], ); for (const [type, events] of supportedNotifications) { this.setValue( - applHost, + ctx, NotificationCCValues.supportedNotificationEvents(type), [...events], ); @@ -832,19 +834,19 @@ export class NotificationCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; // Refreshing values only works on pull nodes - if (NotificationCC.getNotificationMode(applHost, node) === "pull") { - const endpoint = this.getEndpoint(applHost)!; + if (NotificationCC.getNotificationMode(ctx, node) === "pull") { + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Notification, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, @@ -852,7 +854,7 @@ export class NotificationCC extends CommandClass { // Load supported notification types and events from cache const supportedNotificationTypes = this.getValue( - applHost, + ctx, NotificationCCValues.supportedNotificationTypes, ) ?? []; const supportedNotificationNames = supportedNotificationTypes.map( @@ -864,7 +866,7 @@ export class NotificationCC extends CommandClass { const name = supportedNotificationNames[i]; // Always query each notification for its current status - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying notification status for ${name}...`, direction: "outbound", @@ -882,7 +884,7 @@ export class NotificationCC extends CommandClass { // Remember when we did this this.setValue( - applHost, + ctx, NotificationCCValues.lastRefresh, Date.now(), ); diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index d3e771bfe405..f7013a94fdcf 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -36,6 +36,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -358,19 +360,19 @@ export class ProtectionCC extends CommandClass { declare ccCommand: ProtectionCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Protection, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -382,7 +384,7 @@ export class ProtectionCC extends CommandClass { // First find out what the device supports if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying protection capabilities...", direction: "outbound", }); @@ -407,7 +409,7 @@ RF protection states: ${ .map((str) => `\n· ${str}`) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -416,36 +418,36 @@ RF protection states: ${ } } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - if (!hadCriticalTimeout) this.setInterviewComplete(applHost, true); + if (!hadCriticalTimeout) this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Protection, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const supportsExclusiveControl = !!this.getValue( - applHost, + ctx, ProtectionCCValues.supportsExclusiveControl, ); const supportsTimeout = !!this.getValue( - applHost, + ctx, ProtectionCCValues.supportsTimeout, ); // Query the current state - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying protection status...", direction: "outbound", }); @@ -457,7 +459,7 @@ local: ${getEnumMemberName(LocalProtectionState, protectionResp.local)}`; logMessage += ` rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -465,13 +467,13 @@ rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; if (supportsTimeout) { // Query the current timeout - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying protection timeout...", direction: "outbound", }); const timeout = await api.getTimeout(); if (timeout) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `received timeout: ${timeout.toString()}`, direction: "inbound", }); @@ -480,13 +482,13 @@ rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; if (supportsExclusiveControl) { // Query the current timeout - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying exclusive control node...", direction: "outbound", }); const nodeId = await api.getExclusiveControl(); if (nodeId != undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: (nodeId !== 0 ? `Node ${padStart(nodeId.toString(), 3, "0")}` : `no node`) + ` has exclusive control`, diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index bca070f34964..5bcc92f658ac 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -34,6 +34,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -299,11 +300,11 @@ export class SceneActuatorConfigurationCC extends CommandClass { // eslint-disable-next-line @typescript-eslint/require-await public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `${this.constructor.name}: setting metadata`, direction: "none", }); @@ -313,14 +314,14 @@ export class SceneActuatorConfigurationCC extends CommandClass { const levelValue = SceneActuatorConfigurationCCValues.level( sceneId, ); - this.ensureMetadata(applHost, levelValue); + this.ensureMetadata(ctx, levelValue); const dimmingDurationValue = SceneActuatorConfigurationCCValues .dimmingDuration(sceneId); - this.ensureMetadata(applHost, dimmingDurationValue); + this.ensureMetadata(ctx, dimmingDurationValue); } - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } // `refreshValues()` would create 255 `Get` commands to be issued to the node diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 44abb7bbfe77..6e09a2e52354 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -36,6 +36,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -377,23 +379,23 @@ export class SceneControllerConfigurationCC extends CommandClass { // eslint-disable-next-line @typescript-eslint/require-await public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); const groupCount = SceneControllerConfigurationCC.getGroupCountCached( - applHost, + ctx, endpoint, ); if (groupCount === 0) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `skipping Scene Controller Configuration interview because Association group count is unknown`, @@ -409,41 +411,41 @@ export class SceneControllerConfigurationCC extends CommandClass { const sceneIdValue = SceneControllerConfigurationCCValues.sceneId( groupId, ); - this.ensureMetadata(applHost, sceneIdValue); + this.ensureMetadata(ctx, sceneIdValue); const dimmingDurationValue = SceneControllerConfigurationCCValues .dimmingDuration(groupId); - this.ensureMetadata(applHost, dimmingDurationValue); + this.ensureMetadata(ctx, dimmingDurationValue); } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Scene Controller Configuration"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const groupCount = SceneControllerConfigurationCC.getGroupCountCached( - applHost, + ctx, endpoint, ); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying all scene controller configurations...", direction: "outbound", }); for (let groupId = 1; groupId <= groupCount; groupId++) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying scene configuration for group #${groupId}...`, @@ -455,7 +457,7 @@ export class SceneControllerConfigurationCC extends CommandClass { `received scene configuration for group #${groupId}: scene ID: ${group.sceneId} dimming duration: ${group.dimmingDuration.toString()}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 0d7360a14586..5258f3411ec8 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -32,6 +32,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -697,25 +698,25 @@ export class ScheduleEntryLockCC extends CommandClass { declare ccCommand: ScheduleEntryLockCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Schedule Entry Lock"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported number of schedule slots...", direction: "outbound", @@ -729,7 +730,7 @@ day of year: ${slotsResp.numYearDaySlots}`; logMessage += ` daily repeating: ${slotsResp.numDailyRepeatingSlots}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -742,7 +743,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; && (!endpoint.supportsCC(CommandClasses.Time) || endpoint.getCCVersion(CommandClasses.Time) < 2) ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "setting timezone information...", direction: "outbound", @@ -753,7 +754,7 @@ daily repeating: ${slotsResp.numDailyRepeatingSlots}`; } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } /** diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 24d055c1e084..f550ff7f87b0 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -40,7 +40,6 @@ import type { CCEncodingContext, CCParsingContext, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; @@ -48,10 +47,10 @@ import { isArray } from "alcalzone-shared/typeguards"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, type CCResponseRole, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -661,19 +660,19 @@ export class Security2CC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { const securityManager = getSecurityManager( - applHost.ownNodeId, - applHost, + ctx.ownNodeId, + ctx, this.nodeId, ); - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Security 2"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, @@ -696,7 +695,7 @@ export class Security2CC extends CommandClass { ]; } else { // For endpoint interviews, the security class MUST be known - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Cannot query securely supported commands for endpoint because the node's security class isn't known...`, @@ -720,7 +719,7 @@ export class Security2CC extends CommandClass { if ( !securityManager?.hasKeysForSecurityClass(secClass) ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Cannot query securely supported commands (${ getEnumMemberName( @@ -733,7 +732,7 @@ export class Security2CC extends CommandClass { continue; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -770,7 +769,7 @@ export class Security2CC extends CommandClass { ) { if (attempts < MAX_ATTEMPTS) { // We definitely know the highest security class - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -783,7 +782,7 @@ export class Security2CC extends CommandClass { await wait(500); continue; } else if (endpoint.index > 0) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -802,7 +801,7 @@ export class Security2CC extends CommandClass { break; } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: `Querying securely supported commands (${ getEnumMemberName( @@ -829,7 +828,7 @@ export class Security2CC extends CommandClass { // unless we were sure about the security class node.setSecurityClass(secClass, false); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `The node was NOT granted the security class ${ getEnumMemberName( SecurityClass, @@ -846,7 +845,7 @@ export class Security2CC extends CommandClass { // Mark the security class as granted unless we were sure about the security class node.setSecurityClass(secClass, true); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `The node was granted the security class ${ getEnumMemberName( SecurityClass, @@ -872,7 +871,7 @@ export class Security2CC extends CommandClass { for (const cc of supportedCCs) { logLines.push(`· ${getCCName(cc)}`); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: endpoint.index, message: logLines.join("\n"), direction: "inbound", @@ -896,7 +895,7 @@ export class Security2CC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } /** Tests if a command should be sent secure and thus requires encapsulation */ diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 421d9ef15241..071c36699ee8 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -33,9 +33,9 @@ import { randomBytes } from "node:crypto"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -379,19 +379,19 @@ export class SecurityCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Security, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "Querying securely supported commands (S0)...", direction: "outbound", }); @@ -408,7 +408,7 @@ export class SecurityCC extends CommandClass { controlledCCs = resp.controlledCCs; break; } else if (attempts < MAX_ATTEMPTS) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying securely supported commands (S0), attempt ${attempts}/${MAX_ATTEMPTS} failed. Retrying in 500ms...`, @@ -420,7 +420,7 @@ export class SecurityCC extends CommandClass { if (!supportedCCs || !controlledCCs) { if (node.hasSecurityClass(SecurityClass.S0_Legacy) === true) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying securely supported commands (S0) failed", level: "warn", @@ -429,7 +429,7 @@ export class SecurityCC extends CommandClass { } else { // We didn't know if the node was secure and it didn't respond, // assume that it doesn't have the S0 security class - applHost.logNode( + ctx.logNode( node.id, `The node was not granted the S0 security class. Continuing interview non-securely.`, ); @@ -449,7 +449,7 @@ export class SecurityCC extends CommandClass { for (const cc of controlledCCs) { logLines.push(`· ${getCCName(cc)}`); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logLines.join("\n"), direction: "inbound", }); @@ -485,14 +485,14 @@ export class SecurityCC extends CommandClass { // We know for sure that the node is included securely if (node.hasSecurityClass(SecurityClass.S0_Legacy) !== true) { node.setSecurityClass(SecurityClass.S0_Legacy, true); - applHost.logNode( + ctx.logNode( node.id, `The node was granted the S0 security class`, ); } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } /** Tests if a command should be sent secure and thus requires encapsulation */ diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index f23888eea97c..8dda10b755c8 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -11,11 +11,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { clamp } from "alcalzone-shared/math"; @@ -30,10 +26,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, type CCResponsePredicate, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -374,37 +370,37 @@ export class SoundSwitchCC extends CommandClass { declare ccCommand: SoundSwitchCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Sound Switch"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "requesting tone count...", direction: "outbound", }); const toneCount = await api.getToneCount(); if (toneCount != undefined) { const logMessage = `supports ${toneCount} tones`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying tone count timed out, skipping interview...", level: "warn", @@ -412,7 +408,7 @@ export class SoundSwitchCC extends CommandClass { return; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "requesting current sound configuration...", direction: "outbound", }); @@ -421,7 +417,7 @@ export class SoundSwitchCC extends CommandClass { const logMessage = `received current sound configuration: default tone ID: ${config.defaultToneId} default volume: ${config.defaultVolume}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -429,7 +425,7 @@ default volume: ${config.defaultVolume}`; const metadataStates: Record = {}; for (let toneId = 1; toneId <= toneCount; toneId++) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: `requesting info for tone #${toneId}`, direction: "outbound", }); @@ -438,7 +434,7 @@ default volume: ${config.defaultVolume}`; const logMessage = `received info for tone #${toneId}: name: ${info.name} duration: ${info.duration} seconds`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -446,7 +442,7 @@ duration: ${info.duration} seconds`; } // Remember tone count and info on the default tone ID metadata - this.setMetadata(applHost, SoundSwitchCCValues.defaultToneId, { + this.setMetadata(ctx, SoundSwitchCCValues.defaultToneId, { ...SoundSwitchCCValues.defaultToneId.meta, min: 1, max: toneCount, @@ -454,7 +450,7 @@ duration: ${info.duration} seconds`; }); // Remember tone count and info on the tone ID metadata - this.setMetadata(applHost, SoundSwitchCCValues.toneId, { + this.setMetadata(ctx, SoundSwitchCCValues.toneId, { ...SoundSwitchCCValues.toneId.meta, min: 0, max: toneCount, @@ -466,7 +462,7 @@ duration: ${info.duration} seconds`; }); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index 2df5dd29b052..101b02f3c008 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -34,6 +34,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -239,26 +241,26 @@ export class ThermostatFanModeCC extends CommandClass { declare ccCommand: ThermostatFanModeCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Fan Mode"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First query the possible modes to set the metadata - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported thermostat fan modes...", direction: "outbound", @@ -274,13 +276,13 @@ export class ThermostatFanModeCC extends CommandClass { ) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported thermostat fan modes timed out, skipping interview...", @@ -288,27 +290,27 @@ export class ThermostatFanModeCC extends CommandClass { return; } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Fan Mode"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current status - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current thermostat fan mode...", direction: "outbound", @@ -324,7 +326,7 @@ export class ThermostatFanModeCC extends CommandClass { if (currentStatus.off != undefined) { logMessage += ` (turned off)`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/ThermostatFanStateCC.ts b/packages/cc/src/cc/ThermostatFanStateCC.ts index 1093c67651ea..51edac9af02f 100644 --- a/packages/cc/src/cc/ThermostatFanStateCC.ts +++ b/packages/cc/src/cc/ThermostatFanStateCC.ts @@ -8,7 +8,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { GetValueDB, ZWaveApplicationHost } from "@zwave-js/host/safe"; +import type { GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { CCAPI, @@ -17,9 +17,10 @@ import { throwUnsupportedProperty, } from "../lib/API"; import { - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, } from "../lib/CommandClass"; import { API, @@ -101,44 +102,44 @@ export class ThermostatFanStateCC extends CommandClass { declare ccCommand: ThermostatFanStateCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Fan State"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current status - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current thermostat fan state...", direction: "outbound", }); const currentStatus = await api.get(); if (currentStatus) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "received current thermostat fan state: " + getEnumMemberName(ThermostatFanState, currentStatus), diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index d33e09fc818d..bbee588b7fa5 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -35,6 +35,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -220,26 +222,26 @@ export class ThermostatModeCC extends CommandClass { declare ccCommand: ThermostatModeCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Mode"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // First query the possible modes to set the metadata - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported thermostat modes...", direction: "outbound", @@ -254,13 +256,13 @@ export class ThermostatModeCC extends CommandClass { ) .join("") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported thermostat modes timed out, skipping interview...", @@ -269,34 +271,34 @@ export class ThermostatModeCC extends CommandClass { return; } - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Mode"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current status - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying current thermostat mode...", direction: "outbound", }); const currentStatus = await api.get(); if (currentStatus) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "received current thermostat mode: " + getEnumMemberName(ThermostatMode, currentStatus.mode), diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index 82700511fd8e..205603f7b565 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -7,7 +7,7 @@ import { enumValuesToMetadataStates, validatePayload, } from "@zwave-js/core/safe"; -import type { GetValueDB, ZWaveApplicationHost } from "@zwave-js/host/safe"; +import type { GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { CCAPI, @@ -20,6 +20,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, } from "../lib/CommandClass"; import { API, @@ -105,37 +107,37 @@ export class ThermostatOperatingStateCC extends CommandClass { declare ccCommand: ThermostatOperatingStateCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Operating State"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the current state - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying thermostat operating state...", direction: "outbound", @@ -143,7 +145,7 @@ export class ThermostatOperatingStateCC extends CommandClass { const state = await api.get(); if (state) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `received current thermostat operating state: ${ getEnumMemberName( diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 345073ac18ec..9a0ac218e926 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -6,11 +6,7 @@ import { type SupervisionResult, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -24,6 +20,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -119,37 +117,37 @@ export class ThermostatSetbackCC extends CommandClass { declare ccCommand: ThermostatSetbackCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - await this.refreshValues(applHost); + await this.refreshValues(ctx); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Setback"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); // Query the thermostat state - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying the current thermostat state...", direction: "outbound", @@ -159,7 +157,7 @@ export class ThermostatSetbackCC extends CommandClass { const logMessage = `received current state: setback type: ${getEnumMemberName(SetbackType, setbackResp.setbackType)} setback state: ${setbackResp.setbackState}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index d79857cf761e..d0a731559d14 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -39,6 +39,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -341,19 +343,19 @@ export class ThermostatSetpointCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Setpoint"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -384,7 +386,7 @@ export class ThermostatSetpointCC extends CommandClass { type, ); // Every time, query the current value - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value of setpoint ${setpointName}...`, @@ -406,7 +408,7 @@ export class ThermostatSetpointCC extends CommandClass { // We're sure about the interpretation - this should not happen logMessage = `setpoint ${setpointName} is not supported`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -415,7 +417,7 @@ export class ThermostatSetpointCC extends CommandClass { // Remember which setpoint types are actually supported this.setValue( - applHost, + ctx, ThermostatSetpointCCValues.supportedSetpointTypes, supportedSetpointTypes, ); @@ -424,7 +426,7 @@ export class ThermostatSetpointCC extends CommandClass { // Query the supported setpoint types let setpointTypes: ThermostatSetpointType[] = []; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving supported setpoint types...", direction: "outbound", @@ -439,13 +441,13 @@ export class ThermostatSetpointCC extends CommandClass { ) .map((name) => `· ${name}`) .join("\n"); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying supported setpoint types timed out, skipping interview...", @@ -460,7 +462,7 @@ export class ThermostatSetpointCC extends CommandClass { type, ); // Find out the capabilities of this setpoint - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `retrieving capabilities for setpoint ${setpointName}...`, @@ -478,7 +480,7 @@ export class ThermostatSetpointCC extends CommandClass { `received capabilities for setpoint ${setpointName}: minimum value: ${setpointCaps.minValue} ${minValueUnit} maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -487,28 +489,28 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; } // Query the current value for all setpoint types - await this.refreshValues(applHost); + await this.refreshValues(ctx); } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Thermostat Setpoint"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const setpointTypes: ThermostatSetpointType[] = this.getValue( - applHost, + ctx, ThermostatSetpointCCValues.supportedSetpointTypes, ) ?? []; @@ -519,7 +521,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; type, ); // Every time, query the current value - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying current value of setpoint ${setpointName}...`, @@ -531,7 +533,7 @@ maximum value: ${setpointCaps.maxValue} ${maxValueUnit}`; `received current value of setpoint ${setpointName}: ${setpoint.value} ${ setpoint.scale.unit ?? "" }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index 52dd4e1894af..5c72beb053e9 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -11,20 +11,16 @@ import { validatePayload, } from "@zwave-js/core"; import { type MaybeNotKnown } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -193,19 +189,19 @@ export class TimeCC extends CommandClass { declare ccCommand: TimeCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses.Time, - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -213,7 +209,7 @@ export class TimeCC extends CommandClass { // Synchronize the slave's time if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "setting timezone information...", direction: "outbound", @@ -224,7 +220,7 @@ export class TimeCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index 6e1ab0a64e6b..f60416d42441 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -34,6 +34,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -224,26 +225,26 @@ export class TimeParametersCC extends CommandClass { declare ccCommand: TimeParametersCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Time Parameters"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); // Synchronize the node's time - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "setting current time...", direction: "outbound", @@ -251,7 +252,7 @@ export class TimeParametersCC extends CommandClass { await api.set(new Date()); // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 45e74c1229e9..42ec0521611b 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -46,6 +46,8 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, + type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -887,19 +889,19 @@ export class UserCodeCC extends CommandClass { declare ccCommand: UserCodeCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["User Code"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -907,13 +909,13 @@ export class UserCodeCC extends CommandClass { // Query capabilities first to determine what needs to be done when refreshing if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying capabilities...", direction: "outbound", }); const caps = await api.getCapabilities(); if (!caps) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "User Code capabilities query timed out, skipping interview...", @@ -923,13 +925,13 @@ export class UserCodeCC extends CommandClass { } } - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying number of user codes...", direction: "outbound", }); const supportedUsers = await api.getUsersCount(); if (supportedUsers == undefined) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "Querying number of user codes timed out, skipping interview...", @@ -939,71 +941,71 @@ export class UserCodeCC extends CommandClass { } for (let userId = 1; userId <= supportedUsers; userId++) { - setUserCodeMetadata.call(this, applHost, userId); + setUserCodeMetadata.call(this, ctx, userId); } // Synchronize user codes and settings - if (applHost.getInterviewOptions()?.queryAllUserCodes) { - await this.refreshValues(applHost); + if (ctx.getInterviewOptions()?.queryAllUserCodes) { + await this.refreshValues(ctx); } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["User Code"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); const supportsAdminCode: boolean = UserCodeCC.supportsAdminCodeCached( - applHost, + ctx, endpoint, ); const supportsUserCodeChecksum: boolean = this.getValue( - applHost, + ctx, UserCodeCCValues.supportsUserCodeChecksum, ) ?? false; const supportedKeypadModes: readonly KeypadMode[] = - this.getValue(applHost, UserCodeCCValues.supportedKeypadModes) + this.getValue(ctx, UserCodeCCValues.supportedKeypadModes) ?? []; const supportedUsers: number = - this.getValue(applHost, UserCodeCCValues.supportedUsers) ?? 0; + this.getValue(ctx, UserCodeCCValues.supportedUsers) ?? 0; const supportsMultipleUserCodeReport = !!this.getValue( - applHost, + ctx, UserCodeCCValues.supportsMultipleUserCodeReport, ); // Check for changed values and codes if (api.version >= 2) { if (supportsAdminCode) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying admin code...", direction: "outbound", }); await api.getAdminCode(); } if (supportedKeypadModes.length > 1) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying active keypad mode...", direction: "outbound", }); await api.getKeypadMode(); } const storedUserCodeChecksum: number = - this.getValue(applHost, UserCodeCCValues.userCodeChecksum) ?? 0; + this.getValue(ctx, UserCodeCCValues.userCodeChecksum) ?? 0; let currentUserCodeChecksum: number | undefined = 0; if (supportsUserCodeChecksum) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "retrieving current user code checksum...", direction: "outbound", }); @@ -1013,7 +1015,7 @@ export class UserCodeCC extends CommandClass { !supportsUserCodeChecksum || currentUserCodeChecksum !== storedUserCodeChecksum ) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "checksum changed or is not supported, querying all user codes...", direction: "outbound", @@ -1027,7 +1029,7 @@ export class UserCodeCC extends CommandClass { if (response) { nextUserId = response.nextUserId; } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying user code #${nextUserId} timed out, skipping the remaining interview...`, @@ -1045,7 +1047,7 @@ export class UserCodeCC extends CommandClass { } } else { // V1 - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "querying all user codes...", direction: "outbound", }); diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 0295b33c97f8..bda8e5f7b67e 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -15,19 +15,15 @@ import { securityClassOrder, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -415,9 +411,9 @@ export class VersionCC extends CommandClass { } public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; // SDS13782: In a Multi Channel device, the Version Command Class MUST be supported by the Root Device, while // the Version Command Class SHOULD NOT be supported by individual End Points. @@ -427,18 +423,18 @@ export class VersionCC extends CommandClass { // implemented by the Multi Channel device; also in cases where the actual Command Class is only // provided by an End Point. - const endpoint = this.getEndpoint(applHost)!; + const endpoint = this.getEndpoint(ctx)!; // Use the CC API of the root device for all queries const api = CCAPI.create( CommandClasses.Version, - applHost, + ctx, node, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", @@ -449,7 +445,7 @@ export class VersionCC extends CommandClass { // but there are Z-Wave certification tests that require us to query all CCs const maxImplemented = getImplementedVersion(cc); if (maxImplemented === 0) { - applHost.logNode( + ctx.logNode( node.id, ` skipping query for ${CommandClasses[cc]} (${ num2hex( @@ -460,7 +456,7 @@ export class VersionCC extends CommandClass { return; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: ` querying the CC version for ${getCCName(cc)}...`, direction: "outbound", @@ -524,12 +520,12 @@ export class VersionCC extends CommandClass { } } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, }); } else { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `CC version query for ${ getCCName( @@ -551,7 +547,7 @@ export class VersionCC extends CommandClass { await queryCCVersion(CommandClasses.Version); // Step 2: Query node versions - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying node versions...", direction: "outbound", @@ -568,7 +564,7 @@ export class VersionCC extends CommandClass { logMessage += `\n hardware version: ${versionGetResponse.hardwareVersion}`; } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -577,7 +573,7 @@ export class VersionCC extends CommandClass { } // Step 3: Query all other CC versions - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying CC versions...", direction: "outbound", @@ -603,7 +599,7 @@ export class VersionCC extends CommandClass { // Step 4: Query VersionCC capabilities (root device only) if (this.endpointIndex === 0 && api.version >= 3) { // Step 4a: Support for SoftwareGet - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying if Z-Wave Software Get is supported...", direction: "outbound", @@ -611,7 +607,7 @@ export class VersionCC extends CommandClass { const capsResponse = await api.getCapabilities(); if (capsResponse) { const { supportsZWaveSoftwareGet } = capsResponse; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Z-Wave Software Get is${ supportsZWaveSoftwareGet ? "" : " not" @@ -621,13 +617,13 @@ export class VersionCC extends CommandClass { if (supportsZWaveSoftwareGet) { // Step 4b: Query Z-Wave Software versions - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Z-Wave software versions...", direction: "outbound", }); await api.getZWaveSoftware(); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "received Z-Wave software versions", direction: "inbound", @@ -637,7 +633,7 @@ export class VersionCC extends CommandClass { } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 43b24d54dd07..70710946aab5 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -31,6 +31,7 @@ import { type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -224,31 +225,31 @@ export class WakeUpCC extends CommandClass { declare ccCommand: WakeUpCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Wake Up"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - if (node.id === applHost.ownNodeId) { - applHost.logNode( + if (node.id === ctx.ownNodeId) { + ctx.logNode( node.id, `skipping wakeup configuration for the controller`, ); } else if (node.isFrequentListening) { - applHost.logNode( + ctx.logNode( node.id, `skipping wakeup configuration for frequent listening device`, ); @@ -260,7 +261,7 @@ export class WakeUpCC extends CommandClass { // Retrieve the allowed wake up intervals and wake on demand support if possible if (api.version >= 2) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving wakeup capabilities from the device...", @@ -274,7 +275,7 @@ minimum wakeup interval: ${wakeupCaps.minWakeUpInterval} seconds maximum wakeup interval: ${wakeupCaps.maxWakeUpInterval} seconds wakeup interval steps: ${wakeupCaps.wakeUpIntervalSteps} seconds wakeup on demand supported: ${wakeupCaps.wakeUpOnDemandSupported}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -288,7 +289,7 @@ wakeup on demand supported: ${wakeupCaps.wakeUpOnDemandSupported}`; // We have no intention of changing the interval (maybe some time in the future) // So for now get the current interval and just set the controller ID - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "retrieving wakeup interval from the device...", direction: "outbound", @@ -299,7 +300,7 @@ wakeup on demand supported: ${wakeupCaps.wakeUpOnDemandSupported}`; const logMessage = `received wakeup configuration: wakeup interval: ${wakeupResp.wakeUpInterval} seconds controller node: ${wakeupResp.controllerNodeId}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -313,7 +314,7 @@ controller node: ${wakeupResp.controllerNodeId}`; currentControllerNodeId = 0; // assume not set } - const ownNodeId = applHost.ownNodeId; + const ownNodeId = ctx.ownNodeId; // Only change the destination if necessary if (currentControllerNodeId !== ownNodeId) { // Spec compliance: Limit the interval to the allowed range, but... @@ -330,18 +331,18 @@ controller node: ${wakeupResp.controllerNodeId}`; ); } - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "configuring wakeup destination node", direction: "outbound", }); await api.setInterval(desiredInterval, ownNodeId); this.setValue( - applHost, + ctx, WakeUpCCValues.controllerNodeId, ownNodeId, ); - applHost.logNode( + ctx.logNode( node.id, "wakeup destination node changed!", ); @@ -349,7 +350,7 @@ controller node: ${wakeupResp.controllerNodeId}`; } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/cc/WindowCoveringCC.ts b/packages/cc/src/cc/WindowCoveringCC.ts index 175c3cd92734..85eba7531edd 100644 --- a/packages/cc/src/cc/WindowCoveringCC.ts +++ b/packages/cc/src/cc/WindowCoveringCC.ts @@ -11,11 +11,7 @@ import { validatePayload, } from "@zwave-js/core"; import { type MaybeNotKnown } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -33,9 +29,9 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -582,25 +578,25 @@ export class WindowCoveringCC extends CommandClass { declare ccCommand: WindowCoveringCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Window Covering"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying supported window covering parameters...", direction: "outbound", @@ -615,7 +611,7 @@ ${ ) .join("\n") }`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -625,31 +621,31 @@ ${ for (const param of supported) { // Default values this.setMetadata( - applHost, + ctx, WindowCoveringCCValues.currentValue(param), ); this.setMetadata( - applHost, + ctx, WindowCoveringCCValues.targetValue(param), ); this.setMetadata( - applHost, + ctx, WindowCoveringCCValues.duration(param), ); // Level change values this.setMetadata( - applHost, + ctx, WindowCoveringCCValues.levelChangeUp(param), ); this.setMetadata( - applHost, + ctx, WindowCoveringCCValues.levelChangeDown(param), ); // And for the odd parameters (with position support), query the position if (param % 2 === 1) { - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `querying position for parameter ${ getEnumMemberName( @@ -665,7 +661,7 @@ ${ } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } public translatePropertyKey( diff --git a/packages/cc/src/cc/ZWavePlusCC.ts b/packages/cc/src/cc/ZWavePlusCC.ts index f5760ac1c687..71eb1db7a881 100644 --- a/packages/cc/src/cc/ZWavePlusCC.ts +++ b/packages/cc/src/cc/ZWavePlusCC.ts @@ -5,19 +5,15 @@ import { MessagePriority, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, + type InterviewContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -123,25 +119,25 @@ export class ZWavePlusCC extends CommandClass { declare ccCommand: ZWavePlusCommand; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; - const endpoint = this.getEndpoint(applHost)!; + const node = this.getNode(ctx)!; + const endpoint = this.getEndpoint(ctx)!; const api = CCAPI.create( CommandClasses["Z-Wave Plus Info"], - applHost, + ctx, endpoint, ).withOptions({ priority: MessagePriority.NodeQuery, }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing ${this.ccName}...`, direction: "none", }); - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: "querying Z-Wave+ information...", direction: "outbound", @@ -155,7 +151,7 @@ role type: ${ZWavePlusRoleType[zwavePlusResponse.roleType]} node type: ${ZWavePlusNodeType[zwavePlusResponse.nodeType]} installer icon: ${num2hex(zwavePlusResponse.installerIcon)} user icon: ${num2hex(zwavePlusResponse.userIcon)}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: logMessage, direction: "inbound", @@ -163,7 +159,7 @@ user icon: ${num2hex(zwavePlusResponse.userIcon)}`; } // Remember that the interview is complete - this.setInterviewComplete(applHost, true); + this.setInterviewComplete(ctx, true); } } diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index a86c5db61c9c..3f64934e7f15 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -37,9 +37,11 @@ import type { CCEncodingContext, CCParsingContext, GetDeviceConfig, + GetInterviewOptions, GetNode, GetSupportedCCVersion, GetValueDB, + LookupManufacturer, ZWaveApplicationHost, } from "@zwave-js/host"; import { MessageOrigin } from "@zwave-js/serial"; @@ -51,7 +53,7 @@ import { staticExtends, } from "@zwave-js/shared"; import { isArray } from "alcalzone-shared/typeguards"; -import type { ValueIDProperties } from "./API"; +import type { CCAPIHost, CCAPINode, ValueIDProperties } from "./API"; import { getCCCommand, getCCCommandConstructor, @@ -143,6 +145,24 @@ export type CCNode = & ListenBehavior & QueryNodeStatus; +export type InterviewContext = + & CCAPIHost< + & CCAPINode + & GetCCs + & SupportsCC + & ControlsCC + & QuerySecurityClasses + & SetSecurityClass + & GetEndpoint + & GetAllEndpoints + > + & GetInterviewOptions + & LookupManufacturer; + +export type RefreshValuesContext = CCAPIHost< + CCAPINode & GetEndpoint +>; + export function getEffectiveCCVersion( ctx: GetSupportedCCVersion, cc: CCId, @@ -515,14 +535,14 @@ export class CommandClass implements CCId { /** * Performs the interview procedure for this CC according to SDS14223 */ - public async interview(_applHost: ZWaveApplicationHost): Promise { + public async interview(_ctx: InterviewContext): Promise { // This needs to be overwritten per command class. In the default implementation, don't do anything } /** * Refreshes all dynamic values of this CC */ - public async refreshValues(_applHost: ZWaveApplicationHost): Promise { + public async refreshValues(_ctx: RefreshValuesContext): Promise { // This needs to be overwritten per command class. In the default implementation, don't do anything } diff --git a/packages/maintenance/src/codeshifts/refactorInterview.ts b/packages/maintenance/src/codeshifts/refactorInterview.ts new file mode 100644 index 000000000000..5d1e6c077945 --- /dev/null +++ b/packages/maintenance/src/codeshifts/refactorInterview.ts @@ -0,0 +1,124 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { + type API, + type FileInfo, + type Identifier, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + {}: Options, +) => { + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + const ccImplementations = root.find(j.ClassDeclaration, { + superClass: { + name: "CommandClass", + }, + }); + + const methods = ccImplementations.find(j.ClassMethod, { + kind: "method", + }).filter(({ node }) => { + return node.key.type === "Identifier" + && (node.key.name === "interview") + && node.params.length >= 1 + && node.params[0].type === "Identifier" + && node.params[0].name === "applHost" + && node.params[0].typeAnnotation?.type === "TSTypeAnnotation" + && node.params[0].typeAnnotation.typeAnnotation.type + === "TSTypeReference" + && node.params[0].typeAnnotation.typeAnnotation.typeName.type + === "Identifier" + && node.params[0].typeAnnotation.typeAnnotation.typeName.name + === "ZWaveApplicationHost"; + }); + + if (!methods.length) return file.source; + + methods.replaceWith(({ node }) => { + const ident = node.params[0] as Identifier; + ident.name = "ctx"; + // @ts-expect-error + ident.typeAnnotation.typeAnnotation.typeName.name = "InterviewContext"; + return node; + }); + + const paramUsages = methods.find(j.Identifier, { + name: "applHost", + }); + paramUsages.replaceWith(({ node }) => { + node.name = "ctx"; + return node; + }); + + const targetDecl = root + .find( + j.ImportDeclaration, + { + source: { + type: "StringLiteral", + value: "../lib/CommandClass", + }, + }, + ); + targetDecl.at(0).get().node.specifiers.push( + j.importSpecifier(j.identifier("InterviewContext")), + ); + + return root.toSource(); + + // const imp = root + // .find( + // j.ImportDeclaration, + // { importKind: typeOnly ? "type" : undefined }, + // ) + // .find(j.ImportSpecifier, { + // imported: { + // name: from, + // }, + // }); + + // return imp.replaceWith(({ node }) => { + // node.imported.name = to; + // return node; + // }).toSource(); + + // return ( + // j(file.source) + // .find(j.FunctionDeclaration) + // // Target a particular function declaration + // .filter(({ node: functionDeclaration }) => functionDeclaration.id.name === functionName) + // .replaceWith(({ node: functionDeclaration }) => { + // // Create a function call expression statement + // const functionCallExpressionStatement = j.expressionStatement( + // j.callExpression(j.identifier(functionNameToCall), []) + // ); + + // // Create a comment and add it as a leading comment to the function call expression + // const commentLine = j.commentLine(comment); + // functionCallExpressionStatement.comments = [commentLine]; + + // // Append the function call expression to the function declaration's existing body + // functionDeclaration.body.body = [...functionDeclaration.body.body, functionCallExpressionStatement]; + // return functionDeclaration; + // }) + // .toSource() + // ); +}; + +export default transform; +export const parser = "ts"; diff --git a/packages/maintenance/src/codeshifts/refactorRefreshValues.ts b/packages/maintenance/src/codeshifts/refactorRefreshValues.ts new file mode 100644 index 000000000000..a6d9c58e9c93 --- /dev/null +++ b/packages/maintenance/src/codeshifts/refactorRefreshValues.ts @@ -0,0 +1,125 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { + type API, + type FileInfo, + type Identifier, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + {}: Options, +) => { + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + const ccImplementations = root.find(j.ClassDeclaration, { + superClass: { + name: "CommandClass", + }, + }); + + const methods = ccImplementations.find(j.ClassMethod, { + kind: "method", + }).filter(({ node }) => { + return node.key.type === "Identifier" + && (node.key.name === "refreshValues") + && node.params.length >= 1 + && node.params[0].type === "Identifier" + && node.params[0].name === "applHost" + && node.params[0].typeAnnotation?.type === "TSTypeAnnotation" + && node.params[0].typeAnnotation.typeAnnotation.type + === "TSTypeReference" + && node.params[0].typeAnnotation.typeAnnotation.typeName.type + === "Identifier" + && node.params[0].typeAnnotation.typeAnnotation.typeName.name + === "ZWaveApplicationHost"; + }); + + if (!methods.length) return file.source; + + methods.replaceWith(({ node }) => { + const ident = node.params[0] as Identifier; + ident.name = "ctx"; + // @ts-expect-error + ident.typeAnnotation.typeAnnotation.typeName.name = + "RefreshValuesContext"; + return node; + }); + + const paramUsages = methods.find(j.Identifier, { + name: "applHost", + }); + paramUsages.replaceWith(({ node }) => { + node.name = "ctx"; + return node; + }); + + const targetDecl = root + .find( + j.ImportDeclaration, + { + source: { + type: "StringLiteral", + value: "../lib/CommandClass", + }, + }, + ); + targetDecl.at(0).get().node.specifiers.push( + j.importSpecifier(j.identifier("RefreshValuesContext")), + ); + + return root.toSource(); + + // const imp = root + // .find( + // j.ImportDeclaration, + // { importKind: typeOnly ? "type" : undefined }, + // ) + // .find(j.ImportSpecifier, { + // imported: { + // name: from, + // }, + // }); + + // return imp.replaceWith(({ node }) => { + // node.imported.name = to; + // return node; + // }).toSource(); + + // return ( + // j(file.source) + // .find(j.FunctionDeclaration) + // // Target a particular function declaration + // .filter(({ node: functionDeclaration }) => functionDeclaration.id.name === functionName) + // .replaceWith(({ node: functionDeclaration }) => { + // // Create a function call expression statement + // const functionCallExpressionStatement = j.expressionStatement( + // j.callExpression(j.identifier(functionNameToCall), []) + // ); + + // // Create a comment and add it as a leading comment to the function call expression + // const commentLine = j.commentLine(comment); + // functionCallExpressionStatement.comments = [commentLine]; + + // // Append the function call expression to the function declaration's existing body + // functionDeclaration.body.body = [...functionDeclaration.body.body, functionCallExpressionStatement]; + // return functionDeclaration; + // }) + // .toSource() + // ); +}; + +export default transform; +export const parser = "ts"; From 2041a5df90c639a02ba01abb0180f17c0b94752c Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 17 Oct 2024 08:21:11 +0200 Subject: [PATCH 55/60] fix: lint --- packages/cc/src/cc/AssociationCC.ts | 1 - packages/cc/src/cc/BinarySwitchCC.ts | 1 - packages/cc/src/cc/ClockCC.ts | 1 - packages/cc/src/cc/DoorLockLoggingCC.ts | 1 - packages/cc/src/cc/HumidityControlOperatingStateCC.ts | 1 - packages/cc/src/cc/LanguageCC.ts | 1 - packages/cc/src/cc/LockCC.ts | 1 - packages/cc/src/cc/ManufacturerProprietaryCC.ts | 1 - packages/cc/src/cc/MultiChannelAssociationCC.ts | 1 - packages/cc/src/cc/NodeNamingCC.ts | 1 - packages/cc/src/cc/ThermostatOperatingStateCC.ts | 1 - packages/cc/src/cc/ThermostatSetbackCC.ts | 1 - 12 files changed, 12 deletions(-) diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 90aec0e87c1a..a2ce46e98e9a 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -25,7 +25,6 @@ import { distinct } from "alcalzone-shared/arrays"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/BinarySwitchCC.ts b/packages/cc/src/cc/BinarySwitchCC.ts index ad47337b4b41..9442d2938386 100644 --- a/packages/cc/src/cc/BinarySwitchCC.ts +++ b/packages/cc/src/cc/BinarySwitchCC.ts @@ -30,7 +30,6 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index ac5256d64031..524422030d9d 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -17,7 +17,6 @@ import { padStart } from "alcalzone-shared/strings"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/DoorLockLoggingCC.ts b/packages/cc/src/cc/DoorLockLoggingCC.ts index 503d4d802d14..cbd016bef743 100644 --- a/packages/cc/src/cc/DoorLockLoggingCC.ts +++ b/packages/cc/src/cc/DoorLockLoggingCC.ts @@ -14,7 +14,6 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts index de807772c6b5..95cd60109923 100644 --- a/packages/cc/src/cc/HumidityControlOperatingStateCC.ts +++ b/packages/cc/src/cc/HumidityControlOperatingStateCC.ts @@ -16,7 +16,6 @@ import { throwUnsupportedProperty, } from "../lib/API"; import { - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/LanguageCC.ts b/packages/cc/src/cc/LanguageCC.ts index 61c3ff329897..907727807b21 100644 --- a/packages/cc/src/cc/LanguageCC.ts +++ b/packages/cc/src/cc/LanguageCC.ts @@ -18,7 +18,6 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/LockCC.ts b/packages/cc/src/cc/LockCC.ts index 24e0bb73bdae..41a1cc32f734 100644 --- a/packages/cc/src/cc/LockCC.ts +++ b/packages/cc/src/cc/LockCC.ts @@ -24,7 +24,6 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/ManufacturerProprietaryCC.ts b/packages/cc/src/cc/ManufacturerProprietaryCC.ts index bdb222a7470f..e16969216443 100644 --- a/packages/cc/src/cc/ManufacturerProprietaryCC.ts +++ b/packages/cc/src/cc/ManufacturerProprietaryCC.ts @@ -10,7 +10,6 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, type CCAPIEndpoint, type CCAPIHost } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 568ab030f9b8..415de5bcfc62 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -26,7 +26,6 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/NodeNamingCC.ts b/packages/cc/src/cc/NodeNamingCC.ts index c524e776957a..78a52401ffa3 100644 --- a/packages/cc/src/cc/NodeNamingCC.ts +++ b/packages/cc/src/cc/NodeNamingCC.ts @@ -23,7 +23,6 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/ThermostatOperatingStateCC.ts b/packages/cc/src/cc/ThermostatOperatingStateCC.ts index 205603f7b565..e863afe1d701 100644 --- a/packages/cc/src/cc/ThermostatOperatingStateCC.ts +++ b/packages/cc/src/cc/ThermostatOperatingStateCC.ts @@ -17,7 +17,6 @@ import { throwUnsupportedProperty, } from "../lib/API"; import { - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, diff --git a/packages/cc/src/cc/ThermostatSetbackCC.ts b/packages/cc/src/cc/ThermostatSetbackCC.ts index 9a0ac218e926..788ffe7dc6c3 100644 --- a/packages/cc/src/cc/ThermostatSetbackCC.ts +++ b/packages/cc/src/cc/ThermostatSetbackCC.ts @@ -17,7 +17,6 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, From a02315eca4d524ecdf27494b587de344a50f9195 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 17 Oct 2024 08:59:37 +0200 Subject: [PATCH 56/60] refactor: replace ZWaveApplicationHost in persistValues --- packages/cc/src/cc/AlarmSensorCC.ts | 26 ++-- packages/cc/src/cc/AssociationGroupInfoCC.ts | 20 ++- packages/cc/src/cc/BarrierOperatorCC.ts | 16 +-- packages/cc/src/cc/BasicCC.ts | 13 +- packages/cc/src/cc/BatteryCC.ts | 19 ++- packages/cc/src/cc/BinarySensorCC.ts | 18 +-- packages/cc/src/cc/CentralSceneCC.ts | 20 ++- packages/cc/src/cc/ColorSwitchCC.ts | 26 ++-- packages/cc/src/cc/ConfigurationCC.ts | 64 ++++----- packages/cc/src/cc/DoorLockCC.ts | 44 +++--- packages/cc/src/cc/EnergyProductionCC.ts | 16 +-- packages/cc/src/cc/EntryControlCC.ts | 16 +-- packages/cc/src/cc/HumidityControlModeCC.ts | 14 +- .../cc/src/cc/HumidityControlSetpointCC.ts | 26 ++-- packages/cc/src/cc/IndicatorCC.ts | 36 +++-- packages/cc/src/cc/IrrigationCC.ts | 76 +++++------ packages/cc/src/cc/MeterCC.ts | 31 ++--- packages/cc/src/cc/MultiChannelCC.ts | 14 +- packages/cc/src/cc/MultilevelSensorCC.ts | 19 ++- packages/cc/src/cc/MultilevelSwitchCC.ts | 14 +- packages/cc/src/cc/NotificationCC.ts | 41 +++--- packages/cc/src/cc/ProtectionCC.ts | 16 +-- .../cc/src/cc/SceneActuatorConfigurationCC.ts | 20 ++- .../src/cc/SceneControllerConfigurationCC.ts | 15 +- packages/cc/src/cc/ScheduleEntryLockCC.ts | 26 ++-- packages/cc/src/cc/ThermostatFanModeCC.ts | 14 +- packages/cc/src/cc/ThermostatModeCC.ts | 24 ++-- packages/cc/src/cc/ThermostatSetpointCC.ts | 26 ++-- packages/cc/src/cc/TimeParametersCC.ts | 15 +- packages/cc/src/cc/UserCodeCC.ts | 23 ++-- packages/cc/src/cc/WakeUpCC.ts | 14 +- .../cc/manufacturerProprietary/FibaroCC.ts | 49 ++++--- packages/cc/src/lib/CommandClass.ts | 18 ++- .../src/codeshifts/refactorPersistValues.ts | 129 ++++++++++++++++++ 34 files changed, 501 insertions(+), 457 deletions(-) create mode 100644 packages/maintenance/src/codeshifts/refactorPersistValues.ts diff --git a/packages/cc/src/cc/AlarmSensorCC.ts b/packages/cc/src/cc/AlarmSensorCC.ts index 4d633aad7acf..3962536b628d 100644 --- a/packages/cc/src/cc/AlarmSensorCC.ts +++ b/packages/cc/src/cc/AlarmSensorCC.ts @@ -11,20 +11,16 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -368,18 +364,18 @@ export class AlarmSensorCCReport extends AlarmSensorCC { }; } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Create metadata if it does not exist - this.createMetadataForSensorType(applHost, this.sensorType); + this.createMetadataForSensorType(ctx, this.sensorType); const stateValue = AlarmSensorCCValues.state(this.sensorType); const severityValue = AlarmSensorCCValues.severity(this.sensorType); const durationValue = AlarmSensorCCValues.duration(this.sensorType); - this.setValue(applHost, stateValue, this.state); - this.setValue(applHost, severityValue, this.severity); - this.setValue(applHost, durationValue, this.duration); + this.setValue(ctx, stateValue, this.state); + this.setValue(ctx, severityValue, this.severity); + this.setValue(ctx, durationValue, this.duration); return true; } @@ -460,11 +456,11 @@ export class AlarmSensorCCSupportedReport extends AlarmSensorCC { return this._supportedSensorTypes; } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Create metadata for each sensor type for (const type of this._supportedSensorTypes) { - this.createMetadataForSensorType(applHost, type); + this.createMetadataForSensorType(ctx, type); } return true; } diff --git a/packages/cc/src/cc/AssociationGroupInfoCC.ts b/packages/cc/src/cc/AssociationGroupInfoCC.ts index 7fc55741bc2d..586443444817 100644 --- a/packages/cc/src/cc/AssociationGroupInfoCC.ts +++ b/packages/cc/src/cc/AssociationGroupInfoCC.ts @@ -11,20 +11,16 @@ import { parseCCId, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { cpp2js, getEnumMemberName, num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { CCAPI, PhysicalCCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -502,9 +498,9 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC { public readonly groupId: number; public readonly name: string; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; - const valueDB = this.getValueDB(applHost); + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; + const valueDB = this.getValueDB(ctx); valueDB.setValue( AssociationGroupInfoCCValues.groupName(this.groupId).endpoint( @@ -632,13 +628,13 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC { public readonly groups: readonly AssociationGroupInfo[]; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; for (const group of this.groups) { const { groupId, mode, profile, eventCode } = group; this.setValue( - applHost, + ctx, AssociationGroupInfoCCValues.groupInfo(groupId), { mode, diff --git a/packages/cc/src/cc/BarrierOperatorCC.ts b/packages/cc/src/cc/BarrierOperatorCC.ts index 456a3ca8275f..0a15deaa326d 100644 --- a/packages/cc/src/cc/BarrierOperatorCC.ts +++ b/packages/cc/src/cc/BarrierOperatorCC.ts @@ -14,11 +14,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember, @@ -41,10 +37,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -741,15 +737,15 @@ export class BarrierOperatorCCEventSignalingReport extends BarrierOperatorCC { this.subsystemState = this.payload[1]; } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; const signalingStateValue = BarrierOperatorCCValues.signalingState( this.subsystemType, ); - this.ensureMetadata(applHost, signalingStateValue); - this.setValue(applHost, signalingStateValue, this.subsystemState); + this.ensureMetadata(ctx, signalingStateValue); + this.setValue(ctx, signalingStateValue, this.subsystemState); return true; } diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index 35ec874704e5..b7746565e656 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -24,7 +24,6 @@ import type { GetNode, GetSupportedCCVersion, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { type AllOrNone, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -41,10 +40,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -457,14 +456,14 @@ export class BasicCCReport extends BasicCC { @ccValue(BasicCCValues.duration) public readonly duration: Duration | undefined; - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(ctx: PersistValuesContext): boolean { // Basic CC Report persists its values itself, since there are some // specific rules when which value may be persisted. // These rules are essentially encoded in the getDefinedValueIDs overload, // so we simply reuse that here. // Figure out which values may be persisted. - const definedValueIDs = this.getDefinedValueIDs(applHost); + const definedValueIDs = this.getDefinedValueIDs(ctx); const shouldPersistCurrentValue = definedValueIDs.some((vid) => BasicCCValues.currentValue.is(vid) ); @@ -477,21 +476,21 @@ export class BasicCCReport extends BasicCC { if (this.currentValue !== undefined && shouldPersistCurrentValue) { this.setValue( - applHost, + ctx, BasicCCValues.currentValue, this.currentValue, ); } if (this.targetValue !== undefined && shouldPersistTargetValue) { this.setValue( - applHost, + ctx, BasicCCValues.targetValue, this.targetValue, ); } if (this.duration !== undefined && shouldPersistDuration) { this.setValue( - applHost, + ctx, BasicCCValues.duration, this.duration, ); diff --git a/packages/cc/src/cc/BatteryCC.ts b/packages/cc/src/cc/BatteryCC.ts index f7dda93d85ee..b4bb1a462cfa 100644 --- a/packages/cc/src/cc/BatteryCC.ts +++ b/packages/cc/src/cc/BatteryCC.ts @@ -24,7 +24,6 @@ import type { GetNode, GetSupportedCCVersion, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { type AllOrNone, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { @@ -36,10 +35,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -474,15 +473,15 @@ export class BatteryCCReport extends BatteryCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Naïve heuristic for a full battery if (this.level >= 90) { // Some devices send Notification CC Reports with battery information, // or this information is mapped from legacy V1 alarm values. // We may need to idle the corresponding values when the battery is full - const notificationCCVersion = applHost.getSupportedCCVersion( + const notificationCCVersion = ctx.getSupportedCCVersion( CommandClasses.Notification, this.nodeId as number, this.endpointIndex, @@ -499,9 +498,9 @@ export class BatteryCCReport extends BatteryCC { "Battery level status", ); // If not undefined and not idle - if (this.getValue(applHost, batteryLevelStatusValue)) { + if (this.getValue(ctx, batteryLevelStatusValue)) { this.setValue( - applHost, + ctx, batteryLevelStatusValue, 0, /* idle */ ); @@ -634,12 +633,12 @@ export class BatteryCCHealthReport extends BatteryCC { this.temperatureScale = scale; } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Update the temperature unit in the value DB const temperatureValue = BatteryCCValues.temperature; - this.setMetadata(applHost, temperatureValue, { + this.setMetadata(ctx, temperatureValue, { ...temperatureValue.meta, unit: this.temperatureScale === 0x00 ? "°C" : undefined, }); diff --git a/packages/cc/src/cc/BinarySensorCC.ts b/packages/cc/src/cc/BinarySensorCC.ts index 3847eddf68b8..49afdf1ce7df 100644 --- a/packages/cc/src/cc/BinarySensorCC.ts +++ b/packages/cc/src/cc/BinarySensorCC.ts @@ -10,11 +10,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, isEnumMember } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -26,10 +22,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -367,14 +363,14 @@ export class BinarySensorCCReport extends BinarySensorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Workaround for devices reporting with sensor type Any -> find first supported sensor type and use that let sensorType = this.type; if (sensorType === BinarySensorType.Any) { const supportedSensorTypes = this.getValue( - applHost, + ctx, BinarySensorCCValues.supportedSensorTypes, ); if (supportedSensorTypes?.length) { @@ -383,8 +379,8 @@ export class BinarySensorCCReport extends BinarySensorCC { } const binarySensorValue = BinarySensorCCValues.state(sensorType); - this.setMetadata(applHost, binarySensorValue, binarySensorValue.meta); - this.setValue(applHost, binarySensorValue, this.value); + this.setMetadata(ctx, binarySensorValue, binarySensorValue.meta); + this.setValue(ctx, binarySensorValue, this.value); return true; } diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 12d6981dd36b..452b9f4da212 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -14,11 +14,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; @@ -33,10 +29,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -318,12 +314,12 @@ export class CentralSceneCCNotification extends CentralSceneCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // In case the interview is not yet completed, we still create some basic metadata const sceneValue = CentralSceneCCValues.scene(this.sceneNumber); - this.ensureMetadata(applHost, sceneValue); + this.ensureMetadata(ctx, sceneValue); // The spec behavior is pretty complicated, so we cannot just store // the value and call it a day. Handling of these notifications will @@ -392,13 +388,13 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Create/extend metadata for all scenes for (let i = 1; i <= this.sceneCount; i++) { const sceneValue = CentralSceneCCValues.scene(i); - this.setMetadata(applHost, sceneValue, { + this.setMetadata(ctx, sceneValue, { ...sceneValue.meta, states: enumValuesToMetadataStates( CentralSceneKeys, diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index a09334e8ea90..0b163ece62c4 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -16,11 +16,7 @@ import { validatePayload, } from "@zwave-js/core"; import { type MaybeNotKnown, encodeBitMask } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { type AllOrNone, getEnumMemberName, @@ -44,10 +40,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -772,19 +768,19 @@ export class ColorSwitchCCReport extends ColorSwitchCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(ctx: PersistValuesContext): boolean { // Duration is stored globally instead of per component - if (!super.persistValues(applHost)) return false; + if (!super.persistValues(ctx)) return false; // Update compound current value const colorTableKey = colorComponentToTableKey(this.colorComponent); if (colorTableKey) { const compoundCurrentColorValue = ColorSwitchCCValues.currentColor; const compoundCurrentColor: Partial> = - this.getValue(applHost, compoundCurrentColorValue) ?? {}; + this.getValue(ctx, compoundCurrentColorValue) ?? {}; compoundCurrentColor[colorTableKey] = this.currentValue; this.setValue( - applHost, + ctx, compoundCurrentColorValue, compoundCurrentColor, ); @@ -794,10 +790,10 @@ export class ColorSwitchCCReport extends ColorSwitchCC { const compoundTargetColorValue = ColorSwitchCCValues.targetColor; const compoundTargetColor: Partial> = - this.getValue(applHost, compoundTargetColorValue) ?? {}; + this.getValue(ctx, compoundTargetColorValue) ?? {}; compoundTargetColor[colorTableKey] = this.targetValue; this.setValue( - applHost, + ctx, compoundTargetColorValue, compoundTargetColor, ); @@ -806,7 +802,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { // Update collective hex value if required const supportsHex = !!this.getValue( - applHost, + ctx, ColorSwitchCCValues.supportsHexColor, ); if ( @@ -817,7 +813,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { ) { const hexColorValue = ColorSwitchCCValues.hexColor; - const hexValue: string = this.getValue(applHost, hexColorValue) + const hexValue: string = this.getValue(ctx, hexColorValue) ?? "000000"; const byteOffset = ColorComponent.Blue - this.colorComponent; const byteMask = 0xff << (byteOffset * 8); @@ -825,7 +821,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC { hexValueNumeric = (hexValueNumeric & ~byteMask) | (this.currentValue << (byteOffset * 8)); this.setValue( - applHost, + ctx, hexColorValue, hexValueNumeric.toString(16).padStart(6, "0"), ); diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index da9c76b4bd4a..6be4759685a0 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -56,10 +56,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -1651,16 +1651,16 @@ export class ConfigurationCCReport extends ConfigurationCC { public valueSize: number; private valueFormat?: ConfigValueFormat; // only used for serialization - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; - const ccVersion = getEffectiveCCVersion(applHost, this); + const ccVersion = getEffectiveCCVersion(ctx, this); // This parameter may be a partial param in the following cases: // * a config file defines it as such // * it was reported by the device as a bit field const partialParams = this.getPartialParamInfos( - applHost, + ctx, this.parameter, ); @@ -1672,19 +1672,19 @@ export class ConfigurationCCReport extends ConfigurationCC { } else { // Check if the initial assumption of SignedInteger holds true const oldParamInformation = this.getParamInformation( - applHost, + ctx, this.parameter, ); cachedValueFormat = oldParamInformation.format; // On older CC versions, these reports may be the only way we can retrieve the value size // Therefore we store it here - this.extendParamInformation(applHost, this.parameter, undefined, { + this.extendParamInformation(ctx, this.parameter, undefined, { valueSize: this.valueSize, }); if ( ccVersion < 3 - && !this.paramExistsInConfigFile(applHost, this.parameter) + && !this.paramExistsInConfigFile(ctx, this.parameter) && oldParamInformation.min == undefined && oldParamInformation.max == undefined ) { @@ -1692,7 +1692,7 @@ export class ConfigurationCCReport extends ConfigurationCC { || oldParamInformation.format === ConfigValueFormat.SignedInteger; this.extendParamInformation( - applHost, + ctx, this.parameter, undefined, getIntegerLimits(this.valueSize as any, isSigned), @@ -1719,7 +1719,7 @@ export class ConfigurationCCReport extends ConfigurationCC { for (const param of partialParams) { if (typeof param.propertyKey === "number") { this.setValue( - applHost, + ctx, ConfigurationCCValues.paramInformation( this.parameter, param.propertyKey, @@ -1738,7 +1738,7 @@ export class ConfigurationCCReport extends ConfigurationCC { } else { // This is a single param this.setValue( - applHost, + ctx, ConfigurationCCValues.paramInformation(this.parameter), this.value, ); @@ -2154,15 +2154,15 @@ export class ConfigurationCCBulkReport extends ConfigurationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Store every received parameter // eslint-disable-next-line prefer-const for (let [parameter, value] of this._values.entries()) { // Check if the initial assumption of SignedInteger holds true const oldParamInformation = this.getParamInformation( - applHost, + ctx, parameter, ); if ( @@ -2180,7 +2180,7 @@ export class ConfigurationCCBulkReport extends ConfigurationCC { } this.setValue( - applHost, + ctx, ConfigurationCCValues.paramInformation(parameter), value, ); @@ -2333,19 +2333,19 @@ export class ConfigurationCCNameReport extends ConfigurationCC { public name: string; public readonly reportsToFollow: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Bitfield parameters that are not documented in a config file // are split into multiple partial parameters. We need to set the name for // all of them. const partialParams = this.getPartialParamInfos( - applHost, + ctx, this.parameter, ); if (partialParams.length === 0) { - this.extendParamInformation(applHost, this.parameter, undefined, { + this.extendParamInformation(ctx, this.parameter, undefined, { label: this.name, }); } else { @@ -2360,7 +2360,7 @@ export class ConfigurationCCNameReport extends ConfigurationCC { if (bitNumber != undefined) { label += ` (bit ${bitNumber})`; } - this.extendParamInformation(applHost, paramNumber, bitMask, { + this.extendParamInformation(ctx, paramNumber, bitMask, { label, }); } @@ -2479,15 +2479,15 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { public info: string; public readonly reportsToFollow: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Bitfield parameters that are not documented in a config file // are split into multiple partial parameters. We need to set the description for // all of them. However, these can get very long, so we put the reported // description on the first partial param, and refer to it from the others const partialParams = this.getPartialParamInfos( - applHost, + ctx, this.parameter, ).sort( (a, b) => @@ -2496,7 +2496,7 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { ); if (partialParams.length === 0) { - this.extendParamInformation(applHost, this.parameter, undefined, { + this.extendParamInformation(ctx, this.parameter, undefined, { description: this.info, }); } else { @@ -2511,7 +2511,7 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { ? `Refer to ${firstParamLabel}` : this.info; - this.extendParamInformation(applHost, paramNumber, bitMask, { + this.extendParamInformation(ctx, paramNumber, bitMask, { description, }); @@ -2519,7 +2519,7 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { // following partial params if (firstParamLabel == undefined) { firstParamLabel = - this.getParamInformation(applHost, paramNumber, bitMask) + this.getParamInformation(ctx, paramNumber, bitMask) .label ?? `parameter ${paramNumber} - ${bitMask}`; } } @@ -2712,8 +2712,8 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // If we actually received parameter info, store it if (this.valueSize > 0) { @@ -2732,7 +2732,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { if (this.valueFormat !== ConfigValueFormat.BitField) { // Do not override param information from a config file - if (!this.paramExistsInConfigFile(applHost, this.parameter)) { + if (!this.paramExistsInConfigFile(ctx, this.parameter)) { const paramInfo = stripUndefined( { ...baseInfo, @@ -2743,7 +2743,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { ); this.extendParamInformation( - applHost, + ctx, this.parameter, undefined, paramInfo, @@ -2759,7 +2759,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { !!(mask & bits) // Do not override param information from a config file && !this.paramExistsInConfigFile( - applHost, + ctx, this.parameter, mask, ) @@ -2774,7 +2774,7 @@ export class ConfigurationCCPropertiesReport extends ConfigurationCC { ); this.extendParamInformation( - applHost, + ctx, this.parameter, mask, paramInfo, diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index acc50c37bead..50f11ac03ad8 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -15,11 +15,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { isArray } from "alcalzone-shared/typeguards"; @@ -35,10 +31,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -908,39 +904,39 @@ export class DoorLockCCOperationReport extends DoorLockCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Only store the door/bolt/latch status if the lock supports it const supportsDoorStatus = !!this.getValue( - applHost, + ctx, DoorLockCCValues.doorSupported, ); if (supportsDoorStatus) { this.setValue( - applHost, + ctx, DoorLockCCValues.doorStatus, this.doorStatus, ); } const supportsBoltStatus = !!this.getValue( - applHost, + ctx, DoorLockCCValues.boltSupported, ); if (supportsBoltStatus) { this.setValue( - applHost, + ctx, DoorLockCCValues.boltStatus, this.boltStatus, ); } const supportsLatchStatus = !!this.getValue( - applHost, + ctx, DoorLockCCValues.latchSupported, ); if (supportsLatchStatus) { this.setValue( - applHost, + ctx, DoorLockCCValues.latchStatus, this.latchStatus, ); @@ -1069,50 +1065,50 @@ export class DoorLockCCConfigurationReport extends DoorLockCC { public readonly twistAssist?: boolean; public readonly blockToBlock?: boolean; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Only store the autoRelockTime etc. params if the lock supports it const supportsAutoRelock = !!this.getValue( - applHost, + ctx, DoorLockCCValues.autoRelockSupported, ); if (supportsAutoRelock) { this.setValue( - applHost, + ctx, DoorLockCCValues.autoRelockTime, this.autoRelockTime, ); } const supportsHoldAndRelease = !!this.getValue( - applHost, + ctx, DoorLockCCValues.holdAndReleaseSupported, ); if (supportsHoldAndRelease) { this.setValue( - applHost, + ctx, DoorLockCCValues.holdAndReleaseTime, this.holdAndReleaseTime, ); } const supportsTwistAssist = !!this.getValue( - applHost, + ctx, DoorLockCCValues.twistAssistSupported, ); if (supportsTwistAssist) { this.setValue( - applHost, + ctx, DoorLockCCValues.twistAssist, this.twistAssist, ); } const supportsBlockToBlock = !!this.getValue( - applHost, + ctx, DoorLockCCValues.blockToBlockSupported, ); if (supportsBlockToBlock) { this.setValue( - applHost, + ctx, DoorLockCCValues.blockToBlock, this.blockToBlock, ); diff --git a/packages/cc/src/cc/EnergyProductionCC.ts b/packages/cc/src/cc/EnergyProductionCC.ts index fc063e5c9f3b..6754b286b5be 100644 --- a/packages/cc/src/cc/EnergyProductionCC.ts +++ b/packages/cc/src/cc/EnergyProductionCC.ts @@ -8,11 +8,7 @@ import { validatePayload, } from "@zwave-js/core"; import { type MaybeNotKnown } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host"; import { getEnumMemberName, pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -23,10 +19,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -224,11 +220,11 @@ export class EnergyProductionCCReport extends EnergyProductionCC { public readonly scale: EnergyProductionScale; public readonly value: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; const valueValue = EnergyProductionCCValues.value(this.parameter); - this.setMetadata(applHost, valueValue, { + this.setMetadata(ctx, valueValue, { ...valueValue.meta, unit: this.scale.unit, ccSpecific: { @@ -236,7 +232,7 @@ export class EnergyProductionCCReport extends EnergyProductionCC { scale: this.scale.key, }, }); - this.setValue(applHost, valueValue, this.value); + this.setValue(ctx, valueValue, this.value); return true; } diff --git a/packages/cc/src/cc/EntryControlCC.ts b/packages/cc/src/cc/EntryControlCC.ts index c86971821171..e48b916c9aae 100644 --- a/packages/cc/src/cc/EntryControlCC.ts +++ b/packages/cc/src/cc/EntryControlCC.ts @@ -13,11 +13,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { buffer2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -31,10 +27,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -570,19 +566,19 @@ export class EntryControlCCEventSupportedReport extends EntryControlCC { this.maxKeyCacheTimeout = this.payload[offset + 3]; } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Store min/max cache size and timeout as metadata const keyCacheSizeValue = EntryControlCCValues.keyCacheSize; - this.setMetadata(applHost, keyCacheSizeValue, { + this.setMetadata(ctx, keyCacheSizeValue, { ...keyCacheSizeValue.meta, min: this.minKeyCacheSize, max: this.maxKeyCacheSize, }); const keyCacheTimeoutValue = EntryControlCCValues.keyCacheTimeout; - this.setMetadata(applHost, keyCacheTimeoutValue, { + this.setMetadata(ctx, keyCacheTimeoutValue, { ...keyCacheTimeoutValue.meta, min: this.minKeyCacheTimeout, max: this.maxKeyCacheTimeout, diff --git a/packages/cc/src/cc/HumidityControlModeCC.ts b/packages/cc/src/cc/HumidityControlModeCC.ts index ccb47e362b7f..940c1735315c 100644 --- a/packages/cc/src/cc/HumidityControlModeCC.ts +++ b/packages/cc/src/cc/HumidityControlModeCC.ts @@ -12,11 +12,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -30,10 +26,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -368,12 +364,12 @@ export class HumidityControlModeCCSupportedReport } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Use this information to create the metadata for the mode property const modeValue = HumidityControlModeCCValues.mode; - this.setMetadata(applHost, modeValue, { + this.setMetadata(ctx, modeValue, { ...modeValue.meta, states: enumValuesToMetadataStates( HumidityControlMode, diff --git a/packages/cc/src/cc/HumidityControlSetpointCC.ts b/packages/cc/src/cc/HumidityControlSetpointCC.ts index 9cbfdc5c78e3..82eb4d7d199c 100644 --- a/packages/cc/src/cc/HumidityControlSetpointCC.ts +++ b/packages/cc/src/cc/HumidityControlSetpointCC.ts @@ -17,11 +17,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -35,10 +31,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -593,8 +589,8 @@ export class HumidityControlSetpointCCReport extends HumidityControlSetpointCC { this.scale = scale; } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; const scale = getScale(this.scale); @@ -602,22 +598,22 @@ export class HumidityControlSetpointCCReport extends HumidityControlSetpointCC { this.type, ); const existingMetadata = this.getMetadata( - applHost, + ctx, setpointValue, ); // Update the metadata when it is missing or the unit has changed if (existingMetadata?.unit !== scale.unit) { - this.setMetadata(applHost, setpointValue, { + this.setMetadata(ctx, setpointValue, { ...(existingMetadata ?? setpointValue.meta), unit: scale.unit, }); } - this.setValue(applHost, setpointValue, this._value); + this.setValue(ctx, setpointValue, this._value); // Remember the device-preferred setpoint scale so it can be used in SET commands this.setValue( - applHost, + ctx, HumidityControlSetpointCCValues.setpointScale(this.type), this.scale, ); @@ -858,14 +854,14 @@ export class HumidityControlSetpointCCCapabilitiesReport parseFloatWithScale(this.payload.subarray(1 + bytesRead))); } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Predefine the metadata const setpointValue = HumidityControlSetpointCCValues.setpoint( this.type, ); - this.setMetadata(applHost, setpointValue, { + this.setMetadata(ctx, setpointValue, { ...setpointValue.meta, min: this._minValue, max: this._maxValue, diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index d76af831f932..8e8e75e03d13 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -15,11 +15,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { clamp, roundTo } from "alcalzone-shared/math"; @@ -35,10 +31,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -1070,19 +1066,19 @@ export class IndicatorCCReport extends IndicatorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; if (this.indicator0Value != undefined) { - if (!this.supportsV2Indicators(applHost)) { + if (!this.supportsV2Indicators(ctx)) { // Publish the value const valueV1 = IndicatorCCValues.valueV1; - this.setMetadata(applHost, valueV1); - this.setValue(applHost, valueV1, this.indicator0Value); + this.setMetadata(ctx, valueV1); + this.setValue(ctx, valueV1, this.indicator0Value); } else { if (this.isSinglecast()) { // Don't! - applHost.logNode(this.nodeId, { + ctx.logNode(this.nodeId, { message: `ignoring V1 indicator report because the node supports V2 indicators`, direction: "none", @@ -1093,7 +1089,7 @@ export class IndicatorCCReport extends IndicatorCC { } else if (this.values) { // Store the simple values first for (const value of this.values) { - this.setIndicatorValue(applHost, value); + this.setIndicatorValue(ctx, value); } // Then group values into the convenience properties @@ -1107,7 +1103,7 @@ export class IndicatorCCReport extends IndicatorCC { if (timeout?.seconds) timeoutString += `${timeout.seconds}s`; this.setValue( - applHost, + ctx, IndicatorCCValues.timeout, timeoutString, ); @@ -1280,13 +1276,13 @@ export class IndicatorCCSupportedReport extends IndicatorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; if (this.indicatorId !== 0x00) { // Remember which property IDs are supported this.setValue( - applHost, + ctx, IndicatorCCValues.supportedPropertyIDs(this.indicatorId), this.supportedProperties, ); @@ -1415,12 +1411,12 @@ export class IndicatorCCDescriptionReport extends IndicatorCC { public indicatorId: number; public description: string; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; if (this.description) { this.setValue( - applHost, + ctx, IndicatorCCValues.indicatorDescription(this.indicatorId), this.description, ); diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 9eb93b56f9ff..5a58c8e1e4b4 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -15,11 +15,7 @@ import { parseFloatWithScale, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; @@ -36,10 +32,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -1728,51 +1724,51 @@ export class IrrigationCCValveInfoReport extends IrrigationCC { public readonly errorHighFlow?: boolean; public readonly errorLowFlow?: boolean; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // connected const valveConnectedValue = IrrigationCCValues.valveConnected( this.valveId, ); - this.ensureMetadata(applHost, valveConnectedValue); - this.setValue(applHost, valveConnectedValue, this.connected); + this.ensureMetadata(ctx, valveConnectedValue); + this.setValue(ctx, valveConnectedValue, this.connected); // nominalCurrent const nominalCurrentValue = IrrigationCCValues.nominalCurrent( this.valveId, ); - this.ensureMetadata(applHost, nominalCurrentValue); - this.setValue(applHost, nominalCurrentValue, this.nominalCurrent); + this.ensureMetadata(ctx, nominalCurrentValue); + this.setValue(ctx, nominalCurrentValue, this.nominalCurrent); // errorShortCircuit const errorShortCircuitValue = IrrigationCCValues.errorShortCircuit( this.valveId, ); - this.ensureMetadata(applHost, errorShortCircuitValue); - this.setValue(applHost, errorShortCircuitValue, this.errorShortCircuit); + this.ensureMetadata(ctx, errorShortCircuitValue); + this.setValue(ctx, errorShortCircuitValue, this.errorShortCircuit); // errorHighCurrent const errorHighCurrentValue = IrrigationCCValues.errorHighCurrent( this.valveId, ); - this.ensureMetadata(applHost, errorHighCurrentValue); - this.setValue(applHost, errorHighCurrentValue, this.errorHighCurrent); + this.ensureMetadata(ctx, errorHighCurrentValue); + this.setValue(ctx, errorHighCurrentValue, this.errorHighCurrent); // errorLowCurrent const errorLowCurrentValue = IrrigationCCValues.errorLowCurrent( this.valveId, ); - this.ensureMetadata(applHost, errorLowCurrentValue); - this.setValue(applHost, errorLowCurrentValue, this.errorLowCurrent); + this.ensureMetadata(ctx, errorLowCurrentValue); + this.setValue(ctx, errorLowCurrentValue, this.errorLowCurrent); if (this.errorMaximumFlow != undefined) { const errorMaximumFlowValue = IrrigationCCValues.errorMaximumFlow( this.valveId, ); - this.ensureMetadata(applHost, errorMaximumFlowValue); + this.ensureMetadata(ctx, errorMaximumFlowValue); this.setValue( - applHost, + ctx, errorMaximumFlowValue, this.errorMaximumFlow, ); @@ -1782,16 +1778,16 @@ export class IrrigationCCValveInfoReport extends IrrigationCC { const errorHighFlowValue = IrrigationCCValues.errorHighFlow( this.valveId, ); - this.ensureMetadata(applHost, errorHighFlowValue); - this.setValue(applHost, errorHighFlowValue, this.errorHighFlow); + this.ensureMetadata(ctx, errorHighFlowValue); + this.setValue(ctx, errorHighFlowValue, this.errorHighFlow); } if (this.errorLowFlow != undefined) { const errorLowFlowValue = IrrigationCCValues.errorLowFlow( this.valveId, ); - this.ensureMetadata(applHost, errorLowFlowValue); - this.setValue(applHost, errorLowFlowValue, this.errorLowFlow); + this.ensureMetadata(ctx, errorLowFlowValue); + this.setValue(ctx, errorLowFlowValue, this.errorLowFlow); } return true; @@ -2013,15 +2009,15 @@ export class IrrigationCCValveConfigReport extends IrrigationCC { this.useMoistureSensor = !!(this.payload[offset] & 0b10); } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // nominalCurrentHighThreshold const nominalCurrentHighThresholdValue = IrrigationCCValues .nominalCurrentHighThreshold(this.valveId); - this.ensureMetadata(applHost, nominalCurrentHighThresholdValue); + this.ensureMetadata(ctx, nominalCurrentHighThresholdValue); this.setValue( - applHost, + ctx, nominalCurrentHighThresholdValue, this.nominalCurrentHighThreshold, ); @@ -2029,45 +2025,45 @@ export class IrrigationCCValveConfigReport extends IrrigationCC { // nominalCurrentLowThreshold const nominalCurrentLowThresholdValue = IrrigationCCValues .nominalCurrentLowThreshold(this.valveId); - this.ensureMetadata(applHost, nominalCurrentLowThresholdValue); + this.ensureMetadata(ctx, nominalCurrentLowThresholdValue); this.setValue( - applHost, + ctx, nominalCurrentLowThresholdValue, this.nominalCurrentLowThreshold, ); // maximumFlow const maximumFlowValue = IrrigationCCValues.maximumFlow(this.valveId); - this.ensureMetadata(applHost, maximumFlowValue); - this.setValue(applHost, maximumFlowValue, this.maximumFlow); + this.ensureMetadata(ctx, maximumFlowValue); + this.setValue(ctx, maximumFlowValue, this.maximumFlow); // highFlowThreshold const highFlowThresholdValue = IrrigationCCValues.highFlowThreshold( this.valveId, ); - this.ensureMetadata(applHost, highFlowThresholdValue); - this.setValue(applHost, highFlowThresholdValue, this.highFlowThreshold); + this.ensureMetadata(ctx, highFlowThresholdValue); + this.setValue(ctx, highFlowThresholdValue, this.highFlowThreshold); // lowFlowThreshold const lowFlowThresholdValue = IrrigationCCValues.lowFlowThreshold( this.valveId, ); - this.ensureMetadata(applHost, lowFlowThresholdValue); - this.setValue(applHost, lowFlowThresholdValue, this.lowFlowThreshold); + this.ensureMetadata(ctx, lowFlowThresholdValue); + this.setValue(ctx, lowFlowThresholdValue, this.lowFlowThreshold); // useRainSensor const useRainSensorValue = IrrigationCCValues.useRainSensor( this.valveId, ); - this.ensureMetadata(applHost, useRainSensorValue); - this.setValue(applHost, useRainSensorValue, this.useRainSensor); + this.ensureMetadata(ctx, useRainSensorValue); + this.setValue(ctx, useRainSensorValue, this.useRainSensor); // useMoistureSensor const useMoistureSensorValue = IrrigationCCValues.useMoistureSensor( this.valveId, ); - this.ensureMetadata(applHost, useMoistureSensorValue); - this.setValue(applHost, useMoistureSensorValue, this.useMoistureSensor); + this.ensureMetadata(ctx, useMoistureSensorValue); + this.setValue(ctx, useMoistureSensorValue, this.useMoistureSensor); return true; } diff --git a/packages/cc/src/cc/MeterCC.ts b/packages/cc/src/cc/MeterCC.ts index 630976aab876..fc0cfd497f11 100644 --- a/packages/cc/src/cc/MeterCC.ts +++ b/packages/cc/src/cc/MeterCC.ts @@ -35,7 +35,6 @@ import type { GetNode, GetSupportedCCVersion, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { type AllOrNone, @@ -60,10 +59,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -951,17 +950,17 @@ export class MeterCCReport extends MeterCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; - const ccVersion = getEffectiveCCVersion(applHost, this); + const ccVersion = getEffectiveCCVersion(ctx, this); const meter = getMeter(this.type); const scale = getMeterScale(this.type, this.scale) ?? getUnknownMeterScale(this.scale); // Filter out unknown meter types and scales, unless the strict validation is disabled - const measurementValidation = !applHost.getDeviceConfig?.( + const measurementValidation = !ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.disableStrictMeasurementValidation; @@ -976,7 +975,7 @@ export class MeterCCReport extends MeterCC { // Filter out unsupported meter types, scales and rate types if possible if (ccVersion >= 2) { const expectedType = this.getValue( - applHost, + ctx, MeterCCValues.type, ); if (expectedType != undefined) { @@ -986,7 +985,7 @@ export class MeterCCReport extends MeterCC { } const supportedScales = this.getValue( - applHost, + ctx, MeterCCValues.supportedScales, ); if (supportedScales?.length) { @@ -996,7 +995,7 @@ export class MeterCCReport extends MeterCC { } const supportedRateTypes = this.getValue( - applHost, + ctx, MeterCCValues.supportedRateTypes, ); if (supportedRateTypes?.length) { @@ -1017,7 +1016,7 @@ export class MeterCCReport extends MeterCC { this.rateType, this.scale, ); - this.setMetadata(applHost, valueValue, { + this.setMetadata(ctx, valueValue, { ...valueValue.meta, label: getValueLabel(this.type, this.scale, this.rateType), unit: scale.label, @@ -1027,7 +1026,7 @@ export class MeterCCReport extends MeterCC { rateType: this.rateType, }, }); - this.setValue(applHost, valueValue, this.value); + this.setValue(ctx, valueValue, this.value); return true; } @@ -1273,15 +1272,15 @@ export class MeterCCSupportedReport extends MeterCC { @ccValue(MeterCCValues.supportedRateTypes) public readonly supportedRateTypes: readonly RateType[]; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; if (!this.supportsReset) return true; - const ccVersion = getEffectiveCCVersion(applHost, this); + const ccVersion = getEffectiveCCVersion(ctx, this); // Create reset values if (ccVersion < 6) { - this.ensureMetadata(applHost, MeterCCValues.resetAll); + this.ensureMetadata(ctx, MeterCCValues.resetAll); } else { for (const scale of this.supportedScales) { // Only accumulated values can be reset @@ -1293,7 +1292,7 @@ export class MeterCCSupportedReport extends MeterCC { rateType, scale, ); - this.ensureMetadata(applHost, resetSingleValue, { + this.ensureMetadata(ctx, resetSingleValue, { ...resetSingleValue.meta, label: `Reset ${ getValueLabel( diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 83fea4b43d3f..cebb26928b3d 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -29,10 +29,10 @@ import { distinct } from "alcalzone-shared/arrays"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, getEffectiveCCVersion, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -933,21 +933,21 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; const deviceClassValue = MultiChannelCCValues.endpointDeviceClass; const ccsValue = MultiChannelCCValues.endpointCCs; if (this.wasRemoved) { - this.removeValue(applHost, deviceClassValue); - this.removeValue(applHost, ccsValue); + this.removeValue(ctx, deviceClassValue); + this.removeValue(ctx, ccsValue); } else { - this.setValue(applHost, deviceClassValue, { + this.setValue(ctx, deviceClassValue, { generic: this.genericDeviceClass, specific: this.specificDeviceClass, }); - this.setValue(applHost, ccsValue, this.supportedCCs); + this.setValue(ctx, ccsValue, this.supportedCCs); } return true; } diff --git a/packages/cc/src/cc/MultilevelSensorCC.ts b/packages/cc/src/cc/MultilevelSensorCC.ts index 02a464946962..ff6d05919377 100644 --- a/packages/cc/src/cc/MultilevelSensorCC.ts +++ b/packages/cc/src/cc/MultilevelSensorCC.ts @@ -37,7 +37,6 @@ import type { GetUserPreferences, GetValueDB, LogNode, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -50,11 +49,11 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, type CCResponsePredicate, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -670,8 +669,8 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; const sensor = getSensor(this.type); const scale = getSensorScale( @@ -680,17 +679,17 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { ) ?? getUnknownScale(this.scale); // Filter out unknown sensor types and scales, unless the strict validation is disabled - const measurementValidation = !applHost.getDeviceConfig?.( + const measurementValidation = !ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.disableStrictMeasurementValidation; - const ccVersion = getEffectiveCCVersion(applHost, this); + const ccVersion = getEffectiveCCVersion(ctx, this); if (measurementValidation) { // Filter out unsupported sensor types and scales if possible if (ccVersion >= 5) { const supportedSensorTypes = this.getValue( - applHost, + ctx, MultilevelSensorCCValues.supportedSensorTypes, ); if (supportedSensorTypes?.length) { @@ -702,7 +701,7 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { } const supportedScales = this.getValue( - applHost, + ctx, MultilevelSensorCCValues.supportedScales(this.type), ); if (supportedScales?.length) { @@ -729,7 +728,7 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { const sensorName = getSensorName(this.type); const sensorValue = MultilevelSensorCCValues.value(sensorName); - this.setMetadata(applHost, sensorValue, { + this.setMetadata(ctx, sensorValue, { ...sensorValue.meta, unit: scale.unit, ccSpecific: { @@ -737,7 +736,7 @@ export class MultilevelSensorCCReport extends MultilevelSensorCC { scale: scale.key, }, }); - this.setValue(applHost, sensorValue, this.value); + this.setValue(ctx, sensorValue, this.value); return true; } diff --git a/packages/cc/src/cc/MultilevelSwitchCC.ts b/packages/cc/src/cc/MultilevelSwitchCC.ts index bc14ee53e3bb..a7a188d8e4f4 100644 --- a/packages/cc/src/cc/MultilevelSwitchCC.ts +++ b/packages/cc/src/cc/MultilevelSwitchCC.ts @@ -13,11 +13,7 @@ import { parseMaybeNumber, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -33,10 +29,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -878,9 +874,9 @@ export class MultilevelSwitchCCSupportedReport extends MultilevelSwitchCC { @ccValue(MultilevelSwitchCCValues.switchType) public readonly switchType: SwitchType; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; - this.createMetadataForLevelChangeActions(applHost, this.switchType); + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; + this.createMetadataForLevelChangeActions(ctx, this.switchType); return true; } diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index d50201f0e5fe..f0704a5d06cf 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -41,7 +41,6 @@ import type { GetSupportedCCVersion, GetValueDB, LogNode, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -55,11 +54,11 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, InvalidCC, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -1034,10 +1033,10 @@ export class NotificationCCReport extends NotificationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; - const ccVersion = getEffectiveCCVersion(applHost, this); + const ccVersion = getEffectiveCCVersion(ctx, this); // Check if we need to re-interpret the alarm values somehow if ( @@ -1050,7 +1049,7 @@ export class NotificationCCReport extends NotificationCC { // to send Alarm frames instead (GH#1034) const supportedNotificationTypes = this.getValue< readonly number[] - >(applHost, NotificationCCValues.supportedNotificationTypes); + >(ctx, NotificationCCValues.supportedNotificationTypes); if ( isArray(supportedNotificationTypes) && supportedNotificationTypes.includes(this.alarmType) @@ -1058,7 +1057,7 @@ export class NotificationCCReport extends NotificationCC { const supportedNotificationEvents = this.getValue< readonly number[] >( - applHost, + ctx, NotificationCCValues.supportedNotificationEvents( this.alarmType, ), @@ -1068,7 +1067,7 @@ export class NotificationCCReport extends NotificationCC { && supportedNotificationEvents.includes(this.alarmLevel) ) { // This alarm frame corresponds to a valid notification event - applHost.logNode( + ctx.logNode( this.nodeId as number, `treating V1 Alarm frame as Notification Report`, ); @@ -1080,7 +1079,7 @@ export class NotificationCCReport extends NotificationCC { } } else { // V1 Alarm, check if there is a compat option to map this V1 report to a V2+ report - const mapping = applHost.getDeviceConfig?.( + const mapping = ctx.getDeviceConfig?.( this.nodeId as number, )?.compat?.alarmMapping; const match = mapping?.find( @@ -1090,7 +1089,7 @@ export class NotificationCCReport extends NotificationCC { || m.from.alarmLevel === this.alarmLevel), ); if (match) { - applHost.logNode( + ctx.logNode( this.nodeId as number, `compat mapping found, treating V1 Alarm frame as Notification Report`, ); @@ -1117,17 +1116,17 @@ export class NotificationCCReport extends NotificationCC { } // Now we can interpret the event parameters and turn them into something useful - this.parseEventParameters(applHost); + this.parseEventParameters(ctx); if (this.alarmType != undefined) { const alarmTypeValue = NotificationCCValues.alarmType; - this.ensureMetadata(applHost, alarmTypeValue); - this.setValue(applHost, alarmTypeValue, this.alarmType); + this.ensureMetadata(ctx, alarmTypeValue); + this.setValue(ctx, alarmTypeValue, this.alarmType); } if (this.alarmLevel != undefined) { const alarmLevelValue = NotificationCCValues.alarmLevel; - this.ensureMetadata(applHost, alarmLevelValue); - this.setValue(applHost, alarmLevelValue, this.alarmLevel); + this.ensureMetadata(ctx, alarmLevelValue); + this.setValue(ctx, alarmLevelValue, this.alarmLevel); } return true; @@ -1635,12 +1634,12 @@ export class NotificationCCEventSupportedReport extends NotificationCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Store which events this notification supports this.setValue( - applHost, + ctx, NotificationCCValues.supportedNotificationEvents( this.notificationType, ), @@ -1653,7 +1652,7 @@ export class NotificationCCEventSupportedReport extends NotificationCC { if (!notification) { // This is an unknown notification this.setMetadata( - applHost, + ctx, NotificationCCValues.unknownNotificationType( this.notificationType, ), @@ -1675,12 +1674,12 @@ export class NotificationCCEventSupportedReport extends NotificationCC { const metadata = getNotificationValueMetadata( isFirst ? undefined - : this.getMetadata(applHost, notificationValue), + : this.getMetadata(ctx, notificationValue), notification, valueConfig, ); - this.setMetadata(applHost, notificationValue, metadata); + this.setMetadata(ctx, notificationValue, metadata); isFirst = false; } diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index f7013a94fdcf..12a29d5e0a1c 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -14,11 +14,7 @@ import { parseBitMask, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { padStart } from "alcalzone-shared/strings"; @@ -33,10 +29,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -616,12 +612,12 @@ export class ProtectionCCSupportedReport extends ProtectionCC { ); } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // update metadata (partially) for the local and rf values const localStateValue = ProtectionCCValues.localProtectionState; - this.setMetadata(applHost, localStateValue, { + this.setMetadata(ctx, localStateValue, { ...localStateValue.meta, states: enumValuesToMetadataStates( LocalProtectionState, @@ -630,7 +626,7 @@ export class ProtectionCCSupportedReport extends ProtectionCC { }); const rfStateValue = ProtectionCCValues.rfProtectionState; - this.setMetadata(applHost, rfStateValue, { + this.setMetadata(ctx, rfStateValue, { ...rfStateValue.meta, states: enumValuesToMetadataStates( RFProtectionState, diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index 5bcc92f658ac..e47c52020b77 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -11,11 +11,7 @@ import { getCCName, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -31,10 +27,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -436,8 +432,8 @@ export class SceneActuatorConfigurationCCReport public readonly level?: number; public readonly dimmingDuration?: Duration; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Do not persist values for an inactive scene if ( @@ -451,14 +447,14 @@ export class SceneActuatorConfigurationCCReport const levelValue = SceneActuatorConfigurationCCValues.level( this.sceneId, ); - this.ensureMetadata(applHost, levelValue); + this.ensureMetadata(ctx, levelValue); const dimmingDurationValue = SceneActuatorConfigurationCCValues .dimmingDuration(this.sceneId); - this.ensureMetadata(applHost, dimmingDurationValue); + this.ensureMetadata(ctx, dimmingDurationValue); - this.setValue(applHost, levelValue, this.level); - this.setValue(applHost, dimmingDurationValue, this.dimmingDuration); + this.setValue(ctx, levelValue, this.level); + this.setValue(ctx, dimmingDurationValue, this.dimmingDuration); return true; } diff --git a/packages/cc/src/cc/SceneControllerConfigurationCC.ts b/packages/cc/src/cc/SceneControllerConfigurationCC.ts index 6e09a2e52354..f028bf3dfa4c 100644 --- a/packages/cc/src/cc/SceneControllerConfigurationCC.ts +++ b/packages/cc/src/cc/SceneControllerConfigurationCC.ts @@ -16,7 +16,6 @@ import type { CCEncodingContext, GetDeviceConfig, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -33,10 +32,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -561,8 +560,8 @@ export class SceneControllerConfigurationCCReport public readonly sceneId: number; public readonly dimmingDuration: Duration; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // If groupId = 0, values are meaningless if (this.groupId === 0) return false; @@ -570,13 +569,13 @@ export class SceneControllerConfigurationCCReport const sceneIdValue = SceneControllerConfigurationCCValues.sceneId( this.groupId, ); - this.ensureMetadata(applHost, sceneIdValue); + this.ensureMetadata(ctx, sceneIdValue); const dimmingDurationValue = SceneControllerConfigurationCCValues .dimmingDuration(this.groupId); - this.ensureMetadata(applHost, dimmingDurationValue); + this.ensureMetadata(ctx, dimmingDurationValue); - this.setValue(applHost, sceneIdValue, this.sceneId); - this.setValue(applHost, dimmingDurationValue, this.dimmingDuration); + this.setValue(ctx, sceneIdValue, this.sceneId); + this.setValue(ctx, dimmingDurationValue, this.dimmingDuration); return true; } diff --git a/packages/cc/src/cc/ScheduleEntryLockCC.ts b/packages/cc/src/cc/ScheduleEntryLockCC.ts index 5258f3411ec8..f8e0782526bd 100644 --- a/packages/cc/src/cc/ScheduleEntryLockCC.ts +++ b/packages/cc/src/cc/ScheduleEntryLockCC.ts @@ -13,11 +13,7 @@ import { validatePayload, } from "@zwave-js/core"; import { type EndpointId, type MaybeNotKnown } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host"; import { type AllOrNone, formatDate, @@ -29,10 +25,10 @@ import { validateArgs } from "@zwave-js/transformers"; import { CCAPI } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -1245,12 +1241,12 @@ export class ScheduleEntryLockCCWeekDayScheduleReport public stopHour?: number; public stopMinute?: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; persistSchedule.call( this, - applHost, + ctx, ScheduleEntryLockScheduleKind.WeekDay, this.userId, this.slotId, @@ -1575,12 +1571,12 @@ export class ScheduleEntryLockCCYearDayScheduleReport public stopHour?: number; public stopMinute?: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; persistSchedule.call( this, - applHost, + ctx, ScheduleEntryLockScheduleKind.YearDay, this.userId, this.slotId, @@ -1981,12 +1977,12 @@ export class ScheduleEntryLockCCDailyRepeatingScheduleReport public durationHour?: number; public durationMinute?: number; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; persistSchedule.call( this, - applHost, + ctx, ScheduleEntryLockScheduleKind.DailyRepeating, this.userId, this.slotId, diff --git a/packages/cc/src/cc/ThermostatFanModeCC.ts b/packages/cc/src/cc/ThermostatFanModeCC.ts index 101b02f3c008..0bace1013cbe 100644 --- a/packages/cc/src/cc/ThermostatFanModeCC.ts +++ b/packages/cc/src/cc/ThermostatFanModeCC.ts @@ -13,11 +13,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -31,10 +27,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -434,12 +430,12 @@ export class ThermostatFanModeCCSupportedReport extends ThermostatFanModeCC { ); } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Remember which fan modes are supported const fanModeValue = ThermostatFanModeCCValues.fanMode; - this.setMetadata(applHost, fanModeValue, { + this.setMetadata(ctx, fanModeValue, { ...fanModeValue.meta, states: enumValuesToMetadataStates( ThermostatFanMode, diff --git a/packages/cc/src/cc/ThermostatModeCC.ts b/packages/cc/src/cc/ThermostatModeCC.ts index bbee588b7fa5..bea74df217b5 100644 --- a/packages/cc/src/cc/ThermostatModeCC.ts +++ b/packages/cc/src/cc/ThermostatModeCC.ts @@ -14,11 +14,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -32,10 +28,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -434,8 +430,8 @@ export class ThermostatModeCCReport extends ThermostatModeCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Update the supported modes if a mode is used that wasn't previously // reported to be supported. This shouldn't happen, but well... it does anyways @@ -443,7 +439,7 @@ export class ThermostatModeCCReport extends ThermostatModeCC { const supportedModesValue = ThermostatModeCCValues.supportedModes; const supportedModes = this.getValue( - applHost, + ctx, supportedModesValue, ); @@ -455,14 +451,14 @@ export class ThermostatModeCCReport extends ThermostatModeCC { supportedModes.push(this.mode); supportedModes.sort(); - this.setMetadata(applHost, thermostatModeValue, { + this.setMetadata(ctx, thermostatModeValue, { ...thermostatModeValue.meta, states: enumValuesToMetadataStates( ThermostatMode, supportedModes, ), }); - this.setValue(applHost, supportedModesValue, supportedModes); + this.setValue(ctx, supportedModesValue, supportedModes); } return true; } @@ -535,12 +531,12 @@ export class ThermostatModeCCSupportedReport extends ThermostatModeCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Use this information to create the metadata for the mode property const thermostatModeValue = ThermostatModeCCValues.thermostatMode; - this.setMetadata(applHost, thermostatModeValue, { + this.setMetadata(ctx, thermostatModeValue, { ...thermostatModeValue.meta, states: enumValuesToMetadataStates( ThermostatMode, diff --git a/packages/cc/src/cc/ThermostatSetpointCC.ts b/packages/cc/src/cc/ThermostatSetpointCC.ts index d0a731559d14..ee12fdf6559d 100644 --- a/packages/cc/src/cc/ThermostatSetpointCC.ts +++ b/packages/cc/src/cc/ThermostatSetpointCC.ts @@ -18,11 +18,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -36,10 +32,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; @@ -644,29 +640,29 @@ export class ThermostatSetpointCCReport extends ThermostatSetpointCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; const scale = getScale(this.scale); const setpointValue = ThermostatSetpointCCValues.setpoint(this.type); const existingMetadata = this.getMetadata( - applHost, + ctx, setpointValue, ); // Update the metadata when it is missing or the unit has changed if (existingMetadata?.unit !== scale.unit) { - this.setMetadata(applHost, setpointValue, { + this.setMetadata(ctx, setpointValue, { ...(existingMetadata ?? setpointValue.meta), unit: scale.unit, }); } - this.setValue(applHost, setpointValue, this.value); + this.setValue(ctx, setpointValue, this.value); // Remember the device-preferred setpoint scale so it can be used in SET commands this.setValue( - applHost, + ctx, ThermostatSetpointCCValues.setpointScale(this.type), scale.key, ); @@ -796,12 +792,12 @@ export class ThermostatSetpointCCCapabilitiesReport } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Predefine the metadata const setpointValue = ThermostatSetpointCCValues.setpoint(this.type); - this.setMetadata(applHost, setpointValue, { + this.setMetadata(ctx, setpointValue, { ...setpointValue.meta, min: this.minValue, max: this.maxValue, diff --git a/packages/cc/src/cc/TimeParametersCC.ts b/packages/cc/src/cc/TimeParametersCC.ts index f60416d42441..7d17582e4f6a 100644 --- a/packages/cc/src/cc/TimeParametersCC.ts +++ b/packages/cc/src/cc/TimeParametersCC.ts @@ -17,7 +17,6 @@ import type { CCEncodingContext, GetDeviceConfig, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { @@ -31,10 +30,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -278,16 +277,16 @@ export class TimeParametersCCReport extends TimeParametersCC { ); } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(ctx: PersistValuesContext): boolean { // If necessary, fix the date and time before persisting it - const local = shouldUseLocalTime(applHost, this.getEndpoint(applHost)!); + const local = shouldUseLocalTime(ctx, this.getEndpoint(ctx)!); if (local) { // The initial assumption was incorrect, re-interpret the time const segments = dateToSegments(this.dateAndTime, false); this._dateAndTime = segmentsToDate(segments, local); } - return super.persistValues(applHost); + return super.persistValues(ctx); } private _dateAndTime: Date; @@ -356,18 +355,18 @@ export class TimeParametersCCSet extends TimeParametersCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(ctx: PersistValuesContext): boolean { // We do not actually persist anything here, but we need access to the node // in order to interpret the date segments correctly - const local = shouldUseLocalTime(applHost, this.getEndpoint(applHost)!); + const local = shouldUseLocalTime(ctx, this.getEndpoint(ctx)!); if (local) { // The initial assumption was incorrect, re-interpret the time const segments = dateToSegments(this.dateAndTime, false); this.dateAndTime = segmentsToDate(segments, local); } - return super.persistValues(applHost); + return super.persistValues(ctx); } public dateAndTime: Date; diff --git a/packages/cc/src/cc/UserCodeCC.ts b/packages/cc/src/cc/UserCodeCC.ts index 42ec0521611b..3569d7a22224 100644 --- a/packages/cc/src/cc/UserCodeCC.ts +++ b/packages/cc/src/cc/UserCodeCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, GetSupportedCCVersion, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, @@ -43,10 +42,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, type RefreshValuesContext, getEffectiveCCVersion, gotDeserializationOptions, @@ -1375,12 +1374,12 @@ export class UserCodeCCReport extends UserCodeCC public readonly userIdStatus: UserIDStatus; public readonly userCode: string | Buffer; - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; persistUserCode.call( this, - applHost, + ctx, this.userId, this.userIdStatus, this.userCode, @@ -1746,17 +1745,17 @@ export class UserCodeCCKeypadModeReport extends UserCodeCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; // Update the keypad modes metadata const supportedKeypadModes: KeypadMode[] = this.getValue( - applHost, + ctx, UserCodeCCValues.supportedKeypadModes, ) ?? [this.keypadMode]; const keypadModeValue = UserCodeCCValues.keypadMode; - this.setMetadata(applHost, keypadModeValue, { + this.setMetadata(ctx, keypadModeValue, { ...keypadModeValue.meta, states: enumValuesToMetadataStates( KeypadMode, @@ -2021,13 +2020,13 @@ export class UserCodeCCExtendedUserCodeReport extends UserCodeCC { this.nextUserId = this.payload.readUInt16BE(offset); } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; for (const { userId, userIdStatus, userCode } of this.userCodes) { persistUserCode.call( this, - applHost, + ctx, userId, userIdStatus, userCode, diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 70710946aab5..1fe8a52c93c3 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -9,11 +9,7 @@ import { supervisedCommandSucceeded, validatePayload, } from "@zwave-js/core/safe"; -import type { - CCEncodingContext, - GetValueDB, - ZWaveApplicationHost, -} from "@zwave-js/host/safe"; +import type { CCEncodingContext, GetValueDB } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; import { clamp } from "alcalzone-shared/math"; @@ -28,10 +24,10 @@ import { } from "../lib/API"; import { type CCCommandOptions, - type CCNode, CommandClass, type CommandClassDeserializationOptions, type InterviewContext, + type PersistValuesContext, gotDeserializationOptions, } from "../lib/CommandClass"; import { @@ -464,9 +460,9 @@ export class WakeUpCCIntervalCapabilitiesReport extends WakeUpCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; - const valueDB = this.getValueDB(applHost); + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; + const valueDB = this.getValueDB(ctx); // Store the received information as metadata for the wake up interval valueDB.setMetadata( diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index 4c7939b6932a..ca3329ef440d 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -14,7 +14,6 @@ import type { CCEncodingContext, GetDeviceConfig, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; @@ -31,8 +30,10 @@ import { } from "../../lib/API"; import { type CCCommandOptions, - type CCNode, type CommandClassDeserializationOptions, + type InterviewContext, + type PersistValuesContext, + type RefreshValuesContext, gotDeserializationOptions, } from "../../lib/CommandClass"; import { expectedCCResponse } from "../../lib/CommandClassDecorators"; @@ -247,33 +248,33 @@ export class FibaroCC extends ManufacturerProprietaryCC { public fibaroCCCommand?: number; public async interview( - applHost: ZWaveApplicationHost, + ctx: InterviewContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; // Iterate through all supported Fibaro CCs and interview them - const supportedFibaroCCIDs = getSupportedFibaroCCIDs(applHost, node.id); + const supportedFibaroCCIDs = getSupportedFibaroCCIDs(ctx, node.id); for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { const instance = new SubConstructor({ nodeId: node.id }); - await instance.interview(applHost); + await instance.interview(ctx); } } } public async refreshValues( - applHost: ZWaveApplicationHost, + ctx: RefreshValuesContext, ): Promise { - const node = this.getNode(applHost)!; + const node = this.getNode(ctx)!; // Iterate through all supported Fibaro CCs and let them refresh their values - const supportedFibaroCCIDs = getSupportedFibaroCCIDs(applHost, node.id); + const supportedFibaroCCIDs = getSupportedFibaroCCIDs(ctx, node.id); for (const ccId of supportedFibaroCCIDs) { const SubConstructor = getFibaroCCConstructor(ccId); if (SubConstructor) { const instance = new SubConstructor({ nodeId: node.id }); - await instance.refreshValues(applHost); + await instance.refreshValues(ctx); } } } @@ -325,31 +326,27 @@ export class FibaroVenetianBlindCC extends FibaroCC { } } - public async interview( - applHost: ZWaveApplicationHost, - ): Promise { - const node = this.getNode(applHost)!; + public async interview(ctx: InterviewContext): Promise { + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Interviewing Fibaro Venetian Blind CC...`, direction: "none", }); // Nothing special, just get the values - await this.refreshValues(applHost); + await this.refreshValues(ctx); } - public async refreshValues( - applHost: ZWaveApplicationHost, - ): Promise { - const node = this.getNode(applHost)!; + public async refreshValues(ctx: RefreshValuesContext): Promise { + const node = this.getNode(ctx)!; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: "Requesting venetian blind position and tilt...", direction: "outbound", }); - const resp = await applHost.sendCommand( + const resp = await ctx.sendCommand( new FibaroVenetianBlindCCGet({ nodeId: this.nodeId, endpoint: this.endpointIndex, @@ -359,7 +356,7 @@ export class FibaroVenetianBlindCC extends FibaroCC { const logMessage = `received venetian blind state: position: ${resp.position} tilt: ${resp.tilt}`; - applHost.logNode(node.id, { + ctx.logNode(node.id, { message: logMessage, direction: "inbound", }); @@ -454,9 +451,9 @@ export class FibaroVenetianBlindCCReport extends FibaroVenetianBlindCC { } } - public persistValues(applHost: ZWaveApplicationHost): boolean { - if (!super.persistValues(applHost)) return false; - const valueDB = this.getValueDB(applHost); + public persistValues(ctx: PersistValuesContext): boolean { + if (!super.persistValues(ctx)) return false; + const valueDB = this.getValueDB(ctx); if (this.position != undefined) { const positionValueId = getFibaroVenetianBlindPositionValueId( diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 3f64934e7f15..ca1269e934fa 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -41,6 +41,7 @@ import type { GetNode, GetSupportedCCVersion, GetValueDB, + LogNode, LookupManufacturer, ZWaveApplicationHost, } from "@zwave-js/host"; @@ -163,6 +164,15 @@ export type RefreshValuesContext = CCAPIHost< CCAPINode & GetEndpoint >; +export type PersistValuesContext = + & GetValueDB + & GetSupportedCCVersion + & GetDeviceConfig + & GetNode< + NodeId & GetEndpoint + > + & LogNode; + export function getEffectiveCCVersion( ctx: GetSupportedCCVersion, cc: CCId, @@ -961,17 +971,17 @@ export class CommandClass implements CCId { * Persists all values for this CC instance into the value DB which are annotated with @ccValue. * Returns `true` if the process succeeded, `false` if the value DB cannot be accessed. */ - public persistValues(applHost: ZWaveApplicationHost): boolean { + public persistValues(ctx: PersistValuesContext): boolean { let valueDB: ValueDB; try { - valueDB = this.getValueDB(applHost); + valueDB = this.getValueDB(ctx); } catch { return false; } // To determine which value IDs to expose, we need to know the CC version // that we're doing this for - const supportedVersion = applHost.getSupportedCCVersion( + const supportedVersion = ctx.getSupportedCCVersion( this.ccId, // Values are only persisted for singlecast, so we know nodeId is a number this.nodeId as number, @@ -1002,7 +1012,7 @@ export class CommandClass implements CCId { // ... or if we know which CC version the node supports // and the value may be automatically created || (supportedVersion >= value.options.minVersion - && this.shouldAutoCreateValue(applHost, value))); + && this.shouldAutoCreateValue(ctx, value))); if (createMetadata && !valueDB.hasMetadata(valueId)) { valueDB.setMetadata(valueId, value.meta); diff --git a/packages/maintenance/src/codeshifts/refactorPersistValues.ts b/packages/maintenance/src/codeshifts/refactorPersistValues.ts new file mode 100644 index 000000000000..d0a7f40c7856 --- /dev/null +++ b/packages/maintenance/src/codeshifts/refactorPersistValues.ts @@ -0,0 +1,129 @@ +// Codemod to rename imports across the entire codebase. +// Run with jscodeshift: https://jscodeshift.com/run/cli/ +// options: +// from: the name of the import to rename +// to: the new name of the import +// typeOnly: whether to only rename type imports (optional, default false) + +// examples: https://github.com/wingy3181/jscodeshift-examples/tree/master/src/examples + +import { + type API, + type FileInfo, + type Identifier, + type JSCodeshift, + type Options, + type Transform, +} from "jscodeshift"; + +const transform: Transform = ( + file: FileInfo, + api: API, + {}: Options, +) => { + const j: JSCodeshift = api.jscodeshift; + const root = j(file.source); + + const ccImplementations = root.find(j.ClassDeclaration, { + superClass(value) { + return value?.type === "Identifier" && value.name.endsWith("CC"); + }, + }); + + const methods = ccImplementations.find(j.ClassMethod, { + kind: "method", + }).filter(({ node }) => { + return node.key.type === "Identifier" + && (node.key.name === "persistValues") + && node.params.length >= 1 + && node.params[0].type === "Identifier" + && node.params[0].name.endsWith("applHost") + && node.params[0].typeAnnotation?.type === "TSTypeAnnotation" + && node.params[0].typeAnnotation.typeAnnotation.type + === "TSTypeReference" + && node.params[0].typeAnnotation.typeAnnotation.typeName.type + === "Identifier" + && node.params[0].typeAnnotation.typeAnnotation.typeName.name + === "ZWaveApplicationHost"; + }); + + if (!methods.length) return file.source; + + methods.replaceWith(({ node }) => { + const ident = node.params[0] as Identifier; + ident.name = "ctx"; + // @ts-expect-error + ident.typeAnnotation.typeAnnotation.typeName.name = + "PersistValuesContext"; + // @ts-expect-error + ident.typeAnnotation.typeAnnotation.typeParameters = undefined; + return node; + }); + + const paramUsages = methods.find(j.Identifier, { + name(value) { + return value.endsWith("applHost"); + }, + }); + paramUsages.replaceWith(({ node }) => { + node.name = "ctx"; + return node; + }); + + const targetDecl = root + .find( + j.ImportDeclaration, + { + source: { + type: "StringLiteral", + value: "../lib/CommandClass", + }, + }, + ); + targetDecl.at(0).get().node.specifiers.push( + j.importSpecifier(j.identifier("PersistValuesContext")), + ); + + return root.toSource(); + + // const imp = root + // .find( + // j.ImportDeclaration, + // { importKind: typeOnly ? "type" : undefined }, + // ) + // .find(j.ImportSpecifier, { + // imported: { + // name: from, + // }, + // }); + + // return imp.replaceWith(({ node }) => { + // node.imported.name = to; + // return node; + // }).toSource(); + + // return ( + // j(file.source) + // .find(j.FunctionDeclaration) + // // Target a particular function declaration + // .filter(({ node: functionDeclaration }) => functionDeclaration.id.name === functionName) + // .replaceWith(({ node: functionDeclaration }) => { + // // Create a function call expression statement + // const functionCallExpressionStatement = j.expressionStatement( + // j.callExpression(j.identifier(functionNameToCall), []) + // ); + + // // Create a comment and add it as a leading comment to the function call expression + // const commentLine = j.commentLine(comment); + // functionCallExpressionStatement.comments = [commentLine]; + + // // Append the function call expression to the function declaration's existing body + // functionDeclaration.body.body = [...functionDeclaration.body.body, functionCallExpressionStatement]; + // return functionDeclaration; + // }) + // .toSource() + // ); +}; + +export default transform; +export const parser = "ts"; From c4daea5f1670725363234180079832363ca00462 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 17 Oct 2024 09:06:11 +0200 Subject: [PATCH 57/60] refactor: replace ZWaveApplicationHost in mergePartialCCs --- packages/cc/src/cc/AssociationCC.ts | 2 -- packages/cc/src/cc/ConfigurationCC.ts | 3 --- packages/cc/src/cc/MultiChannelAssociationCC.ts | 2 -- packages/cc/src/cc/MultiChannelCC.ts | 2 -- packages/cc/src/cc/SceneActuatorConfigurationCC.ts | 8 ++++---- packages/cc/src/cc/SecurityCC.ts | 3 --- packages/cc/src/cc/TransportServiceCC.ts | 2 -- packages/cc/src/lib/CommandClass.ts | 2 -- packages/host/src/mocks.ts | 14 +++++++++----- packages/zwave-js/src/lib/driver/Driver.ts | 6 +++--- .../zwave-js/src/lib/telemetry/deviceConfig.ts | 3 +-- .../ignoreCCVersion0ForKnownSupportedCCs.test.ts | 1 - .../test/driver/nodeAsleepBlockNonceReport.test.ts | 1 - .../lib/test/driver/s0AndS2Encapsulation.test.ts | 2 +- .../src/lib/test/driver/s0Encapsulation.test.ts | 2 +- .../test/driver/s0EncapsulationTwoNodes.test.ts | 1 - test/decodeMessage.ts | 6 +++--- 17 files changed, 22 insertions(+), 38 deletions(-) diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index a2ce46e98e9a..31a9157602c6 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -18,7 +18,6 @@ import type { CCParsingContext, GetDeviceConfig, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { distinct } from "alcalzone-shared/arrays"; @@ -667,7 +666,6 @@ export class AssociationCCReport extends AssociationCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: AssociationCCReport[], _ctx: CCParsingContext, ): void { diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index 6be4759685a0..422253fabd89 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -36,7 +36,6 @@ import type { GetNode, GetSupportedCCVersion, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -2389,7 +2388,6 @@ export class ConfigurationCCNameReport extends ConfigurationCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: ConfigurationCCNameReport[], _ctx: CCParsingContext, ): void { @@ -2548,7 +2546,6 @@ export class ConfigurationCCInfoReport extends ConfigurationCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: ConfigurationCCInfoReport[], _ctx: CCParsingContext, ): void { diff --git a/packages/cc/src/cc/MultiChannelAssociationCC.ts b/packages/cc/src/cc/MultiChannelAssociationCC.ts index 415de5bcfc62..15dd6dd36a81 100644 --- a/packages/cc/src/cc/MultiChannelAssociationCC.ts +++ b/packages/cc/src/cc/MultiChannelAssociationCC.ts @@ -19,7 +19,6 @@ import type { CCEncodingContext, CCParsingContext, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; @@ -818,7 +817,6 @@ export class MultiChannelAssociationCCReport extends MultiChannelAssociationCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: MultiChannelAssociationCCReport[], _ctx: CCParsingContext, ): void { diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index cebb26928b3d..af3069711f05 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -22,7 +22,6 @@ import type { CCEncodingContext, CCParsingContext, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { validateArgs } from "@zwave-js/transformers"; import { distinct } from "alcalzone-shared/arrays"; @@ -1106,7 +1105,6 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: MultiChannelCCEndPointFindReport[], _ctx: CCParsingContext, ): void { diff --git a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts index e47c52020b77..d2d6640025bf 100644 --- a/packages/cc/src/cc/SceneActuatorConfigurationCC.ts +++ b/packages/cc/src/cc/SceneActuatorConfigurationCC.ts @@ -323,15 +323,15 @@ export class SceneActuatorConfigurationCC extends CommandClass { // `refreshValues()` would create 255 `Get` commands to be issued to the node // Therefore, I think we should not implement it. Here is how it would be implemented // - // public async refreshValues(applHost: ZWaveApplicationHost): Promise { - // const node = this.getNode(applHost)!; - // const endpoint = this.getEndpoint(applHost)!; + // public async refreshValues(ctx: RefreshValuesContext): Promise { + // const node = this.getNode(ctx)!; + // const endpoint = this.getEndpoint(ctx)!; // const api = endpoint.commandClasses[ // "Scene Actuator Configuration" // ].withOptions({ // priority: MessagePriority.NodeQuery, // }); - // this.applHost.logNode(node.id, { + // ctx.logNode(node.id, { // message: "querying all scene actuator configs...", // direction: "outbound", // }); diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index 071c36699ee8..d569657858db 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -25,7 +25,6 @@ import type { CCEncodingContext, CCParsingContext, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { wait } from "alcalzone-shared/async"; @@ -754,7 +753,6 @@ export class SecurityCCCommandEncapsulation extends SecurityCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: SecurityCCCommandEncapsulation[], ctx: CCParsingContext, ): void { @@ -1044,7 +1042,6 @@ export class SecurityCCCommandsSupportedReport extends SecurityCC { public controlledCCs: CommandClasses[]; public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: SecurityCCCommandsSupportedReport[], ): void { // Concat the lists of CCs diff --git a/packages/cc/src/cc/TransportServiceCC.ts b/packages/cc/src/cc/TransportServiceCC.ts index 80c6809adc50..fbabeca8c79d 100644 --- a/packages/cc/src/cc/TransportServiceCC.ts +++ b/packages/cc/src/cc/TransportServiceCC.ts @@ -11,7 +11,6 @@ import type { CCEncodingContext, CCParsingContext, GetValueDB, - ZWaveApplicationHost, } from "@zwave-js/host/safe"; import { buffer2hex } from "@zwave-js/shared/safe"; import { @@ -343,7 +342,6 @@ export class TransportServiceCCSubsequentSegment extends TransportServiceCC { } public mergePartialCCs( - applHost: ZWaveApplicationHost, partials: [ TransportServiceCCFirstSegment, ...TransportServiceCCSubsequentSegment[], diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index ca1269e934fa..13fa5e2b6099 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -43,7 +43,6 @@ import type { GetValueDB, LogNode, LookupManufacturer, - ZWaveApplicationHost, } from "@zwave-js/host"; import { MessageOrigin } from "@zwave-js/serial"; import { @@ -1048,7 +1047,6 @@ export class CommandClass implements CCId { /** Include previously received partial responses into a final CC */ public mergePartialCCs( - _applHost: ZWaveApplicationHost, _partials: CommandClass[], _ctx: CCParsingContext, ): void { diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index 6adff03f356c..e1fdc269de13 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -14,12 +14,16 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { createThrowingMap } from "@zwave-js/shared"; -import type { HostIDs, ZWaveApplicationHost } from "./ZWaveHost"; +import type { + GetSafeCCVersion, + GetSupportedCCVersion, + HostIDs, + ZWaveApplicationHost, +} from "./ZWaveHost"; -export interface CreateTestingHostOptions extends HostIDs { - getSafeCCVersion: ZWaveApplicationHost["getSafeCCVersion"]; - getSupportedCCVersion?: ZWaveApplicationHost["getSupportedCCVersion"]; -} +export interface CreateTestingHostOptions + extends HostIDs, GetSafeCCVersion, Partial +{} export type BaseTestEndpoint = & EndpointId diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 2bab99cfc38c..d3326a458e64 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -1,5 +1,6 @@ import { JsonlDB, type JsonlDBOptions } from "@alcalzone/jsonl-db"; import { + type CCAPIHost, CRC16CC, CRC16CCCommandEncapsulation, type CommandClass, @@ -113,7 +114,6 @@ import type { CCEncodingContext, HostIDs, NodeSchedulePollOptions, - ZWaveApplicationHost, ZWaveHostOptions, } from "@zwave-js/host"; import { @@ -598,7 +598,7 @@ export type DriverEvents = Extract; * instance or its associated nodes. */ export class Driver extends TypedEventEmitter - implements ZWaveApplicationHost + implements CCAPIHost { public constructor( private port: string | ZWaveSerialPortImplementation, @@ -4460,7 +4460,7 @@ export class Driver extends TypedEventEmitter // this is the final one, merge the previous responses this.partialCCSessions.delete(partialSessionKey!); try { - command.mergePartialCCs(this, session, { + command.mergePartialCCs(session, { sourceNodeId: msg.command.nodeId as number, ...this.getCCParsingContext(), }); diff --git a/packages/zwave-js/src/lib/telemetry/deviceConfig.ts b/packages/zwave-js/src/lib/telemetry/deviceConfig.ts index 898afa2c07e0..bb501b3be2f2 100644 --- a/packages/zwave-js/src/lib/telemetry/deviceConfig.ts +++ b/packages/zwave-js/src/lib/telemetry/deviceConfig.ts @@ -1,7 +1,6 @@ // import got from "@esm2cjs/got"; // import { AssociationGroupInfoCC, ConfigurationCC } from "@zwave-js/cc"; // import { CommandClasses } from "@zwave-js/core"; -import type { ZWaveApplicationHost } from "@zwave-js/host"; // import { formatId } from "@zwave-js/shared"; // import { isObject } from "alcalzone-shared/typeguards"; import type { ZWaveNode } from "../node/Node"; @@ -9,7 +8,7 @@ import type { ZWaveNode } from "../node/Node"; // const missingDeviceConfigCache = new Set(); export async function reportMissingDeviceConfig( - _applHost: ZWaveApplicationHost, + _ctx: any, _node: ZWaveNode & { manufacturerId: number; productType: number; diff --git a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts index dca5da8aca41..d8b586c642f7 100644 --- a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts @@ -351,7 +351,6 @@ integrationTest( receivedCC instanceof SecurityCCCommandEncapsulation ) { receivedCC.mergePartialCCs( - undefined as any, [], {} as any, ); diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts index 73a87927d27e..c2ca706a514e 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts @@ -68,7 +68,6 @@ integrationTest( instanceof SecurityCCCommandEncapsulation ) { receivedCC.mergePartialCCs( - undefined as any, [], {} as any, ); diff --git a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts index ea33e8ce33fe..2c51783170f9 100644 --- a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts @@ -110,7 +110,7 @@ integrationTest("S0 commands are S0-encapsulated, even when S2 is supported", { handleCC(controller, self, receivedCC) { // We don't support sequenced commands here if (receivedCC instanceof SecurityCCCommandEncapsulation) { - receivedCC.mergePartialCCs(undefined as any, [], {} as any); + receivedCC.mergePartialCCs([], {} as any); } return undefined; }, diff --git a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts index 8e5cde068156..8d910d3b8988 100644 --- a/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0Encapsulation.test.ts @@ -169,7 +169,7 @@ integrationTest("Communication via Security S0 works", { handleCC(controller, self, receivedCC) { // We don't support sequenced commands here if (receivedCC instanceof SecurityCCCommandEncapsulation) { - receivedCC.mergePartialCCs(undefined as any, [], {} as any); + receivedCC.mergePartialCCs([], {} as any); } // This just decodes - we need to call further handlers return undefined; diff --git a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts index 800d14e5119e..572a410358ec 100644 --- a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts @@ -207,7 +207,6 @@ integrationTest( receivedCC instanceof SecurityCCCommandEncapsulation ) { receivedCC.mergePartialCCs( - undefined as any, [], {} as any, ); diff --git a/test/decodeMessage.ts b/test/decodeMessage.ts index 5c1ede129e40..df22dbc05bb1 100644 --- a/test/decodeMessage.ts +++ b/test/decodeMessage.ts @@ -8,7 +8,7 @@ import { NodeIDType, SPANState, SecurityClass, - SecurityManager, + type SecurityManager, SecurityManager2, generateAuthKey, generateEncryptionKey, @@ -97,10 +97,10 @@ import { Message } from "@zwave-js/serial"; getHighestSecurityClass: () => SecurityClass.S2_AccessControl, hasSecurityClass: () => true, }; - const msg = Message.from(host as any, { data, ctx: ctx as any }); + const msg = Message.from({ data, ctx: ctx as any }); if (isCommandClassContainer(msg)) { - msg.command.mergePartialCCs(host as any, [], {} as any); + msg.command.mergePartialCCs([], {} as any); } msg; debugger; From bd5aeeaeec990743e00f4a03734bf2af9964f8a2 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 17 Oct 2024 10:52:09 +0200 Subject: [PATCH 58/60] refactor: rework TestingHost --- packages/host/src/mocks.ts | 99 ++++++++------- packages/serial/src/message/Message.test.ts | 6 - .../Controller.manageAssociations.test.ts | 60 ++++----- packages/zwave-js/src/lib/driver/Driver.ts | 19 ++- .../BridgeApplicationCommandRequest.test.ts | 5 - .../capability/SerialAPISetupMessages.test.ts | 3 - .../src/lib/test/cc/AssociationCC.test.ts | 3 - .../test/cc/AssociationGroupInfoCC.test.ts | 3 - .../zwave-js/src/lib/test/cc/BasicCC.test.ts | 34 +++-- .../src/lib/test/cc/BatteryCC.test.ts | 3 - .../src/lib/test/cc/BinarySensorCC.test.ts | 3 - .../src/lib/test/cc/BinarySwitchCC.test.ts | 4 +- .../zwave-js/src/lib/test/cc/CRC16CC.test.ts | 3 - .../src/lib/test/cc/CentralSceneCC.test.ts | 3 - .../src/lib/test/cc/ColorSwitchCC.test.ts | 4 +- .../src/lib/test/cc/CommandClass.test.ts | 5 +- .../src/lib/test/cc/DoorLockLoggingCC.test.ts | 3 - .../src/lib/test/cc/EntryControlCC.test.ts | 3 - .../zwave-js/src/lib/test/cc/FibaroCC.test.ts | 3 - .../HumidityControlOperatingStateCC.test.ts | 3 - .../src/lib/test/cc/LanguageCC.test.ts | 3 - .../test/cc/ManufacturerSpecificCC.test.ts | 3 - .../test/cc/MultiChannelAssociationCC.test.ts | 3 - .../src/lib/test/cc/MultiChannelCC.test.ts | 3 - .../src/lib/test/cc/MultiCommandCC.test.ts | 3 - .../lib/test/cc/MultilevelSwitchCC.test.ts | 4 +- .../src/lib/test/cc/NoOperationCC.test.ts | 3 - .../src/lib/test/cc/PowerlevelCC.test.ts | 3 - .../src/lib/test/cc/SceneActivationCC.test.ts | 3 - .../cc/SceneActuatorConfigurationCC.test.ts | 3 - .../cc/SceneControllerConfigurationCC.test.ts | 47 +------ .../src/lib/test/cc/SupervisionCC.test.ts | 6 +- .../lib/test/cc/ThermostatFanModeCC.test.ts | 3 - .../lib/test/cc/ThermostatFanStateCC.test.ts | 3 - .../zwave-js/src/lib/test/cc/TimeCC.test.ts | 3 - .../zwave-js/src/lib/test/cc/WakeUpCC.test.ts | 5 +- .../src/lib/test/cc/ZWavePlusCC.test.ts | 3 - packages/zwave-js/src/lib/test/mocks.ts | 119 ++++++++++-------- 38 files changed, 176 insertions(+), 313 deletions(-) diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index e1fdc269de13..cf079b5e8da7 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/require-await */ import { type ControlsCC, type EndpointId, @@ -15,15 +14,16 @@ import { } from "@zwave-js/core"; import { createThrowingMap } from "@zwave-js/shared"; import type { - GetSafeCCVersion, + GetAllNodes, + GetDeviceConfig, + GetNode, GetSupportedCCVersion, + GetValueDB, HostIDs, - ZWaveApplicationHost, + LogNode, } from "./ZWaveHost"; -export interface CreateTestingHostOptions - extends HostIDs, GetSafeCCVersion, Partial -{} +export interface CreateTestingHostOptions extends HostIDs, GetDeviceConfig {} export type BaseTestEndpoint = & EndpointId @@ -42,38 +42,42 @@ export type BaseTestNode = & IsCCSecure & GetEndpoint; -export type TestingHost< - TNode extends BaseTestNode, -> = - & ZWaveApplicationHost - & { - setNode(nodeId: number, node: TNode): void; - }; +export interface TestingHost extends + HostIDs, + GetValueDB, + // GetSafeCCVersion, + GetSupportedCCVersion, + GetAllNodes, + GetNode, + GetDeviceConfig, + LogNode +{ + setNode(nodeId: number, node: BaseTestNode): void; +} /** Creates a {@link ZWaveApplicationHost} that can be used for testing */ -export function createTestingHost< - TNode extends BaseTestNode, ->( +export function createTestingHost( options: Partial = {}, -): TestingHost { +): TestingHost { const valuesStorage = new Map(); const metadataStorage = new Map(); const valueDBCache = new Map(); - const nodes = createThrowingMap((nodeId) => { + const nodes = createThrowingMap((nodeId) => { throw new ZWaveError( `Node ${nodeId} was not found!`, ZWaveErrorCodes.Controller_NodeNotFound, ); }); - const ret: TestingHost = { + const ret: TestingHost = { homeId: options.homeId ?? 0x7e570001, ownNodeId: options.ownNodeId ?? 1, - securityManager: undefined, - securityManager2: undefined, - securityManagerLR: undefined, - getDeviceConfig: () => undefined, - lookupManufacturer: () => undefined, + getDeviceConfig: options.getDeviceConfig ?? (() => undefined), + // securityManager: undefined, + // securityManager2: undefined, + // securityManagerLR: undefined, + // getDeviceConfig: () => undefined, + // lookupManufacturer: () => undefined, logNode: () => {}, // options: { // attempts: { @@ -87,18 +91,18 @@ export function createTestingHost< // refreshValueAfterTransition: 1000, // }, // }, - getInterviewOptions() { - return {}; - }, - getUserPreferences() { - return undefined; - }, - getCommunicationTimeouts() { - return { - refreshValue: 5000, - refreshValueAfterTransition: 1000, - }; - }, + // getInterviewOptions() { + // return {}; + // }, + // getUserPreferences() { + // return undefined; + // }, + // getCommunicationTimeouts() { + // return { + // refreshValue: 5000, + // refreshValueAfterTransition: 1000, + // }; + // }, getNode(nodeId) { return nodes.get(nodeId); }, @@ -111,11 +115,14 @@ export function createTestingHost< setNode(nodeId, node) { nodes.set(nodeId, node); }, - getSafeCCVersion: options.getSafeCCVersion ?? (() => 100), + // getSafeCCVersion: options.getSafeCCVersion ?? (() => 100), getSupportedCCVersion: (cc, nodeId, endpoint) => { - return options.getSupportedCCVersion?.(cc, nodeId, endpoint) - ?? options.getSafeCCVersion?.(cc, nodeId, endpoint) - ?? 100; + 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)) { @@ -145,12 +152,12 @@ export function createTestingHost< // const node = nodes.getOrThrow(nodeId); // node.setSecurityClass(securityClass, granted); // }, - sendCommand: async (_command, _options) => { - return undefined as any; - }, - schedulePoll: (_nodeId, _valueId, _options) => { - return false; - }, + // sendCommand: async (_command, _options) => { + // return undefined as any; + // }, + // schedulePoll: (_nodeId, _valueId, _options) => { + // return false; + // }, }; return ret; } diff --git a/packages/serial/src/message/Message.test.ts b/packages/serial/src/message/Message.test.ts index a052fcc78983..5eff3b02e893 100644 --- a/packages/serial/src/message/Message.test.ts +++ b/packages/serial/src/message/Message.test.ts @@ -6,7 +6,6 @@ import type { INodeQuery } from "./INodeQuery"; import { Message, messageTypes } from "./Message"; test("should deserialize and serialize correctly", (t) => { - const host = createTestingHost(); // actual messages from OZW const okayMessages = [ Buffer.from([ @@ -46,7 +45,6 @@ test("should deserialize and serialize correctly", (t) => { }); test("should serialize correctly when the payload is null", (t) => { - const host = createTestingHost(); // synthetic message const expected = Buffer.from([0x01, 0x03, 0x00, 0xff, 0x03]); const message = new Message({ @@ -57,7 +55,6 @@ test("should serialize correctly when the payload is null", (t) => { }); test("should throw the correct error when parsing a faulty message", (t) => { - const host = createTestingHost(); // fake messages to produce certain errors const brokenMessages: [Buffer, string, ZWaveErrorCodes][] = [ // too short (<5 bytes) @@ -252,7 +249,6 @@ test("isComplete() should work correctly", (t) => { }); test("toJSON() should return a semi-readable JSON representation", (t) => { - const host = createTestingHost(); const msg1 = new Message({ type: MessageType.Request, functionType: FunctionType.GetControllerVersion, @@ -312,7 +308,6 @@ test("getConstructor() should return `Message` for an unknown packet type", (t) }); test(`the constructor should throw when no message type is specified`, (t) => { - const host = createTestingHost(); assertZWaveError( t, () => new Message({ functionType: 0xff as any }), @@ -332,7 +327,6 @@ test(`the constructor should throw when no message type is specified`, (t) => { }); test(`the constructor should throw when no function type is specified`, (t) => { - const host = createTestingHost(); assertZWaveError( t, () => new Message({ type: MessageType.Request }), diff --git a/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts b/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts index 9d43f4bdb535..27bb3d5d9d0a 100644 --- a/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts +++ b/packages/zwave-js/src/lib/controller/Controller.manageAssociations.test.ts @@ -7,41 +7,33 @@ import { import { CommandClasses, SecurityClass } from "@zwave-js/core/safe"; import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -import { createTestNode } from "../test/mocks"; +import { type CreateTestNodeOptions, createTestNode } from "../test/mocks"; test("associations between insecure nodes are allowed", (t) => { // This test simulates two Zooz ZEN76 switches, included insecurely - const host = createTestingHost({ - getSupportedCCVersion(cc, nodeId, endpointIndex) { - switch (cc) { - case CommandClasses["Association Group Information"]: - return 1; - case CommandClasses.Association: - return 3; - case CommandClasses["Multi Channel Association"]: - return 4; - case CommandClasses.Basic: - return 2; - case CommandClasses["Binary Switch"]: - return 2; - } - return 0; + const host = createTestingHost(); + + const commandClasses: CreateTestNodeOptions["commandClasses"] = { + [CommandClasses["Association Group Information"]]: { + version: 1, }, - }); + [CommandClasses.Association]: { + version: 3, + }, + [CommandClasses["Multi Channel Association"]]: { + version: 4, + }, + [CommandClasses.Basic]: { + version: 2, + }, + [CommandClasses["Binary Switch"]]: { + version: 2, + }, + }; const node2 = createTestNode(host, { id: 2, - supportsCC(cc) { - switch (cc) { - case CommandClasses["Association Group Information"]: - case CommandClasses.Association: - case CommandClasses["Multi Channel Association"]: - case CommandClasses.Basic: - case CommandClasses["Binary Switch"]: - return true; - } - return false; - }, + commandClasses, }); host.setNode(node2.id, node2); @@ -52,17 +44,7 @@ test("associations between insecure nodes are allowed", (t) => { const node3 = createTestNode(host, { id: 3, - supportsCC(cc) { - switch (cc) { - case CommandClasses["Association Group Information"]: - case CommandClasses.Association: - case CommandClasses["Multi Channel Association"]: - case CommandClasses.Basic: - case CommandClasses["Binary Switch"]: - return true; - } - return false; - }, + commandClasses, }); host.setNode(node3.id, node3); diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index d3326a458e64..f62bc819f10b 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -6,10 +6,13 @@ import { type CommandClass, type FirmwareUpdateResult, type ICommandClassContainer, + type InterviewContext, InvalidCC, KEXFailType, MultiChannelCC, + type PersistValuesContext, type Powerlevel, + type RefreshValuesContext, Security2CC, Security2CCCommandsSupportedGet, Security2CCCommandsSupportedReport, @@ -598,7 +601,11 @@ export type DriverEvents = Extract; * instance or its associated nodes. */ export class Driver extends TypedEventEmitter - implements CCAPIHost + implements + CCAPIHost, + InterviewContext, + RefreshValuesContext, + PersistValuesContext { public constructor( private port: string | ZWaveSerialPortImplementation, @@ -992,17 +999,17 @@ export class Driver extends TypedEventEmitter return this.controller.ownNodeId!; } - /** @internal Used for compatibility with the ZWaveApplicationHost interface */ + /** @internal Used for compatibility with the CCAPIHost interface */ public getNode(nodeId: number): ZWaveNode | undefined { return this.controller.nodes.get(nodeId); } - /** @internal Used for compatibility with the ZWaveApplicationHost interface */ + /** @internal Used for compatibility with the CCAPIHost interface */ public getNodeOrThrow(nodeId: number): ZWaveNode { return this.controller.nodes.getOrThrow(nodeId); } - /** @internal Used for compatibility with the ZWaveApplicationHost interface */ + /** @internal Used for compatibility with the CCAPIHost interface */ public getAllNodes(): ZWaveNode[] { return [...this.controller.nodes.values()]; } @@ -2931,14 +2938,14 @@ export class Driver extends TypedEventEmitter /** * **!!! INTERNAL !!!** * - * Not intended to be used by applications + * Not intended to be used by applications. + * Needed for compatibility with CCAPIHost */ public schedulePoll( nodeId: number, valueId: ValueID, options: NodeSchedulePollOptions, ): boolean { - // Needed for ZWaveApplicationHost const node = this.controller.nodes.getOrThrow(nodeId); return node.schedulePoll(valueId, options); } diff --git a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts index cfeaed9dc9f5..923f0e17cdbd 100644 --- a/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts +++ b/packages/zwave-js/src/lib/serialapi/application/BridgeApplicationCommandRequest.test.ts @@ -1,13 +1,8 @@ // import "@zwave-js/cc"; -import { createTestingHost } from "@zwave-js/host"; import { Message } from "@zwave-js/serial"; import test from "ava"; test("BridgeApplicationCommandRequest can be parsed without RSSI", async (t) => { - t.timeout(30000); - - const host = createTestingHost(); - // Repro for https://github.com/zwave-js/node-zwave-js/issues/4335 t.notThrows(() => Message.from({ diff --git a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts index f013c4fc354e..a35d3570ab53 100644 --- a/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts +++ b/packages/zwave-js/src/lib/serialapi/capability/SerialAPISetupMessages.test.ts @@ -1,10 +1,7 @@ -import { createTestingHost } from "@zwave-js/host"; import { Message } from "@zwave-js/serial"; import test from "ava"; import { SerialAPISetup_GetSupportedCommandsResponse } from "./SerialAPISetupMessages"; -const host = createTestingHost(); - test("GetSupportedCommandsResponse with extended bitmask parses correctly (pre-7.19.1 encoding)", (t) => { const data = Buffer.from( "0116010b01fe160103000100000001000000000000000109", diff --git a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts index 2ea9287042b8..06a44672522f 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationCC.test.ts @@ -8,11 +8,8 @@ import { AssociationCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts index dd9b5bb70c26..0bf177f9dda6 100644 --- a/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/AssociationGroupInfoCC.test.ts @@ -11,11 +11,8 @@ import { BasicCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts index f7080e9f28ff..2780b0928c66 100644 --- a/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BasicCC.test.ts @@ -11,7 +11,7 @@ import { CommandClasses } from "@zwave-js/core"; import { createTestingHost } from "@zwave-js/host"; import test from "ava"; import * as nodeUtils from "../../node/utils"; -import { createTestNode } from "../mocks"; +import { type CreateTestNodeOptions, createTestNode } from "../mocks"; const host = createTestingHost(); @@ -99,28 +99,22 @@ test("deserializing an unsupported command should return an unspecified version t.is(basicCC.constructor, BasicCC); }); -test("getDefinedValueIDs() should include the target value for all endpoints except the node itself", (t) => { +test.only("getDefinedValueIDs() should include the target value for all endpoints except the node itself", (t) => { // Repro for GH#377 + const commandClasses: CreateTestNodeOptions["commandClasses"] = { + [CommandClasses.Basic]: { + version: 1, + }, + [CommandClasses["Multi Channel"]]: { + version: 2, + }, + }; const node2 = createTestNode(host, { id: 2, - numEndpoints: 2, - supportsCC(cc) { - switch (cc) { - case CommandClasses.Basic: - case CommandClasses["Multi Channel"]: - return true; - } - return false; - }, - getCCVersion(cc) { - switch (cc) { - case CommandClasses.Basic: - // We only support V1, so no report of the target value - return 1; - case CommandClasses["Multi Channel"]: - return 2; - } - return 0; + commandClasses, + endpoints: { + 1: { commandClasses }, + 2: { commandClasses }, }, }); host.setNode(node2.id, node2); diff --git a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts index d54671ffc6c9..34694b45787f 100644 --- a/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BatteryCC.test.ts @@ -7,11 +7,8 @@ import { BatteryReplacementStatus, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - test("the Get command should serialize correctly", (t) => { const batteryCC = new BatteryCCGet({ nodeId: 1 }); const expected = Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts index 31d5251a1dca..523931edfa9e 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySensorCC.test.ts @@ -8,11 +8,8 @@ import { BinarySensorType, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts index 3e6495c77ff5..5e5450d8f262 100644 --- a/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/BinarySwitchCC.test.ts @@ -6,11 +6,9 @@ import { BinarySwitchCommand, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; -import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts index e7b47b43c866..64cefd9110ef 100644 --- a/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts @@ -7,11 +7,8 @@ import { InvalidCC, isEncapsulatingCommandClass, } from "@zwave-js/cc"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - test("should be detected as an encapsulating CC", (t) => { const basicCCSet = new BasicCCSet({ nodeId: 3, diff --git a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts index 0121b582754a..0aa07df4f406 100644 --- a/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CentralSceneCC.test.ts @@ -10,11 +10,8 @@ import { CentralSceneKeys, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts index e0ed797ac7f2..957a23f0fd1e 100644 --- a/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ColorSwitchCC.test.ts @@ -16,11 +16,9 @@ import { ZWaveErrorCodes, assertZWaveError, } from "@zwave-js/core"; -import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts index eb17d9ecc98b..034bf949489f 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.test.ts @@ -10,12 +10,9 @@ import { implementedVersion, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; import { SendDataRequest } from "../../serialapi/transport/SendDataMessages"; -const host = createTestingHost(); - @implementedVersion(7) @commandClass(0xffff as any) class DummyCC extends CommandClass {} @@ -82,7 +79,7 @@ test("getImplementedVersion() should return the implemented version for a numeri test("getImplementedVersion() should return 0 for a non-existing CC", (t) => { const cc = -1; - t.is(getImplementedVersion(cc), 0); + t.is(getImplementedVersion(cc as any), 0); }); test("getImplementedVersion() should work with inheritance", (t) => { diff --git a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts index 9cb09032a6a6..c8e234abb8c4 100644 --- a/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/DoorLockLoggingCC.test.ts @@ -7,11 +7,8 @@ import { DoorLockLoggingEventType, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts index 630b9bb5aa01..168677275714 100644 --- a/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/EntryControlCC.test.ts @@ -12,11 +12,8 @@ import { EntryControlEventTypes, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts index ecfa727c74e0..7d21f7330e97 100644 --- a/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/FibaroCC.test.ts @@ -6,11 +6,8 @@ import { FibaroVenetianBlindCCSet, } from "@zwave-js/cc/manufacturerProprietary/FibaroCC"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts index 0242cd68f4f1..158b1926bf2f 100644 --- a/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/HumidityControlOperatingStateCC.test.ts @@ -5,11 +5,8 @@ import { HumidityControlOperatingStateCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts index 123641b29e2f..6fd678841444 100644 --- a/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/LanguageCC.test.ts @@ -6,11 +6,8 @@ import { LanguageCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts index ecb39a3c1f84..66e1ba7dac7e 100644 --- a/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ManufacturerSpecificCC.test.ts @@ -4,11 +4,8 @@ import { ManufacturerSpecificCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts index c30089a19a20..12db92f59c6f 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelAssociationCC.test.ts @@ -8,11 +8,8 @@ import { MultiChannelAssociationCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts index 837d4ce6fd49..78053cc8e033 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts @@ -16,11 +16,8 @@ import { isEncapsulatingCommandClass, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts index ec558c7d4099..90aed18f813c 100644 --- a/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts @@ -4,11 +4,8 @@ import { MultiCommandCC, isMultiEncapsulatingCommandClass, } from "@zwave-js/cc"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - test("is a multi-encapsulating CommandClass", (t) => { let cc: CommandClass = new BasicCCSet({ nodeId: 1, diff --git a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts index 9abaca1e6c75..2d5f30b129dd 100644 --- a/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/MultilevelSwitchCC.test.ts @@ -9,11 +9,9 @@ import { MultilevelSwitchCommand, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; -import { type GetSupportedCCVersion, createTestingHost } from "@zwave-js/host"; +import { type GetSupportedCCVersion } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts b/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts index 6e989b490328..4c2aedc3533e 100644 --- a/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/NoOperationCC.test.ts @@ -1,10 +1,7 @@ import { NoOperationCC } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts index 0505807c0410..d847a7b75013 100644 --- a/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/PowerlevelCC.test.ts @@ -7,11 +7,8 @@ import { PowerlevelCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts index 670ead3b48bb..4520223956af 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActivationCC.test.ts @@ -4,11 +4,8 @@ import { SceneActivationCommand, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts index 7a017569ec06..7270aef3ee8a 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneActuatorConfigurationCC.test.ts @@ -6,11 +6,8 @@ import { SceneActuatorConfigurationCommand, } from "@zwave-js/cc"; import { CommandClasses, Duration } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts index 4bef4a2f4dcf..ff76ea6285ec 100644 --- a/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SceneControllerConfigurationCC.test.ts @@ -5,11 +5,8 @@ import { SceneControllerConfigurationCCSet, SceneControllerConfigurationCommand, } from "@zwave-js/cc"; -import { AssociationCCValues } from "@zwave-js/cc/AssociationCC"; -import { CommandClasses, Duration, type IZWaveNode } from "@zwave-js/core"; -import { type TestingHost, createTestingHost } from "@zwave-js/host"; +import { CommandClasses, Duration } from "@zwave-js/core"; import test from "ava"; -import { createTestNode } from "../mocks"; function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ @@ -20,20 +17,7 @@ function buildCCBuffer(payload: Buffer): Buffer { ]); } -const fakeGroupCount = 5; -const groupCountValueId = AssociationCCValues.groupCount.id; - -function prepareTest(): { host: TestingHost; node2: IZWaveNode } { - const host = createTestingHost(); - const node2 = createTestNode(host, { id: 2 }); - host.setNode(2, node2); - host.getValueDB(2).setValue(groupCountValueId, fakeGroupCount); - - return { host, node2 }; -} - test("the Get command should serialize correctly", (t) => { - const { host } = prepareTest(); const cc = new SceneControllerConfigurationCCGet({ nodeId: 2, groupId: 1, @@ -47,19 +31,7 @@ test("the Get command should serialize correctly", (t) => { t.deepEqual(cc.serialize({} as any), expected); }); -test.skip("the Get command should throw if GroupId > groupCount", (t) => { - const { host } = prepareTest(); - // TODO: This check now lives on the CC API - t.notThrows(() => { - new SceneControllerConfigurationCCGet({ - nodeId: 2, - groupId: fakeGroupCount + 1, - }); - }); -}); - test("the Set command should serialize correctly", (t) => { - const { host } = prepareTest(); const cc = new SceneControllerConfigurationCCSet({ nodeId: 2, groupId: 3, @@ -78,7 +50,6 @@ test("the Set command should serialize correctly", (t) => { }); test("the Set command should serialize correctly with undefined duration", (t) => { - const { host } = prepareTest(); const cc = new SceneControllerConfigurationCCSet({ nodeId: 2, groupId: 3, @@ -96,22 +67,7 @@ test("the Set command should serialize correctly with undefined duration", (t) = t.deepEqual(cc.serialize({} as any), expected); }); -test.skip("the Set command should throw if GroupId > groupCount", (t) => { - const { host } = prepareTest(); - // TODO: This check now lives on the CC API - t.notThrows( - () => - new SceneControllerConfigurationCCSet({ - nodeId: 2, - groupId: fakeGroupCount + 1, - sceneId: 240, - dimmingDuration: Duration.parseSet(0x05)!, - }), - ); -}); - test("the Report command (v1) should be deserialized correctly", (t) => { - const { host } = prepareTest(); const ccData = buildCCBuffer( Buffer.from([ SceneControllerConfigurationCommand.Report, // CC Command @@ -132,7 +88,6 @@ test("the Report command (v1) should be deserialized correctly", (t) => { }); test("deserializing an unsupported command should return an unspecified version of SceneControllerConfigurationCC", (t) => { - const { host } = prepareTest(); const serializedCC = buildCCBuffer( Buffer.from([255]), // not a valid command ); diff --git a/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts b/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts index 99d8cb0ad2e6..155f7bc9025a 100644 --- a/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts @@ -1,16 +1,14 @@ import { BasicCCSet, SupervisionCC, SupervisionCCReport } from "@zwave-js/cc"; import { SupervisionStatus } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - test("SupervisionCCGet should expect a response", (t) => { const ccRequest = SupervisionCC.encapsulate( new BasicCCSet({ nodeId: 2, targetValue: 5, }), + 1, ); t.true(ccRequest.expectsCCResponse()); }); @@ -21,6 +19,7 @@ test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = exp nodeId: 2, targetValue: 5, }), + 2, ); const ccResponse = new SupervisionCCReport({ nodeId: 2, @@ -38,6 +37,7 @@ test("SupervisionCC/BasicCCSet => SupervisionCCReport (wrong session ID) = unexp nodeId: 2, targetValue: 5, }), + 3, ); const ccResponse = new SupervisionCCReport({ nodeId: 2, diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts index 47f13f581a62..72cc8c72bef7 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanModeCC.test.ts @@ -6,11 +6,8 @@ import { ThermostatFanModeCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts index a8267806d3bd..03ff89fe8d98 100644 --- a/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ThermostatFanStateCC.test.ts @@ -6,11 +6,8 @@ import { ThermostatFanStateCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts index 682b49f2ce30..8635a5ec304e 100644 --- a/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/TimeCC.test.ts @@ -7,11 +7,8 @@ import { TimeCommand, } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts index 9e86bdd31298..6de0e0e34cb0 100644 --- a/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts @@ -4,12 +4,9 @@ import { WakeUpCCNoMoreInformation, } from "@zwave-js/cc"; import { generateAuthKey, generateEncryptionKey } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; import { randomBytes } from "node:crypto"; -const host = createTestingHost(); - test("WakeUpCCNoMoreInformation should expect no response", (t) => { const cc = new WakeUpCCNoMoreInformation({ nodeId: 2, @@ -41,7 +38,7 @@ test("SecurityCC/WakeUpCCNoMoreInformation should expect NO response", (t) => { }; const ccRequest = SecurityCC.encapsulate( - host.ownNodeId, + 1, securityManager as any, new WakeUpCCNoMoreInformation({ nodeId: 2, diff --git a/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts b/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts index f9764aec4e6f..4933a967c143 100644 --- a/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts +++ b/packages/zwave-js/src/lib/test/cc/ZWavePlusCC.test.ts @@ -1,10 +1,7 @@ import { ZWavePlusCCGet, ZWavePlusCommand } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; -import { createTestingHost } from "@zwave-js/host"; import test from "ava"; -const host = createTestingHost(); - function buildCCBuffer(payload: Buffer): Buffer { return Buffer.concat([ Buffer.from([ diff --git a/packages/zwave-js/src/lib/test/mocks.ts b/packages/zwave-js/src/lib/test/mocks.ts index b7542df9fbb5..40c9e0d56c09 100644 --- a/packages/zwave-js/src/lib/test/mocks.ts +++ b/packages/zwave-js/src/lib/test/mocks.ts @@ -1,6 +1,7 @@ import { getImplementedVersion } from "@zwave-js/cc"; import { ConfigManager } from "@zwave-js/config"; import { + type CommandClassInfo, type CommandClasses, type FLiRS, type InterviewStage, @@ -16,7 +17,7 @@ import { import type { BaseTestEndpoint, BaseTestNode, - GetSafeCCVersion, + GetNode, GetValueDB, } from "@zwave-js/host"; import { @@ -209,34 +210,35 @@ export interface CreateTestNodeOptions { interviewStage?: InterviewStage; isSecure?: MaybeNotKnown; - numEndpoints?: number; - - supportsCC?: (cc: CommandClasses) => boolean; - controlsCC?: (cc: CommandClasses) => boolean; - isCCSecure?: (cc: CommandClasses) => boolean; - getCCVersion?: (cc: CommandClasses) => number; + commandClasses?: Partial< + Record< + CommandClasses, + Partial + > + >; + endpoints?: Record< + number, + Omit + >; } -export type TestNode = T & { +export type TestNode = BaseTestNode & { setEndpoint(endpoint: CreateTestEndpointOptions): void; }; export function createTestNode( - host: GetValueDB & GetSafeCCVersion, + host: GetValueDB & GetNode, options: CreateTestNodeOptions, -): TestNode { +): TestNode { const endpointCache = new Map(); const securityClasses = new Map(); - const ret: TestNode = { + const ret: TestNode = { id: options.id, ...createTestEndpoint(host, { nodeId: options.id, index: 0, - supportsCC: options.supportsCC, - controlsCC: options.controlsCC, - isCCSecure: options.isCCSecure, - getCCVersion: options.getCCVersion, + commandClasses: options.commandClasses, }), isListening: options.isListening ?? true, @@ -257,34 +259,24 @@ export function createTestNode( createTestEndpoint(host, { nodeId: options.id, index: endpoint.index, - supportsCC: endpoint.supportsCC ?? options.supportsCC, - controlsCC: endpoint.controlsCC ?? options.controlsCC, - isCCSecure: endpoint.isCCSecure ?? options.isCCSecure, - getCCVersion: endpoint.getCCVersion ?? options.getCCVersion, + commandClasses: endpoint.commandClasses, }), ); }, getEndpoint: ((index: number) => { - // When the endpoint count is known, return undefined for non-existent endpoints - if ( - options.numEndpoints != undefined - && index > options.numEndpoints - ) { - return undefined; - } + if (index === 0) return ret; if (!endpointCache.has(index)) { - ret.setEndpoint( - createTestEndpoint(host, { - nodeId: options.id, - index, - supportsCC: options.supportsCC, - controlsCC: options.controlsCC, - isCCSecure: options.isCCSecure, - getCCVersion: options.getCCVersion, - }), - ); + if (!options.endpoints?.[index]) { + return undefined; + } + + ret.setEndpoint({ + nodeId: options.id, + index, + commandClasses: options.endpoints[index].commandClasses, + }); } return endpointCache.get(index); }) as BaseTestNode["getEndpoint"], @@ -340,11 +332,16 @@ export function createTestNode( endpointCache.set(0, ret); // If the number of endpoints are given, use them as the individual endpoint count - if (options.numEndpoints != undefined) { + if (options.endpoints) { nodeUtils.setIndividualEndpointCount( host, ret.id, - options.numEndpoints, + Object.keys(options.endpoints).length, + ); + nodeUtils.setEndpointIndizes( + host, + ret.id, + Object.keys(options.endpoints).map((index) => parseInt(index, 10)), ); nodeUtils.setAggregatedEndpointCount(host, ret.id, 0); nodeUtils.setMultiChannelInterviewComplete(host, ret.id, true); @@ -356,30 +353,46 @@ export function createTestNode( export interface CreateTestEndpointOptions { nodeId: number; index: number; - supportsCC?: (cc: CommandClasses) => boolean; - controlsCC?: (cc: CommandClasses) => boolean; - isCCSecure?: (cc: CommandClasses) => boolean; - getCCVersion?: (cc: CommandClasses) => number; + commandClasses?: Partial< + Record< + CommandClasses, + Partial + > + >; } export function createTestEndpoint( - host: GetSafeCCVersion, + host: GetNode, options: CreateTestEndpointOptions, ): BaseTestEndpoint { const ret: BaseTestEndpoint = { virtual: false, nodeId: options.nodeId, index: options.index, - supportsCC: options.supportsCC ?? (() => true), - controlsCC: options.controlsCC ?? (() => false), - isCCSecure: options.isCCSecure ?? (() => false), - getCCVersion: (cc) => - options.getCCVersion?.(cc) - ?? host.getSafeCCVersion(cc, options.nodeId, options.index) - ?? 0, - // tryGetNode: function(): IZWaveNode | undefined { - // return host.nodes.get(options.nodeId); - // }, + supportsCC: (cc) => { + const ccInfo = options.commandClasses?.[cc]; + if (!ccInfo) return false; + return ccInfo.isSupported ?? true; + }, + controlsCC: (cc) => { + const ccInfo = options.commandClasses?.[cc]; + if (!ccInfo) return false; + return ccInfo.isControlled ?? false; + }, + isCCSecure: (cc) => { + const ccInfo = options.commandClasses?.[cc]; + if (!ccInfo) return false; + return ccInfo.secure ?? false; + }, + getCCVersion: (cc) => { + const ccInfo = options.commandClasses?.[cc]; + const defaultVersion = ccInfo?.isSupported + ? getImplementedVersion(cc) + : 0; + return ccInfo?.version + ?? host.getNode(options.nodeId)?.getCCVersion(cc) + ?? defaultVersion; + }, }; return ret; From 4627146c40de3449c03e2519e2ab57cc67f6a330 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 17 Oct 2024 10:54:30 +0200 Subject: [PATCH 59/60] refactor: nuke ZWaveApplicationHost into orbit --- packages/host/src/ZWaveHost.ts | 19 ------------------- packages/host/src/mocks.ts | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/packages/host/src/ZWaveHost.ts b/packages/host/src/ZWaveHost.ts index 1211ba1647e0..ce10e851ffd9 100644 --- a/packages/host/src/ZWaveHost.ts +++ b/packages/host/src/ZWaveHost.ts @@ -161,25 +161,6 @@ export interface GetCommunicationTimeouts { export type LogNode = Pick; -export interface ZWaveApplicationHost - extends - GetValueDB, - HostIDs, - GetNode, - GetAllNodes, - SecurityManagers, - GetDeviceConfig, - LookupManufacturer, - SchedulePoll, - GetSupportedCCVersion, - GetSafeCCVersion, - SendCommand, - GetInterviewOptions, - GetUserPreferences, - GetCommunicationTimeouts, - LogNode -{} - /** Allows scheduling a value refresh (poll) for a later time */ export interface SchedulePoll { schedulePoll( diff --git a/packages/host/src/mocks.ts b/packages/host/src/mocks.ts index cf079b5e8da7..b851a29271b9 100644 --- a/packages/host/src/mocks.ts +++ b/packages/host/src/mocks.ts @@ -42,20 +42,20 @@ export type BaseTestNode = & IsCCSecure & GetEndpoint; -export interface TestingHost extends - HostIDs, - GetValueDB, - // GetSafeCCVersion, - GetSupportedCCVersion, - GetAllNodes, - GetNode, - GetDeviceConfig, - LogNode +export interface TestingHost + extends + HostIDs, + GetValueDB, + GetSupportedCCVersion, + GetAllNodes, + GetNode, + GetDeviceConfig, + LogNode { setNode(nodeId: number, node: BaseTestNode): void; } -/** Creates a {@link ZWaveApplicationHost} that can be used for testing */ +/** Creates a {@link TestingHost} that can be used instead of a real driver instance in tests */ export function createTestingHost( options: Partial = {}, ): TestingHost { From 7e3bb68d256d307e0c7d0ff45a003ee04c025e3d Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Thu, 17 Oct 2024 11:33:55 +0200 Subject: [PATCH 60/60] fix: rename toLogEntry argument --- packages/cc/src/lib/CommandClass.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 13fa5e2b6099..cc02852ffb5f 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -492,7 +492,7 @@ export class CommandClass implements CCId { } /** Generates a representation of this CC for the log */ - public toLogEntry(_host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(_ctx?: GetValueDB): MessageOrCCLogEntry { let tag = this.constructor.name; const message: MessageRecord = {}; if (this.constructor === CommandClass) { @@ -1253,7 +1253,7 @@ export class InvalidCC extends CommandClass { } public readonly reason?: string | ZWaveErrorCodes; - public toLogEntry(_host?: GetValueDB): MessageOrCCLogEntry { + public toLogEntry(_ctx?: GetValueDB): MessageOrCCLogEntry { return { tags: [this.ccName, "INVALID"], message: this.reason != undefined