Repository: home-assistant/core
File: homeassistant/components/teslemetry/coordinator.py (Python)

Code before:
            name="Teslemetry Energy Site Live",
            update_interval=ENERGY_LIVE_INTERVAL,
        )
        self.api = api

        # Convert Wall Connectors from array to dict
        data["wall_connectors"] = {
            wc["din"]: wc for wc in (data.get("wall_connectors") or [])
        }
        self.data = data

    async def _async_update_data(self) -> dict[str, Any]:
        """Update energy site data using Teslemetry API."""
        for attempt in range(MAX_RETRIES):
            try:
                data = (await self.api.live_status())["response"]
                # Convert Wall Connectors from array to dict
                data["wall_connectors"] = {
                    wc["din"]: wc for wc in (data.get("wall_connectors") or [])
                }
            except (InvalidToken, SubscriptionRequired) as e:
                raise ConfigEntryAuthFailed from e
            except RETRY_EXCEPTIONS as e:
                if attempt == MAX_RETRIES - 1:
                    raise UpdateFailed(e.message) from e
                await asyncio.sleep(_get_wait_time(e))
            except TeslaFleetError as e:
                raise UpdateFailed(e.message) from e
            else:
                return data
        raise RuntimeError("Unreachable")


class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
    """Class to manage fetching energy site info from the Teslemetry API."""

    config_entry: TeslemetryConfigEntry

    def __init__(
        self,
        hass: HomeAssistant,
        config_entry: TeslemetryConfigEntry,
        api: EnergySite,
        product: dict,
    ) -> None:
        """Initialize Teslemetry Energy Info coordinator."""
        super().__init__(
            hass,
            LOGGER,
            config_entry=config_entry,
            name="Teslemetry Energy Site Info",

Review comment (bug):
Instead of using a sleep here, would the `retry_after` in the `UpdateFailed` be a more suitable candidate. You can find more information here: https://developers.home-assistant.io/blog/2025/11/17/retry-after-update-failed

Code after:
            wc["din"]: wc for wc in (data.get("wall_connectors") or [])
        }
        self.data = data

    async def _async_update_data(self) -> dict[str, Any]:
        """Update energy site data using Teslemetry API."""
        try:
            data = (await self.api.live_status())["response"]
        except (InvalidToken, SubscriptionRequired) as e:
            raise ConfigEntryAuthFailed from e
        except RETRY_EXCEPTIONS as e:
            raise UpdateFailed(e.message, retry_after=_get_retry_after(e)) from e
        except TeslaFleetError as e:
            raise UpdateFailed(e.message) from e
        # Convert Wall Connectors from array to dict
        data["wall_connectors"] = {
            wc["din"]: wc for wc in (data.get("wall_connectors") or [])
        }
        return data


class TeslemetryEnergySiteInfoCoordinator(DataUpdateCoordinator[dict[str, Any]]):
    """Class to manage fetching energy site info from the Teslemetry API."""

    config_entry: TeslemetryConfigEntry

    def __init__(
        self,
        hass: HomeAssistant,
        config_entry: TeslemetryConfigEntry,
        api: EnergySite,
        product: dict,
    ) -> None:
        """Initialize Teslemetry Energy Info coordinator."""
        super().__init__(
            hass,
            LOGGER,
            config_entry=config_entry,
            name="Teslemetry Energy Site Info",
            update_interval=ENERGY_INFO_INTERVAL,
        )
        self.api = api
        self.data = product

    async def _async_update_data(self) -> dict[str, Any]:
        """Update energy site data using Teslemetry API."""
        try:
            data = (await self.api.site_info())["response"]
        except (InvalidToken, SubscriptionRequired) as e:
            raise ConfigEntryAuthFailed from e
        except RETRY_EXCEPTIONS as e: