Fix china login for bmw_connected_drive (#93180)

* Bump bimmer_connected to 0.13.5

* Fix snapshots after dependency bump

* Load gcid from config entry if available

* Add tests

---------

Co-authored-by: rikroe <rikroe@users.noreply.github.com>
This commit is contained in:
rikroe 2023-05-17 02:03:01 +02:00 committed by GitHub
parent 210c309770
commit defc23cc7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 7 deletions

View file

@ -16,7 +16,7 @@ from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from . import DOMAIN
from .const import CONF_ALLOWED_REGIONS, CONF_READ_ONLY, CONF_REFRESH_TOKEN
from .const import CONF_ALLOWED_REGIONS, CONF_GCID, CONF_READ_ONLY, CONF_REFRESH_TOKEN
DATA_SCHEMA = vol.Schema(
{
@ -51,6 +51,8 @@ async def validate_input(
retval = {"title": f"{data[CONF_USERNAME]}{data.get(CONF_SOURCE, '')}"}
if auth.refresh_token:
retval[CONF_REFRESH_TOKEN] = auth.refresh_token
if auth.gcid:
retval[CONF_GCID] = auth.gcid
return retval
@ -80,6 +82,7 @@ class BMWConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
entry_data = {
**user_input,
CONF_REFRESH_TOKEN: info.get(CONF_REFRESH_TOKEN),
CONF_GCID: info.get(CONF_GCID),
}
except CannotConnect:
errors["base"] = "cannot_connect"

View file

@ -11,6 +11,7 @@ CONF_ALLOWED_REGIONS = ["china", "north_america", "rest_of_world"]
CONF_READ_ONLY = "read_only"
CONF_ACCOUNT = "account"
CONF_REFRESH_TOKEN = "refresh_token"
CONF_GCID = "gcid"
DATA_HASS_CONFIG = "hass_config"

View file

@ -15,7 +15,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import CONF_READ_ONLY, CONF_REFRESH_TOKEN, DOMAIN
from .const import CONF_GCID, CONF_READ_ONLY, CONF_REFRESH_TOKEN, DOMAIN
DEFAULT_SCAN_INTERVAL_SECONDS = 300
SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL_SECONDS)
@ -41,7 +41,10 @@ class BMWDataUpdateCoordinator(DataUpdateCoordinator[None]):
self._entry = entry
if CONF_REFRESH_TOKEN in entry.data:
self.account.set_refresh_token(entry.data[CONF_REFRESH_TOKEN])
self.account.set_refresh_token(
refresh_token=entry.data[CONF_REFRESH_TOKEN],
gcid=entry.data.get(CONF_GCID),
)
super().__init__(
hass,

View file

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/bmw_connected_drive",
"iot_class": "cloud_polling",
"loggers": ["bimmer_connected"],
"requirements": ["bimmer_connected==0.13.3"]
"requirements": ["bimmer_connected==0.13.5"]
}

View file

@ -431,7 +431,7 @@ beautifulsoup4==4.11.1
bellows==0.35.5
# homeassistant.components.bmw_connected_drive
bimmer_connected==0.13.3
bimmer_connected==0.13.5
# homeassistant.components.bizkaibus
bizkaibus==0.1.1

View file

@ -364,7 +364,7 @@ beautifulsoup4==4.11.1
bellows==0.35.5
# homeassistant.components.bmw_connected_drive
bimmer_connected==0.13.3
bimmer_connected==0.13.5
# homeassistant.components.bluetooth
bleak-retry-connector==3.0.2

View file

@ -13,6 +13,7 @@ import respx
from homeassistant import config_entries
from homeassistant.components.bmw_connected_drive.const import (
CONF_GCID,
CONF_READ_ONLY,
CONF_REFRESH_TOKEN,
DOMAIN as BMW_DOMAIN,
@ -33,6 +34,7 @@ FIXTURE_USER_INPUT = {
CONF_REGION: "rest_of_world",
}
FIXTURE_REFRESH_TOKEN = "SOME_REFRESH_TOKEN"
FIXTURE_GCID = "SOME_GCID"
FIXTURE_CONFIG_ENTRY = {
"entry_id": "1",
@ -43,6 +45,7 @@ FIXTURE_CONFIG_ENTRY = {
CONF_PASSWORD: FIXTURE_USER_INPUT[CONF_PASSWORD],
CONF_REGION: FIXTURE_USER_INPUT[CONF_REGION],
CONF_REFRESH_TOKEN: FIXTURE_REFRESH_TOKEN,
CONF_GCID: FIXTURE_GCID,
},
"options": {CONF_READ_ONLY: False},
"source": config_entries.SOURCE_USER,

View file

@ -2357,6 +2357,7 @@
}),
]),
'info': dict({
'gcid': 'SOME_GCID',
'password': '**REDACTED**',
'refresh_token': '**REDACTED**',
'region': 'rest_of_world',
@ -3860,6 +3861,7 @@
}),
]),
'info': dict({
'gcid': 'SOME_GCID',
'password': '**REDACTED**',
'refresh_token': '**REDACTED**',
'region': 'rest_of_world',
@ -4692,6 +4694,7 @@
}),
]),
'info': dict({
'gcid': 'SOME_GCID',
'password': '**REDACTED**',
'refresh_token': '**REDACTED**',
'region': 'rest_of_world',

View file

@ -15,7 +15,12 @@ from homeassistant.components.bmw_connected_drive.const import (
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from . import FIXTURE_CONFIG_ENTRY, FIXTURE_REFRESH_TOKEN, FIXTURE_USER_INPUT
from . import (
FIXTURE_CONFIG_ENTRY,
FIXTURE_GCID,
FIXTURE_REFRESH_TOKEN,
FIXTURE_USER_INPUT,
)
from tests.common import MockConfigEntry
@ -26,6 +31,7 @@ FIXTURE_IMPORT_ENTRY = {**FIXTURE_USER_INPUT, CONF_REFRESH_TOKEN: None}
def login_sideeffect(self: MyBMWAuthentication):
"""Mock logging in and setting a refresh token."""
self.refresh_token = FIXTURE_REFRESH_TOKEN
self.gcid = FIXTURE_GCID
async def test_show_form(hass: HomeAssistant) -> None: