Adds fleet status endpoint
All checks were successful
Build, Push and Run Container / build (push) Successful in 25s
All checks were successful
Build, Push and Run Container / build (push) Successful in 25s
Adds an endpoint to retrieve fleet status information. This endpoint uses a Tesla API proxy to fetch the fleet status based on provided VINs. It handles authentication using a bearer token and sends a POST request to the /api/1/vehicles/fleet_status endpoint. Also introduces new data models to properly serialize/deserialize the fleet status response.
This commit is contained in:
25
Source/ProofOfConcept/Models/FleetResponse.cs
Normal file
25
Source/ProofOfConcept/Models/FleetResponse.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace ProofOfConcept.Models;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class FleetRootResponse
|
||||
{
|
||||
[JsonPropertyName("response")] public FleetResponse FleetResponse { get; set; } = new FleetResponse();
|
||||
}
|
||||
|
||||
public class FleetResponse
|
||||
{
|
||||
[JsonPropertyName("key_paired_vins")] public List<string> KeyPairedVins { get; set; } = new List<string>();
|
||||
[JsonPropertyName("unpaired_vins")] public List<string> UnpairedVins { get; set; } = new List<string>();
|
||||
[JsonPropertyName("vehicle_info")] public Dictionary<string, VehicleInfo> VehicleInfo { get; set; } = new Dictionary<string, VehicleInfo>();
|
||||
}
|
||||
|
||||
public class VehicleInfo
|
||||
{
|
||||
[JsonPropertyName("firmware_version")] public string FirmwareVersion { get; set; } = "";
|
||||
[JsonPropertyName("vehicle_command_protocol_required")] public bool VehicleCommandProtocolRequired { get; set; }
|
||||
[JsonPropertyName("discounted_device_data")] public bool DiscountedDeviceData { get; set; }
|
||||
[JsonPropertyName("fleet_telemetry_version")] public string FleetTelemetryVersion { get; set; } = "";
|
||||
[JsonPropertyName("total_number_of_keys")] public int TotalNumberOfKeys { get; set; }
|
||||
}
|
||||
@@ -288,6 +288,22 @@ if (app.Environment.IsDevelopment())
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("FleetStatus", async (IHttpClientFactory httpClientFactory) =>
|
||||
{
|
||||
string access_token = "eyJhbGci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OSitmxPrxr9MOT8A9KUgTOSIrPxD36JHWnBmQpbkDNqNkM4MLEbbM-95p8YnFJ0VuB9_fzz0CbJyOm_oUelA2JnNhIQ5uGfJojYPM2UKN0rUx6uMAuFgc4CslPY1P43crAXrFlH6B3D2Yk47w9Xeh-Vg_ZiX-nJqMzph_ciqYRuiySJMjM3ez7EheGy50BR_esz4muit89H3nq0rURWBN3-weauu2bcWnuYp0Nk5-zFuO3O_FKuLt-1HqYH3CAeTF2JRBJHim-hA";
|
||||
|
||||
HttpClient client = httpClientFactory.CreateClient("InsecureClient");
|
||||
client.BaseAddress = new Uri("https://tesla_command_proxy");
|
||||
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {access_token}");
|
||||
|
||||
//Get fleet_status endpoint
|
||||
var requestObject = new { vins = new string[] { "5YJ3E7EB7KF291652" } };
|
||||
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync("/api/1/vehicles/fleet_status", requestObject);
|
||||
|
||||
return Results.Ok(response.Content.ReadAsStringAsync());
|
||||
});
|
||||
|
||||
//Map static assets
|
||||
app.MapStaticAssets();
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace ProofOfConcept.Services;
|
||||
|
||||
public class MQTTClient : IHostedService
|
||||
{
|
||||
private ILogger<MQTTClient> logger;
|
||||
private MQTTClientConfiguration configuration;
|
||||
private MQTTServerConfiguration serverConfiguration;
|
||||
private readonly ILogger<MQTTClient> logger;
|
||||
private readonly MQTTClientConfiguration configuration;
|
||||
private readonly MQTTServerConfiguration serverConfiguration;
|
||||
|
||||
private readonly IMqttClient client;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user