codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.06k stars 339 forks source link

toString causing issues, please use toString() #28

Closed drumfreak closed 6 years ago

drumfreak commented 6 years ago

thisRequest.dps[options.dps.toString] = options.set;

Seems to be missing the () behind toString. This caused issues setting dps values with using this package from homebridge.

For example:

tuya.set({id: 'xxxxxxxxxxxxxxxxxxxx', 'dps': 2, set: true}).then(() => console.log('device was changed'))

Would fail because toString is not a function in prototype.

Proposed change:

thisRequest.dps[options.dps.toString()] = options.set;

or even:

if (options.dps === undefined) { thisRequest.dps = {1: options.set}; } else { thisRequest.dps = {}; thisRequest.dps[options.dps] = options.set; }

https://github.com/codetheweb/tuyapi/blob/290d6e937130d15e091a143cd094b6f8b2979eab/index.js#L233

codetheweb commented 6 years ago

Oops, thanks for the heads up. (I should really get around to adding test cases.) Should be fixed now.

drumfreak commented 6 years ago

Thank you @codetheweb