palazzem / econnect-python

API adapter used to control programmatically an Elmo alarm system
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

Handle token expiration #64

Closed palazzem closed 3 years ago

palazzem commented 3 years ago

Overview

When a new session is created, the stored session_id is a short-lived token with 10 minutes expiration (at the time of writing). With this change, after the token is retrieved via client.auth() API call but it's used later when it's not valid anymore, the @required_session decorator detects 401 HTTPError exceptions and translates these in InvalidToken exceptions.

The caller should catch the exception and repeat the authentication via client.auth().

Example

try:
    client.arm()
except InvalidToken:
    client.auth("test", "test")
palazzem commented 3 years ago

This is a draft and needs a bit of experimentation before merging.

palazzem commented 3 years ago

Removing the expiration part, but keeping other exceptions.