I’m currently trying to develop a new pimatic plugin that creates a HomeKit bridge using HAP-NodeJS, but it seems that i’m having problems with the use of the Promise library.
I’m fairly new to js and node development, so maybe the problem is me .
It seems that every method magically turns into a Promise, because i’m seeing errors when HAP-NodeJS wants to set the headers in a response, but the response was already sent:
01:06:17.923 [pimatic] A uncaught exception occured: Error: Can’t set headers after they are sent.
01:06:17.923 [pimatic]> at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
01:06:17.923 [pimatic]> at ServerResponse.res.setHeader (/Users/michaelkotten/Development/github/pimatic/node_modules/express/node_modules/connect/lib/patch.js:63:22)
01:06:17.923 [pimatic]> at ServerResponse.<anonymous> (/Users/michaelkotten/Development/github/pimatic/node_modules/express/node_modules/connect/lib/patch.js:80:14)
01:06:17.923 [pimatic]> at Array.forEach (native)
01:06:17.923 [pimatic]> at ServerResponse.res.writeHead (/Users/michaelkotten/Development/github/pimatic/node_modules/express/node_modules/connect/lib/patch.js:79:28)
01:06:17.923 [pimatic]> at HAPServer.<anonymous> (/Users/michaelkotten/Development/github/pimatic-hap/node_modules/hap-nodejs/lib/HAPServer.js:672:16)
01:06:17.923 [pimatic]> at Bridge.Accessory._handleGetCharacteristics (/Users/michaelkotten/Development/github/pimatic-hap/node_modules/hap-nodejs/lib/Accessory.js:471:5)
01:06:17.923 [pimatic]> at HAPServer.emit (events.js:118:17)
01:06:17.923 [pimatic]> at HAPServer._handleCharacteristics (/Users/michaelkotten/Development/github/pimatic-hap/node_modules/hap-nodejs/lib/HAPServer.js:659:10)
01:06:17.923 [pimatic]> at HAPServer.<anonymous> (/Users/michaelkotten/Development/github/pimatic-hap/node_modules/hap-nodejs/lib/HAPServer.js:172:39)
01:06:17.923 [pimatic]> at IncomingMessage.emit (events.js:104:17)
01:06:17.923 [pimatic]> at _stream_readable.js:908:16
01:06:17.923 [pimatic]> at process._tickCallback (node.js:355:11)
01:06:17.923 [pimatic]> This is most probably a bug in pimatic or in a module, please report it!