Replace executor with async_add_job (#7658)
* Remove executor * Lint * Lint * Fix tests
This commit is contained in:
1 parent
9e9705d6b2
commit
f43db3c615
46 files changed
+196
-248
No files matched your search
@@ -122,8 +122,8 @@ def async_setup(hass, config):
|
||||
if update_tasks:
|
||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||
|
||||
descriptions = yield from hass.loop.run_in_executor(
|
||||
None, load_yaml_config_file, os.path.join(
|
||||
descriptions = yield from hass.async_add_job(
|
||||
load_yaml_config_file, os.path.join(
|
||||
os.path.dirname(__file__), 'services.yaml'))
|
||||
|
||||
hass.services.async_register(
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user