Foddy / node-red-contrib-huemagic

Philips Hue node to control bridges, lights, groups, motion sensors, temperature sensors and Lux sensors using Node-RED.
https://flows.nodered.org/node/node-red-contrib-huemagic
Apache License 2.0
201 stars 67 forks source link

"TypeError: Cannot read property 'apply' of undefined" #306

Open Darkman1900 opened 2 years ago

Darkman1900 commented 2 years ago

Hi, I'm getting the error from "hue light node" after using a physical switch to turn on the light. The node is showing (turned off - not reachable) before the error occurs. The light is turned on I think by the hue bridge directly because power is "restored". The light flashes for a short moment and after that the light is off - I think triggered by node red. Thank you

ptweety commented 2 years ago

Hi @Darkman1900 , can you please share the respective log?

Darkman1900 commented 2 years ago

Hi, today I got the error with log enabled. But the output is missing - do not know why?

The console output 20.2.2022, 23:32:54[node: Hue_Lampen_Status](http://homematic-raspi/addons/red/#) msg : Object object payload: object info: object updated: object lastState: object command: object _msgid: "71a4a5976c3bb7f6" 20.2.2022, 23:32:54[node: Arbeitszimmer](http://homematic-raspi/addons/red/#) msg : error "TypeError: Cannot read property 'apply' of undefined" 20.2.2022, 23:32:55[node: Hue_Lampen_Status](http://homematic-raspi/addons/red/#) msg : Object object payload: object info: object updated: object lastState: object command: object _msgid: "559cb6aaef4425dd" log.txt

bland328 commented 2 years ago

I'm also running into this error, and consistently run into it if I tell a bulb to fade slowly to brightness zero (msg.payload = {"brightness": 0, "transitionTime": 20}) , then send that command again a couple seconds later, while the bulb is still fading.

I hope that helps, and I'm happy to share logs, if desired, and if I can figure out how to generate them--I have level: "trace" set in my settings file, but what appears in the log around the time of the error is just 25 Feb 17:47:50 - [error] [hue-light:Bonus] TypeError: Cannot read property 'apply' of undefined, and nothing else.

ptweety commented 2 years ago

Hi @bland328, I'm not sure, but this might be related to these lines: https://github.com/Foddy/node-red-contrib-huemagic/blob/7a0d17d7d0f9924e1ef3b92b81393722c68edfec/huemagic/hue-light.js#L114-L115

You can try to patch them as follows and see if the error persists:

send = send || function() { if (scope.send && typeof scope.send.apply != 'undefined') scope.send.apply(scope,arguments); }
done = done || function() { if (scope.done && typeof scope.done.apply != 'undefined') scope.done.apply(scope,arguments); }
m4rkv5 commented 2 years ago

Hi @bland328, I'm not sure, but this might be related to these lines:

https://github.com/Foddy/node-red-contrib-huemagic/blob/7a0d17d7d0f9924e1ef3b92b81393722c68edfec/huemagic/hue-light.js#L114-L115

You can try to patch them as follows and see if the error persists:

send = send || function() { if (scope.send && typeof scope.send.apply != 'undefined') scope.send.apply(scope,arguments); }
done = done || function() { if (scope.done && typeof scope.done.apply != 'undefined') scope.done.apply(scope,arguments); }

Fixed the fading issue for me in version 4.2.1

I got "TypeError: Cannot read property 'apply' of undefined" after sending 'msg.payload={"decrementBrightness":25}'