Skip to content

feat(USA): retry start_climate without seat settings on parameter failure - #1179

Open
blka wants to merge 7 commits into
Hyundai-Kia-Connect:masterfrom
blka:feat/usa-climate-seat-retry
Open

feat(USA): retry start_climate without seat settings on parameter failure#1179
blka wants to merge 7 commits into
Hyundai-Kia-Connect:masterfrom
blka:feat/usa-climate-seat-retry

Conversation

@blka

@blka blka commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Some USA vehicles (particularly gen 3 EVs with heated/vented seats) reject the seatHeaterVentInfo/heatVentSeat payload in start_climate(). The API returns an error code, but the command itself is valid — it just needs to be sent without seat settings.

This matches behavior in egmp-bluelink-scriptable, which retries climate start without seat settings on any failure.

Solution

HyundaiBlueLinkApiUSA — Response-level check

Instead of catching APIError (which misses errorCode 502 due to the 502→AuthenticationError mapping), check the response JSON before calling _check_response_for_errors:

if response_json is not None and "errorCode" in response_json:
    if "seatHeaterVentInfo" in data:
        del data["seatHeaterVentInfo"]
        response = self.sessions.post(url, json=data, headers=headers)
        response_json = _safe_parse_json(response, "start_climate")

if response_json is not None:
    _check_response_for_errors(response_json)

This pattern:

  • Catches any errorCode (including 502) for the retry decision
  • Still raises the correct exception type from the final response
  • Matches the CA climate retry pattern (response-level check before exception handling)

Why not except APIError? errorCode "502" is overloaded in the Hyundai USA API — it maps to AuthenticationError in _check_response_for_errors, but the server also uses 502 for non-auth failures (e.g., rate limiting with errorSubCode == "HT_534"). If the server returns 502 for seat parameter errors, except APIError would never catch it.

KiaUvoApiUSA — Explicit auth error bypass

Added except AuthenticationError: raise before except RequestException so auth errors don't trigger the seat-setting retry.

Testing

Hyundai USA — 6 tests:

  • Retry on parameter errorCode (400)
  • Retry on errorCode 502 (response-level, not exception-based)
  • No retry on success
  • APIError when both attempts fail
  • AuthenticationError when both attempts return 502
  • No retry when no seat settings in payload (gen 2 vehicle)

Kia USA — 4 tests:

  • Retry without seats on failure
  • No retry on success
  • Raise when both fail
  • No retry on auth error

@cdnninja — I went with a response-level check pattern for Hyundai USA instead of exception-based retry, because errorCode 502 is overloaded (auth + rate limiting + possibly parameter errors). This means 502 triggers the retry too — if it's truly an auth error, the second call also gets 502 and raises AuthenticationError (one extra API call, no harm). Would appreciate your take on this approach vs a stricter exception-based one.

blka added 7 commits June 16, 2026 14:50
…exception

HyundaiBlueLinkApiUSA: replace except APIError with response-level check
('errorCode' in response_json). This fixes the errorCode 502 overload
problem — 502 triggers retry too (one extra API call if truly auth, but
no missed parameter-error-502). Matches CA climate retry pattern.

KiaUvoApiUSA: add explicit except AuthenticationError: raise before
except RequestException to prevent seat retry on auth failures.

Add design doc with analysis of errorCode 502 overload and approach
comparison (egmp vs exception-based vs response-level).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant