diff --git a/homeassistant/components/__init__.py b/homeassistant/components/__init__.py index f0c4f7bb3e238..06e28c42b13c6 100644 --- a/homeassistant/components/__init__.py +++ b/homeassistant/components/__init__.py @@ -167,7 +167,7 @@ def async_handle_turn_service(service): def async_handle_core_service(call): """Service handler for handling core services.""" if call.service == SERVICE_HOMEASSISTANT_STOP: - hass.async_add_job(hass.async_stop()) + hass.async_create_task(hass.async_stop()) return try: @@ -183,7 +183,7 @@ def async_handle_core_service(call): return if call.service == SERVICE_HOMEASSISTANT_RESTART: - hass.async_add_job(hass.async_stop(RESTART_EXIT_CODE)) + hass.async_create_task(hass.async_stop(RESTART_EXIT_CODE)) hass.services.async_register( ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP, async_handle_core_service) diff --git a/homeassistant/components/alarm_control_panel/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py index 84a72945a7e26..0a4dd6bde784e 100644 --- a/homeassistant/components/alarm_control_panel/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -187,7 +187,7 @@ def async_alarm_disarm(self, code=None): This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.alarm_disarm, code) + return self.hass.async_add_executor_job(self.alarm_disarm, code) def alarm_arm_home(self, code=None): """Send arm home command.""" @@ -198,7 +198,7 @@ def async_alarm_arm_home(self, code=None): This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.alarm_arm_home, code) + return self.hass.async_add_executor_job(self.alarm_arm_home, code) def alarm_arm_away(self, code=None): """Send arm away command.""" @@ -209,7 +209,7 @@ def async_alarm_arm_away(self, code=None): This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.alarm_arm_away, code) + return self.hass.async_add_executor_job(self.alarm_arm_away, code) def alarm_arm_night(self, code=None): """Send arm night command.""" @@ -220,7 +220,7 @@ def async_alarm_arm_night(self, code=None): This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.alarm_arm_night, code) + return self.hass.async_add_executor_job(self.alarm_arm_night, code) def alarm_trigger(self, code=None): """Send alarm trigger command.""" @@ -231,7 +231,7 @@ def async_alarm_trigger(self, code=None): This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.alarm_trigger, code) + return self.hass.async_add_executor_job(self.alarm_trigger, code) def alarm_arm_custom_bypass(self, code=None): """Send arm custom bypass command.""" @@ -242,7 +242,8 @@ def async_alarm_arm_custom_bypass(self, code=None): This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.alarm_arm_custom_bypass, code) + return self.hass.async_add_executor_job( + self.alarm_arm_custom_bypass, code) @property def state_attributes(self): diff --git a/homeassistant/components/alert.py b/homeassistant/components/alert.py index 9d47e4bd322f1..80a02b3275d6d 100644 --- a/homeassistant/components/alert.py +++ b/homeassistant/components/alert.py @@ -68,7 +68,7 @@ def turn_on(hass, entity_id): def async_turn_on(hass, entity_id): """Async reset the alert.""" data = {ATTR_ENTITY_ID: entity_id} - hass.async_add_job( + hass.async_create_task( hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data)) @@ -81,7 +81,7 @@ def turn_off(hass, entity_id): def async_turn_off(hass, entity_id): """Async acknowledge the alert.""" data = {ATTR_ENTITY_ID: entity_id} - hass.async_add_job( + hass.async_create_task( hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data)) @@ -94,7 +94,7 @@ def toggle(hass, entity_id): def async_toggle(hass, entity_id): """Async toggle acknowledgement of alert.""" data = {ATTR_ENTITY_ID: entity_id} - hass.async_add_job( + hass.async_create_task( hass.services.async_call(DOMAIN, SERVICE_TOGGLE, data)) @@ -217,7 +217,7 @@ def begin_alerting(self): else: yield from self._schedule_notify() - self.hass.async_add_job(self.async_update_ha_state) + self.async_schedule_update_ha_state() @asyncio.coroutine def end_alerting(self): @@ -228,7 +228,7 @@ def end_alerting(self): self._firing = False if self._done_message and self._send_done_message: yield from self._notify_done_message() - self.hass.async_add_job(self.async_update_ha_state) + self.async_schedule_update_ha_state() @asyncio.coroutine def _schedule_notify(self): diff --git a/homeassistant/components/android_ip_webcam.py b/homeassistant/components/android_ip_webcam.py index 13fa64438d378..5da117e74c382 100644 --- a/homeassistant/components/android_ip_webcam.py +++ b/homeassistant/components/android_ip_webcam.py @@ -214,11 +214,11 @@ def async_update_data(now): CONF_PASSWORD: password }) - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'camera', 'mjpeg', mjpeg_camera, config)) if sensors: - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'sensor', DOMAIN, { CONF_NAME: name, CONF_HOST: host, @@ -226,7 +226,7 @@ def async_update_data(now): }, config)) if switches: - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'switch', DOMAIN, { CONF_NAME: name, CONF_HOST: host, @@ -234,7 +234,7 @@ def async_update_data(now): }, config)) if motion: - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'binary_sensor', DOMAIN, { CONF_HOST: host, CONF_NAME: name, diff --git a/homeassistant/components/apple_tv.py b/homeassistant/components/apple_tv.py index 68445092db7e6..958e4a197775f 100644 --- a/homeassistant/components/apple_tv.py +++ b/homeassistant/components/apple_tv.py @@ -218,10 +218,10 @@ def _setup_atv(hass, atv_config): ATTR_POWER: power } - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'media_player', DOMAIN, atv_config)) - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'remote', DOMAIN, atv_config)) diff --git a/homeassistant/components/cast/__init__.py b/homeassistant/components/cast/__init__.py index a4ee25f0915c9..966107bcb36ae 100644 --- a/homeassistant/components/cast/__init__.py +++ b/homeassistant/components/cast/__init__.py @@ -14,7 +14,7 @@ async def async_setup(hass, config): async def async_setup_entry(hass, entry): """Set up Cast from a config entry.""" - hass.async_add_job(hass.config_entries.async_forward_entry_setup( + hass.async_create_task(hass.config_entries.async_forward_entry_setup( entry, 'media_player')) return True @@ -23,7 +23,7 @@ async def _async_has_devices(hass): """Return if there are devices that can be discovered.""" from pychromecast.discovery import discover_chromecasts - return await hass.async_add_job(discover_chromecasts) + return await hass.async_add_executor_job(discover_chromecasts) config_entry_flow.register_discovery_flow( diff --git a/homeassistant/components/deconz/__init__.py b/homeassistant/components/deconz/__init__.py index 414d4b0766c82..e0982c65f3344 100644 --- a/homeassistant/components/deconz/__init__.py +++ b/homeassistant/components/deconz/__init__.py @@ -97,7 +97,7 @@ def async_add_device_callback(device_type, device): hass.data[DATA_DECONZ_UNSUB] = [] for component in ['binary_sensor', 'light', 'scene', 'sensor']: - hass.async_add_job(hass.config_entries.async_forward_entry_setup( + hass.async_create_task(hass.config_entries.async_forward_entry_setup( config_entry, component)) @callback diff --git a/homeassistant/components/eight_sleep.py b/homeassistant/components/eight_sleep.py index 704eab1846bb7..209fa7ba87933 100644 --- a/homeassistant/components/eight_sleep.py +++ b/homeassistant/components/eight_sleep.py @@ -143,12 +143,12 @@ async def async_update_user_data(now): # No users, cannot continue return False - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'sensor', DOMAIN, { CONF_SENSORS: sensors, }, config)) - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'binary_sensor', DOMAIN, { CONF_BINARY_SENSORS: binary_sensors, }, config)) diff --git a/homeassistant/components/envisalink.py b/homeassistant/components/envisalink.py index 5ffd97ef0e31d..7dd4e7dc32ae6 100644 --- a/homeassistant/components/envisalink.py +++ b/homeassistant/components/envisalink.py @@ -167,21 +167,21 @@ def stop_envisalink(event): # Load sub-components for Envisalink if partitions: - hass.async_add_job(async_load_platform( + hass.async_create_task(async_load_platform( hass, 'alarm_control_panel', 'envisalink', { CONF_PARTITIONS: partitions, CONF_CODE: code, CONF_PANIC: panic_type }, config )) - hass.async_add_job(async_load_platform( + hass.async_create_task(async_load_platform( hass, 'sensor', 'envisalink', { CONF_PARTITIONS: partitions, CONF_CODE: code }, config )) if zones: - hass.async_add_job(async_load_platform( + hass.async_create_task(async_load_platform( hass, 'binary_sensor', 'envisalink', { CONF_ZONES: zones }, config diff --git a/homeassistant/components/homematicip_cloud/hap.py b/homeassistant/components/homematicip_cloud/hap.py index 57bb9488ee83f..9715a5fc02400 100644 --- a/homeassistant/components/homematicip_cloud/hap.py +++ b/homeassistant/components/homematicip_cloud/hap.py @@ -117,7 +117,7 @@ async def retry_setup(_now): self.config_entry.data.get(HMIPC_HAPID)) for component in COMPONENTS: - self.hass.async_add_job( + self.hass.async_create_task( self.hass.config_entries.async_forward_entry_setup( self.config_entry, component) ) diff --git a/homeassistant/components/hue/bridge.py b/homeassistant/components/hue/bridge.py index f528de462efec..b7cf0e1de07d3 100644 --- a/homeassistant/components/hue/bridge.py +++ b/homeassistant/components/hue/bridge.py @@ -78,7 +78,7 @@ async def retry_setup(_now): host) return False - hass.async_add_job(hass.config_entries.async_forward_entry_setup( + hass.async_create_task(hass.config_entries.async_forward_entry_setup( self.config_entry, 'light')) hass.services.async_register( diff --git a/homeassistant/components/insteon_plm/__init__.py b/homeassistant/components/insteon_plm/__init__.py index 7845b47e21894..055015b74f5de 100644 --- a/homeassistant/components/insteon_plm/__init__.py +++ b/homeassistant/components/insteon_plm/__init__.py @@ -148,7 +148,7 @@ def async_plm_new_device(device): device.states[state_key].name, platform) - hass.async_add_job( + hass.async_create_task( discovery.async_load_platform( hass, platform, DOMAIN, discovered={'address': device.address.id, diff --git a/homeassistant/components/knx.py b/homeassistant/components/knx.py index c6101230031cc..5b3af3029b4f4 100644 --- a/homeassistant/components/knx.py +++ b/homeassistant/components/knx.py @@ -107,7 +107,7 @@ async def async_setup(hass, config): ('scene', 'Scene'), ('notify', 'Notification')): found_devices = _get_devices(hass, discovery_type) - hass.async_add_job( + hass.async_create_task( discovery.async_load_platform(hass, component, DOMAIN, { ATTR_DISCOVER_DEVICES: found_devices }, config)) diff --git a/homeassistant/components/lutron_caseta.py b/homeassistant/components/lutron_caseta.py index 7b1b7417cfd98..2535fb7612090 100644 --- a/homeassistant/components/lutron_caseta.py +++ b/homeassistant/components/lutron_caseta.py @@ -63,8 +63,8 @@ def async_setup(hass, base_config): _LOGGER.info("Connected to Lutron smartbridge at %s", config[CONF_HOST]) for component in LUTRON_CASETA_COMPONENTS: - hass.async_add_job(discovery.async_load_platform(hass, component, - DOMAIN, {}, config)) + hass.async_create_task(discovery.async_load_platform( + hass, component, DOMAIN, {}, config)) return True diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py index a7de62cd32928..8c80604d1881e 100644 --- a/homeassistant/components/mysensors/gateway.py +++ b/homeassistant/components/mysensors/gateway.py @@ -178,7 +178,7 @@ async def _discover_persistent_devices(hass, gateway): @callback def _discover_mysensors_platform(hass, platform, new_devices): """Discover a MySensors platform.""" - task = hass.async_add_job(discovery.async_load_platform( + task = hass.async_create_task(discovery.async_load_platform( hass, platform, DOMAIN, {ATTR_DEVICES: new_devices, CONF_NAME: DOMAIN})) return task diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index 23a331b21b2df..4406062c82140 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -127,7 +127,7 @@ async def async_setup_entry(hass, entry): return False for component in 'climate', 'camera', 'sensor', 'binary_sensor': - hass.async_add_job(hass.config_entries.async_forward_entry_setup( + hass.async_create_task(hass.config_entries.async_forward_entry_setup( entry, component)) def set_mode(service): diff --git a/homeassistant/components/rainmachine/__init__.py b/homeassistant/components/rainmachine/__init__.py index b6546f2e67b72..9f15c8b373fa6 100644 --- a/homeassistant/components/rainmachine/__init__.py +++ b/homeassistant/components/rainmachine/__init__.py @@ -151,7 +151,7 @@ async def async_setup(hass, config): ('sensor', conf[CONF_SENSORS]), ('switch', conf[CONF_SWITCHES]), ]: - hass.async_add_job( + hass.async_create_task( discovery.async_load_platform(hass, component, DOMAIN, schema, config)) diff --git a/homeassistant/components/sabnzbd.py b/homeassistant/components/sabnzbd.py index a7b33b4c69702..b9c75c87c1d1e 100644 --- a/homeassistant/components/sabnzbd.py +++ b/homeassistant/components/sabnzbd.py @@ -134,7 +134,7 @@ def async_setup_sabnzbd(hass, sab_api, config, name): if config.get(CONF_SENSORS): hass.data[DATA_SABNZBD] = sab_api_data - hass.async_add_job( + hass.async_create_task( discovery.async_load_platform(hass, 'sensor', DOMAIN, {}, config)) async def async_service_handler(service): diff --git a/homeassistant/components/satel_integra.py b/homeassistant/components/satel_integra.py index 4247855da39d6..128377d19f761 100644 --- a/homeassistant/components/satel_integra.py +++ b/homeassistant/components/satel_integra.py @@ -98,10 +98,10 @@ def _close(): conf, conf.get(CONF_ARM_HOME_MODE)) - task_control_panel = hass.async_add_job( + task_control_panel = hass.async_create_task( async_load_platform(hass, 'alarm_control_panel', DOMAIN, conf, config)) - task_zones = hass.async_add_job( + task_zones = hass.async_create_task( async_load_platform(hass, 'binary_sensor', DOMAIN, {CONF_ZONES: zones}, config)) diff --git a/homeassistant/components/sonos/__init__.py b/homeassistant/components/sonos/__init__.py index 7c3de21076815..c67a3dffaaf22 100644 --- a/homeassistant/components/sonos/__init__.py +++ b/homeassistant/components/sonos/__init__.py @@ -14,7 +14,7 @@ async def async_setup(hass, config): async def async_setup_entry(hass, entry): """Set up Sonos from a config entry.""" - hass.async_add_job(hass.config_entries.async_forward_entry_setup( + hass.async_create_task(hass.config_entries.async_forward_entry_setup( entry, 'media_player')) return True @@ -23,7 +23,7 @@ async def _async_has_devices(hass): """Return if there are devices that can be discovered.""" import soco - return await hass.async_add_job(soco.discover) + return await hass.async_add_executor_job(soco.discover) config_entry_flow.register_discovery_flow(DOMAIN, 'Sonos', _async_has_devices) diff --git a/homeassistant/components/spc.py b/homeassistant/components/spc.py index 52d4165f3fafd..bf7db87f06b37 100644 --- a/homeassistant/components/spc.py +++ b/homeassistant/components/spc.py @@ -56,14 +56,14 @@ def async_setup(hass, config): # add sensor devices for each zone (typically motion/fire/door sensors) zones = yield from api.get_zones() if zones: - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'binary_sensor', DOMAIN, {ATTR_DISCOVER_DEVICES: zones}, config)) # create a separate alarm panel for each area areas = yield from api.get_areas() if areas: - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'alarm_control_panel', DOMAIN, {ATTR_DISCOVER_AREAS: areas}, config)) diff --git a/homeassistant/components/tradfri.py b/homeassistant/components/tradfri.py index 9ed613abde04e..b2e41902552bf 100644 --- a/homeassistant/components/tradfri.py +++ b/homeassistant/components/tradfri.py @@ -166,8 +166,8 @@ async def _setup_gateway(hass, hass_config, host, identity, key, return True gateways[gateway_id] = gateway - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'light', DOMAIN, {'gateway': gateway_id}, hass_config)) - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'sensor', DOMAIN, {'gateway': gateway_id}, hass_config)) return True diff --git a/homeassistant/components/upnp.py b/homeassistant/components/upnp.py index 8aeb93fed25f3..b4fe9d3fce9c6 100644 --- a/homeassistant/components/upnp.py +++ b/homeassistant/components/upnp.py @@ -88,7 +88,7 @@ async def async_setup(hass, config): service = device.find_first_service(IP_SERVICE) if _service['serviceType'] == CIC_SERVICE: unit = config.get(CONF_UNITS) - hass.async_add_job(discovery.async_load_platform( + hass.async_create_task(discovery.async_load_platform( hass, 'sensor', DOMAIN, {'unit': unit}, config)) except UpnpSoapError as error: _LOGGER.error(error) diff --git a/homeassistant/components/velux.py b/homeassistant/components/velux.py index 47daf17f2a925..c3c6c1e211400 100644 --- a/homeassistant/components/velux.py +++ b/homeassistant/components/velux.py @@ -39,7 +39,7 @@ async def async_setup(hass, config): return False for component in SUPPORTED_DOMAINS: - hass.async_add_job( + hass.async_create_task( discovery.async_load_platform(hass, component, DOMAIN, {}, config)) return True diff --git a/homeassistant/helpers/discovery.py b/homeassistant/helpers/discovery.py index cb587c432c181..7d0730a969c68 100644 --- a/homeassistant/helpers/discovery.py +++ b/homeassistant/helpers/discovery.py @@ -145,7 +145,7 @@ async def async_load_platform(hass, component, platform, discovered=None, Use `listen_platform` to register a callback for these events. Warning: Do not await this inside a setup method to avoid a dead lock. - Use `hass.async_add_job(async_load_platform(..))` instead. + Use `hass.async_create_task(async_load_platform(..))` instead. This method is a coroutine. """ diff --git a/tests/components/deconz/test_init.py b/tests/components/deconz/test_init.py index 1cee08feb0a27..8f5342de1e3ad 100644 --- a/tests/components/deconz/test_init.py +++ b/tests/components/deconz/test_init.py @@ -91,7 +91,7 @@ async def test_setup_entry_successful(hass): """Test setup entry is successful.""" entry = Mock() entry.data = {'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'} - with patch.object(hass, 'async_add_job') as mock_add_job, \ + with patch.object(hass, 'async_create_task') as mock_add_job, \ patch.object(hass, 'config_entries') as mock_config_entries, \ patch('pydeconz.DeconzSession.async_load_parameters', return_value=mock_coro(True)):