Catch Mill timeout error (#114068)
* Catch Mill timeout error * Catch Mill timeout error * Catch Mill timeout error
This commit is contained in:
parent
82016ff528
commit
ce12d45b50
2 changed files with 22 additions and 2 deletions
|
@ -66,8 +66,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
key = entry.data[CONF_USERNAME]
|
key = entry.data[CONF_USERNAME]
|
||||||
conn_type = CLOUD
|
conn_type = CLOUD
|
||||||
|
|
||||||
|
try:
|
||||||
if not await mill_data_connection.connect():
|
if not await mill_data_connection.connect():
|
||||||
raise ConfigEntryNotReady
|
raise ConfigEntryNotReady
|
||||||
|
except TimeoutError as error:
|
||||||
|
raise ConfigEntryNotReady from error
|
||||||
data_coordinator = MillDataUpdateCoordinator(
|
data_coordinator = MillDataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
mill_data_connection=mill_data_connection,
|
mill_data_connection=mill_data_connection,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Tests for Mill init."""
|
"""Tests for Mill init."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components import mill
|
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
|
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:
|
async def test_setup_with_old_cloud_config(hass: HomeAssistant) -> None:
|
||||||
"""Test setup of old cloud config."""
|
"""Test setup of old cloud config."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue