Danielhiversen / home_assistant_airthings_cloud

Airthings cloud
Apache License 2.0
32 stars 6 forks source link

Suddenly Unauthorized #14

Closed allanedk closed 3 years ago

allanedk commented 3 years ago

Thank you for sharing your code!

I installed the component yesterday and it worked fine. I see in the logs, that a couple of hours later the the calls to to Airthings server started to fail:

[custom_components.airthings_cloud.sensor] Error connecting to Airthings, resp code: 401 Unauthorized

Maybe there's a max number of allowed calls to the Airthings server? However I am able to login to the Airthings dashboard using a browser (from the same IP + user credentials).

cfaelled commented 3 years ago

Im seeing the same problem. The connection works again after a HA reboot.

thillerup commented 3 years ago

I also see the same problem, it runs for 2-3 hours and then requires a reboot to get access again.

allanedk commented 3 years ago

I restarted and it worked again. However, after exactly 3 hours it stopped working and I seethe "Unauthorized" entries in the log again.

avocadosalsa commented 3 years ago

I just checked and the tokens returned by the API contain an expires_in value. Mine was 10800 seconds which would be 3 hours. I think the code needs modified such that when the update_data method gets a 401 response it needs to set self.access_token = None then await self.get_user_credentials() to obtain a new authorization token before trying the call again.

allanedk commented 3 years ago

Sounds good. Thank you - looking forward to try it.

Danielhiversen commented 3 years ago

Fixed by https://github.com/Danielhiversen/home_assistant_airthings_cloud/pull/16

allanedk commented 3 years ago

This has been working like a charm for the past couple of days.

Thanks a lot!