1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-27 14:31:13 +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

@@ -8,6 +8,7 @@ There are two different types of discoveries that can be fired/listened for.
import asyncio
from homeassistant import setup, core
from homeassistant.loader import bind_hass
from homeassistant.const import (
ATTR_DISCOVERED, ATTR_SERVICE, EVENT_PLATFORM_DISCOVERED)
from homeassistant.exceptions import HomeAssistantError
@@ -18,6 +19,7 @@ EVENT_LOAD_PLATFORM = 'load_platform.{}'
ATTR_PLATFORM = 'platform'
@bind_hass
def listen(hass, service, callback):
"""Set up listener for discovery of specific service.
@@ -28,6 +30,7 @@ def listen(hass, service, callback):
@core.callback
@bind_hass
def async_listen(hass, service, callback):
"""Set up listener for discovery of specific service.
@@ -48,6 +51,7 @@ def async_listen(hass, service, callback):
hass.bus.async_listen(EVENT_PLATFORM_DISCOVERED, discovery_event_listener)
@bind_hass
def discover(hass, service, discovered=None, component=None, hass_config=None):
"""Fire discovery event. Can ensure a component is loaded."""
hass.add_job(
@@ -55,6 +59,7 @@ def discover(hass, service, discovered=None, component=None, hass_config=None):
@asyncio.coroutine
@bind_hass
def async_discover(hass, service, discovered=None, component=None,
hass_config=None):
"""Fire discovery event. Can ensure a component is loaded."""
@@ -76,6 +81,7 @@ def async_discover(hass, service, discovered=None, component=None,
hass.bus.async_fire(EVENT_PLATFORM_DISCOVERED, data)
@bind_hass
def listen_platform(hass, component, callback):
"""Register a platform loader listener."""
run_callback_threadsafe(
@@ -83,6 +89,7 @@ def listen_platform(hass, component, callback):
).result()
@bind_hass
def async_listen_platform(hass, component, callback):
"""Register a platform loader listener.
@@ -109,6 +116,7 @@ def async_listen_platform(hass, component, callback):
EVENT_PLATFORM_DISCOVERED, discovery_platform_listener)
@bind_hass
def load_platform(hass, component, platform, discovered=None,
hass_config=None):
"""Load a component and platform dynamically.
@@ -127,6 +135,7 @@ def load_platform(hass, component, platform, discovered=None,
@asyncio.coroutine
@bind_hass
def async_load_platform(hass, component, platform, discovered=None,
hass_config=None):
"""Load a component and platform dynamically.