Issues trying to run homebridge-awair
jwhits opened this issue · 9 comments
I installed with sudo npm install -g homebridge-awair
Then got my token and configured the config file. However I have run into a few issues trying to run it.
When I ran homebridge, I got the following error on my local copy on my Raspberry Pi
Issue 1
ERROR LOADING PLUGIN homebridge-awair: [2018-8-13 10:41:43] /usr/lib/node_modules/homebridge-awair/index.js:184 that.log.debug(JSON.stringify(JSON.parse(response),null,2););
So I removed the extra ; also one on line 191.
Issue 2
I then got this error which was strange because I checked the node_modules folder inside homebridge-awair folder and it was there. I also checked npm list and it seemed to be there
ERROR LOADING PLUGIN homebridge-awair: [2018-8-13 11:09:55] Error: Cannot find module 'awairnode' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15) at Function.Module._load (internal/modules/cjs/loader.js:475:25) at Module.require (internal/modules/cjs/loader.js:598:17) at require (internal/modules/cjs/helpers.js:11:18) at Object.<anonymous> (/usr/lib/node_modules/homebridge-awair/index.js:2:13) at Module._compile (internal/modules/cjs/loader.js:654:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) at tryModuleLoad (internal/modules/cjs/loader.js:506:12) at Function.Module._load (internal/modules/cjs/loader.js:498:3) [2018-8-13 11:09:55] ====================
Tried uninstalling and reinstalling homebridge-awair no difference.
In the index.js I then changed
var awair = require('awairnode');
to
var awair = require('./node_modules/awairnode/lib/awairnode');
This seemed to work as it didn't error anymore, however I am not sure why it couldn't find the module?
Issue 3
I then got this error
`ERROR LOADING PLUGIN homebridge-awair:
[2018-8-13 17:08:33] /usr/lib/node_modules/homebridge-awair/node_modules/awairnode/lib/awairnode.js:55
url: 'http://developer-apis.awair.is/v1/users/self/devices/' + devType + '/' + devId + '/' + that.chainedRequests.join('');
^
SyntaxError: Unexpected token ;
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (internal/modules/cjs/loader.js:618:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)`
The options don't seem to be formatted correctly? in awairnode.js I changed this
// Construct the url var options = { url: 'https://afb-api.awair.is/v1/orgs/self/devices/' + devType + '/' + devId + '/air-data' + that.chainedRequests.join(''); headers: { 'Authorization': 'Bearer ' + orgToken }
to this
var cR = that.chainedRequests.join(''); // Construct the url var options = { url: 'https://afb-api.awair.is/v1/orgs/self/devices/' + devType + '/' + devId + '/air-data' + cR, headers: { 'Authorization': 'Bearer ' + orgToken }
This made the error go away but again not sure it it's correct?
Issue 4
I then got this error
ERROR LOADING PLUGIN homebridge-awair: [2018-8-13 17:58:49] Error: Cannot find module 'request' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15) at Function.Module._load (internal/modules/cjs/loader.js:475:25) at Module.require (internal/modules/cjs/loader.js:598:17) at require (internal/modules/cjs/helpers.js:11:18) at Object.<anonymous> (/usr/lib/node_modules/homebridge-awair/node_modules/awairnode/lib/awairnode.js:1:77) at Module._compile (internal/modules/cjs/loader.js:654:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) at tryModuleLoad (internal/modules/cjs/loader.js:506:12) at Function.Module._load (internal/modules/cjs/loader.js:498:3)
No idea why it couldn't find the request module as it's in npm list -g
I installed the request module locally by doing
sudo npm install request --save
This added request into the homebridge-awair package.json as a dependency and also the homebridge-awair local node_modules folder.
Issue 5
I then got the same error as issue 4 for lower-case and did the same fix.
Error: Cannot find module 'lower-case'
Issue 6
I then got this error
`Loading 1 accessories...
[2018-8-13 18:44:48] [Bedroom] Initializing Awair accessory...
/usr/lib/node_modules/homebridge-awair/index.js:19
this.awair = new Awair(config['token']);
^
ReferenceError: Awair is not defined
at new AwairAccessory (/usr/lib/node_modules/homebridge-awair/index.js:19:19)
at Server._loadAccessories (/usr/lib/node_modules/homebridge/lib/server.js:275:29)
at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:86:38)
at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object. (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
`
And after spending time trying to fix it I got stuck :(
Does this plugin actually run on someone else setup or is this to do with my install?
@jwhits wow! Amazing debugging. I’m not a developer, so I’ve been attempting to adapt this from various other plugins. I know it isn’t working, but I didn’t know it was this bad 😐
I’m considering reducing the scope of this project by making it self-contained, running all of the requests within the plugin instead of calling awairnode
.
@deanlyoung I am not developer either :(
I think it is pretty close to working. Making it self contained could be easier, as you don't have to deal with node dependency issues, which I am sure is easy for a developer. It's been ages since I have played with nodejs. It would be awesome if you could get this to work, I am trying to think how I might be able to help? What was the plugin you were adapting it from? a sensor based one?
I didn't realize this was not yet active yet. I'm expecting an Awair Glow today. I'll try to take a look as well and see if I can help get this working. I'd also like to get the smart switch portion of the glow active through this as well. I haven't made a homebridge plugin yet either, but hopefully with a few people looking at this it'll get there. Thanks for everything so far!
Hi all - threw together a working plugin just for the Glow here: https://www.npmjs.com/package/homebridge-awair-glow Hopefully that will help you some of the development here.
Wow, amazing @henrypoydar! Do you mind if I reference your implementation?
Also, being that I’m not a developer..., I thought I’d have to grab each sensor value based on the component name rather than the array index. Is it safe to assume that the sensor components will always be in the same order in the array?
Go for it! Hope it helps.
Good point - probably safer to pull the component values in by name. I suppose that choosing to dish them out as an array rather than a hash implies order, but that presumption is worthless if the implementation breaks. ;)
@jwhits @ShermanThruGA this is now officially working!
Thanks a ton to @henrypoydar!
Closing this issue out now.