Async syntax 7, switch & tts & vacuum (#17021)
This commit is contained in:
parent
9aaf11de8c
commit
121dba659c
20 changed files with 163 additions and 253 deletions
|
@ -80,11 +80,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
config.get(CONF_MAC).encode().replace(b':', b''))
|
||||
switch_type = config.get(CONF_TYPE)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _learn_command(call):
|
||||
async def _learn_command(call):
|
||||
"""Handle a learn command."""
|
||||
try:
|
||||
auth = yield from hass.async_add_job(broadlink_device.auth)
|
||||
auth = await hass.async_add_job(broadlink_device.auth)
|
||||
except socket.timeout:
|
||||
_LOGGER.error("Failed to connect to device, timeout")
|
||||
return
|
||||
|
@ -92,12 +91,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
_LOGGER.error("Failed to connect to device")
|
||||
return
|
||||
|
||||
yield from hass.async_add_job(broadlink_device.enter_learning)
|
||||
await hass.async_add_job(broadlink_device.enter_learning)
|
||||
|
||||
_LOGGER.info("Press the key you want Home Assistant to learn")
|
||||
start_time = utcnow()
|
||||
while (utcnow() - start_time) < timedelta(seconds=20):
|
||||
packet = yield from hass.async_add_job(
|
||||
packet = await hass.async_add_job(
|
||||
broadlink_device.check_data)
|
||||
if packet:
|
||||
log_msg = "Received packet is: {}".\
|
||||
|
@ -106,13 +105,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
hass.components.persistent_notification.async_create(
|
||||
log_msg, title='Broadlink switch')
|
||||
return
|
||||
yield from asyncio.sleep(1, loop=hass.loop)
|
||||
await asyncio.sleep(1, loop=hass.loop)
|
||||
_LOGGER.error("Did not received any signal")
|
||||
hass.components.persistent_notification.async_create(
|
||||
"Did not received any signal", title='Broadlink switch')
|
||||
|
||||
@asyncio.coroutine
|
||||
def _send_packet(call):
|
||||
async def _send_packet(call):
|
||||
"""Send a packet."""
|
||||
packets = call.data.get('packet', [])
|
||||
for packet in packets:
|
||||
|
@ -122,12 +120,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
if extra > 0:
|
||||
packet = packet + ('=' * (4 - extra))
|
||||
payload = b64decode(packet)
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
broadlink_device.send_data, payload)
|
||||
break
|
||||
except (socket.timeout, ValueError):
|
||||
try:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
broadlink_device.auth)
|
||||
except socket.timeout:
|
||||
if retry == DEFAULT_RETRY-1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue