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 CC parsing from creation #7288

Merged
merged 13 commits into from
Oct 22, 2024
Merged

Conversation

AlCalzone
Copy link
Member

@AlCalzone AlCalzone commented Oct 18, 2024

As a followup to #7260, this PR separates the constructors of CC implementations, which previously dealt with both deserializing and constructing CC instances.

This PR changes the constructor signature so it exclusively deals with constructing a CC instance. Parsing binary payloads now happens in the static from() method.


List of breaking API changes:

  • The [CCName]CC[CCCommand]Options interfaces no longer extend another interface and now exclusively contain the CC-specific properties required for constructing that particular CC
  • CC-specific constructors now accept a single options object of type WithAddress<...>, which is the CC-specific options interface, extended by nodeId and endpointIndex. Note that endpointIndex was previously just called endpoint.
  • The CommandClassDeserializationOptions interface and the gotDeserializationOptions method no longer exist
  • Instead, CCs parse their specific payload using the new static from method, which takes a pre-parsed CCRaw (ccId, ccCommand, binary payload) and the CCParsingContext. All CCs with a custom constructor implementations are expected to implement this aswell.
    To parse an arbitrary CC buffer use CommandClass.parse(buffer, context).
  • Several CCs had their constructor options type reworked slightly for correctness. In some cases it is now necessary to pass properties that were previously inferred.
  • The CommandClassOptions type and CommandClassCreationOptions type have been merged into CommandClassOptions, which now consists only of the CC destination and optional overrides for ccId, ccCommand and payload.
  • CommandClass.deserialize has been removed. It's functionality is now provided by the parse method and CCRaw.
  • CommandClass.getCommandClass, CommandClass.getCCCommand have been removed. Their functionality is now provided by CCRaw.parse
  • CommandClass.getConstructor has been removed. If really needed, the functionality is available via the getCCConstructor and getCCCommandConstructor methods exported by @zwave-js/cc.
  • The origin property of the CommandClass class was removed, since it served no real purpose.

@AlCalzone AlCalzone marked this pull request as ready for review October 22, 2024 10:37
@AlCalzone AlCalzone added the breaking This is a breaking change label Oct 22, 2024
@AlCalzone AlCalzone force-pushed the decouple-cc-parsing branch from 8b77138 to 316f8e6 Compare October 22, 2024 11:07
@AlCalzone AlCalzone merged commit 02fced2 into v14 Oct 22, 2024
15 checks passed
@AlCalzone AlCalzone deleted the decouple-cc-parsing branch October 22, 2024 11:16
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