Skip to content

Commit

Permalink
Merge pull request #344 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Oct 3, 2022
2 parents 5f69c46 + c90a418 commit aa54110
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TeslaSolarCharger/Server/Contracts/IChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TeslaSolarCharger.Server.Contracts;

public interface IChargingCostService
{
Task AddPowerDistributionForAllCharingCars();
Task AddPowerDistributionForAllChargingCars();
Task FinalizeHandledCharges();
Task<DtoChargeSummary> GetChargeSummary(int carId);
Task UpdateChargePrice(DtoChargePrice dtoChargePrice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class IssueKeys
public string HomeBatterySocNotPlausible = "HomeBatterySocNotPlausible";
public string HomeBatteryPowerNotAvailable = "HomeBatteryPowerNotAvailable";
public string HomeBatteryHalfConfigured = "HomeBatteryHalfConfigured";
public string HomeBatteryMinimumSocNotConfigured = "HomeBatteryMinimumSocNotConfigured";
public string HomeBatteryChargingPowerNotConfigured = "HomeBatteryChargingPowerNotConfigured";
public string TeslaMateApiNotAvailable = "TeslaMateApiNotAvailable";
public string DatabaseNotAvailable = "DatabaseNotAvailable";
public string GeofenceNotAvailable = "GeofenceNotAvailable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public PossibleIssues(IssueKeys issueKeys)
"Update the car IDs in your Base Configuration to existing car IDs in TeslaMate."
)
},
{
issueKeys.HomeBatteryMinimumSocNotConfigured, CreateIssue("Although you did set settings for your home battery you did not set Home Battery Minimum Soc (%)",
IssueType.Error,
"Set the Home Battery Minimum Soc (%) in your Base Configuration"
)
},
{
issueKeys.HomeBatteryChargingPowerNotConfigured, CreateIssue("Although you did set settings for your home battery you did not set Home Battery charging power (W)",
IssueType.Error,
"Set the Home Battery charging power (W) in your Base Configuration"
)
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public PowerDistributionAddJob(ILogger<ChargeTimeUpdateJob> logger, IChargingCos
public async Task Execute(IJobExecutionContext context)
{
_logger.LogTrace("Executing Job to update ChargeTimes");
await _service.AddPowerDistributionForAllCharingCars().ConfigureAwait(false);
await _service.AddPowerDistributionForAllChargingCars().ConfigureAwait(false);
}
}
4 changes: 2 additions & 2 deletions TeslaSolarCharger/Server/Services/ChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public async Task<List<DtoChargePrice>> GetChargePrices()
return chargePrices;
}

public async Task AddPowerDistributionForAllCharingCars()
public async Task AddPowerDistributionForAllChargingCars()
{
_logger.LogTrace("{method}()", nameof(AddPowerDistributionForAllCharingCars));
_logger.LogTrace("{method}()", nameof(AddPowerDistributionForAllChargingCars));
//ToDO: remove before release
var chargePrice = await _teslaSolarChargerContext.ChargePrices
.FirstOrDefaultAsync().ConfigureAwait(false);
Expand Down
18 changes: 9 additions & 9 deletions TeslaSolarCharger/Server/Services/ChargingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task SetNewChargingValues()
if (powerToControlIncludingChargingPower <
minimumChargingPower)
{
_logger.LogDebug("Set Should charge since to early date so car will stop charing.");
_logger.LogDebug("Set Should charge since to early date so car will stop charging.");
relevantCar.CarState.ShouldStopChargingSince = new DateTime(2022, 1, 1);
}
}
Expand Down Expand Up @@ -136,32 +136,32 @@ private int CalculatePowerToControl(List<Car> relevantCars)
_logger.LogDebug("Averaged overage {averagedOverage}", averagedOverage);

var overage = averagedOverage - buffer;
_logger.LogTrace("Overage after subtracting power buffer ({buffer}): {overage}", buffer, overage);
_logger.LogDebug("Overage after subtracting power buffer ({buffer}): {overage}", buffer, overage);

