Skip to content

Commit

Permalink
Upgrade pyupgrade to 2.21.2, apply its changes (home-assistant#52987)
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored Jul 19, 2021
1 parent c96f01d commit 470f2dd
Show file tree
Hide file tree
Showing 73 changed files with 152 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.16.0
rev: v2.21.2
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/analytics/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ async def send_analytics(self, _=None) -> None:
ATTR_STATISTICS, False
):
configured_integrations = await asyncio.gather(
*[
*(
async_get_integration(self.hass, domain)
for domain in async_get_loaded_integrations(self.hass)
],
),
return_exceptions=True,
)

Expand All @@ -201,10 +201,10 @@ async def send_analytics(self, _=None) -> None:

if supervisor_info is not None:
installed_addons = await asyncio.gather(
*[
*(
hassio.async_get_addon_info(self.hass, addon[ATTR_SLUG])
for addon in supervisor_info[ATTR_ADDONS]
]
)
)
for addon in installed_addons:
addons.append(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/apple_tv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ async def on_hass_stop(event):
async def setup_platforms():
"""Set up platforms and initiate connection."""
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS
]
)
)
await manager.init()

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/arcam_fmj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType):

async def _stop(_):
asyncio.gather(
*[_await_cancel(task) for task in hass.data[DOMAIN_DATA_TASKS].values()]
*(_await_cancel(task) for task in hass.data[DOMAIN_DATA_TASKS].values())
)

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _stop)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/august/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ async def _async_refresh(self, time):

async def _async_refresh_device_detail_by_ids(self, device_ids_list):
await asyncio.gather(
*[
*(
self._async_refresh_device_detail_by_id(device_id)
for device_id in device_ids_list
]
)
)

async def _async_refresh_device_detail_by_id(self, device_id):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/august/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ async def _async_refresh(self, time):
async def _async_update_device_activities(self, time):
_LOGGER.debug("Start retrieving device activities")
await asyncio.gather(
*[
*(
self._update_debounce[house_id].async_call()
for house_id in self._house_ids
]
)
)
self._last_update_time = time

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/automation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ async def async_validate_config_item(hass, config, full_config=None):

if CONF_CONDITION in config:
config[CONF_CONDITION] = await asyncio.gather(
*[
*(
async_validate_condition_config(hass, cond)
for cond in config[CONF_CONDITION]
]
)
)

config[CONF_ACTION] = await script.async_validate_actions_config(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/awair/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def _async_update_data(self) -> Any | None:
user = await self._awair.user()
devices = await user.devices()
results = await gather(
*[self._fetch_air_data(device) for device in devices]
*(self._fetch_air_data(device) for device in devices)
)
return {result.device.uuid: result for result in results}
except AuthError as err:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/axis/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ async def async_setup(self):

async def start_platforms():
await asyncio.gather(
*[
*(
self.hass.config_entries.async_forward_entry_setup(
self.config_entry, platform
)
for platform in PLATFORMS
]
)
)
if self.option_events:
self.api.stream.connection_status_callback.append(
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/climacell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ async def _async_update_data(self) -> dict[str, Any]:
CC_V3_ATTR_WIND_GUST,
CC_V3_ATTR_CLOUD_COVER,
CC_V3_ATTR_PRECIPITATION_TYPE,
*[
*(
sensor_type[ATTR_FIELD]
for sensor_type in CC_V3_SENSOR_TYPES
],
),
]
)
data[FORECASTS][HOURLY] = await self._api.forecast_hourly(
Expand Down Expand Up @@ -283,7 +283,7 @@ async def _async_update_data(self) -> dict[str, Any]:
CC_ATTR_WIND_GUST,
CC_ATTR_CLOUD_COVER,
CC_ATTR_PRECIPITATION_TYPE,
*[sensor_type[ATTR_FIELD] for sensor_type in CC_SENSOR_TYPES],
*(sensor_type[ATTR_FIELD] for sensor_type in CC_SENSOR_TYPES),
],
[
CC_ATTR_TEMPERATURE_LOW,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def enable_google(_):
tasks.append(enable_google)

if tasks:
await asyncio.gather(*[task(None) for task in tasks])
await asyncio.gather(*(task(None) for task in tasks))

async def cleanups(self) -> None:
"""Cleanup some stuff after logout."""
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/devolo_home_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
await asyncio.gather(
*[
*(
hass.async_add_executor_job(gateway.websocket_disconnect)
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]
]
)
)
hass.data[DOMAIN][entry.entry_id]["listener"]()
hass.data[DOMAIN].pop(entry.entry_id)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ async def async_sync_entities(self, agent_user_id: str):
async def async_sync_entities_all(self):
"""Sync all entities to Google for all registered agents."""
res = await gather(
*[
*(
self.async_sync_entities(agent_user_id)
for agent_user_id in self._store.agent_user_ids
]
)
)
return max(res, default=204)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/google_assistant/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ async def handle_devices_execute(hass, data, payload):
executions[entity_id] = [execution]

