onokje / node-red-contrib-tesla

Node red nodes to control Tesla vehicles and devices
MIT License
20 stars 11 forks source link

Enhancement - Nodered error output #56

Open ASomerN opened 1 year ago

ASomerN commented 1 year ago

Hi,

Great API in NodeRed and I've been able to completely automate charging of the car using solar power, modulating in real time for cloud cover and so on, and auto-shut-off if it exceeds charge and starts using too much house battery.

I've encountered an issue where Nodered can't easily capture failures on the API (i set the car to use my own wifi and opened a can of worms of mesh network but that's a different issue and resulted in me finding a potential improvement). As it stands it appears any error is stuck within the API request. Would it be possible to update so there are two outputs from the API, in essence (excuse the pseudo-code):

apirequest().then((success) => {
   return [{payload: success},null]
}).catch((error) => {
  return [null,{payload:error}]
})

This ought not to be a breaking change, as currently success is returned in the first instance anyway, but not the error. This would allow us to handle some rejected responses, instead of creating a mechanism in Nodered to detect a failed request based on nothing happening.

If the error included details we can map specific flows based on the error type.

Thanks for all the really great work you have done.

ASomerN commented 1 year ago

Hi,

I've forked this to build and do some testing: https://github.com/ASomerN/node-red-contrib-tesla/tree/try-catch-outputs

Example working flow (had to wait for the vehicle to sleep): image

Everything is working as intended, it outputs either success or fails, some minor changes are required but need to test the upgrade to see if it causes anything to break. Changed colour of the node to match the logo but this was more to differentiate locally.

The only change required is in the tesla.js send call and function, and setting outputs to 2 in the html.