Implement PlatformNotReady on onewire integration (#42395)

This commit is contained in:
epenet
2020-10-26 16:33:13 +01:00
committed by GitHub
parent 935c2df7cb
commit 0de52c173c
6 changed files with 146 additions and 47 deletions
+8 -3
View File
@@ -2,6 +2,7 @@
from asynctest.mock import patch
from homeassistant.components.onewire.const import (
CONF_MOUNT_DIR,
CONF_TYPE_OWSERVER,
CONF_TYPE_SYSBUS,
DEFAULT_SYSBUS_MOUNT_DIR,
@@ -20,6 +21,7 @@ async def setup_onewire_sysbus_integration(hass):
source="user",
data={
CONF_TYPE: CONF_TYPE_SYSBUS,
CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR,
},
unique_id=f"{CONF_TYPE_SYSBUS}:{DEFAULT_SYSBUS_MOUNT_DIR}",
connection_class=CONN_CLASS_LOCAL_POLL,
@@ -28,8 +30,11 @@ async def setup_onewire_sysbus_integration(hass):
)
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
with patch(
"homeassistant.components.onewire.onewirehub.os.path.isdir", return_value=True
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry
@@ -52,7 +57,7 @@ async def setup_onewire_owserver_integration(hass):
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.onewire.sensor.protocol.proxy",
"homeassistant.components.onewire.onewirehub.protocol.proxy",
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
+67 -2
View File
@@ -1,9 +1,74 @@
"""Tests for 1-Wire config flow."""
from homeassistant.components.onewire.const import DOMAIN
from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED
from asynctest.mock import patch
from pyownet.protocol import ConnError, OwnetError
from homeassistant.components.onewire.const import CONF_TYPE_OWSERVER, DOMAIN
from homeassistant.config_entries import (
CONN_CLASS_LOCAL_POLL,
ENTRY_STATE_LOADED,
ENTRY_STATE_NOT_LOADED,
ENTRY_STATE_SETUP_RETRY,
)
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
from . import setup_onewire_owserver_integration, setup_onewire_sysbus_integration
from tests.common import MockConfigEntry
async def test_owserver_platform_not_ready(hass):
"""Create the 1-Wire integration."""
config_entry_owserver = MockConfigEntry(
domain=DOMAIN,
source="user",
data={
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: "1234",
},
unique_id=f"{CONF_TYPE_OWSERVER}:1.2.3.4:1234",
connection_class=CONN_CLASS_LOCAL_POLL,
options={},
entry_id="2",
)
config_entry_owserver.add_to_hass(hass)
with patch(
"homeassistant.components.onewire.onewirehub.protocol.proxy",
side_effect=ConnError,
):
await hass.config_entries.async_setup(config_entry_owserver.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry_owserver.state == ENTRY_STATE_SETUP_RETRY
assert not hass.data.get(DOMAIN)
async def test_failed_owserver_listing(hass):
"""Create the 1-Wire integration."""
config_entry_owserver = MockConfigEntry(
domain=DOMAIN,
source="user",
data={
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: "1234",
},
unique_id=f"{CONF_TYPE_OWSERVER}:1.2.3.4:1234",
connection_class=CONN_CLASS_LOCAL_POLL,
options={},
entry_id="2",
)
config_entry_owserver.add_to_hass(hass)
with patch("homeassistant.components.onewire.onewirehub.protocol.proxy") as owproxy:
owproxy.return_value.dir.side_effect = OwnetError
await hass.config_entries.async_setup(config_entry_owserver.entry_id)
await hass.async_block_till_done()
return config_entry_owserver
async def test_unload_entry(hass):
"""Test being able to unload an entry."""