Async syntax 4/8 (#17018)
* Async syntax 4, media_player & notify * Pylint fixes
This commit is contained in:
1 parent
3b5e5cbcd6
commit
134eeecd65
17 files changed
+212
-314
No files matched your search
@@ -49,18 +49,16 @@ NOTIFY_SERVICE_SCHEMA = vol.Schema({
|
||||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the notify services."""
|
||||
targets = {}
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(p_type, p_config=None, discovery_info=None):
|
||||
async def async_setup_platform(p_type, p_config=None, discovery_info=None):
|
||||
"""Set up a notify platform."""
|
||||
if p_config is None:
|
||||
p_config = {}
|
||||
|
||||
platform = yield from async_prepare_setup_platform(
|
||||
platform = await async_prepare_setup_platform(
|
||||
hass, config, DOMAIN, p_type)
|
||||
|
||||
if platform is None:
|
||||
@@ -71,10 +69,10 @@ def async_setup(hass, config):
|
||||
notify_service = None
|
||||
try:
|
||||
if hasattr(platform, 'async_get_service'):
|
||||
notify_service = yield from \
|
||||
notify_service = await \
|
||||
platform.async_get_service(hass, p_config, discovery_info)
|
||||
elif hasattr(platform, 'get_service'):
|
||||
notify_service = yield from hass.async_add_job(
|
||||
notify_service = await hass.async_add_job(
|
||||
platform.get_service, hass, p_config, discovery_info)
|
||||
else:
|
||||
raise HomeAssistantError("Invalid notify platform.")
|
||||
@@ -97,8 +95,7 @@ def async_setup(hass, config):
|
||||
if discovery_info is None:
|
||||
discovery_info = {}
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_notify_message(service):
|
||||
async def async_notify_message(service):
|
||||
"""Handle sending notification message service calls."""
|
||||
kwargs = {}
|
||||
message = service.data[ATTR_MESSAGE]
|
||||
@@ -117,7 +114,7 @@ def async_setup(hass, config):
|
||||
kwargs[ATTR_MESSAGE] = message.async_render()
|
||||
kwargs[ATTR_DATA] = service.data.get(ATTR_DATA)
|
||||
|
||||
yield from notify_service.async_send_message(**kwargs)
|
||||
await notify_service.async_send_message(**kwargs)
|
||||
|
||||
if hasattr(notify_service, 'targets'):
|
||||
platform_name = (
|
||||
@@ -147,12 +144,11 @@ def async_setup(hass, config):
|
||||
in config_per_platform(config, DOMAIN)]
|
||||
|
||||
if setup_tasks:
|
||||
yield from asyncio.wait(setup_tasks, loop=hass.loop)
|
||||
await asyncio.wait(setup_tasks, loop=hass.loop)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_platform_discovered(platform, info):
|
||||
async def async_platform_discovered(platform, info):
|
||||
"""Handle for discovered platform."""
|
||||
yield from async_setup_platform(platform, discovery_info=info)
|
||||
await async_setup_platform(platform, discovery_info=info)
|
||||
|
||||
discovery.async_listen_platform(hass, DOMAIN, async_platform_discovered)
|
||||
|
||||
|
||||
Reference in new issue
Block a user