From 443fe1a716b424b9de92211566b32fd9fe993281 Mon Sep 17 00:00:00 2001 From: Guy Khmelnitsky Date: Sun, 15 Feb 2026 15:22:14 +0200 Subject: [PATCH] Add delay between statistics tasks to prevent API flooding When multiple contracts exist, statistics tasks are spawned concurrently which can cause API rate limiting. Added 1 second delay between starting each statistics task. --- custom_components/iec/coordinator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/iec/coordinator.py b/custom_components/iec/coordinator.py index 9136c58..d3dee15 100644 --- a/custom_components/iec/coordinator.py +++ b/custom_components/iec/coordinator.py @@ -552,6 +552,9 @@ async def _update_data( for contract_id in self._contract_ids: # Because IEC API provides historical usage/cost with a delay of a couple of days # we need to insert data into statistics. + # Add small delay between tasks to avoid API flooding + if self._contract_ids.index(contract_id) > 0: + await asyncio.sleep(1) self.hass.async_create_task( self._insert_statistics( contract_id, contracts.get(contract_id).smart_meter