mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Handle http error in Renault initialisation (#97530)
This commit is contained in:
parent
ed3ebdfea5
commit
927905ac84
@ -26,7 +26,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
raise ConfigEntryAuthFailed()
|
raise ConfigEntryAuthFailed()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
try:
|
||||||
await renault_hub.async_initialise(config_entry)
|
await renault_hub.async_initialise(config_entry)
|
||||||
|
except aiohttp.ClientResponseError as exc:
|
||||||
|
raise ConfigEntryNotReady() from exc
|
||||||
|
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = renault_hub
|
hass.data[DOMAIN][config_entry.entry_id] = renault_hub
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Tests for Renault setup process."""
|
"""Tests for Renault setup process."""
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import pytest
|
import pytest
|
||||||
@ -76,3 +76,22 @@ async def test_setup_entry_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")
|
||||||
|
async def test_setup_entry_kamereon_exception(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Test ConfigEntryNotReady when API raises an exception during entry setup."""
|
||||||
|
# In this case we are testing the condition where renault_hub fails to retrieve
|
||||||
|
# list of vehicles (see Gateway Time-out on #97324).
|
||||||
|
with patch(
|
||||||
|
"renault_api.renault_client.RenaultClient.get_api_account",
|
||||||
|
side_effect=aiohttp.ClientResponseError(Mock(), (), status=504),
|
||||||
|
):
|
||||||
|
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…
x
Reference in New Issue
Block a user