Skip to content

Commit

Permalink
fix: Add login token lifetime to consts and use it in all API clients (
Browse files Browse the repository at this point in the history
  • Loading branch information
freaksdotcom committed Dec 28, 2023
1 parent ed8476e commit 10d38b3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
9 changes: 5 additions & 4 deletions hyundai_kia_connect_api/KiaUvoAPIUSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from .Token import Token
from .Vehicle import Vehicle
from .const import (
DOMAIN,
VEHICLE_LOCK_ACTION,
TEMPERATURE_UNITS,
DISTANCE_UNITS,
DOMAIN,
LOGIN_TOKEN_LIFETIME,
OrderStatus,
TEMPERATURE_UNITS,
VEHICLE_LOCK_ACTION,
)
from .utils import get_child_value

Expand Down Expand Up @@ -176,7 +177,7 @@ def login(self, username: str, password: str) -> Token:
f"{DOMAIN} - No session id returned in login. Response: {response.text} headers {response.headers} cookies {response.cookies}" # noqa
)
_LOGGER.debug(f"got session id {session_id}")
valid_until = dt.datetime.now(pytz.utc) + dt.timedelta(hours=1)
valid_until = dt.datetime.now(pytz.utc) + LOGIN_TOKEN_LIFETIME
return Token(
username=username,
password=password,
Expand Down
13 changes: 7 additions & 6 deletions hyundai_kia_connect_api/KiaUvoApiCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
from .Token import Token
from .Vehicle import Vehicle
from .const import (
BRAND_GENESIS,
BRAND_HYUNDAI,
BRAND_KIA,
BRAND_GENESIS,
BRANDS,
DOMAIN,
DISTANCE_UNITS,
TEMPERATURE_UNITS,
SEAT_STATUS,
DOMAIN,
ENGINE_TYPES,
VEHICLE_LOCK_ACTION,
LOGIN_TOKEN_LIFETIME,
OrderStatus,
SEAT_STATUS,
TEMPERATURE_UNITS,
VEHICLE_LOCK_ACTION,
)

from .exceptions import AuthenticationError, APIError
Expand Down Expand Up @@ -133,7 +134,7 @@ def login(self, username: str, password: str) -> Token:
_LOGGER.debug(f"{DOMAIN} - Access Token Value {access_token}")
_LOGGER.debug(f"{DOMAIN} - Refresh Token Value {refresh_token}")

valid_until = dt.datetime.now(pytz.utc) + dt.timedelta(hours=23)
valid_until = dt.datetime.now(pytz.utc) + LOGIN_TOKEN_LIFETIME

return Token(
username=username,
Expand Down
13 changes: 7 additions & 6 deletions hyundai_kia_connect_api/KiaUvoApiCN.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
BRAND_HYUNDAI,
BRAND_KIA,
BRANDS,
DOMAIN,
DISTANCE_UNITS,
TEMPERATURE_UNITS,
SEAT_STATUS,
VEHICLE_LOCK_ACTION,
CHARGE_PORT_ACTION,
DISTANCE_UNITS,
DOMAIN,
ENGINE_TYPES,
LOGIN_TOKEN_LIFETIME,
OrderStatus,
SEAT_STATUS,
TEMPERATURE_UNITS,
VEHICLE_LOCK_ACTION,
)
from .exceptions import *
from .utils import (
Expand Down Expand Up @@ -158,7 +159,7 @@ def login(self, username: str, password: str) -> Token:

_, access_token, authorization_code = self._get_access_token(authorization_code)
_, refresh_token = self._get_refresh_token(authorization_code)
valid_until = dt.datetime.now(pytz.utc) + dt.timedelta(hours=23)
valid_until = dt.datetime.now(pytz.utc) + LOGIN_TOKEN_LIFETIME

return Token(
username=username,
Expand Down
15 changes: 8 additions & 7 deletions hyundai_kia_connect_api/KiaUvoApiEU.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@
DayTripCounts,
)
from .const import (
BRAND_GENESIS,
BRAND_HYUNDAI,
BRAND_KIA,
BRAND_GENESIS,
BRANDS,
DOMAIN,
DISTANCE_UNITS,
TEMPERATURE_UNITS,
SEAT_STATUS,
VEHICLE_LOCK_ACTION,
CHARGE_PORT_ACTION,
DISTANCE_UNITS,
DOMAIN,
ENGINE_TYPES,
LOGIN_TOKEN_LIFETIME,
OrderStatus,
SEAT_STATUS,
TEMPERATURE_UNITS,
VEHICLE_LOCK_ACTION,
)
from .exceptions import *
from .utils import (
Expand Down Expand Up @@ -250,7 +251,7 @@ def login(self, username: str, password: str) -> Token:
stamp, authorization_code
)
_, refresh_token = self._get_refresh_token(stamp, authorization_code)
valid_until = dt.datetime.now(pytz.utc) + dt.timedelta(hours=23)
valid_until = dt.datetime.now(pytz.utc) + LOGIN_TOKEN_LIFETIME

return Token(
username=username,
Expand Down
3 changes: 3 additions & 0 deletions hyundai_kia_connect_api/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""const.py"""
# pylint:disable=invalid-name,missing-class-docstring

import datetime
from enum import Enum, IntEnum

DOMAIN: str = "hyundai_kia_connect_api"
Expand All @@ -23,6 +24,8 @@
5: REGION_AUSTRALIA,
}

LOGIN_TOKEN_LIFETIME = datetime.timedelta(hours=23)

LENGTH_KILOMETERS = "km"
LENGTH_MILES = "mi"
DISTANCE_UNITS = {None: None, 0: None, 1: LENGTH_KILOMETERS, 3: LENGTH_MILES}
Expand Down

0 comments on commit 10d38b3

Please sign in to comment.