Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throttle updates #213

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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