Skip to content

Commit

Permalink
Add support for Python 3.12 (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Aug 9, 2023
1 parent b27e299 commit b036c25
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
- name: Install dependencies
run: |
Expand Down Expand Up @@ -71,7 +72,7 @@ jobs:
- name: Test with black
run: |
black --check bimmer_connected
mypy:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 7 additions & 2 deletions bimmer_connected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
This library is not affiliated with or endorsed by BMW Group.
"""

import pkg_resources # part of setuptools
import sys

__version__ = pkg_resources.get_distribution("bimmer_connected").version
if sys.version_info >= (3, 8):
from importlib.metadata import version
else:
from importlib_metadata import version

__version__ = version("bimmer_connected")
8 changes: 4 additions & 4 deletions bimmer_connected/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async def _login_row_na(self):
code = response.next_request.url.params["code"]

# With code, get token
current_utc_time = datetime.datetime.utcnow()
current_utc_time = datetime.datetime.now(tz=datetime.timezone.utc)
response = await client.post(
oauth_settings["tokenEndpoint"],
data={
Expand Down Expand Up @@ -237,7 +237,7 @@ async def _refresh_token_row_na(self):
oauth_settings = r_oauth_settings.json()

# With code, get token
current_utc_time = datetime.datetime.utcnow()
current_utc_time = datetime.datetime.now(tz=datetime.timezone.utc)
response = await client.post(
oauth_settings["tokenEndpoint"],
data={
Expand Down Expand Up @@ -314,7 +314,7 @@ async def _login_china(self):

return {
"access_token": response_json["access_token"],
"expires_at": datetime.datetime.utcfromtimestamp(decoded_token["exp"]),
"expires_at": datetime.datetime.fromtimestamp(decoded_token["exp"], tz=datetime.timezone.utc),
"refresh_token": response_json["refresh_token"],
"gcid": response_json["gcid"],
}
Expand All @@ -324,7 +324,7 @@ async def _refresh_token_china(self):
async with MyBMWLoginClient(region=self.region) as client:
_LOGGER.debug("Authenticating with refresh token for China.")

current_utc_time = datetime.datetime.utcnow()
current_utc_time = datetime.datetime.now(tz=datetime.timezone.utc)

# Try logging in using refresh_token
response = await client.post(
Expand Down
3 changes: 2 additions & 1 deletion bimmer_connected/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def generate_cn_nonce(username: str) -> str:
possible_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
random_str = "".join(random.choice(possible_chars) for _ in range(8))

phone_text = f"{username}&{datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')}&{random_str}"
time_str = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%a, %d %b %Y %H:%M:%S GMT")
phone_text = f"{username}&{time_str}&{random_str}"

cipher_aes = AES.new(key.encode(), AES.MODE_CBC, iv.encode())

Expand Down
3 changes: 1 addition & 2 deletions bimmer_connected/vehicle/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def set_remote_service_position(self, remote_service_dict: Dict):
_LOGGER.error("Error retrieving vehicle position. %s: %s", error["title"], error["description"])
else:
pos = remote_service_dict["positionData"]["position"]
pos["timestamp"] = datetime.datetime.utcnow()
pos["timestamp"] = pos["timestamp"].replace(tzinfo=datetime.timezone.utc)
pos["timestamp"] = datetime.datetime.now(tz=datetime.timezone.utc)

self.remote_service_position = pos

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
httpx
pycryptodome>=3.4
pyjwt>=2.1.0
pyjwt>=2.1.0
importlib-metadata;python_version<"3.8"
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifier =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
keywords =
BMW
Connected Drive
Expand All @@ -35,6 +36,6 @@ console_scripts =
bimmerconnected = bimmer_connected.cli:main

[options.package_data]
bimmer_connected =
bimmer_connected =
py.typed
bimmer_connected/tests/responses/*
bimmer_connected/tests/responses/*
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"httpx",
"pycryptodome>=3.4",
"pyjwt>=2.1.0",
"importlib-metadata;python_version<'3.8'",
],
)

0 comments on commit b036c25

Please sign in to comment.