Async migration device_tracker (#4406)
* Async migration device_tracker * change location stuff to async * address paulus comments * fix lint & add async discovery listener * address paulus comments v2 * fix tests * fix test_mqtt * fix test_init * fix gps_acc * fix lint * change async_update_stale to callback
This commit is contained in:
parent
265232af98
commit
c56f99baaf
7 changed files with 233 additions and 120 deletions
|
@ -14,6 +14,16 @@ ATTR_PLATFORM = 'platform'
|
|||
def listen(hass, service, callback):
|
||||
"""Setup listener for discovery of specific service.
|
||||
|
||||
Service can be a string or a list/tuple.
|
||||
"""
|
||||
run_callback_threadsafe(
|
||||
hass.loop, async_listen, hass, service, callback).result()
|
||||
|
||||
|
||||
@core.callback
|
||||
def async_listen(hass, service, callback):
|
||||
"""Setup listener for discovery of specific service.
|
||||
|
||||
Service can be a string or a list/tuple.
|
||||
"""
|
||||
if isinstance(service, str):
|
||||
|
@ -21,12 +31,14 @@ def listen(hass, service, callback):
|
|||
else:
|
||||
service = tuple(service)
|
||||
|
||||
@core.callback
|
||||
def discovery_event_listener(event):
|
||||
"""Listen for discovery events."""
|
||||
if ATTR_SERVICE in event.data and event.data[ATTR_SERVICE] in service:
|
||||
callback(event.data[ATTR_SERVICE], event.data.get(ATTR_DISCOVERED))
|
||||
hass.async_add_job(callback, event.data[ATTR_SERVICE],
|
||||
event.data.get(ATTR_DISCOVERED))
|
||||
|
||||
hass.bus.listen(EVENT_PLATFORM_DISCOVERED, discovery_event_listener)
|
||||
hass.bus.async_listen(EVENT_PLATFORM_DISCOVERED, discovery_event_listener)
|
||||
|
||||
|
||||
def discover(hass, service, discovered=None, component=None, hass_config=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue