Skip to content

inet: wait for the vehicle to come online after wake_up - #528

Open
AkshayShah03 wants to merge 2 commits into
teslamotors:mainfrom
AkshayShah03:fix/wakeup-poll-until-online
Open

AkshayShah03 wants to merge 2 commits into
teslamotors:mainfrom
AkshayShah03:fix/wakeup-poll-until-online

Conversation

@AkshayShah03

@AkshayShah03 AkshayShah03 commented Oct 24, 2026 •

Copy link
Copy Markdown

Description

Issue: inet.Connection.Wakeup returns success while the vehicle is still asleep. When wake_up answers 200 with "state": "asleep", err is nil, so protocol.Temporary(err) is false and the function returns after one request. The 10 second poll loop never runs.

Fix: send one wake_up (resent only if the request fails), then poll the unbilled GET api/1/vehicles/{vin} endpoint every second until the vehicle reports online. If the context expires first, return the new ErrWakeupPending, which wraps the context error.

Tests:

  • TestWakeupPollsVehicleStateUntilOnline
  • TestWakeupResendsFailedWakeRequest
  • TestWakeupPendingWhenContextExpires

All three fail on main. go test -race ./... passes.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Checklist:

  • My code follows the style of this project.
  • I have performed a self-review of my code.
  • I have made corresponding updates to the documentation.
  • I have added/updated unit tests to cover my changes.

Wakeup returned nil as soon as wake_up answered 200 with a state other
than "online", because protocol.Temporary(nil) is false. The 10s poll
loop never ran, so tesla-control wake returned while the car was asleep.
Comment thread pkg/connector/inet/inet.go Outdated
}

if !protocol.Temporary(err) {
// A nil err means the vehicle answered but isn't online yet, so keep polling.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a fix but there are some issues here.

I believe the server will send a wake up to the car and then immediately reply with the car's current state (not necessarily online). If we poll here by sending more wake calls, then this could very easily hit API limits; wakes are their own billing category: https://developer.tesla.com/docs/fleet-api/billing-and-limits.

Additionally, some callers invoke this function with shorter timeouts than wakePollInterval.

A better approach would be to poll on the vehicle endpoint https://developer.tesla.com/docs/fleet-api/endpoints/vehicle-endpoints#vehicle, which is not billed but does report online status. Return an error if the vehicle doesn't go to online before the context expires. Probably a special error that indicates the car was sent the request but has not (yet) reponsed, which the caller might want to handle differently than other failures.

Wake ups are billed separately, so resending wake_up every interval
could quickly hit API limits. Send a single wake_up (resending it only
if the request itself fails) and then poll GET api/1/vehicles/{vin},
which is not billed, until it reports online.

Poll every second instead of every 10 seconds, since some callers use
shorter timeouts than that. If the context expires after the wake up
was sent, return ErrWakeupPending wrapping the context error so callers
can tell that the vehicle was asked to wake up but has not come online
yet.
@AkshayShah03 AkshayShah03 changed the title inet: keep polling wake_up until the vehicle reports online inet: wait for the vehicle to come online after wake_up Oct 27, 2026
@AkshayShah03

Copy link
Copy Markdown
Author

Thanks, that makes sense. I've reworked it in 297ba95:

  • Wakeup sends a single wake_up (resent only if the request itself fails), then polls GET api/1/vehicles/{vin} until the state is online.
  • The poll interval is now 1 second, so it works with short caller timeouts.
  • If the context expires after the wake up was sent, it returns ErrWakeupPending, which wraps the context error. It's marked may-have-succeeded and temporary.

One question about the proxy: httpStatusCode maps unknown errors to 500, so a wake_up through tesla-http-proxy that doesn't finish within the proxy timeout (10s by default) now returns 500, where before it returned 200 right away. Would you like ErrWakeupPending mapped to 408, like ErrVehicleNotAwake, or something else? I can add it here or in a follow-up.

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