smartapp-sdk-nodejs icon indicating copy to clipboard operation
smartapp-sdk-nodejs copied to clipboard

fix: Type issue for non-default DeviceCommandHandlers

Open AmineI opened this issue 1 year ago • 0 comments

There is a type issue with deviceCommand() callback's type, impacting the usage of smartApp.deviceCommand() in TypeScript.

deviceCommand() defines a callback with a command parameter of type DeviceCommand. This is incorrect, as DeviceCommand has a component attribute, instead of componentId attribute as obtained from the APIs.

Default deviceCommandHandler() is not impacted, as it uses the interface DeviceCommandsEvent, itself using the correct type DeviceCommandsEventCommand.

This is becoming a mouthful. Here are the current classes :

Incorrect for deviceCommand() https://github.com/SmartThingsCommunity/smartthings-core-sdk/blob/bdd6bcc59044daef46725524e7fb3234d4cc0c1a/src/endpoint/rules.ts#L185-L191

Correct for deviceCommand() https://github.com/SmartThingsCommunity/smartapp-sdk-nodejs/blob/3725c0f5c6ff1f82a8219ba5399019e707526b49/lib/lifecycle-events.d.ts#L192-L197

Note that this PR is marked as incomplete, as this DeviceCommandsEventCommand is difficult to import for external projects. I would leave that decision to you in order to export or create an interface.

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [x] I have read the CONTRIBUTING document
  • [x] My code follows the code style of this project (hint: install an xo editor plugin)
  • [ ] Any required documentation has been added
  • [ ] I have added tests to cover my changes

AmineI avatar Dec 29 '23 03:12 AmineI