Fix Renault AssertionError (#99189)
parent
b5ff0b4ec2
commit
c81d39f651
|
@ -19,6 +19,7 @@ from homeassistant.const import (
|
||||||
ATTR_SW_VERSION,
|
ATTR_SW_VERSION,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
|
@ -57,8 +58,15 @@ class RenaultHub:
|
||||||
|
|
||||||
self._account = await self._client.get_api_account(account_id)
|
self._account = await self._client.get_api_account(account_id)
|
||||||
vehicles = await self._account.get_vehicles()
|
vehicles = await self._account.get_vehicles()
|
||||||
device_registry = dr.async_get(self._hass)
|
|
||||||
if vehicles.vehicleLinks:
|
if vehicles.vehicleLinks:
|
||||||
|
if any(
|
||||||
|
vehicle_link.vehicleDetails is None
|
||||||
|
for vehicle_link in vehicles.vehicleLinks
|
||||||
|
):
|
||||||
|
raise ConfigEntryNotReady(
|
||||||
|
"Failed to retrieve vehicle details from Renault servers"
|
||||||
|
)
|
||||||
|
device_registry = dr.async_get(self._hass)
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*(
|
*(
|
||||||
self.async_initialise_vehicle(
|
self.async_initialise_vehicle(
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"accountId": "account-id-1",
|
||||||
|
"country": "FR",
|
||||||
|
"vehicleLinks": [
|
||||||
|
{
|
||||||
|
"brand": "RENAULT",
|
||||||
|
"vin": "VF1AAAAA555777999",
|
||||||
|
"status": "ACTIVE",
|
||||||
|
"linkType": "OWNER",
|
||||||
|
"garageBrand": "RENAULT",
|
||||||
|
"annualMileage": 16000,
|
||||||
|
"mileage": 26464,
|
||||||
|
"startDate": "2017-08-07",
|
||||||
|
"createdDate": "2019-05-23T21:38:16.409008Z",
|
||||||
|
"lastModifiedDate": "2020-11-17T08:41:40.497400Z",
|
||||||
|
"ownershipStartDate": "2017-08-01",
|
||||||
|
"cancellationReason": {},
|
||||||
|
"connectedDriver": {
|
||||||
|
"role": "MAIN_DRIVER",
|
||||||
|
"createdDate": "2019-06-17T09:49:06.880627Z",
|
||||||
|
"lastModifiedDate": "2019-06-17T09:49:06.880627Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -95,3 +95,19 @@ async def test_setup_entry_kamereon_exception(
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
assert not hass.data.get(DOMAIN)
|
assert not hass.data.get(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("patch_renault_account", "patch_get_vehicles")
|
||||||
|
@pytest.mark.parametrize("vehicle_type", ["missing_details"], indirect=True)
|
||||||
|
async def test_setup_entry_missing_vehicle_details(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Test ConfigEntryNotReady when vehicleDetails is missing."""
|
||||||
|
# In this case we are testing the condition where renault_hub fails to retrieve
|
||||||
|
# vehicle details (see #99127).
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
assert not hass.data.get(DOMAIN)
|
||||||
|
|
Loading…
Reference in New Issue