From c567ac5320afda91e5be5fb2f8a4d9423820efd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sun, 16 Jun 2024 23:55:23 +0200 Subject: [PATCH] feat(ChargingCostService): add default charge price --- .../Server/Contracts/IChargingCostService.cs | 1 + TeslaSolarCharger/Server/Program.cs | 1 + .../Server/Services/ChargingCostService.cs | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+) 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