Async syntax 5, light & lock & remote & scene & telegram & helpers (#17019)
This commit is contained in:
1 parent
9e4c8f45d6
commit
3b5e5cbcd6
28 files changed
+112
-195
No files matched your search
@@ -4,7 +4,6 @@ Component to interface with universal remote control devices.
|
||||
For more details about this component, please refer to the documentation
|
||||
at https://home-assistant.io/components/remote/
|
||||
"""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
@@ -70,12 +69,11 @@ def is_on(hass, entity_id=None):
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Track states and offer events for remotes."""
|
||||
component = EntityComponent(
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_REMOTES)
|
||||
yield from component.async_setup(config)
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_TURN_OFF, REMOTE_SERVICE_ACTIVITY_SCHEMA,
|
||||
|
||||
@@ -4,7 +4,6 @@ Remote control support for Apple TV.
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/remote.apple_tv/
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.apple_tv import (
|
||||
ATTR_ATV, ATTR_POWER, DATA_APPLE_TV)
|
||||
@@ -15,9 +14,8 @@ from homeassistant.const import (CONF_NAME, CONF_HOST)
|
||||
DEPENDENCIES = ['apple_tv']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Apple TV remote platform."""
|
||||
if not discovery_info:
|
||||
return
|
||||
@@ -59,16 +57,14 @@ class AppleTVRemote(remote.RemoteDevice):
|
||||
"""No polling needed for Apple TV."""
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on.
|
||||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
self._power.set_power_on(True)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off.
|
||||
|
||||
This method is a coroutine.
|
||||
@@ -81,12 +77,11 @@ class AppleTVRemote(remote.RemoteDevice):
|
||||
This method must be run in the event loop and returns a coroutine.
|
||||
"""
|
||||
# Send commands in specified order but schedule only one coroutine
|
||||
@asyncio.coroutine
|
||||
def _send_commands():
|
||||
async def _send_commands():
|
||||
for single_command in command:
|
||||
if not hasattr(self._atv.remote_control, single_command):
|
||||
continue
|
||||
|
||||
yield from getattr(self._atv.remote_control, single_command)()
|
||||
await getattr(self._atv.remote_control, single_command)()
|
||||
|
||||
return _send_commands()
|
||||
@@ -4,7 +4,6 @@ Support for Harmony Hub devices.
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/remote.harmony/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
|
||||
@@ -152,8 +151,7 @@ class HarmonyRemote(remote.RemoteDevice):
|
||||
pyharmony.ha_write_config_file(self._config, self._config_path)
|
||||
self._delay_secs = delay_secs
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Complete the initialization."""
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
|
||||
@@ -61,9 +61,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Xiaomi IR Remote (Chuangmi IR) platform."""
|
||||
from miio import ChuangmiIr, DeviceException
|
||||
|
||||
@@ -109,8 +108,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
||||
|
||||
async_add_entities([xiaomi_miio_remote])
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_service_handler(service):
|
||||
async def async_service_handler(service):
|
||||
"""Handle a learn command."""
|
||||
if service.service != SERVICE_LEARN:
|
||||
_LOGGER.error("We should not handle service: %s", service.service)
|
||||
@@ -130,14 +128,14 @@ def async_setup_platform(hass, config, async_add_entities,
|
||||
|
||||
slot = service.data.get(CONF_SLOT, entity.slot)
|
||||
|
||||
yield from hass.async_add_job(device.learn, slot)
|
||||
await hass.async_add_job(device.learn, slot)
|
||||
|
||||
timeout = service.data.get(CONF_TIMEOUT, entity.timeout)
|
||||
|
||||
_LOGGER.info("Press the key you want Home Assistant to learn")
|
||||
start_time = utcnow()
|
||||
while (utcnow() - start_time) < timedelta(seconds=timeout):
|
||||
message = yield from hass.async_add_job(
|
||||
message = await hass.async_add_job(
|
||||
device.read, slot)
|
||||
_LOGGER.debug("Message received from device: '%s'", message)
|
||||
|
||||
@@ -150,9 +148,9 @@ def async_setup_platform(hass, config, async_add_entities,
|
||||
|
||||
if ('error' in message and
|
||||
message['error']['message'] == "learn timeout"):
|
||||
yield from hass.async_add_job(device.learn, slot)
|
||||
await hass.async_add_job(device.learn, slot)
|
||||
|
||||
yield from asyncio.sleep(1, loop=hass.loop)
|
||||
await asyncio.sleep(1, loop=hass.loop)
|
||||
|
||||
_LOGGER.error("Timeout. No infrared command captured")
|
||||
hass.components.persistent_notification.async_create(
|
||||
@@ -230,14 +228,12 @@ class XiaomiMiioRemote(RemoteDevice):
|
||||
return {'hidden': 'true'}
|
||||
return
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
_LOGGER.error("Device does not support turn_on, "
|
||||
"please use 'remote.send_command' to send commands.")
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
_LOGGER.error("Device does not support turn_off, "
|
||||
"please use 'remote.send_command' to send commands.")
|
||||
|
||||
Reference in new issue
Block a user