Source code for bimmer_connected.api.regions

"""Get the right url for the different countries."""
from base64 import b64decode
from typing import Dict, List

from bimmer_connected.const import AES_KEYS, APP_VERSIONS, OCP_APIM_KEYS, SERVER_URLS_MYBMW, Regions

[docs]def valid_regions() -> List[str]: """Get list of valid regions as strings.""" return [ for region in Regions]
[docs]def get_region_from_name(name: str) -> Regions: """Get a region for a string. This function is not case-sensitive. """ for region in Regions: if name.lower() == return region raise ValueError(f"Unknown region {name}. Valid regions are: {','.join(valid_regions())}")
[docs]def get_server_url(region: Regions) -> str: """Get the url of the server for the region.""" return f"https://{SERVER_URLS_MYBMW[region]}"
[docs]def get_app_version(region: Regions) -> str: """Get the app version & build number for the region.""" return APP_VERSIONS[region]
[docs]def get_ocp_apim_key(region: Regions) -> str: """Get the authorization for OAuth settings.""" return b64decode(OCP_APIM_KEYS[region]).decode()
[docs]def get_aes_keys(region: Regions) -> Dict[str, bytes]: """Get the keys for login nonce.""" return {k: b64decode(v) for k, v in AES_KEYS[region].items()}