Replace executor with async_add_job (#7658)

* Remove executor

* Lint

* Lint

* Fix tests
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2017-05-26 08:28:07 -07:00
1 parent 9e9705d6b2
commit f43db3c615
46 files changed
+196 -248

No files matched your search

+8 -10
View File
@@ -72,8 +72,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
@asyncio.coroutine
def _learn_command(call):
try:
auth = yield from hass.loop.run_in_executor(None,
broadlink_device.auth)
auth = yield from hass.async_add_job(broadlink_device.auth)
except socket.timeout:
_LOGGER.error("Failed to connect to device, timeout")
return
@@ -81,14 +80,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error("Failed to connect to device")
return
yield from hass.loop.run_in_executor(
None, broadlink_device.enter_learning)
yield from hass.async_add_job(broadlink_device.enter_learning)
_LOGGER.info("Press the key you want HASS to learn")
start_time = utcnow()
while (utcnow() - start_time) < timedelta(seconds=20):
packet = yield from hass.loop.run_in_executor(
None, broadlink_device.check_data)
packet = yield from hass.async_add_job(
broadlink_device.check_data)
if packet:
log_msg = "Recieved packet is: {}".\
format(b64encode(packet).decode('utf8'))
@@ -108,13 +106,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for retry in range(DEFAULT_RETRY):
try:
payload = b64decode(packet)
yield from hass.loop.run_in_executor(
None, broadlink_device.send_data, payload)
yield from hass.async_add_job(
broadlink_device.send_data, payload)
break
except (socket.timeout, ValueError):
try:
yield from hass.loop.run_in_executor(
None, broadlink_device.auth)
yield from hass.async_add_job(
broadlink_device.auth)
except socket.timeout:
if retry == DEFAULT_RETRY-1:
_LOGGER.error("Failed to send packet to device")