mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fix setup timings when config entry platform loads are not awaited (#113959)
* Move setup time logging into the context manager We were fetching the time twice but since the context manager already has the timing, move it there * remove log setup assertions from integration test * tweak logging to give us better data for tracking issues * redundant * adjust * preen * fixes * adjust * make api change internal so nobody uses it * coverage * fix test * fix more tests * coverage * more tests assuming internal calls * fix more * adjust * adjust * fix axis tests * fix broadlink -- it does not call async_forward_entry_setup * missed some * remove useless patch * rename, detect it both ways * clear * debug * try to fix * handle phase finishing out while paused * where its set does not need to know its late as that is an implemenation detail of setup * where its set does not need to know its late as that is an implemenation detail of setup * tweak * simplify * reduce complexity * revert order change as it makes review harder * revert naming changes as it makes review harder * improve comment * improve debug * late dispatch test * test the other way as well * Update setup.py * Update setup.py * Update setup.py * simplify * reduce
This commit is contained in:
@@ -21,7 +21,7 @@ async def test_device_setup(hass: HomeAssistant) -> None:
|
||||
device = get_device("Office")
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -32,9 +32,9 @@ async def test_device_setup(hass: HomeAssistant) -> None:
|
||||
assert mock_setup.api.get_fwversion.call_count == 1
|
||||
assert mock_setup.factory.call_count == 1
|
||||
|
||||
forward_entries = {c[1][1] for c in mock_forward.mock_calls}
|
||||
forward_entries = set(mock_forward.mock_calls[0][1][1])
|
||||
domains = get_domains(mock_setup.api.type)
|
||||
assert mock_forward.call_count == len(domains)
|
||||
assert mock_forward.call_count == 1
|
||||
assert forward_entries == domains
|
||||
assert mock_init.call_count == 0
|
||||
|
||||
@@ -46,7 +46,7 @@ async def test_device_setup_authentication_error(hass: HomeAssistant) -> None:
|
||||
mock_api.auth.side_effect = blke.AuthenticationError()
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -70,7 +70,7 @@ async def test_device_setup_network_timeout(hass: HomeAssistant) -> None:
|
||||
mock_api.auth.side_effect = blke.NetworkTimeoutError()
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -89,7 +89,7 @@ async def test_device_setup_os_error(hass: HomeAssistant) -> None:
|
||||
mock_api.auth.side_effect = OSError()
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -108,7 +108,7 @@ async def test_device_setup_broadlink_exception(hass: HomeAssistant) -> None:
|
||||
mock_api.auth.side_effect = blke.BroadlinkException()
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -127,7 +127,7 @@ async def test_device_setup_update_network_timeout(hass: HomeAssistant) -> None:
|
||||
mock_api.check_sensors.side_effect = blke.NetworkTimeoutError()
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -150,7 +150,7 @@ async def test_device_setup_update_authorization_error(hass: HomeAssistant) -> N
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -160,9 +160,9 @@ async def test_device_setup_update_authorization_error(hass: HomeAssistant) -> N
|
||||
assert mock_setup.api.auth.call_count == 2
|
||||
assert mock_setup.api.check_sensors.call_count == 2
|
||||
|
||||
forward_entries = {c[1][1] for c in mock_forward.mock_calls}
|
||||
forward_entries = set(mock_forward.mock_calls[0][1][1])
|
||||
domains = get_domains(mock_api.type)
|
||||
assert mock_forward.call_count == len(domains)
|
||||
assert mock_forward.call_count == 1
|
||||
assert forward_entries == domains
|
||||
assert mock_init.call_count == 0
|
||||
|
||||
@@ -175,7 +175,7 @@ async def test_device_setup_update_authentication_error(hass: HomeAssistant) ->
|
||||
mock_api.auth.side_effect = (None, blke.AuthenticationError())
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -200,7 +200,7 @@ async def test_device_setup_update_broadlink_exception(hass: HomeAssistant) -> N
|
||||
mock_api.check_sensors.side_effect = blke.BroadlinkException()
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward, patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
) as mock_init:
|
||||
@@ -221,13 +221,15 @@ async def test_device_setup_get_fwversion_broadlink_exception(
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.get_fwversion.side_effect = blke.BroadlinkException()
|
||||
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setup") as mock_forward:
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward:
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_setup.entry.state is ConfigEntryState.LOADED
|
||||
forward_entries = {c[1][1] for c in mock_forward.mock_calls}
|
||||
forward_entries = set(mock_forward.mock_calls[0][1][1])
|
||||
domains = get_domains(mock_setup.api.type)
|
||||
assert mock_forward.call_count == len(domains)
|
||||
assert mock_forward.call_count == 1
|
||||
assert forward_entries == domains
|
||||
|
||||
|
||||
@@ -237,13 +239,15 @@ async def test_device_setup_get_fwversion_os_error(hass: HomeAssistant) -> None:
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.get_fwversion.side_effect = OSError()
|
||||
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setup") as mock_forward:
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward:
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
assert mock_setup.entry.state is ConfigEntryState.LOADED
|
||||
forward_entries = {c[1][1] for c in mock_forward.mock_calls}
|
||||
forward_entries = set(mock_forward.mock_calls[0][1][1])
|
||||
domains = get_domains(mock_setup.api.type)
|
||||
assert mock_forward.call_count == len(domains)
|
||||
assert mock_forward.call_count == 1
|
||||
assert forward_entries == domains
|
||||
|
||||
|
||||
@@ -281,7 +285,7 @@ async def test_device_unload_works(hass: HomeAssistant) -> None:
|
||||
"""Test we unload the device."""
|
||||
device = get_device("Office")
|
||||
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setup"):
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setups"):
|
||||
mock_setup = await device.setup_entry(hass)
|
||||
|
||||
with patch.object(
|
||||
@@ -302,7 +306,7 @@ async def test_device_unload_authentication_error(hass: HomeAssistant) -> None:
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.auth.side_effect = blke.AuthenticationError()
|
||||
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setup"), patch.object(
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setups"), patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
):
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
@@ -322,7 +326,7 @@ async def test_device_unload_update_failed(hass: HomeAssistant) -> None:
|
||||
mock_api = device.get_mock_api()
|
||||
mock_api.check_sensors.side_effect = blke.NetworkTimeoutError()
|
||||
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setup"):
|
||||
with patch.object(hass.config_entries, "async_forward_entry_setups"):
|
||||
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
|
||||
|
||||
with patch.object(
|
||||
|
||||
Reference in New Issue
Block a user