finish06 / pyunifi

https://unifi-sdn.ubnt.com/
MIT License
223 stars 100 forks source link

Implement retry_login as a decorator to handle token expires #4

Closed sdague closed 7 years ago

sdague commented 7 years ago

This demonstrates using retry_login in the even that we get an error thrown during connectivity to ensure that we can roll over a unifi controller upgrade.

(This isn't tested, but is a quick sketch that "should" work)

finish06 commented 7 years ago

@sdague Thanks! I was just reading about decorators in Python. Then I saw you already started the "sketch". I will work on this and see if I can get it set up correctly. This definitely seems like a better alternative to my time.sleep(xx) because like you said, sleeping doesn't go well with async. I will continue to work on this approach.

sdague commented 7 years ago

Awesome. Yeh, I mostly wanted to provide a starting point so that you wouldn't need to invent from whole cloth. Take this and modify it, or just use it for learning, however you want to run with it.

finish06 commented 7 years ago

@sdague Please check out this implementation when time permits. I would definitely appreciate your feedback. I decided to raise a class specific 'APIError' to the calling program, e.g. home-assistant, therefore letting the originating program handle the error as it deems necessary.