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

switch status is not changing(on/off) #222

Closed nishanthhegde closed 5 years ago

nishanthhegde commented 5 years ago

Connect to the switch using the tuyapi and change the status of the switch To Reproduce Steps to reproduce the behavior:

  1. Enter the id of the switch
  2. retriever the details of the switch
  3. tuya.set({set: true}).then(() => console.log('device was turned on'))
  4. this piece of code is not working , the statement is executing by default.
  5. switch status remains the same.

Expected behavior Switch should change the status if 'true' then switch ON and if 'false' then OFF.

P.S. I'm not an expert in this field , it would really help if there is any solution to this issue.

Apollon77 commented 5 years ago

I think you misunderstand the Promie resolvement here. The "response" only tellss you that the command was really send out to the device. Alternatively the call is rejected on error.

If you want to verify that the device reacted correctly to the call you need to add more logic.

I would consider this as a "not an issue" for the library

nishanthhegde commented 5 years ago

can you please tell me what should i do in order to check if the device reacted properly? @Apollon77

nishanthhegde commented 5 years ago

// Set default property to opposite if (!stateHasChanged) { device.set({set: !(data.dps['1'])});

// Otherwise we'll be stuck in an endless
// loop of toggling the state.
stateHasChanged = true;

here- device.set({set: !(data.dps['1'])}); is doing nothing.

codetheweb commented 5 years ago

@nishanthhegde just call device.get() after setting the device to confirm that it now has the intended state.

Thanks for helping out @Apollon77.