derekprior / homebridge-schluter-thermostat

A homebridge plugin to control Schluter thermostats
MIT License
9 stars 2 forks source link

Reuse Schluter session ids when possible #9

Closed derekprior closed 2 years ago

derekprior commented 2 years ago

Previously, we were logging in on every single request to the API, even though session ids seem to be valid for somewhere between 30-60 minutes. We now store the most recent session id in state and use an interceptor to append it to all requests that are not sign in requests.

I also added a response interceptor that clears the stored session id when we encounter a 401 unauthorized error. This doesn't go as far as I would like, as ideally we'd then retry the request so it could pick up a new session id, but when I tried that, I was getting weird behavior. I'll leave it for later.

Finally, I also added some error handling to the signIn function to handle cases where the endpoint returns 200 Ok but the sign in request actually fails.

closes #5