Repository navigation
inet: wait for the vehicle to come online after wake_up - #528
AkshayShah03 wants to merge 1 commit into
Conversation
| } | ||
|
|
||
| if !protocol.Temporary(err) { | ||
| // A nil err means the vehicle answered but isn't online yet, so keep polling. |
There was a problem hiding this comment.
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.
|
Thanks, that makes sense. I've reworked it in 297ba95:
One question about the proxy: |
|
408 sounds right for a wake fail. Squash commits and force push. |
Wakeup returned nil as soon as wake_up answered 200 with a state other
than "online", because protocol.Temporary(nil) is false. The poll loop
never ran, so tesla-control wake returned while the car was asleep.
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, since
some callers use short timeouts.
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.
tesla-http-proxy maps ErrWakeupPending to 408, like ErrVehicleNotAwake.
297ba95 to
ee6c209
Compare
|
Added the 408 mapping for |
Description
Issue:
inet.Connection.Wakeupreturns success while the vehicle is still asleep. Whenwake_upanswers 200 with"state": "asleep",erris nil, soprotocol.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 unbilledGET api/1/vehicles/{vin}endpoint every second until the vehicle reportsonline. If the context expires first, return the newErrWakeupPending, which wraps the context error.Tests:
TestWakeupPollsVehicleStateUntilOnlineTestWakeupResendsFailedWakeRequestTestWakeupPendingWhenContextExpiresAll three fail on main.
go test -race ./...passes.Type of change
Checklist: