teslamateapi
teslamateapi copied to clipboard
Recommendation: Endpoint to List Available Drive/Charge IDs
This isn't an issue, but a recommendation that I want to open discussion for.
Issue When designing a UI to hook up to this API, I find it hard to scrape for all charge and/or drive data. I may want to do this to run queries against the entire set of charge and drive data or simply to cache relevant information.
Why It's hard to assume we have all the data since drive and charge IDs aren't always ordered one after the other. For example, if TeslaMate is down while a charge finishes, that charge will never be completed and will be considered invalid. In this case, we may have charges with ID = 1, 2, and 4, but where charge ID = 3 is an invalid charge and not relevant to the API response.
Current Option The best existing option here is to poll the "/charges" or "/drives" endpoint and go one page at a time until an invalid response is received (and hope this is because we have exhausted the data, and not because of a TeslaMateAPI error). This leaves the client wondering just how much data there is, until the heavy lifting is finished. It also makes it hard to schedule the data fetch in the background.
Suggestion
Add a new meta endpoint to return the IDs (and potentially other basic meta) of all valid objects, like this
Example
Request: /api/v1/cars/:CarID/meta
Response:
{
"charges": {
"ids": [1, 2, 4, 7, 8, 9, 10, ..., 762, 764, 765]
},
"drives": { ... }
}
Additional (simpler) option, add this as a URL query to existing API endpoints.
Example
Request: /api/v1/cars/:CarID/charges?meta_only=true
Hi @alecdoconnor,
This is a nice suggestion, I really like this! I can take a look at this next week (quite busy with stuff).