mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
* Revert "Address late review of config entry wait for states tests (#81801)" This reverts commit 12d76a8a4f1cbc9403798a32dd335d928dd61373. * Revert "Implement ConfigEntry async_wait_for_states (#81771)" This reverts commit 3cc9ecf1dc0dc5fdace19770c076eb47d2f1c746.
This commit is contained in:
parent
c5c23cbc95
commit
c720742ec9
@ -12,8 +12,6 @@ from types import MappingProxyType, MethodType
|
|||||||
from typing import TYPE_CHECKING, Any, Optional, TypeVar, cast
|
from typing import TYPE_CHECKING, Any, Optional, TypeVar, cast
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
import async_timeout
|
|
||||||
|
|
||||||
from . import data_entry_flow, loader
|
from . import data_entry_flow, loader
|
||||||
from .backports.enum import StrEnum
|
from .backports.enum import StrEnum
|
||||||
from .components import persistent_notification
|
from .components import persistent_notification
|
||||||
@ -22,7 +20,7 @@ from .core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback
|
|||||||
from .data_entry_flow import FlowResult
|
from .data_entry_flow import FlowResult
|
||||||
from .exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady, HomeAssistantError
|
from .exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady, HomeAssistantError
|
||||||
from .helpers import device_registry, entity_registry, storage
|
from .helpers import device_registry, entity_registry, storage
|
||||||
from .helpers.dispatcher import async_dispatcher_connect, async_dispatcher_send
|
from .helpers.dispatcher import async_dispatcher_send
|
||||||
from .helpers.event import async_call_later
|
from .helpers.event import async_call_later
|
||||||
from .helpers.frame import report
|
from .helpers.frame import report
|
||||||
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
|
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
|
||||||
@ -1249,36 +1247,6 @@ class ConfigEntries:
|
|||||||
await entry.async_setup(self.hass, integration=integration)
|
await entry.async_setup(self.hass, integration=integration)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_wait_for_states(
|
|
||||||
self, entry: ConfigEntry, states: set[ConfigEntryState], timeout: float = 60.0
|
|
||||||
) -> ConfigEntryState:
|
|
||||||
"""Wait for the setup of an entry to reach one of the supplied states state.
|
|
||||||
|
|
||||||
Returns the state the entry reached or raises asyncio.TimeoutError if the
|
|
||||||
entry did not reach one of the supplied states within the timeout.
|
|
||||||
"""
|
|
||||||
state_reached_future: asyncio.Future[ConfigEntryState] = asyncio.Future()
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def _async_entry_changed(
|
|
||||||
change: ConfigEntryChange, event_entry: ConfigEntry
|
|
||||||
) -> None:
|
|
||||||
if (
|
|
||||||
event_entry is entry
|
|
||||||
and change is ConfigEntryChange.UPDATED
|
|
||||||
and entry.state in states
|
|
||||||
):
|
|
||||||
state_reached_future.set_result(entry.state)
|
|
||||||
|
|
||||||
unsub = async_dispatcher_connect(
|
|
||||||
self.hass, SIGNAL_CONFIG_ENTRY_CHANGED, _async_entry_changed
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
async with async_timeout.timeout(timeout):
|
|
||||||
return await state_reached_future
|
|
||||||
finally:
|
|
||||||
unsub()
|
|
||||||
|
|
||||||
async def async_unload_platforms(
|
async def async_unload_platforms(
|
||||||
self, entry: ConfigEntry, platforms: Iterable[Platform | str]
|
self, entry: ConfigEntry, platforms: Iterable[Platform | str]
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
@ -3332,105 +3332,6 @@ async def test_reauth(hass):
|
|||||||
assert len(hass.config_entries.flow.async_progress()) == 2
|
assert len(hass.config_entries.flow.async_progress()) == 2
|
||||||
|
|
||||||
|
|
||||||
async def test_wait_for_loading_entry(hass: HomeAssistant) -> None:
|
|
||||||
"""Test waiting for entry to be set up."""
|
|
||||||
|
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
|
||||||
|
|
||||||
mock_setup_entry = AsyncMock(return_value=True)
|
|
||||||
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
|
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
|
||||||
|
|
||||||
await entry.async_setup(hass)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
flow = hass.config_entries.flow
|
|
||||||
|
|
||||||
async def _load_entry() -> None:
|
|
||||||
assert await async_setup_component(hass, "test", {})
|
|
||||||
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
flow = hass.config_entries.flow
|
|
||||||
with patch.object(flow, "async_init", wraps=flow.async_init):
|
|
||||||
hass.async_create_task(_load_entry())
|
|
||||||
new_state = await hass.config_entries.async_wait_for_states(
|
|
||||||
entry,
|
|
||||||
{
|
|
||||||
config_entries.ConfigEntryState.LOADED,
|
|
||||||
config_entries.ConfigEntryState.SETUP_ERROR,
|
|
||||||
},
|
|
||||||
timeout=1.0,
|
|
||||||
)
|
|
||||||
assert new_state is config_entries.ConfigEntryState.LOADED
|
|
||||||
assert entry.state is config_entries.ConfigEntryState.LOADED
|
|
||||||
|
|
||||||
|
|
||||||
async def test_wait_for_loading_failed_entry(hass: HomeAssistant) -> None:
|
|
||||||
"""Test waiting for entry to be set up that fails loading."""
|
|
||||||
|
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
|
||||||
|
|
||||||
mock_setup_entry = AsyncMock(side_effect=HomeAssistantError)
|
|
||||||
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
|
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
flow = hass.config_entries.flow
|
|
||||||
|
|
||||||
async def _load_entry() -> None:
|
|
||||||
assert await async_setup_component(hass, "test", {})
|
|
||||||
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
flow = hass.config_entries.flow
|
|
||||||
with patch.object(flow, "async_init", wraps=flow.async_init):
|
|
||||||
hass.async_create_task(_load_entry())
|
|
||||||
new_state = await hass.config_entries.async_wait_for_states(
|
|
||||||
entry,
|
|
||||||
{
|
|
||||||
config_entries.ConfigEntryState.LOADED,
|
|
||||||
config_entries.ConfigEntryState.SETUP_ERROR,
|
|
||||||
},
|
|
||||||
timeout=1.0,
|
|
||||||
)
|
|
||||||
assert new_state is config_entries.ConfigEntryState.SETUP_ERROR
|
|
||||||
assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR
|
|
||||||
|
|
||||||
|
|
||||||
async def test_wait_for_loading_timeout(hass: HomeAssistant) -> None:
|
|
||||||
"""Test waiting for entry to be set up that fails with a timeout."""
|
|
||||||
|
|
||||||
async def _async_setup_entry(hass, entry):
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
return True
|
|
||||||
|
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
|
||||||
|
|
||||||
mock_integration(hass, MockModule("test", async_setup_entry=_async_setup_entry))
|
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
flow = hass.config_entries.flow
|
|
||||||
|
|
||||||
async def _load_entry() -> None:
|
|
||||||
assert await async_setup_component(hass, "test", {})
|
|
||||||
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
flow = hass.config_entries.flow
|
|
||||||
with patch.object(flow, "async_init", wraps=flow.async_init):
|
|
||||||
hass.async_create_task(_load_entry())
|
|
||||||
with pytest.raises(asyncio.exceptions.TimeoutError):
|
|
||||||
await hass.config_entries.async_wait_for_states(
|
|
||||||
entry,
|
|
||||||
{
|
|
||||||
config_entries.ConfigEntryState.LOADED,
|
|
||||||
config_entries.ConfigEntryState.SETUP_ERROR,
|
|
||||||
},
|
|
||||||
timeout=0.1,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_active_flows(hass):
|
async def test_get_active_flows(hass):
|
||||||
"""Test the async_get_active_flows helper."""
|
"""Test the async_get_active_flows helper."""
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user