mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Make run_immediately the default for core EventBus listeners (#113752)
* DNM: Make run_immediately the default for listeners This is a test to see how much progress we have made twords this goal https://github.com/home-assistant/core/pull/113727#issuecomment-2004587947 * fix shutdown * Revert "fix shutdown" This reverts commit a8969d7db9fed10040cb8b7b25459dc9d812eb9c. * set false since it break utility meter tests * one more * fix rfxtrx test * test needs to be explict now * fix matrix * fail sooner
This commit is contained in:
parent
bf5cf382dc
commit
fb98a6f026
@ -219,7 +219,9 @@ class MatrixBot:
|
||||
loop_sleep_time=1_000,
|
||||
) # milliseconds.
|
||||
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, handle_startup)
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_START, handle_startup, run_immediately=False
|
||||
)
|
||||
|
||||
def _load_commands(self, commands: list[ConfigCommand]) -> None:
|
||||
for command in commands:
|
||||
|
@ -280,7 +280,9 @@ async def async_setup_internal(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
hass.data[DOMAIN][DATA_RFXOBJECT] = rfx_object
|
||||
|
||||
entry.async_on_unload(
|
||||
hass.bus.async_listen(dr.EVENT_DEVICE_REGISTRY_UPDATED, _updated_device)
|
||||
hass.bus.async_listen(
|
||||
dr.EVENT_DEVICE_REGISTRY_UPDATED, _updated_device, run_immediately=False
|
||||
)
|
||||
)
|
||||
|
||||
def _shutdown_rfxtrx(event: Event) -> None:
|
||||
|
@ -1485,7 +1485,7 @@ class EventBus:
|
||||
event_type: str,
|
||||
listener: Callable[[Event[_DataT]], Coroutine[Any, Any, None] | None],
|
||||
event_filter: Callable[[_DataT], bool] | None = None,
|
||||
run_immediately: bool = False,
|
||||
run_immediately: bool = True,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Listen for all events or events of a specific type.
|
||||
|
||||
@ -1558,7 +1558,7 @@ class EventBus:
|
||||
self,
|
||||
event_type: str,
|
||||
listener: Callable[[Event[Any]], Coroutine[Any, Any, None] | None],
|
||||
run_immediately: bool = False,
|
||||
run_immediately: bool = True,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Listen once for event of a specific type.
|
||||
|
||||
|
@ -272,7 +272,10 @@ def async_track_state_change(
|
||||
return async_track_state_change_event(hass, entity_ids, state_change_listener)
|
||||
|
||||
return hass.bus.async_listen(
|
||||
EVENT_STATE_CHANGED, state_change_dispatcher, event_filter=state_change_filter
|
||||
EVENT_STATE_CHANGED,
|
||||
state_change_dispatcher,
|
||||
event_filter=state_change_filter,
|
||||
run_immediately=False,
|
||||
)
|
||||
|
||||
|
||||
|
@ -47,7 +47,9 @@ def _async_at_core_state(
|
||||
if unsub:
|
||||
unsub()
|
||||
|
||||
unsub = hass.bus.async_listen_once(event_type, _matched_event)
|
||||
unsub = hass.bus.async_listen_once(
|
||||
event_type, _matched_event, run_immediately=False
|
||||
)
|
||||
return cancel
|
||||
|
||||
|
||||
|
@ -358,7 +358,9 @@ async def async_test_home_assistant(
|
||||
"""Clear global instance."""
|
||||
INSTANCES.remove(hass)
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, clear_instance)
|
||||
hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_CLOSE, clear_instance, run_immediately=False
|
||||
)
|
||||
|
||||
yield hass
|
||||
|
||||
|
@ -2512,7 +2512,9 @@ async def test_recursive_automation_starting_script(
|
||||
hass.services.async_register(
|
||||
"test", "automation_started", async_service_handler
|
||||
)
|
||||
hass.bus.async_listen("automation_triggered", async_automation_triggered)
|
||||
hass.bus.async_listen(
|
||||
"automation_triggered", async_automation_triggered, run_immediately=False
|
||||
)
|
||||
|
||||
hass.bus.async_fire("trigger_automation")
|
||||
await asyncio.wait_for(script_done_event.wait(), 10)
|
||||
|
@ -3361,9 +3361,11 @@ async def test_report_state_listener_restrictions(hass: HomeAssistant) -> None:
|
||||
"""Mock filter."""
|
||||
return False
|
||||
|
||||
# run_immediately not set
|
||||
# run_immediately set to False
|
||||
with pytest.raises(HomeAssistantError):
|
||||
hass.bus.async_listen(EVENT_STATE_REPORTED, listener, event_filter=filter)
|
||||
hass.bus.async_listen(
|
||||
EVENT_STATE_REPORTED, listener, event_filter=filter, run_immediately=False
|
||||
)
|
||||
|
||||
# no filter
|
||||
with pytest.raises(HomeAssistantError):
|
||||
|
Loading…
x
Reference in New Issue
Block a user