Allow async_setup changes to config entry data be taken into a… (#34166)
* Allow async_setup changes to config entry data be taken into account * Fix tests * Limit scope try…finally * Update tests/test_config_entries.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Fix import Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
1 parent
0db1fcca0f
commit
0b90ebf91e
10 files changed
+176
-33
No files matched your search
@@ -9,19 +9,6 @@ from .test_device import MAC, setup_axis_integration
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
|
||||
|
||||
async def test_setup_device_already_configured(hass):
|
||||
"""Test already configured device does not configure a second."""
|
||||
with patch.object(hass, "config_entries") as mock_config_entries:
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
axis.DOMAIN,
|
||||
{axis.DOMAIN: {"device_name": {axis.CONF_HOST: "1.2.3.4"}}},
|
||||
)
|
||||
|
||||
assert not mock_config_entries.flow.mock_calls
|
||||
|
||||
|
||||
async def test_setup_no_config(hass):
|
||||
"""Test setup without configuration."""
|
||||
assert await async_setup_component(hass, axis.DOMAIN, {})
|
||||
|
||||
@@ -230,7 +230,7 @@ async def test_setup_with_no_config(hass):
|
||||
assert konnected.YAML_CONFIGS not in hass.data[konnected.DOMAIN]
|
||||
|
||||
|
||||
async def test_setup_defined_hosts_known_auth(hass):
|
||||
async def test_setup_defined_hosts_known_auth(hass, mock_panel):
|
||||
"""Test we don't initiate a config entry if configured panel is known."""
|
||||
MockConfigEntry(
|
||||
domain="konnected",
|
||||
|
||||
@@ -15,7 +15,9 @@ async def test_config_with_sensor_passed_to_config_entry(hass):
|
||||
CONF_SCAN_INTERVAL: 600,
|
||||
}
|
||||
|
||||
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
|
||||
with patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_config_entries, patch.object(
|
||||
luftdaten, "configured_sensors", return_value=[]
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, conf) is True
|
||||
@@ -27,7 +29,9 @@ async def test_config_already_registered_not_passed_to_config_entry(hass):
|
||||
"""Test that an already registered sensor does not initiate an import."""
|
||||
conf = {CONF_SENSOR_ID: "12345abcde"}
|
||||
|
||||
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
|
||||
with patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_config_entries, patch.object(
|
||||
luftdaten, "configured_sensors", return_value=["12345abcde"]
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, conf) is True
|
||||
|
||||
@@ -55,7 +55,9 @@ def get_homekit_info_mock(model):
|
||||
|
||||
async def test_setup(hass, mock_zeroconf):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.object(hass.config_entries, "flow") as mock_config_flow, patch.object(
|
||||
with patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_config_flow, patch.object(
|
||||
zeroconf, "ServiceBrowser", side_effect=service_update_mock
|
||||
) as mock_service_browser:
|
||||
mock_zeroconf.get_service_info.side_effect = get_service_info_mock
|
||||
@@ -72,7 +74,9 @@ async def test_homekit_match_partial_space(hass, mock_zeroconf):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.dict(
|
||||
zc_gen.ZEROCONF, {zeroconf.HOMEKIT_TYPE: ["homekit_controller"]}, clear=True
|
||||
), patch.object(hass.config_entries, "flow") as mock_config_flow, patch.object(
|
||||
), patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_config_flow, patch.object(
|
||||
zeroconf, "ServiceBrowser", side_effect=service_update_mock
|
||||
) as mock_service_browser:
|
||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock("LIFX bulb")
|
||||
@@ -87,7 +91,9 @@ async def test_homekit_match_partial_dash(hass, mock_zeroconf):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.dict(
|
||||
zc_gen.ZEROCONF, {zeroconf.HOMEKIT_TYPE: ["homekit_controller"]}, clear=True
|
||||
), patch.object(hass.config_entries, "flow") as mock_config_flow, patch.object(
|
||||
), patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_config_flow, patch.object(
|
||||
zeroconf, "ServiceBrowser", side_effect=service_update_mock
|
||||
) as mock_service_browser:
|
||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
||||
@@ -104,7 +110,9 @@ async def test_homekit_match_full(hass, mock_zeroconf):
|
||||
"""Test configured options for a device are loaded via config entry."""
|
||||
with patch.dict(
|
||||
zc_gen.ZEROCONF, {zeroconf.HOMEKIT_TYPE: ["homekit_controller"]}, clear=True
|
||||
), patch.object(hass.config_entries, "flow") as mock_config_flow, patch.object(
|
||||
), patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_config_flow, patch.object(
|
||||
zeroconf, "ServiceBrowser", side_effect=service_update_mock
|
||||
) as mock_service_browser:
|
||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock("BSB002")
|
||||
|
||||
Reference in new issue
Block a user