Optimize API polling patterns to avoid excessive calls and improve performance. Use appropriate update intervals based on data freshness requirements rather than aggressive polling schedules.
Key principles:
Example of problematic polling:
super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=timedelta(seconds=5), # Too frequent!
)
Better approach using coordinator with reasonable intervals:
class DeviceDataCoordinator(DataUpdateCoordinator):
def __init__(self, hass: HomeAssistant, api: DeviceAPI):
super().__init__(
hass,
_LOGGER,
name="device_coordinator",
update_interval=timedelta(minutes=15), # More reasonable
)
self.api = api
async def _async_update_data(self):
# Group multiple API calls together
return await self.api.get_all_device_data()
This approach reduces API rate limit issues, improves performance, and provides better user experience while future-proofing for additional platforms.
Enter the URL of a public GitHub repository