TeslaLogger
TeslaLogger copied to clipboard
Reduce number of API calls for 2023.38.X
Describe the bug While the fix to support 2023.38.X is working great, it is effectively doubling the amount of calls to the Tesla API.
https://github.com/bassmaster187/TeslaLogger/blob/ce9f3f74cd95d18b1389708d3a577230bddc0bde/TeslaLogger/WebHelper.cs#L2974-L2998
For firmware version 2023.38.X, the Tesla API reply to the first call will never contain the latitude, always forcing Teslalogger to make a second call.
The Tesla API supports getting all relevant information in a single call. To achieve this, all necessary parameters must directly be passed as URL parameters in the first call. TeslaMate shows how this is done and this is also backwards compatible for older firmware versions: https://github.com/teslamate-org/teslamate/pull/3373/files
Background information The Tesla API documentation has a section for pricing. While currently the pricing is fixed at $0/week, there is no guarantee that this will continue to be the case. There is also a limit for the amount of API requests, which means that in the future it may be prudent to reduce the number of calls
While it may not seem necessary at the moment, it would be wise to optimize the amount of calls necessary, if not only in order to be a good citizen and to reduce the possibility of potential connectivity issues.
Due to time issues, I can't offer a PR at the moment, but I would like to leave this issue here, so either I can try to fix it in the future or maybe someone else can have a go in the meantime.
I played with this
https://github.com/superfloh247/TeslaLogger/tree/bugfix-1132
but all I get ist 408 timeout, both with an old MCU1 car and an up to date Model Y
Thanks for giving this a shot. About the 408 - that is usually a sign that either the car is unreachable (car is asleep or no internet connection) or that another client (e.g. the official app) is currently active.
Does the 408 message contain a reason (such as "VEHICLE_UNAVAILABLE")?
Maybe it makes sense to only request specific parameters while driving (line 2955).
https://github.com/bassmaster187/TeslaLogger/blob/ce9f3f74cd95d18b1389708d3a577230bddc0bde/TeslaLogger/WebHelper.cs#L2950-L2955
According to the Tesla API documentation: "This may return cached data if the vehicle is offline." https://developer.tesla.com/docs/fleet-api#vehicle_data
I am not sure if and how the cache also works when we are passing specific URL parameters. Maybe it makes sense to only address this in driving state for now, where we know that the car is online.