diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37da7f0e..12704127 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ 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 @@ -20,6 +20,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + allow-prereleases: true cache: pip - name: Install dependencies run: | @@ -71,7 +72,7 @@ jobs: - name: Test with black run: | black --check bimmer_connected - + mypy: runs-on: ubuntu-latest steps: diff --git a/bimmer_connected/__init__.py b/bimmer_connected/__init__.py index be6fcf2d..a42f0a31 100644 --- a/bimmer_connected/__init__.py +++ b/bimmer_connected/__init__.py @@ -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") diff --git a/bimmer_connected/api/authentication.py b/bimmer_connected/api/authentication.py index 1f763b10..94aa3fdb 100644 --- a/bimmer_connected/api/authentication.py +++ b/bimmer_connected/api/authentication.py @@ -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={ @@ -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={ @@ -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"], } @@ -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( diff --git a/bimmer_connected/api/utils.py b/bimmer_connected/api/utils.py index d00472bd..ea5de76b 100644 --- a/bimmer_connected/api/utils.py +++ b/bimmer_connected/api/utils.py @@ -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()) diff --git a/bimmer_connected/vehicle/location.py b/bimmer_connected/vehicle/location.py index 57d17c21..521355cb 100644 --- a/bimmer_connected/vehicle/location.py +++ b/bimmer_connected/vehicle/location.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 2a7c91d6..0638d286 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ httpx pycryptodome>=3.4 -pyjwt>=2.1.0 \ No newline at end of file +pyjwt>=2.1.0 +importlib-metadata;python_version<"3.8" diff --git a/setup.cfg b/setup.cfg index 5be90d65..3f928de3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -35,6 +36,6 @@ console_scripts = bimmerconnected = bimmer_connected.cli:main [options.package_data] -bimmer_connected = +bimmer_connected = py.typed - bimmer_connected/tests/responses/* \ No newline at end of file + bimmer_connected/tests/responses/* diff --git a/setup.py b/setup.py index 5f2e7a1b..73d66ab0 100644 --- a/setup.py +++ b/setup.py @@ -8,5 +8,6 @@ "httpx", "pycryptodome>=3.4", "pyjwt>=2.1.0", + "importlib-metadata;python_version<'3.8'", ], )