Skip to content

Storm Watch silently degrading on stale Fleet API token - #665

Open
MikeBishop wants to merge 2 commits into
mainfrom
storm_watch
Open

Storm Watch silently degrading on stale Fleet API token#665
MikeBishop wants to merge 2 commits into
mainfrom
storm_watch

Conversation

@MikeBishop

@MikeBishop MikeBishop commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Storm Watch (TeslaPowerwall2.getStormWatch()) only ever read the Fleet API bearer token/expiry passively — it never triggered a refresh itself, and the only refresh path in the codebase (TeslaAPI.car_api_available()) was called exclusively from vehicle-command code (charge, wake, apply limit). Any deployment where nothing sends those commands — e.g. relying on BLE for local vehicle control never refreshed the token, so Storm Watch quietly went stale and cached an empty result for up to 30 minutes at a time with zero logging.

Fix: extracted the refresh-if-stale check out of car_api_available() into a standalone TeslaAPI.refreshTokenIfNeeded(), called it directly from getStormWatch(), and added a periodic call to it in the main loop (every 5 minutes) independent of any vehicle command.

(Also fixed a latent UnboundLocalError in the exception handler (referenced r.status_code when the request itself could throw before r was ever assigned) and added a debug-level log line for the previously-silent skip path.)

Token refresh only happened as a side effect of car_api_available(),
which is only called from charge/wake/limit commands. Deployments
that never send those (BLE-only vehicle control, Powerwall-only
monitoring) never refreshed the token at all. Extract the refresh
check into TeslaAPI.refreshTokenIfNeeded() and call it periodically
from the main loop, independent of any vehicle command.
getStormWatch() only read the bearer token/expiry passively and
silently skipped the whole check when stale, caching an empty result
for up to cloudUpdateInterval with no log output. Have it call the
new refreshTokenIfNeeded() before checking, log the skip path, and
fix a latent UnboundLocalError where the except handler referenced
r.status_code even when the request itself raised before r was
assigned.
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Test Results

4 456 tests  ±0   4 352 ✅ ±0   13m 26s ⏱️ -5s
   12 suites ±0       8 💤 ±0 
   12 files   ±0      96 ❌ ±0 

For more details on these failures, see this check.

Results for commit 02c56cf. ± Comparison against base commit 827e71d.

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