Skip to content

Fix Meebook JWT token expiry: invalidate cached token and retry#1

Merged
Jogge merged 8 commits into
mainfrom
copilot/fix-intermittent-failure
Apr 6, 2026
Merged

Fix Meebook JWT token expiry: invalidate cached token and retry#1
Jogge merged 8 commits into
mainfrom
copilot/fix-intermittent-failure

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 20, 2026

  • Review all changes made in the branch against the base
  • Delete tests/test_client_response_handling.py (owner requested removal)
  • Verify all remaining client.py changes are necessary
  • Run validation (CodeQL clean, code review clean for changed code)

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 20, 2026 10:27
…onses

When the Meebook API returns a JSON string instead of a JSON array
(e.g., after token expiration), json.loads() returns a Python string.
Iterating over a string gives individual characters, causing
TypeError: string indices must be integers on person["name"].

Changes:
- Meebook: Wrap json.loads in try/except, validate data is a list
  before iterating, preserve exceptionMessage handling for dict responses
- Huskelisten: Fix incomplete exception handling (set data=None on
  failure), validate data is a list before iterating
- Use specific exception types instead of bare except

Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix intermittent failure in Home Assistant custom integration Fix TypeError when Meebook/Huskelisten APIs return non-list JSON responses Mar 20, 2026
Copilot AI requested a review from Jogge March 20, 2026 10:29
…piry response

When Meebook API returns {'message': 'JWT-Token expired, please renew.'},
clear the cached token for widget 0004 and retry the request once with a
fresh token. This allows automatic recovery without requiring a restart.

Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Jogge/aula/sessions/28528ad2-5ca5-4520-af27-45d36d02646e
Copilot AI changed the title Fix TypeError when Meebook/Huskelisten APIs return non-list JSON responses Fix Meebook JWT token expiry: invalidate cached token and retry Mar 24, 2026
When Meebook returns 'JWT-Token expired', the widget token cache was
cleared and a new widget token was fetched from aulaToken.getAulaToken.
But the Aula session access token itself was stale, so the new widget
token was also expired by Meebook.

Fix: Call self.login() to refresh the Aula session before getting a new
widget token. This ensures aulaToken.getAulaToken generates a valid
token from a fresh session. The login call is wrapped in try/except to
handle gracefully if refresh fails.

Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Jogge/aula/sessions/92e87394-bf32-4707-bfbe-748281ed7a1f
When Meebook says "JWT-Token expired", login() was called but it saw
the Aula access token was still valid and reused it. This meant
aulaToken.getAulaToken generated widget tokens from the same session,
which Meebook still rejected.

Fix: Add force_refresh parameter to login() that skips the "reuse valid
token" shortcut and proceeds directly to renew_access_token(). The
Meebook retry path now calls login(force_refresh=True) to ensure the
Aula access token is actually renewed before fetching a new widget token.

Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Jogge/aula/sessions/e60de5ef-ca34-4f82-a0fb-6c3ee8e86c5f
When Meebook returns "JWT-Token expired", the retry refreshed the OAuth
access token but kept the same requests.Session() with stale Aula
server-side session cookies. The aulaToken.getAulaToken endpoint then
returned a Meebook JWT that was already expired because the stale cookies
pointed to an expired server-side session.

Fix: Reset self._session = None before login retry, so
_apply_token_to_session() creates a fresh requests.Session() with no
stale cookies. This matches the behavior on HA restart (which works).

Agent-Logs-Url: https://github.com/Jogge/aula/sessions/b0d0263c-0500-481f-9a22-4622ba526a9e

Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Review confirmed all client.py changes are necessary:
- login(force_refresh) for Meebook retry flow
- Session reset + token refresh on Meebook JWT expiry
- Defensive JSON parsing (try/except, type guards)
- Huskelisten bare except narrowed + data=None on failure

Agent-Logs-Url: https://github.com/Jogge/aula/sessions/594a9cd8-54e4-451c-aa38-86ea03600994

Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Copilot finished work on behalf of Jogge April 6, 2026 06:12
@Jogge Jogge marked this pull request as ready for review April 6, 2026 06:13
Copilot finished work on behalf of Jogge April 6, 2026 06:23
@Jogge Jogge merged commit 4ce91bf into main Apr 6, 2026
1 check passed
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.

2 participants