G-Two / subarulink

A python package for interacting with Subaru STARLINK remote vehicle services.
Apache License 2.0
84 stars 14 forks source link

update service results in invalid token #48

Closed ACiDGRiM closed 2 years ago

ACiDGRiM commented 2 years ago

I can start the car using the start service, vin and climate preset, however I rely on the update service to monitor when the car is turned off by polling every minute.

I get this response when calling update:

Failed to call service subaru.update. Service update failed for 2019 Ascent Limited: Unhandled API error: InvalidToken - {'success': False, 'errorCode': 'InvalidToken', 'dataName': 'errorResponse', 'data': {'errorLabel': 'InvalidToken', 'errorDescription': 'E003'}}

G-Two commented 2 years ago

My theory is the session between the web server backend and the telematics provider expires after some condition, even if validateSession returns success. It might be time based (previous API versions expired after 24 hours and required a forced authentication sequence). Since you are attempting every 1 minute, you probably have the best data to help me understand the conditions. Can you check your logs and tell me the time delta between when the subaru integration logged in and when the InvalidToken first appeared? If you do a search for login.json, that should give you the first timestamp. I have a potential fix ready to go, but it would help to have more data. Thanks.

ACiDGRiM commented 2 years ago

To add some detail, the step that calls the update service is called in node-red when "input_boolean.remote_start" is turned on, then it progresses to the remote_start service, and then loops every minute until the ignition sensor is detected as off.

I'm looking into getting the info you need, but since the first step in the flow fails, nothing is actually being polled every minute.

This is also an issue for my "are any doors or windows open at night" flow which calls update once.

G-Two commented 2 years ago

Got it. In that case just try the latest v0.6.0rc2 and see if it fixes the error.

ACiDGRiM commented 2 years ago

So I'm trying to reproduce the issue, and I had suspected this since I call the remote start flow in the morning before I leave for work on a schedule and I don't get the API failure alert/errors often times. It's calling the update service successfully at this moment.

However, intermittently I'll call it or it will be called automatically and I'll get the error like it was doing consistently when I opened this issue.

I'll report back with the requested info when it acts up again.

ACiDGRiM commented 2 years ago

I've been sitting on this through some release candidates for the upstream HA integration. I'm still not able to get the same reliability I was before subaru corked everything up with the new feature.

Currently I am seeing this error after replacing all of my automations with the new "button" model

fetch command failed for 2019 Ascent Limited: HTTP 500: <ClientResponse(https://mobileapi.prod.subarucs.com/g2v21/service/g2/locate/execute.json) [500 ]> <CIMultiDictProxy('Date': 'Wed, 05 Jan 2022 14:47:19 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE', 'Access-Control-Allow-Headers': 'Accept, Content-Type', 'Cache-Control': 'max-age=0, no-cache, no-store, must-revalidate', 'Pragma': 'no-cache')>

One thing that I HAVE noticed recently and can correlate with what I had seen when I opened this issue, is that the remote features work well in the EVENING, after 11-12PM (not a concrete time cutoff for debugging!) but in the MORNING, they do not work well. For example, i use remote start in the morning at 7AM (AKST) and get frequent errors, (now and 7 days ago), however I refresh in the evening to check if the doors are open and then lock them, OR If I call the remote start flow in the afternoon time it will remote start without error.

ACiDGRiM commented 2 years ago

upon reviewing my flows, the fetch button had the VIN still provided in the data value. This may be fixed after all.

G-Two commented 2 years ago

To be clear these errors are not InvalidToken errors which this issue is for (and has been fixed in v0.6.0rc5). If you are still having InvalidToken errors in rc5, let me know.

I'm not sure what I can do for the HTTP 500/502 errors since these are server side. The integration is providing consistent calls to the Subaru API, and the server is failing for whatever reason. I've had mine running rc5 continuously for one week and have received 8 500/502 errors (6AM, 5PM, Noon EST) during automatic refresh. Mine is running at the default 5 minute refresh interval. I've also noticed that each time the 500 error occurs, it takes the Subaru server 30 seconds to internally timeout and send the 500 error.