diff --git a/custom_components/polestar_api/const.py b/custom_components/polestar_api/const.py index f80665f..e42cdf3 100644 --- a/custom_components/polestar_api/const.py +++ b/custom_components/polestar_api/const.py @@ -1,8 +1,11 @@ """Constants for the Polestar API integration.""" +from datetime import timedelta + DOMAIN = "polestar_api" TIMEOUT = 90 CACHE_TIME = 30 +DEFAULT_SCAN_INTERVAL = timedelta(seconds=60) CONF_VIN = Final = "vin" diff --git a/custom_components/polestar_api/polestar.py b/custom_components/polestar_api/polestar.py index 039ce81..111796c 100644 --- a/custom_components/polestar_api/polestar.py +++ b/custom_components/polestar_api/polestar.py @@ -7,8 +7,9 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.httpx_client import get_async_client +from homeassistant.util import Throttle -from .const import DOMAIN as POLESTAR_API_DOMAIN +from .const import DEFAULT_SCAN_INTERVAL, DOMAIN as POLESTAR_API_DOMAIN from .pypolestar.exception import PolestarApiException, PolestarAuthException from .pypolestar.polestar import PolestarApi @@ -31,6 +32,8 @@ def __init__( self.model = str( self.get_value("getConsumerCarsV2", "content/model/name") or "Unknown model" ) + self.scan_interval = DEFAULT_SCAN_INTERVAL + self.async_update = Throttle(min_time=self.scan_interval)(self.async_update) def get_unique_id(self) -> str: """Return unique identifier"""