Migrate one time listeners to use async_run_hass_job (#113179)

pull/105382/head^2
J. Nick Koston 2024-03-13 00:06:30 -10:00 committed by GitHub
parent 488dae43d4
commit d6f1405874
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View File

@ -1264,7 +1264,7 @@ _FilterableJobType = tuple[
@dataclass(slots=True)
class _OneTimeListener:
hass: HomeAssistant
listener: Callable[[Event], Coroutine[Any, Any, None] | None]
listener_job: HassJob[[Event], Coroutine[Any, Any, None] | None]
remove: CALLBACK_TYPE | None = None
@callback
@ -1275,14 +1275,14 @@ class _OneTimeListener:
return
self.remove()
self.remove = None
self.hass.async_run_job(self.listener, event)
self.hass.async_run_hass_job(self.listener_job, event)
def __repr__(self) -> str:
"""Return the representation of the listener and source module."""
module = inspect.getmodule(self.listener)
module = inspect.getmodule(self.listener_job.target)
if module:
return f"<_OneTimeListener {module.__name__}:{self.listener}>"
return f"<_OneTimeListener {self.listener}>"
return f"<_OneTimeListener {module.__name__}:{self.listener_job.target}>"
return f"<_OneTimeListener {self.listener_job.target}>"
class EventBus:
@ -1472,7 +1472,7 @@ class EventBus:
This method must be run in the event loop.
"""
one_time_listener = _OneTimeListener(self._hass, listener)
one_time_listener = _OneTimeListener(self._hass, HassJob(listener))
remove = self._async_listen_filterable_job(
event_type,
(

View File

@ -3098,7 +3098,7 @@ def test_one_time_listener_repr(hass: HomeAssistant) -> None:
def _listener(event: ha.Event):
"""Test listener."""
one_time_listener = ha._OneTimeListener(hass, _listener)
one_time_listener = ha._OneTimeListener(hass, HassJob(_listener))
repr_str = repr(one_time_listener)
assert "OneTimeListener" in repr_str
assert "test_core" in repr_str