SmartThingsCommunity / smartapp-sdk-nodejs

Javascript/NodeJS SDK to create SmartThings SmartApps
https://smartthings.developer.samsung.com/
Apache License 2.0
143 stars 80 forks source link

fix: Type issue for non-default DeviceCommandHandlers #256

Open AmineI opened 8 months ago

AmineI commented 8 months ago

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