Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: decouple CCs and messages from host instance, split ZWaveNode class into "mixins" #7260

Merged
merged 62 commits into from
Oct 17, 2024

Conversation

AlCalzone
Copy link
Member

@AlCalzone AlCalzone commented Oct 9, 2024

CC and Serial API message instances were decoupled from the host instance they previously required. Instead, contexts with the relevant functionality are now passed where they are necessary (parsing, serializing, interview, ...).

A lot of the code has been reworked to define which functionality is expected from those contexts. To do so, the previous ZWaveHost and ZWaveApplicationHost interfaces have been split into multiple smaller "traits".

Edit: While working on this PR, the focus has drastically changed. The original change is still in there, but it's merely a side effect now:
Although TS 5.6 made working with large files more bearable, it's time to start breaking the biggest offenders into smaller chunks, starting with the ZWaveNode class.

With this PR, related functionality is now grouped into individual "mixin" classes. They are not really mixins in the traditional sense, but rather a long chain of partial classes that are inherited to compose the building blocks of the ZWaveNode class.


List of breaking API changes:

  • The ZWaveHost and ZWaveApplicationHost interfaces have been split into multiple smaller "traits"
  • The Driver class still implements all those traits, but receiving functions now just require the necessary subset.
  • The CommandClassDeserializationOptions type now contains all additional info it needs in the new property context: CCParsingContext. frameType was moved there.
  • CC Constructors no longer take an instance of ZWaveHost as the first parameter. All needed information has been merged into the CCParsingContext type.
  • The CommandClass.from method no longer takes an instance of ZWaveHost as the first parameter for the same reason.
  • CommandClass instances no longer store a reference to their host. They are now "just data".
  • The serialize() implementations of CCs now take an argument of type CCEncodingContext
  • The toLogEntry() implementations of CCs now take an argument of type GetValueDB instead of ZWaveHost
  • The interview() implementations of CCs now take an argument of type InterviewContext instead of ZWaveApplicationHost
  • The refreshValues() implementations of CCs now take an argument of type RefreshValuesContext instead of ZWaveApplicationHost
  • The persistValues() implementations of CCs now take an argument of type PersistValuesContext instead of ZWaveApplicationHost
  • The translateProperty() and translatePropertyKey() implementations of CCs now take an argument of type GetValueDB instead of ZWaveApplicationHost
  • The mergePartialCCs signature has changed:
     -    mergePartialCCs(applHost: ZWaveApplicationHost, partials: CommandClass[]): void;
     +    mergePartialCCs(partials: CommandClass[], ctx: CCParsingContext): void;
  • The ICommandClass interface has been eliminated. Where applicable, it has been replaced with the CCId interface whose sole purpose is to identify the command and destination of a CC.
  • The IZWaveNode, IZWaveEndpoint, IVirtualNode and IVirtualEndpoint interfaces have been eliminated and replaced with more specific "trait" interfaces where they were previously used.
  • The TestingHost, TestNode and TestEndpoint interfaces and implementations have been reworked to be more declarative and require less input in tests.
  • The MessageDeserializationOptions type now contains all additional info it needs in the new property ctx: MessageParsingContext.
  • Serial API Message constructors no longer take an instance of ZWaveHost as the first parameter. All needed information has been merged into the MessageParsingContext type.
  • The Message.from method no longer takes an instance of ZWaveHost as the first parameter for the same reason.
  • The callbackId of a Message instance is no longer automatically generated when reading it for the first time. Instead, the callbackId can be undefined and has to be explicitly set before serializing if necessary.
  • The serialize() implementations of Messages now take an argument of type MessageEncodingContext
  • The Message.getNodeUnsafe() method has been renamed to Message.tryGetNode
  • The Driver.getNodeUnsafe(message) method has been renamed to Driver.tryGetNode(message)
  • Driver.controllerLog is no longer public.
  • Driver.getSafeCCVersion can now return undefined if the requested CC is not implemented in zwave-js
  • Driver.isControllerNode(nodeId) has been removed. Compare with ownNodeId instead.
  • The Endpoint.getNodeUnsafe() method has been renamed to tryGetNode

@AlCalzone AlCalzone added the breaking This is a breaking change label Oct 14, 2024
packages/host/src/mocks.ts Fixed Show fixed Hide fixed
@AlCalzone AlCalzone changed the title refactor: split ZWaveNode class into "mixins" refactor: decouple CCs and messages from host instance, split ZWaveNode class into "mixins" Oct 16, 2024
@AlCalzone AlCalzone changed the base branch from master to v14 October 17, 2024 09:46
@AlCalzone AlCalzone marked this pull request as ready for review October 17, 2024 09:47
@AlCalzone AlCalzone merged commit 9342f91 into v14 Oct 17, 2024
17 checks passed
@AlCalzone AlCalzone deleted the mixin-refactor branch October 17, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This is a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant