Reset Tesla Fleet energy history interval after rate limit backoff (#182453)

This commit is contained in:
Brett Adams
2026-09-19 09:46:48 +02:00
committed by GitHub
parent e0010d3356
commit 94594f5990
2 changed files with 37 additions and 0 deletions
@@ -322,6 +322,8 @@ class TeslaFleetEnergySiteHistoryCoordinator(DataUpdateCoordinator[dict[str, Any
async def _async_update_data(self) -> dict[str, Any]:
"""Update energy site history data using Tesla Fleet API."""
self.update_interval = ENERGY_HISTORY_INTERVAL
try:
data = (await self.api.energy_history(TeslaEnergyPeriod.DAY))["response"]
except RateLimited as e:
+35
View File
@@ -944,6 +944,41 @@ async def test_energy_history_refresh_ratelimited(
assert mock_energy_history.call_count == 2
async def test_energy_history_refresh_ratelimited_not_sticky(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_energy_history: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test a 429 backoff only delays the next energy history refresh."""
await setup_platform(hass, normal_config_entry)
after = ENERGY_HISTORY_INTERVAL + timedelta(seconds=10)
# The library passes the raw Retry-After header through as a string
mock_energy_history.side_effect = RateLimited(
{"after": str(int(after.total_seconds()))}
)
freezer.tick(ENERGY_HISTORY_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert mock_energy_history.call_count == 1
mock_energy_history.side_effect = None
freezer.tick(after)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert mock_energy_history.call_count == 2
freezer.tick(ENERGY_HISTORY_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert mock_energy_history.call_count == 3
async def test_init_region_issue(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,