Skip to content

Commit 6ef6bb4

Browse files
authored
Add support for 2026 model year and Hyundai Ioniq 9 (#29)
* Add support for 2026 model year and Hyundai Ioniq 9 * Refine logic for invalid Hyundai year/model response
1 parent e3dd959 commit 6ef6bb4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/libs/common_query_params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CommonInventoryQueryParams:
1111

1212
valid_models = [
1313
r"^Ioniq(%20|\+|\s|\-)5((%20|\+|\-)N)?$", # Hyundai Ioniq 5 and 5 N # noqa: W605
14-
r"^Ioniq(%20|\+|\s|\-)6$", # Hyundai Ioniq 6 # noqa: W605
14+
r"^Ioniq(%20|\+|\s|\-)(6|9)$", # Hyundai Ioniq 6, 9 # noqa: W605
1515
r"^Kona(%20|\+|\s)Ev$", # Hyundai Kona EV # noqa: W605
1616
"^N$", # Kia EV6
1717
"^V$", # Kia Niro EV
@@ -45,8 +45,8 @@ def __init__(
4545
self,
4646
# https://facts.usps.com/42000-zip-codes/. Starting zip code is 00501
4747
zip: int = Query(ge=501, le=99950),
48-
year: int = Query(ge=2022, le=2025),
49-
radius: int = Query(gt=0, lt=1000),
48+
year: int = Query(ge=2022, le=2026),
49+
radius: int = Query(gt=0, lt=500),
5050
model: str = Query(pattern="|".join(valid_models)),
5151
):
5252
# Zip is passed in as a query parameter string. When casting to an int, the

src/routers/hyundai.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from fastapi import APIRouter, Depends, Request
22

33
from src.libs.common_query_params import CommonInventoryQueryParams
4-
from src.libs.responses import error_response, send_response
54
from src.libs.http import AsyncHTTPClient
5+
from src.libs.responses import error_response, send_response
66

77
router = APIRouter(prefix="/api")
88
verify_ssl = True
@@ -53,6 +53,15 @@ async def get_hyundai_inventory(
5353
if "SUCCESS" in inventory["status"]:
5454
return send_response(response_data=inventory)
5555
else:
56+
# If the API response does not have a data key, there is no inventory.
57+
# Return an empty dict response which the UI will use to display the no inventory
58+
# message. This most commonly occurs when the user selects a year that is not
59+
# valid for a selected model.
60+
try:
61+
inventory["data"]
62+
except KeyError:
63+
return send_response(response_data={})
64+
5665
try:
5766
error_message = inventory.text
5867
except AttributeError:

0 commit comments

Comments
 (0)