Skip to content

Commit

Permalink
Merge pull request #1323 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Jun 16, 2024
2 parents 368a551 + 9991a2c commit 679c7f7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/Contracts/IChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface IChargingCostService
Task DeleteDuplicatedHandleCharges();
Task<List<SpotPrice>> GetSpotPrices();
Task ConvertToNewChargingProcessStructure();
Task AddFirstChargePrice();
}
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async Task DoStartupStuff(WebApplication webApplication, ILogger<Program> 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<ICarConfigurationService>();
Expand Down
22 changes: 22 additions & 0 deletions TeslaSolarCharger/Server/Services/ChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions TeslaSolarCharger/Server/Services/TeslaBleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ private async Task<DtoBleResult> 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)
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public async Task RefreshCarData()
if (vehicleData?.Error?.Contains("offline") == true)
{
car.State = CarStateEnum.Offline;
car.ChargerActualCurrent = 0;
}
if (vehicleDataResult == default)
{
Expand Down

0 comments on commit 679c7f7

Please sign in to comment.