mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Update discovery to use HassJob (#41511)
Predetermine the listener types for discovery
This commit is contained in:
parent
3a863c4a0f
commit
852d1b2e67
@ -42,12 +42,14 @@ def async_listen(
|
||||
else:
|
||||
service = tuple(service)
|
||||
|
||||
job = core.HassJob(callback)
|
||||
|
||||
@core.callback
|
||||
def discovery_event_listener(event: core.Event) -> None:
|
||||
"""Listen for discovery events."""
|
||||
if ATTR_SERVICE in event.data and event.data[ATTR_SERVICE] in service:
|
||||
hass.async_add_job(
|
||||
callback, event.data[ATTR_SERVICE], event.data.get(ATTR_DISCOVERED)
|
||||
hass.async_add_hass_job(
|
||||
job, event.data[ATTR_SERVICE], event.data.get(ATTR_DISCOVERED)
|
||||
)
|
||||
|
||||
hass.bus.async_listen(EVENT_PLATFORM_DISCOVERED, discovery_event_listener)
|
||||
@ -110,6 +112,7 @@ def async_listen_platform(
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
service = EVENT_LOAD_PLATFORM.format(component)
|
||||
job = core.HassJob(callback)
|
||||
|
||||
@core.callback
|
||||
def discovery_platform_listener(event: core.Event) -> None:
|
||||
@ -122,7 +125,7 @@ def async_listen_platform(
|
||||
if not platform:
|
||||
return
|
||||
|
||||
hass.async_run_job(callback, platform, event.data.get(ATTR_DISCOVERED))
|
||||
hass.async_run_hass_job(job, platform, event.data.get(ATTR_DISCOVERED))
|
||||
|
||||
hass.bus.async_listen(EVENT_PLATFORM_DISCOVERED, discovery_platform_listener)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user