Catch Mill timeout error (#114068)

* Catch Mill timeout error

* Catch Mill timeout error

* Catch Mill timeout error
This commit is contained in:
Joost Lekkerkerker 2024-03-23 20:57:22 +01:00 committed by GitHub
parent 82016ff528
commit ce12d45b50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -66,8 +66,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
key = entry.data[CONF_USERNAME]
conn_type = CLOUD
if not await mill_data_connection.connect():
raise ConfigEntryNotReady
try:
if not await mill_data_connection.connect():
raise ConfigEntryNotReady
except TimeoutError as error:
raise ConfigEntryNotReady from error
data_coordinator = MillDataUpdateCoordinator(
hass,
mill_data_connection=mill_data_connection,

View file

@ -1,5 +1,6 @@
"""Tests for Mill init."""
import asyncio
from unittest.mock import patch
from homeassistant.components import mill
@ -45,6 +46,22 @@ async def test_setup_with_cloud_config_fails(hass: HomeAssistant) -> None:
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_setup_with_cloud_config_times_out(hass: HomeAssistant) -> None:
"""Test setup of cloud config will retry if timed out."""
entry = MockConfigEntry(
domain=mill.DOMAIN,
data={
mill.CONF_USERNAME: "user",
mill.CONF_PASSWORD: "pswd",
mill.CONNECTION_TYPE: mill.CLOUD,
},
)
entry.add_to_hass(hass)
with patch("mill.Mill.connect", side_effect=asyncio.TimeoutError):
await hass.config_entries.async_setup(entry.entry_id)
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_setup_with_old_cloud_config(hass: HomeAssistant) -> None:
"""Test setup of old cloud config."""
entry = MockConfigEntry(