mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix OwnetError preventing onewire initialisation (#61696)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
550004f109
commit
7f823f7211
@ -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
|
||||
|
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user