1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

RFC: Use bind_hass for helpers (#9745)

* Add Helpers bind_hass functionality

* Update other helpers
This commit is contained in:
Paulus Schoutsen
2017-10-08 08:17:54 -07:00
committed by GitHub
parent e19e9a1f2b
commit ca54bbfcc9
16 changed files with 108 additions and 25 deletions

View File

@@ -2,6 +2,7 @@
import logging
from homeassistant.core import callback
from homeassistant.loader import bind_hass
from homeassistant.util.async import run_callback_threadsafe
@@ -9,6 +10,7 @@ _LOGGER = logging.getLogger(__name__)
DATA_DISPATCHER = 'dispatcher'
@bind_hass
def dispatcher_connect(hass, signal, target):
"""Connect a callable function to a signal."""
async_unsub = run_callback_threadsafe(
@@ -22,6 +24,7 @@ def dispatcher_connect(hass, signal, target):
@callback
@bind_hass
def async_dispatcher_connect(hass, signal, target):
"""Connect a callable function to a signal.
@@ -49,12 +52,14 @@ def async_dispatcher_connect(hass, signal, target):
return async_remove_dispatcher
@bind_hass
def dispatcher_send(hass, signal, *args):
"""Send signal and data."""
hass.loop.call_soon_threadsafe(async_dispatcher_send, hass, signal, *args)
@callback
@bind_hass
def async_dispatcher_send(hass, signal, *args):
"""Send signal and data.