Repository: home-assistant/core
File: homeassistant/components/ecovacs/controller.py (Python)

Code before:
            country=country,
            override_mqtt_url=mqtt_url,
            ssl_context=ssl_context,
        )
        self._mqtt_client: MqttClient | None = None

        self._added_legacy_entities: set[str] = set()

    async def initialize(self) -> None:
        """Init controller."""
        try:
            devices, credentials = await asyncio.gather(
                self._api_client.get_devices(),
                self._authenticator.authenticate(),
            )
            mqtt = await self._get_mqtt_client()
            mqtt_devices = [Device(info, self._authenticator) for info in devices.mqtt]

            # Initialize all devices concurrently
            results = await asyncio.gather(
                *(device.initialize(mqtt) for device in mqtt_devices),
                return_exceptions=True,
            )

            # Keep only successful ones, we could also use extend and then end up with:
            # self._devices.extend(mqtt_devices), I believe. But up to the ones who know the integration better. :)
            for device, _ in zip(mqtt_devices, results, strict=False):
                self._devices.append(device)

            for device_config in devices.xmpp:
                bot = VacBot(
                    credentials.user_id,
                    EcoVacsAPI.REALM,
                    self._device_id[0:8],
                    credentials.token,
                    device_config,
                    self._continent,
                    monitor=True,
                )
                self._legacy_devices.append(bot)

            for device_config in devices.not_supported:
                _LOGGER.warning(
                    (
                        'Device "%s" not supported. More information at '
                        "https://github.com/DeebotUniverse/client.py/issues/612: %s"
                    ),
                    device_config["deviceName"],
                    device_config,
                )


Review comment (suggestion):
You specified that we raise on any exception from the gathering above, so this comment makes no sense as we will only reach this part if all devices are valid. Therefore, zip is not needed and can be simplified 

Code after:
            country=country,
            override_mqtt_url=mqtt_url,
            ssl_context=ssl_context,
        )
        self._mqtt_client: MqttClient | None = None

        self._added_legacy_entities: set[str] = set()

    async def initialize(self) -> None:
        """Init controller."""
        try:
            devices = await self._api_client.get_devices()
            credentials = await self._authenticator.authenticate()

            if devices.mqtt:
                mqtt = await self._get_mqtt_client()
                mqtt_devices = [
                    Device(info, self._authenticator) for info in devices.mqtt
                ]
                async with asyncio.TaskGroup() as tg:

                    async def _init(device: Device) -> None:
                        """Initialize MQTT device."""
                        await device.initialize(mqtt)
                        self._devices.append(device)

                    for device in mqtt_devices:
                        tg.create_task(_init(device))

            for device_config in devices.xmpp:
                bot = VacBot(
                    credentials.user_id,
                    EcoVacsAPI.REALM,
                    self._device_id[0:8],
                    credentials.token,
                    device_config,
                    self._continent,
                    monitor=True,
                )
                self._legacy_devices.append(bot)
            for device_config in devices.not_supported:
                _LOGGER.warning(
                    (
                        'Device "%s" not supported. More information at '
                        "https://github.com/DeebotUniverse/client.py/issues/612: %s"
                    ),
                    device_config["deviceName"],
                    device_config,
                )

        except InvalidAuthenticationError as ex: