Fix deprecated asyncio.wait use with coroutines (#44981)

https://docs.python.org/3/library/asyncio-task.html#asyncio-example-wait-coroutine
This commit is contained in:
Ville Skyttä 2021-02-10 15:16:58 +02:00 committed by GitHub
parent 4b493c5ab9
commit a6358430b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 13 deletions

View File

@ -65,11 +65,11 @@ async def async_setup(hass, config):
hass.bus.async_listen(EVENT_COMPONENT_LOADED, component_loaded) hass.bus.async_listen(EVENT_COMPONENT_LOADED, component_loaded)
tasks = [setup_panel(panel_name) for panel_name in SECTIONS] tasks = [asyncio.create_task(setup_panel(panel_name)) for panel_name in SECTIONS]
for panel_name in ON_DEMAND: for panel_name in ON_DEMAND:
if panel_name in hass.config.components: if panel_name in hass.config.components:
tasks.append(setup_panel(panel_name)) tasks.append(asyncio.create_task(setup_panel(panel_name)))
if tasks: if tasks:
await asyncio.wait(tasks) await asyncio.wait(tasks)

View File

@ -153,7 +153,7 @@ async def async_setup_integration(hass: HomeAssistantType, config: ConfigType) -
legacy_platforms = await async_extract_config(hass, config) legacy_platforms = await async_extract_config(hass, config)
setup_tasks = [ setup_tasks = [
legacy_platform.async_setup_legacy(hass, tracker) asyncio.create_task(legacy_platform.async_setup_legacy(hass, tracker))
for legacy_platform in legacy_platforms for legacy_platform in legacy_platforms
] ]

View File

@ -855,7 +855,7 @@ class ForkedDaapdUpdater:
) )
if update_events: if update_events:
await asyncio.wait( await asyncio.wait(
[event.wait() for event in update_events.values()] [asyncio.create_task(event.wait()) for event in update_events.values()]
) # make sure callbacks done before update ) # make sure callbacks done before update
async_dispatcher_send( async_dispatcher_send(
self.hass, SIGNAL_UPDATE_MASTER.format(self._entry_id), True self.hass, SIGNAL_UPDATE_MASTER.format(self._entry_id), True

View File

@ -81,7 +81,7 @@ async def async_setup(hass, config):
update_tasks = [] update_tasks = []
for entity in image_entities: for entity in image_entities:
entity.async_set_context(service.context) entity.async_set_context(service.context)
update_tasks.append(entity.async_update_ha_state(True)) update_tasks.append(asyncio.create_task(entity.async_update_ha_state(True)))
if update_tasks: if update_tasks:
await asyncio.wait(update_tasks) await asyncio.wait(update_tasks)

View File

@ -84,7 +84,7 @@ async def async_setup(hass, config):
await component.async_add_entities([mailbox_entity]) await component.async_add_entities([mailbox_entity])
setup_tasks = [ setup_tasks = [
async_setup_platform(p_type, p_config) asyncio.create_task(async_setup_platform(p_type, p_config))
for p_type, p_config in config_per_platform(config, DOMAIN) for p_type, p_config in config_per_platform(config, DOMAIN)
] ]

View File

@ -275,7 +275,9 @@ class MicrosoftFace:
for person in persons: for person in persons:
self._store[g_id][person["name"]] = person["personId"] self._store[g_id][person["name"]] = person["personId"]
tasks.append(self._entities[g_id].async_update_ha_state()) tasks.append(
asyncio.create_task(self._entities[g_id].async_update_ha_state())
)
if tasks: if tasks:
await asyncio.wait(tasks) await asyncio.wait(tasks)

View File

@ -312,7 +312,7 @@ async def async_setup(hass, config):
) )
setup_tasks = [ setup_tasks = [
async_setup_platform(integration_name, p_config) asyncio.create_task(async_setup_platform(integration_name, p_config))
for integration_name, p_config in config_per_platform(config, DOMAIN) for integration_name, p_config in config_per_platform(config, DOMAIN)
] ]

View File

@ -62,7 +62,7 @@ async def async_setup(hass: HomeAssistantType, config):
return return
setup_tasks = [ setup_tasks = [
async_setup_platform(p_type, p_config) asyncio.create_task(async_setup_platform(p_type, p_config))
for p_type, p_config in config_per_platform(config, DOMAIN) for p_type, p_config in config_per_platform(config, DOMAIN)
] ]

View File

@ -194,7 +194,7 @@ async def async_setup(hass, config):
) )
setup_tasks = [ setup_tasks = [
async_setup_platform(p_type, p_config) asyncio.create_task(async_setup_platform(p_type, p_config))
for p_type, p_config in config_per_platform(config, DOMAIN) for p_type, p_config in config_per_platform(config, DOMAIN)
] ]

View File

@ -1055,7 +1055,7 @@ class Script:
raise raise
async def _async_stop(self, update_state): async def _async_stop(self, update_state):
aws = [run.async_stop() for run in self._runs] aws = [asyncio.create_task(run.async_stop()) for run in self._runs]
if not aws: if not aws:
return return
await asyncio.wait(aws) await asyncio.wait(aws)

View File

@ -602,9 +602,11 @@ async def entity_service_call(
done, pending = await asyncio.wait( done, pending = await asyncio.wait(
[ [
asyncio.create_task(
entity.async_request_call( entity.async_request_call(
_handle_entity_call(hass, entity, func, data, call.context) _handle_entity_call(hass, entity, func, data, call.context)
) )
)
for entity in entities for entity in entities
] ]
) )