diff --git a/TeslaSolarCharger/Server/Contracts/IChargingCostService.cs b/TeslaSolarCharger/Server/Contracts/IChargingCostService.cs index a54ab0a2d..06460f5a2 100644 --- a/TeslaSolarCharger/Server/Contracts/IChargingCostService.cs +++ b/TeslaSolarCharger/Server/Contracts/IChargingCostService.cs @@ -12,4 +12,5 @@ public interface IChargingCostService Task DeleteDuplicatedHandleCharges(); Task> GetSpotPrices(); Task ConvertToNewChargingProcessStructure(); + Task AddFirstChargePrice(); } diff --git a/TeslaSolarCharger/Server/Program.cs b/TeslaSolarCharger/Server/Program.cs index 5be596c22..78dc042a9 100644 --- a/TeslaSolarCharger/Server/Program.cs +++ b/TeslaSolarCharger/Server/Program.cs @@ -167,6 +167,7 @@ async Task DoStartupStuff(WebApplication webApplication, ILogger logger await configJsonService.ConvertOldCarsToNewCar().ConfigureAwait(false); //This needs to be done after converting old cars to new cars as IDs might change await chargingCostService.ConvertToNewChargingProcessStructure().ConfigureAwait(false); + await chargingCostService.AddFirstChargePrice().ConfigureAwait(false); await configJsonService.UpdateAverageGridVoltage().ConfigureAwait(false); var carConfigurationService = webApplication.Services.GetRequiredService(); diff --git a/TeslaSolarCharger/Server/Services/ChargingCostService.cs b/TeslaSolarCharger/Server/Services/ChargingCostService.cs index e34489f73..f26c2f393 100644 --- a/TeslaSolarCharger/Server/Services/ChargingCostService.cs +++ b/TeslaSolarCharger/Server/Services/ChargingCostService.cs @@ -147,6 +147,28 @@ public async Task UpdateChargePrice(DtoChargePrice dtoChargePrice) await tscOnlyChargingCostService.UpdateChargePricesOfAllChargingProcesses().ConfigureAwait(false); } + public async Task AddFirstChargePrice() + { + logger.LogTrace("{method}()", nameof(AddFirstChargePrice)); + var chargePrices = await teslaSolarChargerContext.ChargePrices + .ToListAsync().ConfigureAwait(false); + if (chargePrices.Any(c => c.ValidSince < new DateTime(2022, 2, 1))) + { + return; + } + var chargePrice = new DtoChargePrice() + { + GridPrice = 0.25m, + SolarPrice = 0.25m, + ValidSince = DateTime.SpecifyKind(new DateTime(2020, 1, 1), DateTimeKind.Utc), + EnergyProvider = EnergyProvider.OldTeslaSolarChargerConfig, + AddSpotPriceToGridPrice = false, + SpotPriceSurcharge = 0.19m, + EnergyProviderConfiguration = null, + }; + await UpdateChargePrice(chargePrice).ConfigureAwait(false); + } + public async Task DeleteChargePriceById(int id) { var chargePrice = await teslaSolarChargerContext.ChargePrices diff --git a/TeslaSolarCharger/Server/Services/TeslaBleService.cs b/TeslaSolarCharger/Server/Services/TeslaBleService.cs index f80429459..89b48a17c 100644 --- a/TeslaSolarCharger/Server/Services/TeslaBleService.cs +++ b/TeslaSolarCharger/Server/Services/TeslaBleService.cs @@ -145,6 +145,8 @@ private async Task SendCommandToBle(DtoBleRequest request) using var client = new HttpClient(); try { + //Default timeout of Tesla Command CLI is 21 seconds. + client.Timeout = TimeSpan.FromSeconds(22); var response = await client.PostAsJsonAsync(url, request.Parameters).ConfigureAwait(false); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (!response.IsSuccessStatusCode) diff --git a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs index 4459ca24f..ec343e280 100644 --- a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs +++ b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs @@ -295,6 +295,7 @@ public async Task RefreshCarData() if (vehicleData?.Error?.Contains("offline") == true) { car.State = CarStateEnum.Offline; + car.ChargerActualCurrent = 0; } if (vehicleDataResult == default) {