execute_results = await asyncio.gather(
*[
*(
_entity_execute(entities[entity_id], data, execution)
for entity_id, execution in executions.items()
]
)
)

for entity_id, result in zip(executions, execute_results):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/home_plus_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ async def async_update_data():
async def start_platforms():
"""Continue setting up the platforms."""
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS
]
)
)
# Only refresh the coordinator after all platforms are loaded.
await coordinator.async_refresh()
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ async def async_handle_reload_config_entry(call):
if not reload_entries:
raise ValueError("There were no matching config entries to reload")
await asyncio.gather(
*[
*(
hass.config_entries.async_reload(config_entry_id)
for config_entry_id in reload_entries
]
)
)

hass.helpers.service.async_register_admin_service(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homekit_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ async def async_setup(hass, config):

async def _async_stop_homekit_controller(event):
await asyncio.gather(
*[
*(
connection.async_unload()
for connection in hass.data[KNOWN_DEVICES].values()
]
)
)

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop_homekit_controller)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/hyperion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ async def async_instances_to_clients_raw(instances: list[dict[str, Any]]) -> Non

async def setup_then_listen() -> None:
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS
]
)
)
assert hyperion_client
if hyperion_client.instances is not None:
Expand Down Expand Up @@ -306,12 +306,12 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

# Disconnect the shared instance clients.
await asyncio.gather(
*[
*(
config_data[CONF_INSTANCE_CLIENTS][
instance_num
].async_client_disconnect()
for instance_num in config_data[CONF_INSTANCE_CLIENTS]
]
)
)

# Disconnect the root client.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/knx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async def reload_service_handler(service_call: ServiceCall) -> None:
await knx_module.xknx.stop()

await asyncio.gather(
*[platform.async_reset() for platform in async_get_platforms(hass, DOMAIN)]
*(platform.async_reset() for platform in async_get_platforms(hass, DOMAIN))
)

await async_setup(hass, config)
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/kodi/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def build_item_response(media_library, payload, get_thumbnail_url=None):
return None

children = await asyncio.gather(
*[item_payload(item, get_thumbnail_url) for item in media]
*(item_payload(item, get_thumbnail_url) for item in media)
)

if search_type in (MEDIA_TYPE_TVSHOW, MEDIA_TYPE_MOVIE) and search_id == "":
Expand Down Expand Up @@ -209,7 +209,7 @@ async def library_payload():
}

library_info.children = await asyncio.gather(
*[
*(
item_payload(
{
"label": item["label"],
Expand All @@ -220,7 +220,7 @@ async def library_payload():
for item in [
{"label": name, "type": type_} for type_, name in library.items()
]
]
)
)

return library_info
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/logbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,10 @@ def _apply_event_types_filter(hass, query, event_types):
def _apply_event_entity_id_matchers(events_query, entity_ids):
return events_query.filter(
sqlalchemy.or_(
*[
*(
Events.event_data.contains(ENTITY_ID_JSON_TEMPLATE.format(entity_id))
for entity_id in entity_ids
]
)
)
)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/lovelace/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ async def system_health_info(hass):
health_info.update(await hass.data[DOMAIN]["resources"].async_get_info())

dashboards_info = await asyncio.gather(
*[
*(
hass.data[DOMAIN]["dashboards"][dashboard].async_get_info()
for dashboard in hass.data[DOMAIN]["dashboards"]
]
)
)

modes = set()
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/motioneye/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ def _async_process_motioneye_cameras() -> None:

async def setup_then_listen() -> None:
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS
]
)
)
entry.async_on_unload(
coordinator.async_add_listener(_async_process_motioneye_cameras)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/mysensors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def finish() -> None:
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS_WITH_ENTRY_SUPPORT
]
)
)
await finish_setup(hass, entry, gateway)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/nilu/air_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def update(self) -> None:

sensors = self._api.data.sensors.values()
if sensors:
max_index = max([s.pollution_index for s in sensors])
max_index = max(s.pollution_index for s in sensors)
self._max_aqi = max_index
self._attrs[ATTR_POLLUTION_INDEX] = POLLUTION_INDEX[self._max_aqi]

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/no_ip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
password = config[DOMAIN].get(CONF_PASSWORD)
timeout = config[DOMAIN].get(CONF_TIMEOUT)

auth_str = base64.b64encode(f"{user}:{password}".encode("utf-8"))
auth_str = base64.b64encode(f"{user}:{password}".encode())

session = hass.helpers.aiohttp_client.async_get_clientsession()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/onewire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ async def start_platforms() -> None:
"""Start platforms and cleanup devices."""
# wait until all required platforms are ready
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS
]
)
)
await cleanup_registry()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ozw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ def async_receive_message(msg):

async def start_platforms():
await asyncio.gather(
*[
*(
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in PLATFORMS
]
)
)
if entry.data.get(CONF_USE_ADDON):
mqtt_client_task = asyncio.create_task(mqtt_client.start_client(manager))
Expand Down
Loading

0 comments on commit 470f2dd

Please sign in to comment.