SmartThingsCommunity / smartapp-sdk-nodejs

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

More flexible API requests #11

Closed erodewald closed 4 years ago

erodewald commented 5 years ago

Is your feature request related to a problem? Please describe. I can't use async-await syntax with API calls.

Describe the solution you'd like To avoid 'callback hell', I would like to be able to use code like this:

 try {
      const { data: unsub } = await ctx.api.subscriptions.unsubscribeAll();
      console.log(`Status: ${unsub.status}`)
      const { data: sub } = await ctx.api.subscriptions.subscribeToDevices(ctx.config.humiditySensors, "relativeHumidityMeasurement", "humidity", "humidityHandler");
      console.log(`Status: ${sub.status}`)
    } catch (err) {
      throw new Error(err)
    }

Describe alternatives you've considered N/A

Additional context It's not a cut-and-dry problem as there has been considerable thought put into making requests sequentially to abstract away complexities.

bflorian commented 4 years ago

@erodewald is this still an issue? I'm not sure about the returned values in these specific cases, but I've been using async / await with the current SDK extensively and not had a problem. What happens when you run the above code?

bflorian commented 4 years ago

The above code does now work, though the returned values are different in the 2.0 version of the SDK which uses the SmartThings Core SDK for API calls.