Closed Salamek closed 3 years ago
@scop Hi, can you check this out? if you have any comments to this changes...
Also what do you think is better? continue using AuthorizedConnection or use UserSession as in example?
I think the ability to swap between authorized/unauthorized accesses using the same connection/session is such a rare one, so I probably wouldn't make expose it to keep the API clean.
I'd also look into combining AuthorizedConnection and Connection to just one; if the URL contains credentials (or if credentials are passed in as separate optional arguments), do the equivalent of UserSession under the hood, otherwise not.
So essentially I think what I'd like to see would be your first example above, but just Connection instead of AuthorizedConnection.
BTW if enforce_authorized_connection is going away, we'll need some changes to the Home Assistant integration. We're currently explicitly invoking it to overcome issues with login required exceptions apparently because of our long lived sessions timing out, see
Yep, it's kind of ugly, but has to my knowledge solved the issue at hand completely.
Anyway I think this is a good change in general, with my suggested changes or not. I personally likely won't have immediate use for it though, as I'm using huawei-lte-api only with the Home Assistant integration in which at least for the time being the session kind of never ends, except in the unusual cases that Home Assistant is being shut down, or the Huawei LTE integration removed/restarted.
Refactor code to use context manager to correctly close requests.Session and correctly logout User, this code should not bring any BC break except login_on_demand deprecation.
So code can be now used in this way:
or (drop that ugly cyclic import of User in AuthorizedConnection)
or original way + added close()