karlg100 / frigidaire

Frigidaire Cloud API
19 stars 11 forks source link

Update frigidaire.js to fix API change #12

Open amaisano opened 1 year ago

amaisano commented 1 year ago

Copied from working fix at https://github.com/bm1549/frigidaire/pull/18

cc @bm1549

marekbrz commented 1 year ago

I also had to add lines 339 and 507 to match the headers in line 204 (x-api-key):

var headers = {
         'x-ibm-client-id': this.clientId,
         'User-Agent': this.userAgent,
         'Content-Type': 'application/json',
         'Authorization': 'Basic ' + this.basicAuthToken,
         'x-api-key': this.basicAuthToken
     }
amaisano commented 1 year ago

I also had to add lines 339 and 507 to match the headers in line 204 (x-api-key):

@marekbrz

In this repo? Or in the homebridge-frigidaire plugin repo? I don't see any other places in THIS file (see file changes in this PR) that use headers...

I already added the x-api-key to this pull request.

pman193 commented 1 year ago

Hey. This is what I get with your updates.

[6/7/2023, 12:53:45 AM] [homebridge-frigidaire] Loaded homebridge-frigidaire v2.1.3 child bridge successfully [6/7/2023, 12:53:45 AM] Loaded 0 cached accessories from cachedAccessories.0E1B2E83A964. failed to parse auth result json: '[object Object]'

/usr/lib/node_modules/homebridge-frigidaire/node_modules/frigidaire/lib/frigidaire.js:540 var sessionKey = body.data.sessionKey ^ TypeError: Cannot read properties of undefined (reading 'sessionKey') at Request.authPostCallback [as _callback] (/usr/lib/node_modules/homebridge-frigidaire/node_modules/frigidaire/lib/frigidaire.js:540:37) at Request.self.callback (/usr/lib/node_modules/homebridge-frigidaire/node_modules/request/request.js:185:22) at Request.emit (node:events:513:28) at Request. (/usr/lib/node_modules/homebridge-frigidaire/node_modules/request/request.js:1154:10) at Request.emit (node:events:513:28) at IncomingMessage. (/usr/lib/node_modules/homebridge-frigidaire/node_modules/request/request.js:1076:12) at Object.onceWrapper (node:events:627:28) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) [6/7/2023, 12:53:46 AM] [homebridge-frigidaire] Child bridge process ended [6/7/2023, 12:53:46 AM] [homebridge-frigidaire] Process Ended. Code: 1, Signal: null

pman193 commented 1 year ago

api.us.ocp.electrolux.one I was messing around with Wireshark and got this url. it make plugin status go from steady red to steady yellow. Old error messages disappear and a new one about the plugin taking too long to load comes up in yellow.

marekbrz commented 1 year ago

@amaisano Was referencing this repo (karlg100/frigidaire). Might be more clear to show what I'm talking about. @pman193 see if this fixes things:

https://github.com/marekbrz/frigidaire/commit/a13daaa6364b8216abc9818383f479f40e8cb53e

pman193 commented 1 year ago

Hey. Thanks for all your work. It's still not connecting. I used Wireshark to see if I could verify the API URL and found this one. api.us.ocp.electrolux.one It got the plugin to go from red to yellow. I'm not coder by any means. Don't know if that URL helps.

pman193 commented 1 year ago

Also, just a thought. Could the new app they released require that the serial number be available in the config.json in Homebridge?

marekbrz commented 1 year ago

Seems like the new app they released is a whole new version of the API, and this project won't work with it yet. However, at least in my case, I'm able to still use the Frigidaire 2.0 app. Make sure any wireshark traces are coming from that app, as anything from the new app won't be applicable.

And FWIW here's my config.json for this plugin (you can ignore the _bridge section)

image
pman193 commented 1 year ago

Hey. Thank you again. My AC unit now only works with the new app. It can no longer be added to the Frigidaire 2.0 app. Appreciate everyones work with this.

amaisano commented 1 year ago

@marekbrz ah I see. So it looks like the plugin has some hard coded lines that need to be updated, too, not just this upstream library. Did you open a pull request there for those updates? Sounds like we will need them AND this PR to be merged.

pman193 commented 1 year ago

So it's working. I changed the password in the phone app. That allowed me to add it to a second device which it wasn't let me do and connect to Google Home. Looks like it's still going thru Frigidaire 2.0 in Homebridge even though I can only use the new app on my phone and tablet. Only thing is that it only shows 1° as current temp and doesn't matter what temp you set to cool to, it only shows 60º as target temp. image

Thanks again for all your hard work.

marekbrz commented 1 year ago

@pman193 see if this commit solves the issue: https://github.com/marekbrz/frigidaire/commit/83425c3f75c73f3e021b88940ba3bd4e09716852

pman193 commented 1 year ago

You're a genius! That fixed it. Thank you!

marekbrz commented 1 year ago

@amaisano did not open a PR against karlg100/frigidaire, will do so shortly. There are two repos: frigidaire, and homebridge-frigidaire. Only one I needed to update was the frigidaire one, did not need to change anything on the homebridge plugin

amaisano commented 1 year ago

@amaisano did not open a PR against karlg100/frigidaire, will do so shortly. There are two repos: frigidaire, and homebridge-frigidaire. Only one I needed to update was the frigidaire one, did not need to change anything on the homebridge plugin

You mean you will open a PR in karlg100/frigidaire-homebridge, yes? THIS is the PR for karlg100/frigidaire... I'm confused.

marekbrz commented 1 year ago

Nope, not karlg100/frigidaire-homebridge. I'm referring to karlg100/frigidaire.

I've been doing all my testing / dev with the demo.js tool in this repo, so as to be intentionally upstream from Homebridge. When I merge the changes from your PR, most of the functions in demo.js work, but several do not. That is fixed by the changes referenced in my comments upthread.

If you look at the frigidaire.js in your PR and compare it to the one I edited and posted upthread (https://github.com/marekbrz/frigidaire/commit/a13daaa6364b8216abc9818383f479f40e8cb53e), you'll see that they're the same file. Just mine has the additional two headers that make all of demo.js work.

So either you should edit your PR and include my additional two lines, or I'll do a separate PR, and let Karlg100 merge it all so it's a single commit.

amaisano commented 1 year ago

@marekbrz I understand now, sorry. I've merged your changes with the existing PR in a new commit just now, to speed things up. Thanks for the contribution.

@pman193 want to try this all again and confirm?

Are we sure nothing needs to change in https://github.com/karlg100/homebridge-frigidaire/blob/master/index.js ?

amaisano commented 1 year ago

@karlg100 if you have a moment to check (and eventually merge) that would be awesome. Thanks.

pman193 commented 1 year ago

@marekbrz I understand now, sorry. I've merged your changes with the existing PR in a new commit just now, to speed things up. Thanks for the contribution.

@pman193 want to try this all again and confirm?

Are we sure nothing needs to change in https://github.com/karlg100/homebridge-frigidaire/blob/master/index.js ?

I was able to edit and add all the changes and can confirm they work. I had to change my login password in the app and that seemed to be the final piece to making it work.

pman193 commented 1 year ago

To be clear I added everything before this last update to get it to work.

marekbrz commented 1 year ago

to everyone in this thread: check out my latest PR and see if it works. frigidaire moved to a new api (as evidenced by a whole new app) and will be deprecating the old API, and this update resolves that issue:

13