From a309dcb6ff5ca07d77ee0627129b76249ae1e3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sat, 21 Dec 2024 10:53:07 +0100 Subject: [PATCH] feat(FleetApiService): test fleet api access with charging current as command scope is removed --- TeslaSolarCharger/Client/Pages/Index.razor | 2 +- .../Server/Contracts/ITeslaService.cs | 1 - .../Server/Controllers/FleetApiController.cs | 14 -------- .../Server/Services/TeslaFleetApiService.cs | 35 ++----------------- 4 files changed, 4 insertions(+), 48 deletions(-) diff --git a/TeslaSolarCharger/Client/Pages/Index.razor b/TeslaSolarCharger/Client/Pages/Index.razor index 05e82e597..cdd31209e 100644 --- a/TeslaSolarCharger/Client/Pages/Index.razor +++ b/TeslaSolarCharger/Client/Pages/Index.razor @@ -87,7 +87,7 @@ else {
- Testing Fleet API access might take about 30 seconds and the headlights might flash... + Testing Fleet API access might take about 30 seconds...
} else if (_isFleetApiWorkingForCar.Any(d => d.Key == car.CarId)) diff --git a/TeslaSolarCharger/Server/Contracts/ITeslaService.cs b/TeslaSolarCharger/Server/Contracts/ITeslaService.cs index 3bde7cedf..b04242663 100644 --- a/TeslaSolarCharger/Server/Contracts/ITeslaService.cs +++ b/TeslaSolarCharger/Server/Contracts/ITeslaService.cs @@ -10,5 +10,4 @@ public interface ITeslaService Task StopCharging(int carId); Task SetAmp(int carId, int amps); Task SetChargeLimit(int carId, int limitSoC); - Task SetSentryMode(int carId, bool active); } diff --git a/TeslaSolarCharger/Server/Controllers/FleetApiController.cs b/TeslaSolarCharger/Server/Controllers/FleetApiController.cs index dd7a0c422..903472dbd 100644 --- a/TeslaSolarCharger/Server/Controllers/FleetApiController.cs +++ b/TeslaSolarCharger/Server/Controllers/FleetApiController.cs @@ -42,20 +42,6 @@ public Task SetChargeLimit(int carId, int percent) return teslaService.SetChargeLimit(carId, percent); } - /// - /// Note: This endpoint is only available in development environment - /// - /// Is thrown when not beeing in dev Mode - [HttpGet] - public Task SetSentryMode(int carId, bool active) - { - if (!configurationWrapper.IsDevelopmentEnvironment()) - { - throw new InvalidOperationException("This method is only available in development environment"); - } - return teslaService.SetSentryMode(carId, active); - } - [HttpGet] public Task> TestFleetApiAccess(int carId) => fleetApiService.TestFleetApiAccess(carId); [HttpGet] diff --git a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs index d51761ae1..4557d94d4 100644 --- a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs +++ b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs @@ -77,20 +77,6 @@ public class TeslaFleetApiService( NeedsProxy = true, TeslaApiRequestType = TeslaApiRequestType.Command, }; - private DtoFleetApiRequest SetSentryModeRequest => new() - { - RequestUrl = constants.SetSentryModeRequestUrl, - NeedsProxy = true, - TeslaApiRequestType = TeslaApiRequestType.Command, - }; - private DtoFleetApiRequest FlashHeadlightsRequest => new() - { - RequestUrl = constants.FlashHeadlightsRequestUrl, - NeedsProxy = true, - //Do not make this BLE compatible as this is used to test fleet api access - BleCompatible = false, - TeslaApiRequestType = TeslaApiRequestType.Charging, - }; private DtoFleetApiRequest WakeUpRequest => new() { RequestUrl = constants.WakeUpRequestUrl, @@ -212,19 +198,6 @@ public async Task SetChargeLimit(int carId, int limitSoC) await SendCommandToTeslaApi(vin, SetChargeLimitRequest, HttpMethod.Post, JsonConvert.SerializeObject(parameters)).ConfigureAwait(false); } - public async Task SetSentryMode(int carId, bool active) - { - logger.LogTrace("{method}({param1}, {param2})", nameof(SetSentryMode), carId, active); - var vin = GetVinByCarId(carId); - var car = settings.Cars.First(c => c.Id == carId); - await WakeUpCarIfNeeded(carId, car.State).ConfigureAwait(false); - var parameters = new Dictionary() - { - { "on", active ? 1 : 0 }, - }; - await SendCommandToTeslaApi(vin, SetSentryModeRequest, HttpMethod.Post, JsonConvert.SerializeObject(parameters)).ConfigureAwait(false); - } - public async Task> TestFleetApiAccess(int carId) { logger.LogTrace("{method}({carId})", nameof(TestFleetApiAccess), carId); @@ -233,7 +206,9 @@ public async Task> TestFleetApiAccess(int carId) try { await WakeUpCarIfNeeded(carId, inMemoryCar.State).ConfigureAwait(false); - var result = await SendCommandToTeslaApi(vin, FlashHeadlightsRequest, HttpMethod.Post).ConfigureAwait(false); + var amps = 7; + var commandData = $"{{\"charging_amps\":{amps}}}"; + var result = await SendCommandToTeslaApi(vin, SetChargingAmpsRequest, HttpMethod.Post, commandData, amps).ConfigureAwait(false); var successResult = result?.Response?.Result == true; var car = teslaSolarChargerContext.Cars.First(c => c.Id == carId); car.TeslaFleetApiState = successResult ? TeslaCarFleetApiState.Ok : TeslaCarFleetApiState.NotWorking; @@ -1022,10 +997,6 @@ private void AddRequestToCar(string vin, DtoFleetApiRequest fleetApiRequest) { car.OtherCommandCalls.Add(currentDate); } - else if (fleetApiRequest.RequestUrl == FlashHeadlightsRequest.RequestUrl) - { - car.OtherCommandCalls.Add(currentDate); - } else if (fleetApiRequest.RequestUrl == WakeUpRequest.RequestUrl) { car.WakeUpCalls.Add(currentDate);