planbnet / livisi_unofficial

Unofficial fork of the home assistant livisi integration without dependencies on the abandoned aiolivisi lib
Apache License 2.0
36 stars 5 forks source link

fix server disconnected error handling #21

Closed DanielHabenicht closed 1 year ago

DanielHabenicht commented 1 year ago

fix #19

Sorry for the closing and opening again, but I needed to test on my main branch...

planbnet commented 1 year ago

Merging this would break reauthentication (at least on v2 shcs). Maybe checking the error code in both code paths will solve both problems?

DanielHabenicht commented 1 year ago

Do you have a V2? In my mind this should also work in V2 (but with one request more), but I can't test it.

If not we can check it on both code paths.

planbnet commented 1 year ago

If you're on this, would you also add a comment that explains the workaround?

planbnet commented 1 year ago

Yes I have a v2. This code works, but only for 24 hours. Then the token is expired and the error code is sent (which does not throw an exception). Checking the error code in your case is only done on the second request inside the except block, so the new token will never be refreshed. I don't know if this is the case only for v2 devices as I don't know when the v1s will drop the connection.

DanielHabenicht commented 1 year ago

got you. I updated the code. It's working on V1. Although I now get a fair amount of warnings about the ErrorCodeException and Server disconnected, but it could also be that I now enabled a higher logging level...

planbnet commented 1 year ago

Thanks. I'm merging this but I have to wait a few days until I can test it in my real setup because I made some bigger changes in 1.3.0 that I need to check for stability first.