diff --git a/homeassistant/components/apple_tv.py b/homeassistant/components/apple_tv.py index 96e31e6bbf1..012e71a08a7 100644 --- a/homeassistant/components/apple_tv.py +++ b/homeassistant/components/apple_tv.py @@ -252,4 +252,4 @@ class AppleTVPowerManager: self.atv.push_updater.start() for listener in self.listeners: - self.hass.async_add_job(listener.async_update_ha_state()) + self.hass.async_create_task(listener.async_update_ha_state()) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 2cf23e0d60c..5897d972b31 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -183,7 +183,7 @@ async def async_setup(hass, config): """Update tokens of the entities.""" for entity in component.entities: entity.async_update_token() - hass.async_add_job(entity.async_update_ha_state()) + hass.async_create_task(entity.async_update_ha_state()) hass.helpers.event.async_track_time_interval( update_tokens, TOKEN_CHANGE_INTERVAL) diff --git a/homeassistant/components/cloud/iot.py b/homeassistant/components/cloud/iot.py index fd525ed33a8..fe89c263488 100644 --- a/homeassistant/components/cloud/iot.py +++ b/homeassistant/components/cloud/iot.py @@ -79,7 +79,7 @@ class CloudIoT: try: # Sleep 2^tries seconds between retries - self.retry_task = hass.async_add_job(asyncio.sleep( + self.retry_task = hass.async_create_task(asyncio.sleep( 2**min(9, self.tries), loop=hass.loop)) yield from self.retry_task self.retry_task = None @@ -106,7 +106,7 @@ class CloudIoT: 'cloud_subscription_expired') # Don't await it because it will cancel this task - hass.async_add_job(self.cloud.logout()) + hass.async_create_task(self.cloud.logout()) return except auth_api.CloudError as err: _LOGGER.warning("Unable to refresh token: %s", err) diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index df0e2f13ac1..f2cfff1f342 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -52,7 +52,7 @@ async def async_setup(hass, config): """Respond to components being loaded.""" panel_name = event.data.get(ATTR_COMPONENT) if panel_name in ON_DEMAND: - hass.async_add_job(setup_panel(panel_name)) + hass.async_create_task(setup_panel(panel_name)) hass.bus.async_listen(EVENT_COMPONENT_LOADED, component_loaded) @@ -136,7 +136,7 @@ class BaseEditConfigView(HomeAssistantView): await hass.async_add_job(_write, path, current) if self.post_write_hook is not None: - hass.async_add_job(self.post_write_hook(hass)) + hass.async_create_task(self.post_write_hook(hass)) return self.json({ 'result': 'ok', diff --git a/homeassistant/components/config/auth.py b/homeassistant/components/config/auth.py index f2af6589f11..6da0fe61d96 100644 --- a/homeassistant/components/config/auth.py +++ b/homeassistant/components/config/auth.py @@ -52,7 +52,7 @@ def websocket_list(hass, connection, msg): connection.send_message( websocket_api.result_message(msg['id'], result)) - hass.async_add_job(send_users()) + hass.async_create_task(send_users()) @callback @@ -79,7 +79,7 @@ def websocket_delete(hass, connection, msg): connection.send_message( websocket_api.result_message(msg['id'])) - hass.async_add_job(delete_user()) + hass.async_create_task(delete_user()) @callback @@ -95,7 +95,7 @@ def websocket_create(hass, connection, msg): 'user': _user_info(user) })) - hass.async_add_job(create_user()) + hass.async_create_task(create_user()) def _user_info(user): diff --git a/homeassistant/components/config/device_registry.py b/homeassistant/components/config/device_registry.py index 54396f8956c..acffd516d21 100644 --- a/homeassistant/components/config/device_registry.py +++ b/homeassistant/components/config/device_registry.py @@ -44,4 +44,4 @@ def websocket_list_devices(hass, connection, msg): } for entry in registry.devices.values()] )) - hass.async_add_job(retrieve_entities()) + hass.async_create_task(retrieve_entities()) diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index b9cc72e5a5a..a9cc122a6f9 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -371,7 +371,7 @@ class DeviceTracker: for device in self.devices.values(): if (device.track and device.last_update_home) and \ device.stale(now): - self.hass.async_add_job(device.async_update_ha_state(True)) + self.hass.async_create_task(device.async_update_ha_state(True)) async def async_setup_tracked_device(self): """Set up all not exists tracked devices. @@ -386,7 +386,7 @@ class DeviceTracker: tasks = [] for device in self.devices.values(): if device.track and not device.last_seen: - tasks.append(self.hass.async_add_job( + tasks.append(self.hass.async_create_task( async_init_single_device(device))) if tasks: @@ -718,10 +718,10 @@ def async_setup_scanner_platform(hass: HomeAssistantType, config: ConfigType, zone_home.attributes[ATTR_LONGITUDE]] kwargs['gps_accuracy'] = 0 - hass.async_add_job(async_see_device(**kwargs)) + hass.async_create_task(async_see_device(**kwargs)) async_track_time_interval(hass, async_device_tracker_scan, interval) - hass.async_add_job(async_device_tracker_scan(None)) + hass.async_create_task(async_device_tracker_scan(None)) def update_config(path: str, dev_id: str, device: Device): diff --git a/homeassistant/components/device_tracker/automatic.py b/homeassistant/components/device_tracker/automatic.py index 4fcc550d7db..9f20eb6d493 100644 --- a/homeassistant/components/device_tracker/automatic.py +++ b/homeassistant/components/device_tracker/automatic.py @@ -113,7 +113,7 @@ def async_setup_scanner(hass, config, async_see, discovery_info=None): # Load the initial vehicle data vehicles = yield from session.get_vehicles() for vehicle in vehicles: - hass.async_add_job(data.load_vehicle(vehicle)) + hass.async_create_task(data.load_vehicle(vehicle)) # Create a task instead of adding a tracking job, since this task will # run until the websocket connection is closed. @@ -188,7 +188,7 @@ class AutomaticAuthCallbackView(HomeAssistantView): code = params['code'] state = params['state'] initialize_callback = hass.data[DATA_CONFIGURING][state] - hass.async_add_job(initialize_callback(code, state)) + hass.async_create_task(initialize_callback(code, state)) return response @@ -209,7 +209,7 @@ class AutomaticData: self.ws_close_requested = False self.client.on_app_event( - lambda name, event: self.hass.async_add_job( + lambda name, event: self.hass.async_create_task( self.handle_event(name, event))) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.ws_close()) diff --git a/homeassistant/components/device_tracker/gpslogger.py b/homeassistant/components/device_tracker/gpslogger.py index 6336ba51d23..f39684aa834 100644 --- a/homeassistant/components/device_tracker/gpslogger.py +++ b/homeassistant/components/device_tracker/gpslogger.py @@ -98,7 +98,7 @@ class GPSLoggerView(HomeAssistantView): if 'activity' in data: attrs['activity'] = data['activity'] - hass.async_add_job(self.async_see( + hass.async_create_task(self.async_see( dev_id=device, gps=gps_location, battery=battery, gps_accuracy=accuracy, diff --git a/homeassistant/components/device_tracker/meraki.py b/homeassistant/components/device_tracker/meraki.py index 416f202ab98..d12aff1127a 100644 --- a/homeassistant/components/device_tracker/meraki.py +++ b/homeassistant/components/device_tracker/meraki.py @@ -121,7 +121,7 @@ class MerakiView(HomeAssistantView): attrs['seenTime'] = i['seenTime'] if i.get('ssid', False): attrs['ssid'] = i['ssid'] - hass.async_add_job(self.async_see( + hass.async_create_task(self.async_see( gps=gps_location, mac=mac, source_type=SOURCE_TYPE_ROUTER, diff --git a/homeassistant/components/device_tracker/mqtt.py b/homeassistant/components/device_tracker/mqtt.py index 3623abf31c3..06bd6d771a4 100644 --- a/homeassistant/components/device_tracker/mqtt.py +++ b/homeassistant/components/device_tracker/mqtt.py @@ -33,7 +33,7 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None): @callback def async_message_received(topic, payload, qos, dev_id=dev_id): """Handle received MQTT message.""" - hass.async_add_job( + hass.async_create_task( async_see(dev_id=dev_id, location_name=payload)) await mqtt.async_subscribe( diff --git a/homeassistant/components/device_tracker/mqtt_json.py b/homeassistant/components/device_tracker/mqtt_json.py index a95180f2eb2..3a820d189f4 100644 --- a/homeassistant/components/device_tracker/mqtt_json.py +++ b/homeassistant/components/device_tracker/mqtt_json.py @@ -55,7 +55,7 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None): return kwargs = _parse_see_args(dev_id, data) - hass.async_add_job(async_see(**kwargs)) + hass.async_create_task(async_see(**kwargs)) await mqtt.async_subscribe( hass, topic, async_message_received, qos) diff --git a/homeassistant/components/discovery.py b/homeassistant/components/discovery.py index 91f9dea704b..9377db52609 100644 --- a/homeassistant/components/discovery.py +++ b/homeassistant/components/discovery.py @@ -168,7 +168,7 @@ async def async_setup(hass, config): results = await hass.async_add_job(_discover, netdisco) for result in results: - hass.async_add_job(new_service_found(*result)) + hass.async_create_task(new_service_found(*result)) async_track_point_in_utc_time(hass, scan_devices, dt_util.utcnow() + SCAN_INTERVAL) @@ -180,7 +180,7 @@ async def async_setup(hass, config): # discovery local services if 'HASSIO' in os.environ: - hass.async_add_job(new_service_found(SERVICE_HASSIO, {})) + hass.async_create_task(new_service_found(SERVICE_HASSIO, {})) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_first) diff --git a/homeassistant/components/emulated_hue/hue_api.py b/homeassistant/components/emulated_hue/hue_api.py index fa24b656d7a..c6fa622513b 100644 --- a/homeassistant/components/emulated_hue/hue_api.py +++ b/homeassistant/components/emulated_hue/hue_api.py @@ -254,11 +254,11 @@ class HueOneLightChangeView(HomeAssistantView): # Separate call to turn on needed if turn_on_needed: - hass.async_add_job(hass.services.async_call( + hass.async_create_task(hass.services.async_call( core.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True)) - hass.async_add_job(hass.services.async_call( + hass.async_create_task(hass.services.async_call( domain, service, data, blocking=True)) json_response = \ diff --git a/homeassistant/components/homematicip_cloud/hap.py b/homeassistant/components/homematicip_cloud/hap.py index 6fddc7c001e..d79e7c1ee14 100644 --- a/homeassistant/components/homematicip_cloud/hap.py +++ b/homeassistant/components/homematicip_cloud/hap.py @@ -142,7 +142,7 @@ class HomematicipHAP: # Explicitly getting an update as device states might have # changed during access point disconnect.""" - job = self.hass.async_add_job(self.get_state()) + job = self.hass.async_create_task(self.get_state()) job.add_done_callback(self.get_state_finished) async def get_state(self): @@ -161,7 +161,7 @@ class HomematicipHAP: # so reconnect loop is taking over. _LOGGER.error( "Updating state after HMIP access point reconnect failed") - self.hass.async_add_job(self.home.disable_events()) + self.hass.async_create_task(self.home.disable_events()) def set_all_to_unavailable(self): """Set all devices to unavailable and tell Home Assistant.""" @@ -212,7 +212,7 @@ class HomematicipHAP: "Retrying in %d seconds", self.config_entry.data.get(HMIPC_HAPID), retry_delay) try: - self._retry_task = self.hass.async_add_job(asyncio.sleep( + self._retry_task = self.hass.async_create_task(asyncio.sleep( retry_delay, loop=self.hass.loop)) await self._retry_task except asyncio.CancelledError: diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 7a781c99f53..8431e5dbe3d 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -108,7 +108,7 @@ async def async_setup(hass, config): # this component we'll have to use hass.async_add_job to avoid a # deadlock: creating a config entry will set up the component but the # setup would block till the entry is created! - hass.async_add_job(hass.config_entries.flow.async_init( + hass.async_create_task(hass.config_entries.flow.async_init( DOMAIN, context={'source': config_entries.SOURCE_IMPORT}, data={ 'host': bridge_conf[CONF_HOST], diff --git a/homeassistant/components/hue/bridge.py b/homeassistant/components/hue/bridge.py index 874c18aaa7e..93241622f0b 100644 --- a/homeassistant/components/hue/bridge.py +++ b/homeassistant/components/hue/bridge.py @@ -50,7 +50,7 @@ class HueBridge: # We are going to fail the config entry setup and initiate a new # linking procedure. When linking succeeds, it will remove the # old config entry. - hass.async_add_job(hass.config_entries.flow.async_init( + hass.async_create_task(hass.config_entries.flow.async_init( DOMAIN, context={'source': config_entries.SOURCE_IMPORT}, data={ 'host': host, diff --git a/homeassistant/components/intent_script.py b/homeassistant/components/intent_script.py index 0c47b8880ba..9c63141e496 100644 --- a/homeassistant/components/intent_script.py +++ b/homeassistant/components/intent_script.py @@ -78,7 +78,7 @@ class ScriptIntentHandler(intent.IntentHandler): if action is not None: if is_async_action: - intent_obj.hass.async_add_job(action.async_run(slots)) + intent_obj.hass.async_create_task(action.async_run(slots)) else: await action.async_run(slots) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 21a501fa6ea..17b9f104f68 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -300,7 +300,7 @@ class LIFXManager: @callback def register(self, bulb): """Handle aiolifx detected bulb.""" - self.hass.async_add_job(self.register_new_bulb(bulb)) + self.hass.async_create_task(self.register_new_bulb(bulb)) async def register_new_bulb(self, bulb): """Handle newly detected bulb.""" @@ -344,7 +344,7 @@ class LIFXManager: entity = self.entities[bulb.mac_addr] _LOGGER.debug("%s unregister", entity.who) entity.registered = False - self.hass.async_add_job(entity.async_update_ha_state()) + self.hass.async_create_task(entity.async_update_ha_state()) class AwaitAioLIFX: @@ -484,12 +484,12 @@ class LIFXLight(Light): async def async_turn_on(self, **kwargs): """Turn the light on.""" kwargs[ATTR_POWER] = True - self.hass.async_add_job(self.set_state(**kwargs)) + self.hass.async_create_task(self.set_state(**kwargs)) async def async_turn_off(self, **kwargs): """Turn the light off.""" kwargs[ATTR_POWER] = False - self.hass.async_add_job(self.set_state(**kwargs)) + self.hass.async_create_task(self.set_state(**kwargs)) async def set_state(self, **kwargs): """Set a color on the light and turn it on/off.""" diff --git a/homeassistant/components/light/template.py b/homeassistant/components/light/template.py index f90147f7169..8aff85c6001 100644 --- a/homeassistant/components/light/template.py +++ b/homeassistant/components/light/template.py @@ -215,7 +215,7 @@ class LightTemplate(Light): optimistic_set = True if ATTR_BRIGHTNESS in kwargs and self._level_script: - self.hass.async_add_job(self._level_script.async_run( + self.hass.async_create_task(self._level_script.async_run( {"brightness": kwargs[ATTR_BRIGHTNESS]})) else: await self._on_script.async_run() diff --git a/homeassistant/components/light/tradfri.py b/homeassistant/components/light/tradfri.py index b62900b204c..a26a2eb828a 100644 --- a/homeassistant/components/light/tradfri.py +++ b/homeassistant/components/light/tradfri.py @@ -127,7 +127,7 @@ class TradfriGroup(Light): cmd = self._group.observe(callback=self._observe_update, err_callback=self._async_start_observe, duration=0) - self.hass.async_add_job(self._api(cmd)) + self.hass.async_create_task(self._api(cmd)) except PytradfriError as err: _LOGGER.warning("Observation failed, trying again", exc_info=err) self._async_start_observe() @@ -346,7 +346,7 @@ class TradfriLight(Light): cmd = self._light.observe(callback=self._observe_update, err_callback=self._async_start_observe, duration=0) - self.hass.async_add_job(self._api(cmd)) + self.hass.async_create_task(self._api(cmd)) except PytradfriError as err: _LOGGER.warning("Observation failed, trying again", exc_info=err) self._async_start_observe() diff --git a/homeassistant/components/media_extractor.py b/homeassistant/components/media_extractor.py index a7093579805..b3c02e5aee6 100644 --- a/homeassistant/components/media_extractor.py +++ b/homeassistant/components/media_extractor.py @@ -148,7 +148,7 @@ class MediaExtractor: if entity_id: data[ATTR_ENTITY_ID] = entity_id - self.hass.async_add_job( + self.hass.async_create_task( self.hass.services.async_call( MEDIA_PLAYER_DOMAIN, SERVICE_PLAY_MEDIA, data) ) diff --git a/homeassistant/components/media_player/anthemav.py b/homeassistant/components/media_player/anthemav.py index c1415f985e8..f1954a1d37e 100644 --- a/homeassistant/components/media_player/anthemav.py +++ b/homeassistant/components/media_player/anthemav.py @@ -49,7 +49,7 @@ async def async_setup_platform(hass, config, async_add_entities, def async_anthemav_update_callback(message): """Receive notification from transport that new data exists.""" _LOGGER.info("Received update callback from AVR: %s", message) - hass.async_add_job(device.async_update_ha_state()) + hass.async_create_task(device.async_update_ha_state()) avr = await anthemav.Connection.create( host=host, port=port, loop=hass.loop, diff --git a/homeassistant/components/media_player/bluesound.py b/homeassistant/components/media_player/bluesound.py index ab012402636..f4ed62b15cd 100644 --- a/homeassistant/components/media_player/bluesound.py +++ b/homeassistant/components/media_player/bluesound.py @@ -96,7 +96,7 @@ def _add_player(hass, async_add_entities, host, port=None, name=None): @callback def _init_player(event=None): """Start polling.""" - hass.async_add_job(player.async_init()) + hass.async_create_task(player.async_init()) @callback def _start_polling(event=None): @@ -272,7 +272,7 @@ class BluesoundPlayer(MediaPlayerDevice): def start_polling(self): """Start the polling task.""" - self._polling_task = self._hass.async_add_job( + self._polling_task = self._hass.async_create_task( self._start_poll_command()) def stop_polling(self): diff --git a/homeassistant/components/media_player/cast.py b/homeassistant/components/media_player/cast.py index 67d8ea0b419..d6515b9476d 100644 --- a/homeassistant/components/media_player/cast.py +++ b/homeassistant/components/media_player/cast.py @@ -343,7 +343,7 @@ class CastDevice(MediaPlayerDevice): # Discovered is not our device. return _LOGGER.debug("Discovered chromecast with same UUID: %s", discover) - self.hass.async_add_job(self.async_set_cast_info(discover)) + self.hass.async_create_task(self.async_set_cast_info(discover)) async def async_stop(event): """Disconnect socket on Home Assistant stop.""" @@ -352,7 +352,7 @@ class CastDevice(MediaPlayerDevice): async_dispatcher_connect(self.hass, SIGNAL_CAST_DISCOVERED, async_cast_discovered) self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop) - self.hass.async_add_job(self.async_set_cast_info(self._cast_info)) + self.hass.async_create_task(self.async_set_cast_info(self._cast_info)) async def async_will_remove_from_hass(self) -> None: """Disconnect Chromecast object when removed.""" diff --git a/homeassistant/components/media_player/kodi.py b/homeassistant/components/media_player/kodi.py index eb97c75c9ef..01d8069dc3b 100644 --- a/homeassistant/components/media_player/kodi.py +++ b/homeassistant/components/media_player/kodi.py @@ -322,7 +322,7 @@ class KodiDevice(MediaPlayerDevice): def on_hass_stop(event): """Close websocket connection when hass stops.""" - self.hass.async_add_job(self._ws_server.close()) + self.hass.async_create_task(self._ws_server.close()) self.hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STOP, on_hass_stop) @@ -387,7 +387,7 @@ class KodiDevice(MediaPlayerDevice): self._properties = {} self._item = {} self._app_properties = {} - self.hass.async_add_job(self._ws_server.close()) + self.hass.async_create_task(self._ws_server.close()) async def _get_players(self): """Return the active player objects or None.""" @@ -456,7 +456,7 @@ class KodiDevice(MediaPlayerDevice): return if self._enable_websocket and not self._ws_server.connected: - self.hass.async_add_job(self.async_ws_connect()) + self.hass.async_create_task(self.async_ws_connect()) self._app_properties = \ await self.server.Application.GetProperties( diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index a9226117b5a..3e25563e9ba 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -254,7 +254,8 @@ def async_publish(hass: HomeAssistantType, topic: Any, payload, qos=None, """Publish message to an MQTT topic.""" data = _build_publish_data(topic, qos, retain) data[ATTR_PAYLOAD] = payload - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_PUBLISH, data)) + hass.async_create_task( + hass.services.async_call(DOMAIN, SERVICE_PUBLISH, data)) @bind_hass @@ -670,7 +671,7 @@ class MQTT: if any(other.topic == topic for other in self.subscriptions): # Other subscriptions on topic remaining - don't unsubscribe. return - self.hass.async_add_job(self._async_unsubscribe(topic)) + self.hass.async_create_task(self._async_unsubscribe(topic)) return async_remove diff --git a/homeassistant/components/mysensors/__init__.py b/homeassistant/components/mysensors/__init__.py index 725494cd197..4f00247495a 100644 --- a/homeassistant/components/mysensors/__init__.py +++ b/homeassistant/components/mysensors/__init__.py @@ -111,7 +111,7 @@ async def async_setup(hass, config): hass.data[MYSENSORS_GATEWAYS] = gateways - hass.async_add_job(finish_setup(hass, gateways)) + hass.async_create_task(finish_setup(hass, gateways)) return True diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py index 88725e67940..558e944f727 100644 --- a/homeassistant/components/mysensors/gateway.py +++ b/homeassistant/components/mysensors/gateway.py @@ -106,7 +106,7 @@ async def _get_gateway(hass, config, gateway_conf, persistence_file): """Call callback.""" sub_cb(*args) - hass.async_add_job( + hass.async_create_task( mqtt.async_subscribe(topic, internal_callback, qos)) gateway = mysensors.AsyncMQTTGateway( @@ -192,7 +192,7 @@ async def _gw_start(hass, gateway): @callback def gw_stop(event): """Trigger to stop the gateway.""" - hass.async_add_job(gateway.stop()) + hass.async_create_task(gateway.stop()) if not connect_task.done(): connect_task.cancel() diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index f609c774b12..c66abf1a8bd 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -105,7 +105,7 @@ async def async_setup(hass, config): filename = config.get(CONF_FILENAME, NEST_CONFIG_FILE) access_token_cache_file = hass.config.path(filename) - hass.async_add_job(hass.config_entries.flow.async_init( + hass.async_create_task(hass.config_entries.flow.async_init( DOMAIN, context={'source': config_entries.SOURCE_IMPORT}, data={ 'nest_conf_path': access_token_cache_file, diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index a0f5cdae24d..9c09ccced3d 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -95,7 +95,8 @@ def async_dismiss(hass: HomeAssistant, notification_id: str) -> None: """Remove a notification.""" data = {ATTR_NOTIFICATION_ID: notification_id} - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_DISMISS, data)) + hass.async_create_task( + hass.services.async_call(DOMAIN, SERVICE_DISMISS, data)) async def async_setup(hass: HomeAssistant, config: dict) -> Awaitable[bool]: diff --git a/homeassistant/components/rflink.py b/homeassistant/components/rflink.py index f96ce3968c4..a8aeca273d6 100644 --- a/homeassistant/components/rflink.py +++ b/homeassistant/components/rflink.py @@ -443,7 +443,7 @@ class RflinkCommand(RflinkDevice): self._protocol.send_command, self._device_id, cmd)) if repetitions > 1: - self._repetition_task = self.hass.async_add_job( + self._repetition_task = self.hass.async_create_task( self._async_send_command(cmd, repetitions - 1)) diff --git a/homeassistant/components/sensor/dsmr.py b/homeassistant/components/sensor/dsmr.py index 02b2a5e8ff5..d54959813f8 100644 --- a/homeassistant/components/sensor/dsmr.py +++ b/homeassistant/components/sensor/dsmr.py @@ -167,7 +167,7 @@ async def async_setup_platform(hass, config, async_add_entities, # Make all device entities aware of new telegram for device in devices: device.telegram = telegram - hass.async_add_job(device.async_update_ha_state()) + hass.async_create_task(device.async_update_ha_state()) # Creates an asyncio.Protocol factory for reading DSMR telegrams from # serial and calls update_entities_telegram to update entities on arrival diff --git a/homeassistant/components/sensor/tradfri.py b/homeassistant/components/sensor/tradfri.py index 769857cb6df..45167874de2 100644 --- a/homeassistant/components/sensor/tradfri.py +++ b/homeassistant/components/sensor/tradfri.py @@ -93,7 +93,7 @@ class TradfriDevice(Entity): cmd = self._device.observe(callback=self._observe_update, err_callback=self._async_start_observe, duration=0) - self.hass.async_add_job(self._api(cmd)) + self.hass.async_create_task(self._api(cmd)) except PytradfriError as err: _LOGGER.warning("Observation failed, trying again", exc_info=err) self._async_start_observe() @@ -107,4 +107,4 @@ class TradfriDevice(Entity): """Receive new state data for this device.""" self._refresh(tradfri_device) - self.hass.async_add_job(self.async_update_ha_state()) + self.hass.async_create_task(self.async_update_ha_state()) diff --git a/homeassistant/components/sisyphus.py b/homeassistant/components/sisyphus.py index dc9f9cc4c25..f875e3a91c7 100644 --- a/homeassistant/components/sisyphus.py +++ b/homeassistant/components/sisyphus.py @@ -54,12 +54,12 @@ async def async_setup(hass, config): tables[name] = table _LOGGER.debug("Connected to %s at %s", name, host) - hass.async_add_job(async_load_platform( + hass.async_create_task(async_load_platform( hass, 'light', DOMAIN, { CONF_NAME: name, }, config )) - hass.async_add_job(async_load_platform( + hass.async_create_task(async_load_platform( hass, 'media_player', DOMAIN, { CONF_NAME: name, CONF_HOST: host, diff --git a/homeassistant/components/switch/netio.py b/homeassistant/components/switch/netio.py index 2ccb4501d73..fc6086f9897 100644 --- a/homeassistant/components/switch/netio.py +++ b/homeassistant/components/switch/netio.py @@ -117,7 +117,7 @@ class NetioApiView(HomeAssistantView): ndev.start_dates = start_dates for dev in DEVICES[host].entities: - hass.async_add_job(dev.async_update_ha_state()) + hass.async_create_task(dev.async_update_ha_state()) return self.json(True) diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index e5eef0e6135..86667782d09 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -299,7 +299,7 @@ class SpeechManager: # Is file store in file cache elif use_cache and key in self.file_cache: filename = self.file_cache[key] - self.hass.async_add_job(self.async_file_to_mem(key)) + self.hass.async_create_task(self.async_file_to_mem(key)) # Load speech from provider into memory else: filename = await self.async_get_tts_audio( @@ -331,7 +331,7 @@ class SpeechManager: self._async_store_to_memcache(key, filename, data) if cache: - self.hass.async_add_job( + self.hass.async_create_task( self.async_save_tts_audio(key, filename, data)) return filename diff --git a/homeassistant/components/tuya.py b/homeassistant/components/tuya.py index 33f34164b02..22a82dec8e2 100644 --- a/homeassistant/components/tuya.py +++ b/homeassistant/components/tuya.py @@ -159,7 +159,7 @@ class TuyaDevice(Entity): def _delete_callback(self, dev_id): """Remove this entity.""" if dev_id == self.object_id: - self.hass.async_add_job(self.async_remove()) + self.hass.async_create_task(self.async_remove()) @callback def _update_callback(self): diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index 7c48a577850..2e74e079d5f 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -109,7 +109,8 @@ async def async_setup(hass, config): await APPLICATION_CONTROLLER.startup(auto_form=True) for device in APPLICATION_CONTROLLER.devices.values(): - hass.async_add_job(listener.async_device_initialized(device, False)) + hass.async_create_task( + listener.async_device_initialized(device, False)) async def permit(service): """Allow devices to join this network.""" @@ -161,7 +162,8 @@ class ApplicationListener: def device_initialized(self, device): """Handle device joined and basic information discovered.""" - self._hass.async_add_job(self.async_device_initialized(device, True)) + self._hass.async_create_task( + self.async_device_initialized(device, True)) def device_left(self, device): """Handle device leaving the network.""" @@ -170,7 +172,7 @@ class ApplicationListener: def device_removed(self, device): """Handle device being removed from the network.""" for device_entity in self._device_registry[device.ieee]: - self._hass.async_add_job(device_entity.async_remove()) + self._hass.async_create_task(device_entity.async_remove()) async def async_device_initialized(self, device, join): """Handle device joined and basic information discovered (async).""" diff --git a/homeassistant/components/zone/__init__.py b/homeassistant/components/zone/__init__.py index 3754bf5edbc..370b52d1360 100644 --- a/homeassistant/components/zone/__init__.py +++ b/homeassistant/components/zone/__init__.py @@ -55,7 +55,7 @@ async def async_setup(hass, config): entry.get(CONF_ICON), entry.get(CONF_PASSIVE)) zone.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, entry[CONF_NAME], entities) - hass.async_add_job(zone.async_update_ha_state()) + hass.async_create_task(zone.async_update_ha_state()) entities.add(zone.entity_id) if ENTITY_ID_HOME not in entities and HOME_ZONE not in zone_entries: @@ -63,7 +63,7 @@ async def async_setup(hass, config): hass.config.latitude, hass.config.longitude, DEFAULT_RADIUS, ICON_HOME, False) zone.entity_id = ENTITY_ID_HOME - hass.async_add_job(zone.async_update_ha_state()) + hass.async_create_task(zone.async_update_ha_state()) return True @@ -77,7 +77,7 @@ async def async_setup_entry(hass, config_entry): entry.get(CONF_PASSIVE, DEFAULT_PASSIVE)) zone.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, name, None, hass) - hass.async_add_job(zone.async_update_ha_state()) + hass.async_create_task(zone.async_update_ha_state()) hass.data[DOMAIN][slugify(name)] = zone return True diff --git a/tests/components/hue/test_bridge.py b/tests/components/hue/test_bridge.py index c20cee0d0e8..ceb30091970 100644 --- a/tests/components/hue/test_bridge.py +++ b/tests/components/hue/test_bridge.py @@ -34,7 +34,7 @@ async def test_bridge_setup_invalid_username(): side_effect=errors.AuthenticationRequired): assert await hue_bridge.async_setup() is False - assert len(hass.async_add_job.mock_calls) == 1 + assert len(hass.async_create_task.mock_calls) == 1 assert len(hass.config_entries.flow.async_init.mock_calls) == 1 assert hass.config_entries.flow.async_init.mock_calls[0][2]['data'] == { 'host': '1.2.3.4' @@ -87,7 +87,7 @@ async def test_reset_if_entry_had_wrong_auth(): side_effect=errors.AuthenticationRequired): assert await hue_bridge.async_setup() is False - assert len(hass.async_add_job.mock_calls) == 1 + assert len(hass.async_create_task.mock_calls) == 1 assert await hue_bridge.async_reset()