vinodsr / node-red-contrib-tuya-smart-device

a node-red module for managing tuya smart devices
https://flows.nodered.org/node/node-red-contrib-tuya-smart-device
MIT License
43 stars 15 forks source link

Error not catched by CATCH node #47

Closed mroziken closed 3 years ago

mroziken commented 3 years ago

The catch node fails to catch the error, for example "Error: Error from socket". I would like to request that node.error is called with a 2nd parameter to permit the catch node to catch errors it raises.

The rationale behind. When tuya-smart-device cannot connect to tuya bulb it generate error and report it to debug window. But when the bulb swith is off then it is normal situation and there is need to handle that programatically. For example catch error from the node and decide not to display in debug.

vinodsr commented 3 years ago

Good thought.

But how will you turn on from the off state ( physical ) . ?

msillano commented 3 years ago

See also issue#429. I found 2 ERRORs not catched:

  3 Mar 18:48:14 - [error] [tuya-smart-device:12896b89.d95c84] Error: find() timed out. Is the device powered on and the ID or IP correct?
  3 Mar 18:49:56 - [error] [tuya-smart-device:e543af34.b2468] Error: Error from socket

More notes on ver. 2.0.0. used in production environment tuyaDAEMON:

  1. New in this version is the extra infos:

    3 Mar 18:56:00 - [info] [tuya-smart-device:12896b89.d95c84] Recieved the config {"id":"12896b89.d95c84","type":"tuya-smart-device","z":"173260fb.d021ff","deviceName":"siren","deviceId":"42027807d8bfc0c5831e","deviceKey":"70e17a0208ae2e5c","deviceIp":"","retryTimeout":"100279","findTimeout":"100291","tuyaVersion":"3.1","x":970,"y":460,"wires":[["2ec83963.a7d146"]],"info":"**tuya_ms_104**   \n\n_tuya bridge for \"WiFi Smart Switch Module MS-104\"_\n\nAfter any command, this device sends (and this node captures) a 'status' message carring only the changed values.\n\nA command can be send by node-red, SmartLife app, Google home, Google voice: in any case this node captures the status message.\n\n_note:_\n If node-red changes the switch state, SmartLife is updated correctly, but Google Home not.\n \n_Input:_\nTo send a command via node-red. the payload structure must be:\n` multiple: true\n  data: object\n    1: true\n    102: 5`\n\n_nb:_\nset **Device Virtual ID** and **Device Key** to a tuya connected and working switch, model M-104 ( see [https://it.aliexpress.com/wholesale?SearchText=smart+switch+ms+104](https://it.aliexpress.com/wholesale?SearchText=smart+switch+ms+104))."}

    All stuff after "tuyaVersion":"3.1" is not usefull.

  2. User config timeouts are very useful: with prime numbers I can better distribute the load over the time. But it would be even better with the dynamic timeouts: so I can "hibernate" some devices via the program (see ISSUE#35).

  3. tuyapi is now ver. 6.1.5

Best regards m.s.

mroziken commented 3 years ago

Good thought.

But how will you turn on from the off state ( physical ) . ?

Hi

I have a phisical/traditional switch in wall (2-wire). So when switch is off the bulb is off. If the wall switch is off then obviously there is not way to switch on the bulb. The status of bulb in my custom app should be INACTIVE. To detect if bulb is connected I'm using status of your tuya-smart-device node. If status is connected then then in my app the bulb is accessible and you can perform operations (On/Off/Dimm/etc). In case of other status I assume the bulb is not connected and it should be inactive in my app (no operations allowed).

I hope that clarifies.

mroziken commented 3 years ago

The catch node fails to catch the error, for example "Error: Error from socket". I would like to request that node.error is called with a 2nd parameter to permit the catch node to catch errors it raises.

The rationale behind. When tuya-smart-device cannot connect to tuya bulb it generate error and report it to debug window. But when the bulb swith is off then it is normal situation and there is need to handle that programatically. For example catch error from the node and decide not to display in debug.

I localy modified the following:

tuya-smart-device.js: var setStatusOnError = function (e, message = "error", msg = {}) { node.error(e, msg); return node.status({ fill: "red", shape: "ring", text: message }); };

And it is working as expected

vinodsr commented 3 years ago

@mroziken Please check version 3.1.0