luc-ass / homebridge-evohome

Homebridge plugin for Honeywell Evohome
29 stars 16 forks source link

Cannot read property 'locationId' of undefined #33

Closed MadMaxCGN closed 6 years ago

MadMaxCGN commented 6 years ago

Hi,

thanks for that great plugin but since the last update (0.4.0) I get the following error. Homebridge with evohome is not working anymore...

2018-2-3 18:28:00] [Evohome] Evohome Failed: TypeError: Cannot read property 'locationId' of undefined at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:125:53 at Function.map (/usr/local/lib/node_modules/homebridge-evohome/node_modules/lodash/dist/lodash.js:3509:27) at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:122:18 at _fulfilled (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:787:54) at self.promiseDispatch.done (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:816:30) at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:749:13) at /usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:557:44 at flush (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:108:17) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9)

fredericvl commented 6 years ago

Seems like there is no locationInfo in the json from Honeywell. Can you please add a line of code (in green below) in lib/evohome.js for debugging, restart the plugin and share your logs again? Then we can see the output from Honeywell and look for a fix.

Session.prototype.getLocations = function() {
    var url = "https://tccna.honeywell.com/WebAPI/emea/api/v1/location/installationInfo?userId=" + this.userInfo.userID + "&includeTemperatureControlSystems=True";
    return this._request(url).then(function(json) {
+       console.log("Debugging locations: " + json);
        return _.map(json, function(location) {
MadMaxCGN commented 6 years ago

Debugging locations: [object Object] [2018-2-7 13:19:18] [Evohome] Evohome Failed: TypeError: Cannot read property 'locationId' of undefined at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:126:53 at Function.map (/usr/local/lib/node_modules/homebridge-evohome/node_modules/lodash/dist/lodash.js:3509:27) at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:123:18 at _fulfilled (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:787:54) at self.promiseDispatch.done (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:816:30) at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:749:13) at /usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:557:44 at flush (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:108:17) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9)

fredericvl commented 6 years ago

My bad, the object has to be converted to json. Can you change the line, restart homebridge and share your ouput again please?

-       console.log("Debugging locations: " + json);
+       console.log("Debugging locations: " + JSON.parse(json));
MadMaxCGN commented 6 years ago

For sure, now I get this...

[2018-2-7 13:58:05] [Evohome] Evohome Failed: SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse () at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:122:52 at _fulfilled (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:787:54) at self.promiseDispatch.done (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:816:30) at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:749:13) at /usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:557:44 at flush (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:108:17) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9)

fredericvl commented 6 years ago

Hopefully now the full json message with this change in code:

-       console.log("Debugging locations: " + JSON.parse(json));
+       console.log("Debugging locations: " + JSON.stringify(json));
MadMaxCGN commented 6 years ago

this gives:

Debugging locations: [{"code":"Unauthorized","message":"Unauthorized."}] [2018-2-7 14:20:32] [Evohome] Evohome Failed: TypeError: Cannot read property 'locationId' of undefined at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:126:53 at Function.map (/usr/local/lib/node_modules/homebridge-evohome/node_modules/lodash/dist/lodash.js:3509:27) at /usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:123:18 at _fulfilled (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:787:54) at self.promiseDispatch.done (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:816:30) at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:749:13) at /usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:557:44 at flush (/usr/local/lib/node_modules/homebridge-evohome/node_modules/q/q.js:108:17) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9)

fredericvl commented 6 years ago

That's indeed what I expected to see, seems that you are not logged in to the honeywell api. Stupid question but just to double check: are you sure your username and password are correct in the config?

MadMaxCGN commented 6 years ago

Username and password are correct. Previous versions of the plugin worked in the past. Some lines further up in the logfile it also says: [2018-2-7 14:20:31] [Evohome] Logged into Evohome!

luc-ass commented 6 years ago

can you please post your config.json (the part of evohome minus your email and password)?

MadMaxCGN commented 6 years ago

tried it with and without location index information. same results

` "platforms": [ { "platform": "Evohome", "name" : "Evohome", "username" : "user", "password" : "pass", "temperatureUnit" : "Celsius", "locationIndex" : "0"

    }
 ],

`

fredericvl commented 6 years ago

I've changed the code and added a check for verifying the login, on failure it will generate an error. When I tested with a wrong username/pass it gives me this error: "invalid_grant". You can find the change on my fork: https://github.com/fredericvl/homebridge-evohome/commit/c8c27597824677ccc3e37edadc463314103e4f7f

@luc-ass I also made a PR out of this one (#35 )

MadMaxCGN commented 6 years ago

Hi,

thanks. I did a test and it gives me "invalid_grant" BUT my username and password are definitively correct. My username has a "+" (username+evohome@mail.com). Might it be possible that this causes an issue?

MadMaxCGN commented 6 years ago

Ok. I did change my email adress and deleted th "+". It is now working. Maybe this can be solved with an update. Thanks you very much for your support. I really appreciate.

fredericvl commented 6 years ago

@MadMaxCGN thanks for finding that one! In the meantime I fixed this, the problem was that special characters were not being encoded while doing the login request to Honeywell... Fix is here: https://github.com/fredericvl/homebridge-evohome/commit/02ee0890aa6f2dce7d2bb792e9054e08a5dbff36 and also in this pull request: #35

luc-ass commented 6 years ago

thank you for solving this problem.

merged. bumped version to v0.4.1. published on NPM.

fvhemert commented 4 years ago

I have downloaded node-red-contrib-evohome this week and after a successful start I noticed the following error message "TypeError: Cannot read property 'locationId' of undefined" Reading through the above posts I understand this issue should have been solved over a year ago but for some reason it has resurfaced.

I noticed the polling works fine for 20-30 minutes and then suddenly stops working and starts generating the above error message. If I disable polling and wait for severtal hours, I can reproduce the behaviour.

Polling is set to 600 secs.

I am using the 1.0.4 version for node-red-contrib-evohome and 0.20.7 of Nodered.

Any advice you can share or additional information I can provide?

luc-ass commented 4 years ago

Hi there, this is the development of homebridge-evohome. Please refer to the repositories of node-red-contrib-evohome if you need help. https://github.com/search?q=node-red-contrib-evohome

fvhemert commented 4 years ago

Sorry, I did not notice that.

BR Francois