async_listen and async_listen_once now errors if used with run_immediately (#182763)

This commit is contained in:
G Johansson
2026-09-20 15:52:28 +02:00
committed by GitHub
parent ef97d7c3f8
commit fbaee67d45
2 changed files with 11 additions and 9 deletions
+6 -4
View File
@@ -1728,8 +1728,9 @@ class EventBus:
frame.report_usage(
"calls `async_listen` with run_immediately",
core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.5",
core_behavior=frame.ReportBehavior.ERROR,
core_integration_behavior=frame.ReportBehavior.ERROR,
custom_integration_behavior=frame.ReportBehavior.ERROR,
)
if event_filter is not None and not is_callback_check_partial(event_filter):
@@ -1798,8 +1799,9 @@ class EventBus:
frame.report_usage(
"calls `async_listen_once` with run_immediately",
core_behavior=frame.ReportBehavior.LOG,
breaks_in_ha_version="2025.5",
core_behavior=frame.ReportBehavior.ERROR,
core_integration_behavior=frame.ReportBehavior.ERROR,
custom_integration_behavior=frame.ReportBehavior.ERROR,
)
one_time_listener: _OneTimeListener[_DataT] = _OneTimeListener(
+5 -5
View File
@@ -3529,11 +3529,11 @@ async def test_async_listen_with_run_immediately_deprecated(
pass
func = getattr(hass.bus, method)
func(EVENT_HOMEASSISTANT_START, _test, run_immediately=run_immediately)
assert (
f"Detected code that calls `{method}` with run_immediately. "
"This will stop working in Home Assistant 2025.5"
) in caplog.text
with pytest.raises(
RuntimeError,
match=f"Detected code that calls `{method}` with run_immediately. Please report this issue",
):
func(EVENT_HOMEASSISTANT_START, _test, run_immediately=run_immediately)
async def test_async_fire_thread_safety(hass: HomeAssistant) -> None: