diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index eeda1db51fc..5f64fd447a6 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -83,8 +83,7 @@ def async_from_config_dict(config: Dict[str, Any], conf_util.async_log_exception(ex, 'homeassistant', core_config, hass) return None - yield from hass.loop.run_in_executor( - None, conf_util.process_ha_config_upgrade, hass) + yield from hass.async_add_job(conf_util.process_ha_config_upgrade, hass) if enable_log: async_enable_logging(hass, verbose, log_rotate_days) @@ -95,7 +94,7 @@ def async_from_config_dict(config: Dict[str, Any], 'This may cause issues.') if not loader.PREPARED: - yield from hass.loop.run_in_executor(None, loader.prepare, hass) + yield from hass.async_add_job(loader.prepare, hass) # Merge packages conf_util.merge_packages_config( @@ -184,14 +183,13 @@ def async_from_config_file(config_path: str, # Set config dir to directory holding config file config_dir = os.path.abspath(os.path.dirname(config_path)) hass.config.config_dir = config_dir - yield from hass.loop.run_in_executor( - None, mount_local_lib_path, config_dir) + yield from hass.async_add_job(mount_local_lib_path, config_dir) async_enable_logging(hass, verbose, log_rotate_days) try: - config_dict = yield from hass.loop.run_in_executor( - None, conf_util.load_yaml_config_file, config_path) + config_dict = yield from hass.async_add_job( + conf_util.load_yaml_config_file, config_path) except HomeAssistantError as err: _LOGGER.error('Error loading %s: %s', config_path, err) return None diff --git a/homeassistant/components/alarm_control_panel/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py index a13abfae8f9..80c5e0ad1cc 100644 --- a/homeassistant/components/alarm_control_panel/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -123,8 +123,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')) for service in SERVICE_TO_METHOD: @@ -158,8 +158,7 @@ class AlarmControlPanel(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.alarm_disarm, code) + return self.hass.async_add_job(self.alarm_disarm, code) def alarm_arm_home(self, code=None): """Send arm home command.""" @@ -170,8 +169,7 @@ class AlarmControlPanel(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.alarm_arm_home, code) + return self.hass.async_add_job(self.alarm_arm_home, code) def alarm_arm_away(self, code=None): """Send arm away command.""" @@ -182,8 +180,7 @@ class AlarmControlPanel(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.alarm_arm_away, code) + return self.hass.async_add_job(self.alarm_arm_away, code) def alarm_trigger(self, code=None): """Send alarm trigger command.""" @@ -194,8 +191,7 @@ class AlarmControlPanel(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.alarm_trigger, code) + return self.hass.async_add_job(self.alarm_trigger, code) @property def state_attributes(self): diff --git a/homeassistant/components/alarm_control_panel/envisalink.py b/homeassistant/components/alarm_control_panel/envisalink.py index 34919a9db79..6029816ba76 100644 --- a/homeassistant/components/alarm_control_panel/envisalink.py +++ b/homeassistant/components/alarm_control_panel/envisalink.py @@ -70,8 +70,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): device.async_alarm_keypress(keypress) # Register Envisalink specific services - 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( diff --git a/homeassistant/components/alert.py b/homeassistant/components/alert.py index 24c14e7c9a8..09db0f84346 100644 --- a/homeassistant/components/alert.py +++ b/homeassistant/components/alert.py @@ -128,8 +128,8 @@ def async_setup(hass, config): all_alerts[entity.entity_id] = entity # Read descriptions - 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')) descriptions = descriptions.get(DOMAIN, {}) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 9227222d479..a99113b6f6f 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -158,8 +158,8 @@ def async_setup(hass, config): yield from _async_process_config(hass, config, component) - descriptions = yield from hass.loop.run_in_executor( - None, conf_util.load_yaml_config_file, os.path.join( + descriptions = yield from hass.async_add_job( + conf_util.load_yaml_config_file, os.path.join( os.path.dirname(__file__), 'services.yaml') ) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 79f0757d006..d33dc996afd 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -138,7 +138,7 @@ class Camera(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor(None, self.camera_image) + return self.hass.async_add_job(self.camera_image) @asyncio.coroutine def handle_async_mjpeg_stream(self, request): diff --git a/homeassistant/components/camera/generic.py b/homeassistant/components/camera/generic.py index 83164c55230..8a9854ab97e 100644 --- a/homeassistant/components/camera/generic.py +++ b/homeassistant/components/camera/generic.py @@ -103,8 +103,8 @@ class GenericCamera(Camera): _LOGGER.error("Error getting camera image: %s", error) return self._last_image - self._last_image = yield from self.hass.loop.run_in_executor( - None, fetch) + self._last_image = yield from self.hass.async_add_job( + fetch) # async else: try: diff --git a/homeassistant/components/camera/mjpeg.py b/homeassistant/components/camera/mjpeg.py index 1e9859fe7c2..6168eb81939 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -88,8 +88,8 @@ class MjpegCamera(Camera): # DigestAuth is not supported if self._authentication == HTTP_DIGEST_AUTHENTICATION or \ self._still_image_url is None: - image = yield from self.hass.loop.run_in_executor( - None, self.camera_image) + image = yield from self.hass.async_add_job( + self.camera_image) return image websession = async_get_clientsession(self.hass) diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 2e2dfbef8ca..f9405e4b040 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -213,8 +213,8 @@ def async_setup(hass, config): component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL) yield from component.async_setup(config) - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) @asyncio.coroutine @@ -569,8 +569,8 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.set_temperature, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.set_temperature, **kwargs)) def set_humidity(self, humidity): """Set new target humidity.""" @@ -581,8 +581,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_humidity, humidity) + return self.hass.async_add_job(self.set_humidity, humidity) def set_fan_mode(self, fan): """Set new target fan mode.""" @@ -593,8 +592,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_fan_mode, fan) + return self.hass.async_add_job(self.set_fan_mode, fan) def set_operation_mode(self, operation_mode): """Set new target operation mode.""" @@ -605,8 +603,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_operation_mode, operation_mode) + return self.hass.async_add_job(self.set_operation_mode, operation_mode) def set_swing_mode(self, swing_mode): """Set new target swing operation.""" @@ -617,8 +614,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_swing_mode, swing_mode) + return self.hass.async_add_job(self.set_swing_mode, swing_mode) def turn_away_mode_on(self): """Turn away mode on.""" @@ -629,8 +625,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.turn_away_mode_on) + return self.hass.async_add_job(self.turn_away_mode_on) def turn_away_mode_off(self): """Turn away mode off.""" @@ -641,8 +636,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.turn_away_mode_off) + return self.hass.async_add_job(self.turn_away_mode_off) def set_hold_mode(self, hold_mode): """Set new target hold mode.""" @@ -653,8 +647,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_hold_mode, hold_mode) + return self.hass.async_add_job(self.set_hold_mode, hold_mode) def turn_aux_heat_on(self): """Turn auxillary heater on.""" @@ -665,8 +658,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.turn_aux_heat_on) + return self.hass.async_add_job(self.turn_aux_heat_on) def turn_aux_heat_off(self): """Turn auxillary heater off.""" @@ -677,8 +669,7 @@ class ClimateDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.turn_aux_heat_off) + return self.hass.async_add_job(self.turn_aux_heat_off) @property def min_temp(self): diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index bbee0e836a3..f913d126c4a 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -175,8 +175,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')) for service_name in SERVICE_TO_METHOD: @@ -263,8 +263,7 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.open_cover, **kwargs)) + return self.hass.async_add_job(ft.partial(self.open_cover, **kwargs)) def close_cover(self, **kwargs): """Close cover.""" @@ -275,8 +274,7 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.close_cover, **kwargs)) + return self.hass.async_add_job(ft.partial(self.close_cover, **kwargs)) def set_cover_position(self, **kwargs): """Move the cover to a specific position.""" @@ -287,8 +285,8 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.set_cover_position, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.set_cover_position, **kwargs)) def stop_cover(self, **kwargs): """Stop the cover.""" @@ -299,8 +297,7 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.stop_cover, **kwargs)) + return self.hass.async_add_job(ft.partial(self.stop_cover, **kwargs)) def open_cover_tilt(self, **kwargs): """Open the cover tilt.""" @@ -311,8 +308,8 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.open_cover_tilt, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.open_cover_tilt, **kwargs)) def close_cover_tilt(self, **kwargs): """Close the cover tilt.""" @@ -323,8 +320,8 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.close_cover_tilt, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.close_cover_tilt, **kwargs)) def set_cover_tilt_position(self, **kwargs): """Move the cover tilt to a specific position.""" @@ -335,8 +332,8 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.set_cover_tilt_position, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.set_cover_tilt_position, **kwargs)) def stop_cover_tilt(self, **kwargs): """Stop the cover.""" @@ -347,5 +344,5 @@ class CoverDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.stop_cover_tilt, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.stop_cover_tilt, **kwargs)) diff --git a/homeassistant/components/device_tracker/gpslogger.py b/homeassistant/components/device_tracker/gpslogger.py index 733127cb0f2..81961b13f7f 100644 --- a/homeassistant/components/device_tracker/gpslogger.py +++ b/homeassistant/components/device_tracker/gpslogger.py @@ -75,10 +75,10 @@ class GPSLoggerView(HomeAssistantView): if 'activity' in data: attrs['activity'] = data['activity'] - yield from hass.loop.run_in_executor( - None, partial(self.see, dev_id=device, - gps=gps_location, battery=battery, - gps_accuracy=accuracy, - attributes=attrs)) + yield from hass.async_add_job( + partial(self.see, dev_id=device, + gps=gps_location, battery=battery, + gps_accuracy=accuracy, + attributes=attrs)) return 'Setting location for {}'.format(device) diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index 668ee6dd8a0..b41326c4192 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -79,10 +79,9 @@ class LocativeView(HomeAssistantView): gps_location = (data[ATTR_LATITUDE], data[ATTR_LONGITUDE]) if direction == 'enter': - yield from hass.loop.run_in_executor( - None, partial(self.see, dev_id=device, - location_name=location_name, - gps=gps_location)) + yield from hass.async_add_job( + partial(self.see, dev_id=device, location_name=location_name, + gps=gps_location)) return 'Setting location to {}'.format(location_name) elif direction == 'exit': @@ -91,10 +90,9 @@ class LocativeView(HomeAssistantView): if current_state is None or current_state.state == location_name: location_name = STATE_NOT_HOME - yield from hass.loop.run_in_executor( - None, partial(self.see, dev_id=device, - location_name=location_name, - gps=gps_location)) + yield from hass.async_add_job( + partial(self.see, dev_id=device, + location_name=location_name, gps=gps_location)) return 'Setting location to not home' else: # Ignore the message if it is telling us to exit a zone that we diff --git a/homeassistant/components/discovery.py b/homeassistant/components/discovery.py index 261d8953940..a068deb076c 100644 --- a/homeassistant/components/discovery.py +++ b/homeassistant/components/discovery.py @@ -115,8 +115,7 @@ def async_setup(hass, config): @asyncio.coroutine def scan_devices(now): """Scan for devices.""" - results = yield from hass.loop.run_in_executor( - None, _discover, netdisco) + results = yield from hass.async_add_job(_discover, netdisco) for result in results: hass.async_add_job(new_service_found(*result)) diff --git a/homeassistant/components/eight_sleep.py b/homeassistant/components/eight_sleep.py index 3a2929f4bd1..db8af964fed 100644 --- a/homeassistant/components/eight_sleep.py +++ b/homeassistant/components/eight_sleep.py @@ -159,8 +159,8 @@ def async_setup(hass, config): CONF_BINARY_SENSORS: binary_sensors, }, config)) - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) @asyncio.coroutine diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 500cebfe73b..54c503c1b9f 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -229,8 +229,8 @@ def async_setup(hass, config: dict): yield from asyncio.wait(update_tasks, loop=hass.loop) # Listen for fan service calls. - 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')) for service_name in SERVICE_TO_METHOD: @@ -256,7 +256,7 @@ class FanEntity(ToggleEntity): """ if speed is SPEED_OFF: return self.async_turn_off() - return self.hass.loop.run_in_executor(None, self.set_speed, speed) + return self.hass.async_add_job(self.set_speed, speed) def set_direction(self: ToggleEntity, direction: str) -> None: """Set the direction of the fan.""" @@ -267,8 +267,7 @@ class FanEntity(ToggleEntity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_direction, direction) + return self.hass.async_add_job(self.set_direction, direction) def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None: """Turn on the fan.""" @@ -281,8 +280,8 @@ class FanEntity(ToggleEntity): """ if speed is SPEED_OFF: return self.async_turn_off() - return self.hass.loop.run_in_executor( - None, ft.partial(self.turn_on, speed, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.turn_on, speed, **kwargs)) def oscillate(self: ToggleEntity, oscillating: bool) -> None: """Oscillate the fan.""" @@ -293,8 +292,7 @@ class FanEntity(ToggleEntity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.oscillate, oscillating) + return self.hass.async_add_job(self.oscillate, oscillating) @property def is_on(self): diff --git a/homeassistant/components/ffmpeg.py b/homeassistant/components/ffmpeg.py index 959962f02ac..45bd651ad95 100644 --- a/homeassistant/components/ffmpeg.py +++ b/homeassistant/components/ffmpeg.py @@ -89,8 +89,8 @@ def async_setup(hass, config): conf.get(CONF_RUN_TEST, DEFAULT_RUN_TEST) ) - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) # Register service diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 617db06be2c..8d55ad879fa 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -268,8 +268,8 @@ class IndexView(HomeAssistantView): no_auth = 'true' icons_url = '/static/mdi-{}.html'.format(FINGERPRINTS['mdi.html']) - template = yield from hass.loop.run_in_executor( - None, self.templates.get_template, 'index.html') + template = yield from hass.async_add_job( + self.templates.get_template, 'index.html') # pylint is wrong # pylint: disable=no-member diff --git a/homeassistant/components/group.py b/homeassistant/components/group.py index 2e97ef9ef3b..f207a9b8b62 100644 --- a/homeassistant/components/group.py +++ b/homeassistant/components/group.py @@ -173,8 +173,8 @@ def async_setup(hass, config): yield from _async_process_config(hass, config, component) - descriptions = yield from hass.loop.run_in_executor( - None, conf_util.load_yaml_config_file, os.path.join( + descriptions = yield from hass.async_add_job( + conf_util.load_yaml_config_file, os.path.join( os.path.dirname(__file__), 'services.yaml') ) diff --git a/homeassistant/components/history.py b/homeassistant/components/history.py index 70c61589bb3..5a960ae894b 100644 --- a/homeassistant/components/history.py +++ b/homeassistant/components/history.py @@ -233,9 +233,9 @@ class HistoryPeriodView(HomeAssistantView): end_time = start_time + one_day entity_id = request.GET.get('filter_entity_id') - result = yield from request.app['hass'].loop.run_in_executor( - None, get_significant_states, request.app['hass'], start_time, - end_time, entity_id, self.filters) + result = yield from request.app['hass'].async_add_job( + get_significant_states, request.app['hass'], start_time, end_time, + entity_id, self.filters) result = result.values() if _LOGGER.isEnabledFor(logging.DEBUG): elapsed = time.perf_counter() - timer_start diff --git a/homeassistant/components/http/ban.py b/homeassistant/components/http/ban.py index 53635af9fc8..d2b9fa402ef 100644 --- a/homeassistant/components/http/ban.py +++ b/homeassistant/components/http/ban.py @@ -40,8 +40,8 @@ def ban_middleware(app, handler): if KEY_BANNED_IPS not in app: hass = app['hass'] - app[KEY_BANNED_IPS] = yield from hass.loop.run_in_executor( - None, load_ip_bans_config, hass.config.path(IP_BANS_FILE)) + app[KEY_BANNED_IPS] = yield from hass.async_add_job( + load_ip_bans_config, hass.config.path(IP_BANS_FILE)) @asyncio.coroutine def ban_middleware_handler(request): @@ -90,9 +90,8 @@ def process_wrong_login(request): request.app[KEY_BANNED_IPS].append(new_ban) hass = request.app['hass'] - yield from hass.loop.run_in_executor( - None, update_ip_bans_config, hass.config.path(IP_BANS_FILE), - new_ban) + yield from hass.async_add_job( + update_ip_bans_config, hass.config.path(IP_BANS_FILE), new_ban) _LOGGER.warning( "Banned IP %s for too many login attempts", remote_addr) diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index 7ca8b48931b..fb1cddcad61 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -72,8 +72,8 @@ def async_setup(hass, config): yield from component.async_setup(config) - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) @asyncio.coroutine @@ -117,7 +117,7 @@ class ImageProcessingEntity(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor(None, self.process_image, image) + return self.hass.async_add_job(self.process_image, image) @asyncio.coroutine def async_update(self): diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 92db75d1e50..2065513630b 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -285,8 +285,8 @@ def async_setup(hass, config): yield from asyncio.wait(update_tasks, loop=hass.loop) # Listen for light on and light off service calls. - 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( @@ -341,8 +341,7 @@ class Profiles: return None return profiles - cls._all = yield from hass.loop.run_in_executor( - None, load_profile_data, hass) + cls._all = yield from hass.async_add_job(load_profile_data, hass) return cls._all is not None @classmethod diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index 7d3e75595e2..27af8d28764 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -108,8 +108,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( @@ -150,8 +150,7 @@ class LockDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.lock, **kwargs)) + return self.hass.async_add_job(ft.partial(self.lock, **kwargs)) def unlock(self, **kwargs): """Unlock the lock.""" @@ -162,8 +161,7 @@ class LockDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.unlock, **kwargs)) + return self.hass.async_add_job(ft.partial(self.unlock, **kwargs)) @property def state_attributes(self): diff --git a/homeassistant/components/logbook.py b/homeassistant/components/logbook.py index 053648e3428..29c69409774 100644 --- a/homeassistant/components/logbook.py +++ b/homeassistant/components/logbook.py @@ -134,8 +134,8 @@ class LogbookView(HomeAssistantView): end_day = start_day + timedelta(days=1) hass = request.app['hass'] - events = yield from hass.loop.run_in_executor( - None, _get_events, hass, start_day, end_day) + events = yield from hass.async_add_job( + _get_events, hass, start_day, end_day) events = _exclude_events(events, self.config) return self.json(humanify(events)) diff --git a/homeassistant/components/logger.py b/homeassistant/components/logger.py index 94a3ad902da..6b79bd40987 100644 --- a/homeassistant/components/logger.py +++ b/homeassistant/components/logger.py @@ -123,8 +123,8 @@ def async_setup(hass, config): """Handle logger services.""" set_log_levels(service.data) - 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( diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 97712e1c0ad..47d018d0849 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -353,8 +353,8 @@ def async_setup(hass, config): yield from component.async_setup(config) - 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')) @asyncio.coroutine @@ -583,8 +583,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.turn_on) + return self.hass.async_add_job(self.turn_on) def turn_off(self): """Turn the media player off.""" @@ -595,8 +594,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.turn_off) + return self.hass.async_add_job(self.turn_off) def mute_volume(self, mute): """Mute the volume.""" @@ -607,8 +605,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.mute_volume, mute) + return self.hass.async_add_job(self.mute_volume, mute) def set_volume_level(self, volume): """Set volume level, range 0..1.""" @@ -619,8 +616,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_volume_level, volume) + return self.hass.async_add_job(self.set_volume_level, volume) def media_play(self): """Send play commmand.""" @@ -631,8 +627,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.media_play) + return self.hass.async_add_job(self.media_play) def media_pause(self): """Send pause command.""" @@ -643,8 +638,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.media_pause) + return self.hass.async_add_job(self.media_pause) def media_stop(self): """Send stop command.""" @@ -655,8 +649,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.media_stop) + return self.hass.async_add_job(self.media_stop) def media_previous_track(self): """Send previous track command.""" @@ -667,8 +660,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.media_previous_track) + return self.hass.async_add_job(self.media_previous_track) def media_next_track(self): """Send next track command.""" @@ -679,8 +671,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.media_next_track) + return self.hass.async_add_job(self.media_next_track) def media_seek(self, position): """Send seek command.""" @@ -691,8 +682,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.media_seek, position) + return self.hass.async_add_job(self.media_seek, position) def play_media(self, media_type, media_id, **kwargs): """Play a piece of media.""" @@ -703,8 +693,8 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.play_media, media_type, media_id, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.play_media, media_type, media_id, **kwargs)) def select_source(self, source): """Select input source.""" @@ -715,8 +705,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.select_source, source) + return self.hass.async_add_job(self.select_source, source) def clear_playlist(self): """Clear players playlist.""" @@ -727,8 +716,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.clear_playlist) + return self.hass.async_add_job(self.clear_playlist) def set_shuffle(self, shuffle): """Enable/disable shuffle mode.""" @@ -739,8 +727,7 @@ class MediaPlayerDevice(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, self.set_shuffle, shuffle) + return self.hass.async_add_job(self.set_shuffle, shuffle) # No need to overwrite these. @property @@ -810,7 +797,7 @@ class MediaPlayerDevice(Entity): """ if hasattr(self, 'toggle'): # pylint: disable=no-member - return self.hass.loop.run_in_executor(None, self.toggle) + return self.hass.async_add_job(self.toggle) if self.state in [STATE_OFF, STATE_IDLE]: return self.async_turn_on() @@ -825,7 +812,7 @@ class MediaPlayerDevice(Entity): """ if hasattr(self, 'volume_up'): # pylint: disable=no-member - yield from self.hass.loop.run_in_executor(None, self.volume_up) + yield from self.hass.async_add_job(self.volume_up) return if self.volume_level < 1: @@ -840,7 +827,7 @@ class MediaPlayerDevice(Entity): """ if hasattr(self, 'volume_down'): # pylint: disable=no-member - yield from self.hass.loop.run_in_executor(None, self.volume_down) + yield from self.hass.async_add_job(self.volume_down) return if self.volume_level > 0: @@ -854,7 +841,7 @@ class MediaPlayerDevice(Entity): """ if hasattr(self, 'media_play_pause'): # pylint: disable=no-member - return self.hass.loop.run_in_executor(None, self.media_play_pause) + return self.hass.async_add_job(self.media_play_pause) if self.state == STATE_PLAYING: return self.async_media_pause() diff --git a/homeassistant/components/media_player/kodi.py b/homeassistant/components/media_player/kodi.py index 9861887df89..b7cc45b68f5 100644 --- a/homeassistant/components/media_player/kodi.py +++ b/homeassistant/components/media_player/kodi.py @@ -175,8 +175,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): if hass.services.has_service(DOMAIN, SERVICE_ADD_MEDIA): return - 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')) for service in SERVICE_TO_METHOD: diff --git a/homeassistant/components/microsoft_face.py b/homeassistant/components/microsoft_face.py index a2a52b68665..49d79ccaea0 100644 --- a/homeassistant/components/microsoft_face.py +++ b/homeassistant/components/microsoft_face.py @@ -133,8 +133,8 @@ def async_setup(hass, config): hass.data[DATA_MICROSOFT_FACE] = face - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) @asyncio.coroutine diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index b4701ad4690..f4b57f0c803 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -403,8 +403,8 @@ def async_setup(hass, config): yield from hass.data[DATA_MQTT].async_publish( msg_topic, payload, qos, retain) - 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( @@ -477,8 +477,8 @@ class MQTT(object): This method must be run in the event loop and returns a coroutine. """ with (yield from self._paho_lock): - yield from self.hass.loop.run_in_executor( - None, self._mqttc.publish, topic, payload, qos, retain) + yield from self.hass.async_add_job( + self._mqttc.publish, topic, payload, qos, retain) @asyncio.coroutine def async_connect(self): @@ -486,8 +486,8 @@ class MQTT(object): This method is a coroutine. """ - result = yield from self.hass.loop.run_in_executor( - None, self._mqttc.connect, self.broker, self.port, self.keepalive) + result = yield from self.hass.async_add_job( + self._mqttc.connect, self.broker, self.port, self.keepalive) if result != 0: import paho.mqtt.client as mqtt @@ -507,7 +507,7 @@ class MQTT(object): self._mqttc.disconnect() self._mqttc.loop_stop() - return self.hass.loop.run_in_executor(None, stop) + return self.hass.async_add_job(stop) @asyncio.coroutine def async_subscribe(self, topic, qos): @@ -522,8 +522,8 @@ class MQTT(object): if topic in self.topics: return - result, mid = yield from self.hass.loop.run_in_executor( - None, self._mqttc.subscribe, topic, qos) + result, mid = yield from self.hass.async_add_job( + self._mqttc.subscribe, topic, qos) _raise_on_error(result) self.progress[mid] = topic @@ -535,8 +535,8 @@ class MQTT(object): This method is a coroutine. """ - result, mid = yield from self.hass.loop.run_in_executor( - None, self._mqttc.unsubscribe, topic) + result, mid = yield from self.hass.async_add_job( + self._mqttc.unsubscribe, topic) _raise_on_error(result) self.progress[mid] = topic diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index cf05629ce1b..f9f9d04c05c 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -69,8 +69,8 @@ def send_message(hass, message, title=None, data=None): @asyncio.coroutine def async_setup(hass, config): """Set up the notify services.""" - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) targets = {} @@ -97,8 +97,8 @@ def async_setup(hass, config): notify_service = yield from \ platform.async_get_service(hass, p_config, discovery_info) elif hasattr(platform, 'get_service'): - notify_service = yield from hass.loop.run_in_executor( - None, platform.get_service, hass, p_config, discovery_info) + notify_service = yield from hass.async_add_job( + platform.get_service, hass, p_config, discovery_info) else: raise HomeAssistantError("Invalid notify platform.") @@ -192,5 +192,5 @@ class BaseNotificationService(object): kwargs can contain ATTR_TITLE to specify a title. This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, partial(self.send_message, message, **kwargs)) + return self.hass.async_add_job( + partial(self.send_message, message, **kwargs)) diff --git a/homeassistant/components/persistent_notification.py b/homeassistant/components/persistent_notification.py index 7173045c06d..5e36c471562 100644 --- a/homeassistant/components/persistent_notification.py +++ b/homeassistant/components/persistent_notification.py @@ -92,8 +92,8 @@ def async_setup(hass, config): hass.states.async_set(entity_id, message, attr) - 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(DOMAIN, SERVICE_CREATE, create_service, diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index a28ebd666f9..40a419eaa58 100755 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -140,8 +140,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( DOMAIN, SERVICE_TURN_OFF, async_handle_remote_service, @@ -171,5 +171,4 @@ class RemoteDevice(ToggleEntity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.send_command, **kwargs)) + return self.hass.async_add_job(ft.partial(self.send_command, **kwargs)) diff --git a/homeassistant/components/remote/kira.py b/homeassistant/components/remote/kira.py index 7ab73068cdb..6f167bfdd05 100755 --- a/homeassistant/components/remote/kira.py +++ b/homeassistant/components/remote/kira.py @@ -75,5 +75,4 @@ class KiraRemote(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.send_command, **kwargs)) + return self.hass.async_add_job(ft.partial(self.send_command, **kwargs)) diff --git a/homeassistant/components/rflink.py b/homeassistant/components/rflink.py index 33feb8c034b..74772943691 100644 --- a/homeassistant/components/rflink.py +++ b/homeassistant/components/rflink.py @@ -371,7 +371,7 @@ class RflinkCommand(RflinkDevice): # Rflink protocol/transport handles asynchronous writing of buffer # to serial/tcp device. Does not wait for command send # confirmation. - self.hass.loop.run_in_executor(None, ft.partial( + self.hass.async_add_job(ft.partial( self._protocol.send_command, self._device_id, cmd)) if repetitions > 1: diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index 5b147fbb656..dd46f469a55 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -112,4 +112,4 @@ class Scene(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor(None, self.activate) + return self.hass.async_add_job(self.activate) diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 786319f4200..0af5dcf4a5c 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -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( diff --git a/homeassistant/components/switch/broadlink.py b/homeassistant/components/switch/broadlink.py index 91bcf6c4aa5..9de81fb9402 100644 --- a/homeassistant/components/switch/broadlink.py +++ b/homeassistant/components/switch/broadlink.py @@ -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") diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index e55d3a089e9..e8f0bc9eeec 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -179,8 +179,8 @@ def load_data(url=None, file=None, username=None, password=None): def async_setup(hass, config): """Set up the Telegram bot component.""" conf = config[DOMAIN] - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) @asyncio.coroutine diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index c91ab47a324..f82d3fa5e88 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -96,8 +96,8 @@ def async_setup(hass, config): hass.http.register_view(TextToSpeechView(tts)) - descriptions = yield from hass.loop.run_in_executor( - None, load_yaml_config_file, + descriptions = yield from hass.async_add_job( + load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')) @asyncio.coroutine @@ -113,8 +113,8 @@ def async_setup(hass, config): provider = yield from platform.async_get_engine( hass, p_config) else: - provider = yield from hass.loop.run_in_executor( - None, platform.get_engine, hass, p_config) + provider = yield from hass.async_add_job( + platform.get_engine, hass, p_config) if provider is None: _LOGGER.error("Error setting up platform %s", p_type) @@ -207,8 +207,8 @@ class SpeechManager(object): return cache_dir try: - self.cache_dir = yield from self.hass.loop.run_in_executor( - None, init_tts_cache_dir, cache_dir) + self.cache_dir = yield from self.hass.async_add_job( + init_tts_cache_dir, cache_dir) except OSError as err: raise HomeAssistantError("Can't init cache dir {}".format(err)) @@ -228,8 +228,7 @@ class SpeechManager(object): return cache try: - cache_files = yield from self.hass.loop.run_in_executor( - None, get_cache_files) + cache_files = yield from self.hass.async_add_job(get_cache_files) except OSError as err: raise HomeAssistantError("Can't read cache dir {}".format(err)) @@ -250,7 +249,7 @@ class SpeechManager(object): _LOGGER.warning( "Can't remove cache file '%s': %s", filename, err) - yield from self.hass.loop.run_in_executor(None, remove_files) + yield from self.hass.async_add_job(remove_files) self.file_cache = {} @callback @@ -355,7 +354,7 @@ class SpeechManager(object): speech.write(data) try: - yield from self.hass.loop.run_in_executor(None, save_speech) + yield from self.hass.async_add_job(save_speech) self.file_cache[key] = filename except OSError: _LOGGER.error("Can't write %s", filename) @@ -378,7 +377,7 @@ class SpeechManager(object): return speech.read() try: - data = yield from self.hass.loop.run_in_executor(None, load_speech) + data = yield from self.hass.async_add_job(load_speech) except OSError: del self.file_cache[key] raise HomeAssistantError("Can't read {}".format(voice_file)) @@ -490,9 +489,8 @@ class Provider(object): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial( - self.get_tts_audio, message, language, options=options)) + return self.hass.async_add_job( + ft.partial(self.get_tts_audio, message, language, options=options)) class TextToSpeechView(HomeAssistantView): diff --git a/homeassistant/components/tts/google.py b/homeassistant/components/tts/google.py index 24e96a239b2..9b12507de36 100644 --- a/homeassistant/components/tts/google.py +++ b/homeassistant/components/tts/google.py @@ -80,8 +80,8 @@ class GoogleProvider(Provider): data = b'' for idx, part in enumerate(message_parts): - part_token = yield from self.hass.loop.run_in_executor( - None, token.calculate_token, part) + part_token = yield from self.hass.async_add_job( + token.calculate_token, part) url_param = { 'ie': 'UTF-8', diff --git a/homeassistant/config.py b/homeassistant/config.py index 1d86953c0cc..d0d7cedf370 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -231,7 +231,7 @@ def async_hass_config_yaml(hass): conf = load_yaml_config_file(path) return conf - conf = yield from hass.loop.run_in_executor(None, _load_hass_yaml_config) + conf = yield from hass.async_add_job(_load_hass_yaml_config) return conf @@ -404,8 +404,8 @@ def async_process_ha_core_config(hass, config): # If we miss some of the needed values, auto detect them if None in (hac.latitude, hac.longitude, hac.units, hac.time_zone): - info = yield from hass.loop.run_in_executor( - None, loc_util.detect_location_info) + info = yield from hass.async_add_job( + loc_util.detect_location_info) if info is None: _LOGGER.error('Could not detect location information') @@ -430,8 +430,8 @@ def async_process_ha_core_config(hass, config): if hac.elevation is None and hac.latitude is not None and \ hac.longitude is not None: - elevation = yield from hass.loop.run_in_executor( - None, loc_util.elevation, hac.latitude, hac.longitude) + elevation = yield from hass.async_add_job( + loc_util.elevation, hac.latitude, hac.longitude) hac.elevation = elevation discovered.append(('elevation', elevation)) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index f687d1e808f..767b3412caf 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -221,8 +221,7 @@ class Entity(object): # pylint: disable=no-member yield from self.async_update() else: - yield from self.hass.loop.run_in_executor( - None, self.update) + yield from self.hass.async_add_job(self.update) except Exception: # pylint: disable=broad-except _LOGGER.exception("Update for %s fails", self.entity_id) return @@ -363,8 +362,8 @@ class ToggleEntity(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.turn_on, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.turn_on, **kwargs)) def turn_off(self, **kwargs) -> None: """Turn the entity off.""" @@ -375,8 +374,8 @@ class ToggleEntity(Entity): This method must be run in the event loop and returns a coroutine. """ - return self.hass.loop.run_in_executor( - None, ft.partial(self.turn_off, **kwargs)) + return self.hass.async_add_job( + ft.partial(self.turn_off, **kwargs)) def toggle(self) -> None: """Toggle the entity.""" diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 9ebad3862f3..58c12bf043e 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -151,8 +151,8 @@ class EntityComponent(object): entity_platform.async_schedule_add_entities, discovery_info ) else: - task = self.hass.loop.run_in_executor( - None, platform.setup_platform, self.hass, platform_config, + task = self.hass.async_add_job( + platform.setup_platform, self.hass, platform_config, entity_platform.schedule_add_entities, discovery_info ) yield from asyncio.wait_for( @@ -195,7 +195,7 @@ class EntityComponent(object): if hasattr(entity, 'async_update'): yield from entity.async_update() else: - yield from self.hass.loop.run_in_executor(None, entity.update) + yield from self.hass.async_add_job(entity.update) if getattr(entity, 'entity_id', None) is None: object_id = entity.name or DEVICE_DEFAULT_NAME diff --git a/homeassistant/helpers/restore_state.py b/homeassistant/helpers/restore_state.py index 08e7a91397a..3afbac5c8dd 100644 --- a/homeassistant/helpers/restore_state.py +++ b/homeassistant/helpers/restore_state.py @@ -76,8 +76,8 @@ def async_get_last_state(hass, entity_id: str): with (yield from hass.data[_LOCK]): if DATA_RESTORE_CACHE not in hass.data: - yield from hass.loop.run_in_executor( - None, _load_restore_cache, hass) + yield from hass.async_add_job( + _load_restore_cache, hass) return hass.data.get(DATA_RESTORE_CACHE, {}).get(entity_id) diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 96d27e3494b..e3a520fff0e 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -83,7 +83,7 @@ def _async_process_requirements(hass: core.HomeAssistant, name: str, with (yield from pip_lock): for req in requirements: - ret = yield from hass.loop.run_in_executor(None, pip_install, req) + ret = yield from hass.async_add_job(pip_install, req) if not ret: _LOGGER.error("Not initializing %s because could not install " "dependency %s", name, req) @@ -184,8 +184,8 @@ def _async_setup_component(hass: core.HomeAssistant, if async_comp: result = yield from component.async_setup(hass, processed_config) else: - result = yield from hass.loop.run_in_executor( - None, component.setup, hass, processed_config) + result = yield from hass.async_add_job( + component.setup, hass, processed_config) except Exception: # pylint: disable=broad-except _LOGGER.exception("Error during setup of component %s", domain) async_notify_setup_error(hass, domain, True) diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index f205b2bcc95..644c8894874 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -31,26 +31,21 @@ def test_generate_entity_id_given_keys(): 'test.another_entity']) == 'test.overwrite_hidden_true' -def test_async_update_support(event_loop): +def test_async_update_support(hass): """Test async update getting called.""" sync_update = [] async_update = [] class AsyncEntity(entity.Entity): - hass = MagicMock() entity_id = 'sensor.test' def update(self): sync_update.append([1]) ent = AsyncEntity() - ent.hass.loop = event_loop + ent.hass = hass - @asyncio.coroutine - def test(): - yield from ent.async_update_ha_state(True) - - event_loop.run_until_complete(test()) + hass.loop.run_until_complete(ent.async_update_ha_state(True)) assert len(sync_update) == 1 assert len(async_update) == 0 @@ -62,7 +57,7 @@ def test_async_update_support(event_loop): ent.async_update = async_update_func - event_loop.run_until_complete(test()) + hass.loop.run_until_complete(ent.async_update_ha_state(True)) assert len(sync_update) == 1 assert len(async_update) == 1