refactor: decouple CC parsing from creation #7288
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
[CCName]CC[CCCommand]Options
interfaces no longer extend another interface and now exclusively contain the CC-specific properties required for constructing that particular CCWithAddress<...>
, which is the CC-specific options interface, extended bynodeId
andendpointIndex
. Note thatendpointIndex
was previously just calledendpoint
.CommandClassDeserializationOptions
interface and thegotDeserializationOptions
method no longer existfrom
method, which takes a pre-parsedCCRaw
(ccId, ccCommand, binary payload) and theCCParsingContext
. All CCs with a custom constructor implementations are expected to implement this aswell.To parse an arbitrary CC buffer use
CommandClass.parse(buffer, context)
.CommandClassOptions
type andCommandClassCreationOptions
type have been merged intoCommandClassOptions
, 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 theparse
method andCCRaw
.CommandClass.getCommandClass
,CommandClass.getCCCommand
have been removed. Their functionality is now provided byCCRaw.parse
CommandClass.getConstructor
has been removed. If really needed, the functionality is available via thegetCCConstructor
andgetCCCommandConstructor
methods exported by@zwave-js/cc
.origin
property of theCommandClass
class was removed, since it served no real purpose.