diff --git a/homeassistant/components/onewire/__init__.py b/homeassistant/components/onewire/__init__.py index 753d30e5958..70a0a5fc856 100644 --- a/homeassistant/components/onewire/__init__.py +++ b/homeassistant/components/onewire/__init__.py @@ -1,6 +1,8 @@ """The 1-Wire component.""" import logging +from pyownet import protocol + from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -18,7 +20,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: onewirehub = OneWireHub(hass) try: await onewirehub.initialize(entry) - except CannotConnect as exc: + except ( + CannotConnect, # Failed to connect to the server + protocol.OwnetError, # Connected to server, but failed to list the devices + ) as exc: raise ConfigEntryNotReady() from exc hass.data[DOMAIN][entry.entry_id] = onewirehub diff --git a/tests/components/onewire/test_init.py b/tests/components/onewire/test_init.py index e3a3fdcc564..763cdc9c071 100644 --- a/tests/components/onewire/test_init.py +++ b/tests/components/onewire/test_init.py @@ -1,6 +1,8 @@ """Tests for 1-Wire config flow.""" import logging +from unittest.mock import MagicMock +from pyownet import protocol import pytest from homeassistant.components.onewire.const import DOMAIN @@ -19,6 +21,20 @@ async def test_owserver_connect_failure(hass: HomeAssistant, config_entry: Confi assert not hass.data.get(DOMAIN) +async def test_owserver_listing_failure( + hass: HomeAssistant, config_entry: ConfigEntry, owproxy: MagicMock +): + """Test listing failure raises ConfigEntryNotReady.""" + owproxy.return_value.dir.side_effect = protocol.OwnetError() + + 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) + + @pytest.mark.usefixtures("owproxy") async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry): """Test being able to unload an entry."""