Skip to content

Commit

Permalink
Add Interface required for China login (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe authored May 16, 2023
1 parent e9f799f commit 8b407b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 8 additions & 2 deletions bimmer_connected/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ def set_observer_position(self, latitude: float, longitude: float) -> None:
"""Set the position of the observer for all vehicles."""
self.config.observer_position = GPSPosition(latitude=latitude, longitude=longitude)

def set_refresh_token(self, refresh_token: str) -> None:
"""Overwrite the current value of the MyBMW refresh token."""
def set_refresh_token(self, refresh_token: str, gcid: Optional[str] = None) -> None:
"""Overwrite the current value of the MyBMW refresh token and GCID (if available)."""
self.config.authentication.refresh_token = refresh_token
self.config.authentication.gcid = gcid

def set_use_metric_units(self, use_metric_units: bool) -> None:
"""Change between using metric units (km, l) if True or imperial units (mi, gal) if False."""
Expand Down Expand Up @@ -194,6 +195,11 @@ def refresh_token(self) -> Optional[str]:
"""Returns the current refresh_token."""
return self.config.authentication.refresh_token

@property
def gcid(self) -> Optional[str]:
"""Returns the current GCID."""
return self.config.authentication.gcid


@deprecated("MyBMWAccount")
class ConnectedDriveAccount(MyBMWAccount):
Expand Down
12 changes: 11 additions & 1 deletion test/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,24 @@ async def test_deprecated_account(caplog):
@account_mock()
@pytest.mark.asyncio
async def test_refresh_token_getset():
"""Test getting/setting the refresh_token."""
"""Test getting/setting the refresh_token and gcid."""
account = MyBMWAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION)
assert account.refresh_token is None
await account.get_vehicles()
assert account.refresh_token == "another_token_string"
assert account.gcid is None

account.set_refresh_token("new_refresh_token")
assert account.refresh_token == "new_refresh_token"
assert account.gcid is None

account = MyBMWAccount(TEST_USERNAME, TEST_PASSWORD, get_region_from_name("china"))
account.set_refresh_token("new_refresh_token", "dummy_gcid")
assert account.refresh_token == "new_refresh_token"
assert account.gcid == "dummy_gcid"
await account.get_vehicles()
assert account.refresh_token == "another_token_string"
assert account.gcid == "DUMMY"


@pytest.mark.asyncio
Expand Down

0 comments on commit 8b407b4

Please sign in to comment.