bwp91 / homebridge-ewelink

Homebridge plugin to integrate eWeLink devices into HomeKit.
MIT License
384 stars 126 forks source link

Suggestions for handling 406 Error #488

Closed Jardaliao closed 12 months ago

Jardaliao commented 1 year ago

Hey, I notice that the plugin homebridge-ewelink does nothing just logs warning when receiving 406 error from WebSocket. In fact, 406 will be responded only if the at is invalid, expired mostly. If so, server close the web socket connection immediately, which leads to that client is caught in a loop of opening a connection, initiating a handshake, and connection being closed.

Thus, my suggestion is that client re-obtains at from login interface and re-establish the web socket connection, then do handshake.

bwp91 commented 1 year ago

Hi @Jardaliao

406 warning also appears when a user who is using the same ewelink account for both the plugin and the ewelink app - logs back into the ewelink app. i know that i suggest with this plugin to use separate accounts for the ewelink app and this plugin. but i am also hesitant to disturb any genuine login into the ewelink app since with your suggestion:

scenario: a user who uses the same credentials for the plugin and the ewelink app has homebridge running and hardly ever uses the ewelink app. They then log into the ewelink app one day, which makes the plugin suddenly start throwing 406 errors in the websocket connection. If I were to implement re-establishing the websocket connection, then in this case the user would be immediately logged out of the ewelink app - with no explanation there as to why.

bwp91 commented 1 year ago

and by the way i think this is a very reasonable suggestion - i am just hesitant about disrupting any user login into the ewelink app.

Jardaliao commented 12 months ago

Hi @bwp91

i am just hesitant about disrupting any user login into the ewelink app.

I totally agree with your point of view, my previous suggestion was inappropriate.

In fact, the server is bearing tens of millions of failed userOnline requests every day, which has brought us some additional costs. From feature analysis, most of the APIKEY uses this plugin.

So, I suggest adding processing for 406 in the onClose callback, such as not reconnecting after receiving 406, but giving the user a prompt. Because after receiving 406, using the same at to go online will definitely not succeed.

We will also make corresponding adjustments on the server to address this phenomenon in the future.

bwp91 commented 12 months ago

Hi @Jardaliao

In fact, the server is bearing tens of millions of failed userOnline requests every day, which has brought us some additional costs. From feature analysis, most of the APIKEY uses this plugin.

Okay will try and sort this as soon as I can 😁

bwp91 commented 12 months ago

thanks for bringing this to my attention

bwp91 commented 12 months ago

the quickest immediate solution @Jardaliao would be for ewelink to allow a user to login to both the ewelink app and a second place at the same time 💪

Jardaliao commented 12 months ago

@bwp91 Thank you for your suggestion . I will present it in the next discussion.

Jardaliao commented 12 months ago

We originally planned to do multiple sign-on, so that the ewelink app could apply for multiple at at the same time, but it has not been included in the schedule yet. In the coming weeks, I will make some adjustments on the server to cope with frequent userOnline failure requests, which are not only from users using this plugin.

bwp91 commented 11 months ago

Am i incorrect or is login in different places supported now with the same account?

bwp91 commented 11 months ago

take that back, ewelink app just took a long time to log me out

bwp91 commented 11 months ago

multiple logins for the same account would be easiest. i can make changes to the plugin, but i cannot force any older users to update

Jardaliao commented 11 months ago

multiple logins for the same account would be easiest. i can make changes to the plugin, but i cannot force any older users to update

Multiple logins is on the way.

bwp91 commented 11 months ago

oh it's like christmas is coming early!

Btw just for some feedback in general I could have probably pushed some more users towards using their own 'free developer' app key if it werent for:

Anyway - multiple logins is super duper ✅ looking forward to this