diff --git a/bimmer_connected/api/authentication.py b/bimmer_connected/api/authentication.py index 7652e523..bab6415f 100644 --- a/bimmer_connected/api/authentication.py +++ b/bimmer_connected/api/authentication.py @@ -14,7 +14,7 @@ from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey import RSA -from bimmer_connected.api.regions import Regions, get_app_version, get_ocp_apim_key, get_server_url +from bimmer_connected.api.regions import Regions, get_app_version, get_ocp_apim_key, get_server_url, get_user_agent from bimmer_connected.api.utils import ( create_s256_code_challenge, generate_cn_nonce, @@ -31,7 +31,6 @@ AUTH_CHINA_TOKEN_URL, HTTPX_TIMEOUT, OAUTH_CONFIG_URL, - USER_AGENT, X_USER_AGENT, ) from bimmer_connected.models import MyBMWAPIError @@ -358,7 +357,7 @@ def __init__(self, *args, **kwargs): region = kwargs.pop("region") kwargs["base_url"] = get_server_url(region) kwargs["headers"] = { - "user-agent": USER_AGENT, + "user-agent": get_user_agent(region), "x-user-agent": X_USER_AGENT.format(brand="bmw", app_version=get_app_version(region), region=region.value), } diff --git a/bimmer_connected/api/client.py b/bimmer_connected/api/client.py index 14b294c7..30d2d211 100644 --- a/bimmer_connected/api/client.py +++ b/bimmer_connected/api/client.py @@ -8,9 +8,9 @@ import httpx from bimmer_connected.api.authentication import MyBMWAuthentication -from bimmer_connected.api.regions import get_app_version, get_server_url +from bimmer_connected.api.regions import get_app_version, get_server_url, get_user_agent from bimmer_connected.api.utils import anonymize_response, get_correlation_id, handle_httpstatuserror -from bimmer_connected.const import HTTPX_TIMEOUT, USER_AGENT, X_USER_AGENT, CarBrands +from bimmer_connected.const import HTTPX_TIMEOUT, X_USER_AGENT, CarBrands from bimmer_connected.models import AnonymizedResponse, GPSPosition _LOGGER = logging.getLogger(__name__) @@ -82,7 +82,7 @@ def generate_default_header(self, brand: Optional[CarBrands] = None) -> Dict[str return { "accept": "application/json", "accept-language": "en", - "user-agent": USER_AGENT, + "user-agent": get_user_agent(self.config.authentication.region), "x-user-agent": X_USER_AGENT.format( brand=(brand or CarBrands.BMW).value, app_version=get_app_version(self.config.authentication.region), diff --git a/bimmer_connected/api/regions.py b/bimmer_connected/api/regions.py index 82425548..4fb6c6c4 100644 --- a/bimmer_connected/api/regions.py +++ b/bimmer_connected/api/regions.py @@ -2,7 +2,7 @@ from base64 import b64decode from typing import List -from bimmer_connected.const import APP_VERSIONS, OCP_APIM_KEYS, SERVER_URLS_MYBMW, Regions +from bimmer_connected.const import APP_VERSIONS, OCP_APIM_KEYS, SERVER_URLS_MYBMW, USER_AGENTS, Regions def valid_regions() -> List[str]: @@ -26,6 +26,11 @@ def get_server_url(region: Regions) -> str: return f"https://{SERVER_URLS_MYBMW[region]}" +def get_user_agent(region: Regions) -> str: + """Get the Dart user agent for the region.""" + return USER_AGENTS[region] + + def get_app_version(region: Regions) -> str: """Get the app version & build number for the region.""" return APP_VERSIONS[region] diff --git a/bimmer_connected/const.py b/bimmer_connected/const.py index eca2d17b..ad2a8985 100644 --- a/bimmer_connected/const.py +++ b/bimmer_connected/const.py @@ -37,14 +37,18 @@ class Regions(str, Enum): } APP_VERSIONS = { - Regions.NORTH_AMERICA: "3.3.1(22418)", - Regions.REST_OF_WORLD: "3.3.1(22418)", + Regions.NORTH_AMERICA: "3.9.0(27760)", + Regions.REST_OF_WORLD: "3.9.0(27760)", Regions.CHINA: "3.6.1(23634)", } HTTPX_TIMEOUT = 30.0 -USER_AGENT = "Dart/2.18 (dart:io)" +USER_AGENTS = { + Regions.NORTH_AMERICA: "Dart/2.19 (dart:io)", + Regions.REST_OF_WORLD: "Dart/2.19 (dart:io)", + Regions.CHINA: "Dart/2.18 (dart:io)", +} X_USER_AGENT = "android(TQ2A.230405.003.B2);{brand};{app_version};{region}"