Skip to content

Commit 2499098

Browse files
thematrixdevclaude
andcommitted
Fix token refresh not triggering on access token expiry
CLP API returns code 100001 ("LR access_token error") when the access token expires after 1 hour, but the refresh logic only checked for code 906. This caused the session to break permanently instead of refreshing the token. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5cf0a14 commit 2499098

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

custom_components/clphk/sensor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,16 @@ async def api_request(
431431
_LOGGER.error(error_message)
432432

433433
if 400 <= e.status < 500:
434-
# Align with webpage behavior: refresh only after token-expired response.
434+
# Refresh on token-expired responses:
435+
# 906 = token expired, 100001 = LR access_token error (also expired)
435436
if (
436437
retry_on_expired
437438
and "refresh_token" not in url
438439
and isinstance(error_data, dict)
439-
and error_data.get("code") == 906
440+
and error_data.get("code") in (906, 100001)
440441
and self._refresh_token
441442
):
442-
_LOGGER.debug("Access token expired (906). Refreshing and retrying once.")
443+
_LOGGER.debug("Access token expired (code=%s). Refreshing and retrying once.", error_data.get("code"))
443444
await self._refresh_access_token()
444445
retry_headers = dict(headers or {})
445446
if "Authorization" in retry_headers:

0 commit comments

Comments
 (0)