var homeBatteryMinSoc = _configurationWrapper.HomeBatteryMinSoc();
_logger.LogTrace("Home battery min soc: {homeBatteryMinSoc}", homeBatteryMinSoc);
_logger.LogDebug("Home battery min soc: {homeBatteryMinSoc}", homeBatteryMinSoc);
var homeBatteryMaxChargingPower = _configurationWrapper.HomeBatteryChargingPower();
_logger.LogTrace("Home battery should charging power: {homeBatteryMaxChargingPower}", homeBatteryMaxChargingPower);
_logger.LogDebug("Home battery should charging power: {homeBatteryMaxChargingPower}", homeBatteryMaxChargingPower);
if (homeBatteryMinSoc != null && homeBatteryMaxChargingPower != null)
{
var actualHomeBatterySoc = _settings.HomeBatterySoc;
_logger.LogTrace("Home battery actual soc: {actualHomeBatterySoc}", actualHomeBatterySoc);
_logger.LogDebug("Home battery actual soc: {actualHomeBatterySoc}", actualHomeBatterySoc);
var actualHomeBatteryPower = _settings.HomeBatteryPower;
_logger.LogTrace("Home battery actual power: {actualHomeBatteryPower}", actualHomeBatteryPower);
_logger.LogDebug("Home battery actual power: {actualHomeBatteryPower}", actualHomeBatteryPower);
if (actualHomeBatterySoc != null && actualHomeBatteryPower != null)
{
if (actualHomeBatterySoc < homeBatteryMinSoc)
{
overage -= (int)homeBatteryMaxChargingPower - (int)actualHomeBatteryPower;

_logger.LogTrace(
_logger.LogDebug(
"Overage after subtracting difference between max home battery charging power ({homeBatteryMaxChargingPower}) and actual home battery charging power ({actualHomeBatteryPower}): {overage}",
homeBatteryMaxChargingPower, actualHomeBatteryPower, overage);
}
else
{
overage += (int)actualHomeBatteryPower;
_logger.LogTrace("Overage after adding home battery power ({actualHomeBatteryPower}): {overage}",
_logger.LogDebug("Overage after adding home battery power ({actualHomeBatteryPower}): {overage}",
actualHomeBatteryPower, overage);
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ private async Task<int> ChangeCarAmp(Car car, int ampToChange)
//Falls Klima an (Laden nicht deaktivierbar), oder Ausschaltbefehl erst seit Kurzem
if (car.CarState.ClimateOn == true || earliestSwitchOff > DateTime.Now)
{
_logger.LogDebug("Can not stop charing: Climate on: {climateState}, earliest Switch Off: {earliestSwitchOff}",
_logger.LogDebug("Can not stop charging: Climate on: {climateState}, earliest Switch Off: {earliestSwitchOff}",
car.CarState.ClimateOn,
earliestSwitchOff);
if (car.CarState.ChargerActualCurrent != minAmpPerCar)
Expand Down
24 changes: 18 additions & 6 deletions TeslaSolarCharger/Server/Services/IssueValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,40 @@ private List<Issue> PvValueIssues()
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.InverterPowerNotAvailable));
}

var isHomeBatterySocConfigured = !(string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatterySocUrl()) && string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatterySocMqttTopic()));
if (isHomeBatterySocConfigured && _settings.HomeBatterySoc == null)
var isHomeBatterySocGettingConfigured = !(string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatterySocUrl()) && string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatterySocMqttTopic()));
if (isHomeBatterySocGettingConfigured && _settings.HomeBatterySoc == null)
{
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.HomeBatterySocNotAvailable));
}

if (isHomeBatterySocConfigured && _settings.HomeBatterySoc != null && (_settings.HomeBatterySoc > 100 || _settings.HomeBatterySoc < 0))
if (isHomeBatterySocGettingConfigured && _settings.HomeBatterySoc != null && (_settings.HomeBatterySoc > 100 || _settings.HomeBatterySoc < 0))
{
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.HomeBatterySocNotPlausible));
}

var isHomeBatteryPowerConfigured = !(string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatteryPowerUrl()) && string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatteryPowerMqttTopic()));
if (isHomeBatteryPowerConfigured && _settings.HomeBatteryPower == null)
var isHomeBatteryPowerGettingConfigured = !(string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatteryPowerUrl()) && string.IsNullOrWhiteSpace(_configurationWrapper.HomeBatteryPowerMqttTopic()));
if (isHomeBatteryPowerGettingConfigured && _settings.HomeBatteryPower == null)
{
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.HomeBatteryPowerNotAvailable));
}

if (isHomeBatteryPowerConfigured != isHomeBatterySocConfigured)
if (isHomeBatteryPowerGettingConfigured != isHomeBatterySocGettingConfigured)
{
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.HomeBatteryHalfConfigured));
}

if ((isHomeBatterySocGettingConfigured || isHomeBatteryPowerGettingConfigured) &&
(_configurationWrapper.HomeBatteryMinSoc() == null))
{
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.HomeBatteryMinimumSocNotConfigured));
}

if ((isHomeBatterySocGettingConfigured || isHomeBatteryPowerGettingConfigured) &&
(_configurationWrapper.HomeBatteryChargingPower() == null))
{
issues.Add(_possibleIssues.GetIssueByKey(_issueKeys.HomeBatteryChargingPowerNotConfigured));
}

return issues;
}
}

0 comments on commit aa54110

Please sign in to comment.