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:
parent
210c309770
commit
defc23cc7c
9 changed files with 26 additions and 7 deletions
|
@ -16,7 +16,7 @@ from homeassistant.core import callback
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from . import DOMAIN
|
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(
|
DATA_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,8 @@ async def validate_input(
|
||||||
retval = {"title": f"{data[CONF_USERNAME]}{data.get(CONF_SOURCE, '')}"}
|
retval = {"title": f"{data[CONF_USERNAME]}{data.get(CONF_SOURCE, '')}"}
|
||||||
if auth.refresh_token:
|
if auth.refresh_token:
|
||||||
retval[CONF_REFRESH_TOKEN] = auth.refresh_token
|
retval[CONF_REFRESH_TOKEN] = auth.refresh_token
|
||||||
|
if auth.gcid:
|
||||||
|
retval[CONF_GCID] = auth.gcid
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +82,7 @@ class BMWConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
entry_data = {
|
entry_data = {
|
||||||
**user_input,
|
**user_input,
|
||||||
CONF_REFRESH_TOKEN: info.get(CONF_REFRESH_TOKEN),
|
CONF_REFRESH_TOKEN: info.get(CONF_REFRESH_TOKEN),
|
||||||
|
CONF_GCID: info.get(CONF_GCID),
|
||||||
}
|
}
|
||||||
except CannotConnect:
|
except CannotConnect:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
|
|
@ -11,6 +11,7 @@ CONF_ALLOWED_REGIONS = ["china", "north_america", "rest_of_world"]
|
||||||
CONF_READ_ONLY = "read_only"
|
CONF_READ_ONLY = "read_only"
|
||||||
CONF_ACCOUNT = "account"
|
CONF_ACCOUNT = "account"
|
||||||
CONF_REFRESH_TOKEN = "refresh_token"
|
CONF_REFRESH_TOKEN = "refresh_token"
|
||||||
|
CONF_GCID = "gcid"
|
||||||
|
|
||||||
DATA_HASS_CONFIG = "hass_config"
|
DATA_HASS_CONFIG = "hass_config"
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
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
|
DEFAULT_SCAN_INTERVAL_SECONDS = 300
|
||||||
SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL_SECONDS)
|
SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL_SECONDS)
|
||||||
|
@ -41,7 +41,10 @@ class BMWDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||||
self._entry = entry
|
self._entry = entry
|
||||||
|
|
||||||
if CONF_REFRESH_TOKEN in entry.data:
|
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__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"documentation": "https://www.home-assistant.io/integrations/bmw_connected_drive",
|
"documentation": "https://www.home-assistant.io/integrations/bmw_connected_drive",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["bimmer_connected"],
|
"loggers": ["bimmer_connected"],
|
||||||
"requirements": ["bimmer_connected==0.13.3"]
|
"requirements": ["bimmer_connected==0.13.5"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,7 +431,7 @@ beautifulsoup4==4.11.1
|
||||||
bellows==0.35.5
|
bellows==0.35.5
|
||||||
|
|
||||||
# homeassistant.components.bmw_connected_drive
|
# homeassistant.components.bmw_connected_drive
|
||||||
bimmer_connected==0.13.3
|
bimmer_connected==0.13.5
|
||||||
|
|
||||||
# homeassistant.components.bizkaibus
|
# homeassistant.components.bizkaibus
|
||||||
bizkaibus==0.1.1
|
bizkaibus==0.1.1
|
||||||
|
|
|
@ -364,7 +364,7 @@ beautifulsoup4==4.11.1
|
||||||
bellows==0.35.5
|
bellows==0.35.5
|
||||||
|
|
||||||
# homeassistant.components.bmw_connected_drive
|
# homeassistant.components.bmw_connected_drive
|
||||||
bimmer_connected==0.13.3
|
bimmer_connected==0.13.5
|
||||||
|
|
||||||
# homeassistant.components.bluetooth
|
# homeassistant.components.bluetooth
|
||||||
bleak-retry-connector==3.0.2
|
bleak-retry-connector==3.0.2
|
||||||
|
|
|
@ -13,6 +13,7 @@ import respx
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.bmw_connected_drive.const import (
|
from homeassistant.components.bmw_connected_drive.const import (
|
||||||
|
CONF_GCID,
|
||||||
CONF_READ_ONLY,
|
CONF_READ_ONLY,
|
||||||
CONF_REFRESH_TOKEN,
|
CONF_REFRESH_TOKEN,
|
||||||
DOMAIN as BMW_DOMAIN,
|
DOMAIN as BMW_DOMAIN,
|
||||||
|
@ -33,6 +34,7 @@ FIXTURE_USER_INPUT = {
|
||||||
CONF_REGION: "rest_of_world",
|
CONF_REGION: "rest_of_world",
|
||||||
}
|
}
|
||||||
FIXTURE_REFRESH_TOKEN = "SOME_REFRESH_TOKEN"
|
FIXTURE_REFRESH_TOKEN = "SOME_REFRESH_TOKEN"
|
||||||
|
FIXTURE_GCID = "SOME_GCID"
|
||||||
|
|
||||||
FIXTURE_CONFIG_ENTRY = {
|
FIXTURE_CONFIG_ENTRY = {
|
||||||
"entry_id": "1",
|
"entry_id": "1",
|
||||||
|
@ -43,6 +45,7 @@ FIXTURE_CONFIG_ENTRY = {
|
||||||
CONF_PASSWORD: FIXTURE_USER_INPUT[CONF_PASSWORD],
|
CONF_PASSWORD: FIXTURE_USER_INPUT[CONF_PASSWORD],
|
||||||
CONF_REGION: FIXTURE_USER_INPUT[CONF_REGION],
|
CONF_REGION: FIXTURE_USER_INPUT[CONF_REGION],
|
||||||
CONF_REFRESH_TOKEN: FIXTURE_REFRESH_TOKEN,
|
CONF_REFRESH_TOKEN: FIXTURE_REFRESH_TOKEN,
|
||||||
|
CONF_GCID: FIXTURE_GCID,
|
||||||
},
|
},
|
||||||
"options": {CONF_READ_ONLY: False},
|
"options": {CONF_READ_ONLY: False},
|
||||||
"source": config_entries.SOURCE_USER,
|
"source": config_entries.SOURCE_USER,
|
||||||
|
|
|
@ -2357,6 +2357,7 @@
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
'info': dict({
|
'info': dict({
|
||||||
|
'gcid': 'SOME_GCID',
|
||||||
'password': '**REDACTED**',
|
'password': '**REDACTED**',
|
||||||
'refresh_token': '**REDACTED**',
|
'refresh_token': '**REDACTED**',
|
||||||
'region': 'rest_of_world',
|
'region': 'rest_of_world',
|
||||||
|
@ -3860,6 +3861,7 @@
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
'info': dict({
|
'info': dict({
|
||||||
|
'gcid': 'SOME_GCID',
|
||||||
'password': '**REDACTED**',
|
'password': '**REDACTED**',
|
||||||
'refresh_token': '**REDACTED**',
|
'refresh_token': '**REDACTED**',
|
||||||
'region': 'rest_of_world',
|
'region': 'rest_of_world',
|
||||||
|
@ -4692,6 +4694,7 @@
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
'info': dict({
|
'info': dict({
|
||||||
|
'gcid': 'SOME_GCID',
|
||||||
'password': '**REDACTED**',
|
'password': '**REDACTED**',
|
||||||
'refresh_token': '**REDACTED**',
|
'refresh_token': '**REDACTED**',
|
||||||
'region': 'rest_of_world',
|
'region': 'rest_of_world',
|
||||||
|
|
|
@ -15,7 +15,12 @@ from homeassistant.components.bmw_connected_drive.const import (
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
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
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -26,6 +31,7 @@ FIXTURE_IMPORT_ENTRY = {**FIXTURE_USER_INPUT, CONF_REFRESH_TOKEN: None}
|
||||||
def login_sideeffect(self: MyBMWAuthentication):
|
def login_sideeffect(self: MyBMWAuthentication):
|
||||||
"""Mock logging in and setting a refresh token."""
|
"""Mock logging in and setting a refresh token."""
|
||||||
self.refresh_token = FIXTURE_REFRESH_TOKEN
|
self.refresh_token = FIXTURE_REFRESH_TOKEN
|
||||||
|
self.gcid = FIXTURE_GCID
|
||||||
|
|
||||||
|
|
||||||
async def test_show_form(hass: HomeAssistant) -> None:
|
async def test_show_form(hass: HomeAssistant) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue