Update discovery to use HassJob (#41511)

Predetermine the listener types for discovery
This commit is contained in:
J. Nick Koston 2020-10-09 02:35:28 -05:00 committed by GitHub
parent 3a863c4a0f
commit 852d1b2e67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)