Skip to content

Commit

Permalink
Refactor auth flow to httpx.Auth (#436)
Browse files Browse the repository at this point in the history
* Change to custom httpx.Auth
* Increase HTTP timeout to 30s
* Add correlation & session id
* Add debug handler for HTTPStatusError
* Clear old refresh token on failure
* Don't check expiration date at all
* Handle HTTP 429 during login
  • Loading branch information
rikroe authored May 22, 2022
1 parent 0b38aba commit 5303fa5
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 208 deletions.
20 changes: 7 additions & 13 deletions bimmer_connected/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Access to a MyBMW account and all vehicles therein."""

import asyncio
import datetime
import logging
import pathlib
Expand All @@ -20,7 +19,6 @@
VALID_UNTIL_OFFSET = datetime.timedelta(seconds=10)

_LOGGER = logging.getLogger(__name__)
# lock = asyncio.Lock()


@dataclass
Expand Down Expand Up @@ -64,18 +62,14 @@ async def get_vehicles(self) -> None:
"appDateTime": int(datetime.datetime.now().timestamp() * 1000),
"tireGuardMode": "ENABLED",
}
vehicles_tasks: List[asyncio.Task] = []
for brand in CarBrands:
vehicles_tasks.append(
asyncio.ensure_future(
client.get(
VEHICLES_URL,
params=vehicles_request_params,
headers=client.generate_default_header(brand),
)
)
vehicles_responses: List[httpx.Response] = [
await client.get(
VEHICLES_URL,
params=vehicles_request_params,
headers=client.generate_default_header(brand),
)
vehicles_responses: List[httpx.Response] = await asyncio.gather(*vehicles_tasks)
for brand in CarBrands
]

for response in vehicles_responses:
for vehicle_dict in response.json():
Expand Down
Loading

0 comments on commit 5303fa5

Please sign in to comment.