fix: refresh stale token before photo upload; guard panel define#636
Merged
Conversation
…perfect-week 50) The number platform defaulted weekend_multiplier to 1.0 and perfect_week_bonus to 0, but the bonus logic (coord_points.py / sensor.py) falls back to 2.0 and 50 when the setting is unset. On a fresh install the entities therefore showed values that didn't match what was actually applied. Use the same defaults.
…d panel define The photo-evidence upload (child card → POST /api/taskmate/photo) sends the auth token by hand via this.hass.auth.data.access_token. That cached token is short-lived (~30 min) and, unlike callWS, is never refreshed, so once a session ages the upload 401s and the card shows its catch-all "Upload failed. Check your connection" — masking the real auth failure (confirmed in http.ban logs). _confirmPhoto now refreshes the token when expired before posting, and retries once after a forced refresh if the POST still returns 401. Server side was verified healthy (valid token → HTTP 200, file stored). Also guard taskmate-panel.js's customElements.define(): after a version bump the browser can briefly hold both the old (?v=prev) and new (?v=current) panel modules, and the second unguarded define() throws "name already used", which surfaced as an uncaught error in the iOS frontend log. Now no-ops if already defined, matching the idempotent pattern the global modules already use.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Photo-evidence upload from the child card fails on long-lived sessions with a generic "Upload failed. Check your connection and try again." The real cause (confirmed in
http.banlogs) is a 401: the request toPOST /api/taskmate/photocarries an expired auth token._confirmPhotois the only place that sends the token by hand (this.hass.auth.data.access_token, rawfetch); everything else usescallWS, which auto-refreshes. The cached access token is short-lived (~30 min) and never refreshed here, so once a session ages the upload 401s — and the card collapses every failure into the same "check your connection" message, masking the cause.Server side verified healthy: POSTing a real JPEG with a valid token returns HTTP 200 and stores the file.
A second, separate error from the iOS log:
After a version bump the browser can briefly hold both the old (
?v=prev) and new (?v=current) panel modules; the unguardedcustomElements.define()throws on the second.Fix
taskmate-child-card.js— refresh the access token if expired before posting; if the POST still returns 401, force a refresh and retry once.taskmate-panel.js— guard thedefine()withif (!customElements.get("taskmate-panel")), matching the idempotent pattern the global modules already use.Verification
node --check.No version bump / no release — JS-only fix.