diff --git a/homeassistant/util/async_.py b/homeassistant/util/async_.py index 0fd1b564f0d..15353d1f7eb 100644 --- a/homeassistant/util/async_.py +++ b/homeassistant/util/async_.py @@ -136,6 +136,10 @@ def check_loop() -> None: found_frame.lineno, found_frame.line.strip(), ) + raise RuntimeError( + f"I/O must be done in the executor; Use `await hass.async_add_executor_job()` " + f"at {found_frame.filename[index:]}, line {found_frame.lineno}: {found_frame.line.strip()}" + ) def protect_loop(func: Callable) -> Callable: diff --git a/tests/util/test_async.py b/tests/util/test_async.py index d4fdce1e912..d5564a90d0e 100644 --- a/tests/util/test_async.py +++ b/tests/util/test_async.py @@ -78,7 +78,7 @@ async def test_check_loop_async(): async def test_check_loop_async_integration(caplog): """Test check_loop detects when called from event loop from integration context.""" - with patch( + with pytest.raises(RuntimeError), patch( "homeassistant.util.async_.extract_stack", return_value=[ Mock( @@ -107,7 +107,7 @@ async def test_check_loop_async_integration(caplog): async def test_check_loop_async_custom(caplog): """Test check_loop detects when called from event loop with custom component context.""" - with patch( + with pytest.raises(RuntimeError), patch( "homeassistant.util.async_.extract_stack", return_value=[ Mock(