muldy / pimatic-wemo

A Wemo Device control plugin for Pimatic
GNU General Public License v2.0
1 stars 1 forks source link

Code needs to be properly promisified #3

Open mwittig opened 8 years ago

mwittig commented 8 years ago

Your code needs to be properly promisified as getState and changeStateTo() need to return promises and should properly complete the promise in all cases, either with an result (if expected) or with an error in the rejection case. I have already done some imrpvements locally which I would like to contribute when issues #2 has been clarified/resolved.

Gernot commented 7 years ago

As @michbeck100 wrote, this leads to crashes when used with primatic-hap. Instead of a promise it seems to return "undefined" from time to time:

10:28:27.621 [pimatic] A uncaught exception occured: TypeError: Cannot read property 'then' of undefined
10:28:27.621 [pimatic]>    at PowerSwitchAccessory.BaseAccessory.handleReturnPromise (/home/pi/pimatic-app/node_modules/pimatic-hap/accessories/base.coffee:50:9)
10:28:27.621 [pimatic]>    at PowerSwitchAccessory.handleReturnPromise (/home/pi/pimatic-app/node_modules/pimatic-hap/accessories/base.coffee:1:1)
10:28:27.621 [pimatic]>    at null.<anonymous> (/home/pi/pimatic-app/node_modules/pimatic-hap/accessories/switch.coffee:39:12)
10:28:27.621 [pimatic]>    at emitThree (events.js:97:13)
10:28:27.621 [pimatic]>    at null.emit (events.js:175:7)
10:28:27.621 [pimatic]>    at null.Characteristic.getValue (/home/pi/pimatic-app/node_modules/pimatic-hap/node_modules/hap-nodejs/lib/Characteristic.js:120:10)
10:28:27.621 [pimatic]>    at Bridge.<anonymous> (/home/pi/pimatic-app/node_modules/pimatic-hap/node_modules/hap-nodejs/lib/Accessory.js:621:20)
10:28:27.621 [pimatic]>    at Array.forEach (native)
10:28:27.621 [pimatic]>    at Bridge.Accessory._handleGetCharacteristics (/home/pi/pimatic-app/node_modules/pimatic-hap/node_modules/hap-nodejs/lib/Accessory.js:585:8)
10:28:27.621 [pimatic]>    at emitMany (events.js:108:13)
10:28:27.621 [pimatic]>    at HAPServer.emit (events.js:182:7)
10:28:27.621 [pimatic]>    at HAPServer._handleCharacteristics (/home/pi/pimatic-app/node_modules/pimatic-hap/node_modules/hap-nodejs/lib/HAPServer.js:921:10)
10:28:27.621 [pimatic]>    at HAPServer.<anonymous> (/home/pi/pimatic-app/node_modules/pimatic-hap/node_modules/hap-nodejs/lib/HAPServer.js:204:39)
10:28:27.621 [pimatic]>    at emitNone (events.js:67:13)
10:28:27.621 [pimatic]>    at IncomingMessage.emit (events.js:166:7)
10:28:27.621 [pimatic]>    at endReadableNT (_stream_readable.js:923:12)
10:28:27.621 [pimatic]>    at nextTickCallbackWith2Args (node.js:458:9)
10:28:27.621 [pimatic]>    at process._tickCallback (node.js:372:17)
10:28:27.621 [pimatic]> This is most probably a bug in pimatic or in a module, please report it!
10:28:27.629 [pimatic] shutting pimatic down...
michbeck100 commented 7 years ago

As far as i can tell, getState always returns undefined (see https://github.com/muldy/pimatic-wemo/blob/master/wemo.coffee#L63). But as https://github.com/pimatic/pimatic/blob/master/lib/devices.coffee#L289 states, getState must always return a promise.

muldy commented 7 years ago

Hi! Thanks for the feedback, will this be suficent: 5009c6edcaf7295bf1bbd77fcccc554fd18c18b1 (getState)