aschzero / homebridge-airmega

Homebridge plugin for the Coway Airmega air purifier.
35 stars 19 forks source link

plugin causing repeated restart of Homebridge #21

Open davidpesetsky opened 2 years ago

davidpesetsky commented 2 years ago

Since updating Homebridge to v1.5.1 on my Raspberry Pi, the homebridge-airmega plugin appears to be triggering a repeated restart:

[29/10/2022, 09:29:31] TypeError: Cannot read properties of null (reading '0') at Authenticator. (/usr/local/lib/node_modules/homebridge-airmega/lib/Authenticator.ts:89:49) at Generator.next () at fulfilled (/usr/local/lib/node_modules/homebridge-airmega/dist/lib/Authenticator.js:4:58) [29/10/2022, 09:29:31] Got SIGTERM, shutting down Homebridge... [29/10/2022, 09:29:31] [Harmony Remote] INFO - shutdown [29/10/2022, 09:29:32] [Homebridge UI] Homebridge restart request received

Disabling the plugin eliminated the problem. (But I would like to start using it again!)

captainalvarez commented 2 years ago

Having the same issue

ohmantics commented 2 years ago

It's broken for everybody. Coway changed their authentication response. Logging in via the iOS app asks you to switch to a "new membership scheme."

Trying to sort out what that authentication looks like, but they've foolishly assumed that they can verify an email with a 5m countdown timer, which is fundamentally incompatible with a popular anti-spam technique called greylisting.

ohmantics commented 2 years ago

Looks like another plugin has already solved the change in authentication methods. Give https://github.com/RobertD502/home-assistant-iocare a try after migrating your account in the IOCare app.

davidpesetsky commented 2 years ago

Looks like another plugin has already solved the change in authentication methods. Give https://github.com/RobertD502/home-assistant-iocare a try after migrating your account in the IOCare app.

Thanks — but this looks like it's a plugin for something called Home Assistant. Is there a version for HomeBridge or a way to install a Home Assistant plugin so it works under HomeBridge?

ohmantics commented 2 years ago

For Homebridge, the updated authentication method will have to be translated from Python to TypeScript.

davidpesetsky commented 2 years ago

Well above my paygrade, unfortunately.

ohmantics commented 2 years ago

I'm looking at it, but I'm not much of a TypeScript developer.

chrisvanhorn commented 2 years ago

Same issue here. Really a bummer! Hoping someone smarter than me can fix this.

dzeleski commented 2 years ago

So it appears as said above the auth mechanism has changed as well as the URIs.

Existing URIs: https://github.com/aschzero/homebridge-airmega/blob/master/lib/Config.ts#L10-L18

Changes made for the URIs in the py lib above: https://github.com/RobertD502/cowayaio/commit/05fd749d9de0d09d7d569011d2f9e8e04d9d00a5

Changes to the auth method from the py lib above: https://github.com/RobertD502/cowayaio/commit/1be2cbee43d215d3e85c4af522acf1583f3f46f7

py client: https://github.com/RobertD502/cowayaio/blob/master/cowayaio/coway_client.py#L21

Existing ts client: https://github.com/aschzero/homebridge-airmega/blob/master/lib/Authenticator.ts#L57-L82

Should be somewhat simple to re implement this in typescript, although im a python dev so I might be speaking out of ignorance. Ill see if I can get a rough POC working over the next few days. If someone happens to stumble across this before I get to it at least the python answer is easily found.

dzeleski commented 2 years ago

In case this helps anyone: https://code.visualstudio.com/docs/languages/typescript

https://www.reddit.com/r/homebridge/comments/puve2v/live_debugging_using_vscode/

ohmantics commented 2 years ago

I've pushed a pull request here: https://github.com/mroth/homebridge-airmega/pull/2

Matthew's fork has a bunch of clean-up changes that looked like a better place to base this work, but I'm hitting the limits of my experience with these languages/tools. There may be some more changes to how tokens are refreshed, but I've gotten the new authentication working and now it's failing in relatively boring parts of the code. If Matthew doesn't reply, any additional eyes are most welcome.

ohmantics commented 1 year ago

As none of the prior contributors to this plugin have responded, I've gone ahead and published my changes on npm as @ohmantics/homebridge-airmega at version 3.3.0.

Many thanks to @RobertD502 for his work on the new authentication scheme and @mroth for his work on cleaning up the plugin structure.

chrisvanhorn commented 1 year ago

As none of the prior contributors to this plugin have responded, I've gone ahead and published my changes on npm as @ohmantics/homebridge-airmega at version 3.3.0.

Many thanks to @RobertD502 for his work on the new authentication scheme and @mroth for his work on cleaning up the plugin structure.

You are a god. Installed and working great over here!

davidpesetsky commented 1 year ago

Fantastic — working perfectly here too. Thank you so much!

RobertD502 commented 1 year ago

@ohmantics I'm glad to hear Cowayaio is helping other projects aside from the Home Assistant integration.

Regarding token refreshes: Your guess is as good as mine as to when a token expires since none of this information is returned in the response. However, I do know for sure that if a token has expired the response header will contain a error_code key with CWIG0304COWAYLgnE as the error. There doesn't seem to be a specific token refresh endpoint, so, I handle those situations with a fresh login.

vponnusamy commented 1 year ago

As none of the prior contributors to this plugin have responded, I've gone ahead and published my changes on npm as @ohmantics/homebridge-airmega at version 3.3.0.

Many thanks to @RobertD502 for his work on the new authentication scheme and @mroth for his work on cleaning up the plugin structure.

Just stumbled on this...this was a minor nuisance in my homebridge, but glad to have it cleaned up now. Thanks!