Skip to content

Commit

Permalink
Merge pull request #213 from jschlyter/throttle_updates
Browse files Browse the repository at this point in the history
Throttle updates
  • Loading branch information
jschlyter authored Nov 9, 2024
2 parents 22415aa + 461772a commit 04b39a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions custom_components/polestar_api/const.py
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion custom_components/polestar_api/polestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"""
Expand Down

0 comments on commit 04b39a1

Please sign in to comment.