From 33085156be6190b885825f550fb0ba1d1015a5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Wed, 23 Aug 2023 14:13:10 +0200 Subject: [PATCH 01/23] fix(IndexService): use charging power at home to generate charge information --- .../Server/Services/ApiServices/IndexService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs index 057be24d4..7446dda69 100644 --- a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs +++ b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs @@ -136,7 +136,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State != CarStateEnum.Charging + if ((!(enabledCar.CarState.ChargingPowerAtHome > 0)) && enabledCar.CarState.EarliestSwitchOn != null && enabledCar.CarState.EarliestSwitchOn > _dateTimeProvider.Now()) { @@ -147,7 +147,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State != CarStateEnum.Charging + if ((!(enabledCar.CarState.ChargingPowerAtHome > 0)) && enabledCar.CarState.EarliestSwitchOn == null) { result.Add(new DtoChargeInformation() @@ -157,7 +157,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State == CarStateEnum.Charging + if (enabledCar.CarState.ChargingPowerAtHome > 0 && enabledCar.CarState.EarliestSwitchOff != null && enabledCar.CarState.EarliestSwitchOff > _dateTimeProvider.Now()) { @@ -168,7 +168,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State != CarStateEnum.Charging + if ((!(enabledCar.CarState.ChargingPowerAtHome > 0)) && (enabledCar.CarState.SocLimit - enabledCar.CarState.SoC) < (_constants.MinimumSocDifference + 1)) { result.Add(new DtoChargeInformation() From 5945e41a643103f1c576c1665bfd2a6df21c2c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Wed, 23 Aug 2023 14:13:10 +0200 Subject: [PATCH 02/23] Revert "fix(IndexService): use charging power at home to generate charge information" This reverts commit 33085156be6190b885825f550fb0ba1d1015a5c1. --- .../Server/Services/ApiServices/IndexService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs index 7446dda69..057be24d4 100644 --- a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs +++ b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs @@ -136,7 +136,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if ((!(enabledCar.CarState.ChargingPowerAtHome > 0)) + if (enabledCar.CarState.State != CarStateEnum.Charging && enabledCar.CarState.EarliestSwitchOn != null && enabledCar.CarState.EarliestSwitchOn > _dateTimeProvider.Now()) { @@ -147,7 +147,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if ((!(enabledCar.CarState.ChargingPowerAtHome > 0)) + if (enabledCar.CarState.State != CarStateEnum.Charging && enabledCar.CarState.EarliestSwitchOn == null) { result.Add(new DtoChargeInformation() @@ -157,7 +157,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.ChargingPowerAtHome > 0 + if (enabledCar.CarState.State == CarStateEnum.Charging && enabledCar.CarState.EarliestSwitchOff != null && enabledCar.CarState.EarliestSwitchOff > _dateTimeProvider.Now()) { @@ -168,7 +168,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if ((!(enabledCar.CarState.ChargingPowerAtHome > 0)) + if (enabledCar.CarState.State != CarStateEnum.Charging && (enabledCar.CarState.SocLimit - enabledCar.CarState.SoC) < (_constants.MinimumSocDifference + 1)) { result.Add(new DtoChargeInformation() From 284dcb0f07acf787e9dd8faf7dd05bd9e6cd8f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Thu, 24 Aug 2023 14:27:56 +0200 Subject: [PATCH 03/23] feat(IndexService): check for car is charging and in home geofence --- .../Server/Services/ApiServices/IndexService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs index 057be24d4..1ce5bd24c 100644 --- a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs +++ b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs @@ -136,7 +136,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State != CarStateEnum.Charging + if ((!(enabledCar.CarState.State == CarStateEnum.Charging && enabledCar.CarState.IsHomeGeofence == true)) && enabledCar.CarState.EarliestSwitchOn != null && enabledCar.CarState.EarliestSwitchOn > _dateTimeProvider.Now()) { @@ -147,7 +147,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State != CarStateEnum.Charging + if ((!(enabledCar.CarState.State == CarStateEnum.Charging && enabledCar.CarState.IsHomeGeofence == true)) && enabledCar.CarState.EarliestSwitchOn == null) { result.Add(new DtoChargeInformation() @@ -157,7 +157,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State == CarStateEnum.Charging + if ((enabledCar.CarState.State == CarStateEnum.Charging && enabledCar.CarState.IsHomeGeofence == true) && enabledCar.CarState.EarliestSwitchOff != null && enabledCar.CarState.EarliestSwitchOff > _dateTimeProvider.Now()) { @@ -168,7 +168,7 @@ private List GenerateChargeInformation(Car enabledCar) }); } - if (enabledCar.CarState.State != CarStateEnum.Charging + if ((!(enabledCar.CarState.State == CarStateEnum.Charging && enabledCar.CarState.IsHomeGeofence == true)) && (enabledCar.CarState.SocLimit - enabledCar.CarState.SoC) < (_constants.MinimumSocDifference + 1)) { result.Add(new DtoChargeInformation() From ecf91dd1988f18257b6fd2309694c973f0b7a938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Thu, 24 Aug 2023 14:30:09 +0200 Subject: [PATCH 04/23] feat(IndexRazor): use Charge state and home geofence to display start/stop charge --- TeslaSolarCharger/Client/Pages/Index.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Client/Pages/Index.razor b/TeslaSolarCharger/Client/Pages/Index.razor index 68a6ddaa9..12d13d71a 100644 --- a/TeslaSolarCharger/Client/Pages/Index.razor +++ b/TeslaSolarCharger/Client/Pages/Index.razor @@ -238,7 +238,7 @@ else @if (car.ChargeInformation.Count > 0) {

- Car will @(car.HomeChargePower > 0 ? "stop" : "start") charging when following conditions are met:
+ Car will @((car.State == CarStateEnum.Charging && car.IsHome) ? "stop" : "start") charging when following conditions are met:

    @foreach (var chargeInfo in car.ChargeInformation) { From 106aa9964054502670aba49dad3239a016658a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sun, 27 Aug 2023 11:42:35 +0200 Subject: [PATCH 05/23] feat(IndexService): Add last updated to PvValues --- TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs | 1 + TeslaSolarCharger/Server/Services/PvValueService.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs index 1ce5bd24c..239addb72 100644 --- a/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs +++ b/TeslaSolarCharger/Server/Services/ApiServices/IndexService.cs @@ -66,6 +66,7 @@ public DtoPvValues GetPvValues() HomeBatterySoc = _settings.HomeBatterySoc, PowerBuffer = powerBuffer, CarCombinedChargingPowerAtHome = _settings.Cars.Select(c => c.CarState.ChargingPowerAtHome).Sum(), + LastUpdated = _settings.LastPvValueUpdate, }; } diff --git a/TeslaSolarCharger/Server/Services/PvValueService.cs b/TeslaSolarCharger/Server/Services/PvValueService.cs index d810553c8..dc1435e2e 100644 --- a/TeslaSolarCharger/Server/Services/PvValueService.cs +++ b/TeslaSolarCharger/Server/Services/PvValueService.cs @@ -37,7 +37,7 @@ public PvValueService(ILogger logger, ISettings settings, public async Task UpdatePvValues() { _logger.LogTrace("{method}()", nameof(UpdatePvValues)); - _settings.LastPvValueUpdate = _dateTimeProvider.DateTimeOffSetNow(); + var gridRequestUrl = _configurationWrapper.CurrentPowerToGridUrl(); var frontendConfiguration = _configurationWrapper.FrontendConfiguration(); HttpRequestMessage? originGridRequest = default; @@ -184,6 +184,7 @@ public async Task UpdatePvValues() _settings.HomeBatteryPower = homeBatteryPower; } + _settings.LastPvValueUpdate = _dateTimeProvider.DateTimeOffSetNow(); } private async Task GetValueByHttpResponse(HttpResponseMessage? httpResponse, string? jsonPattern, string? xmlPattern, From 871bd41bb051609e7f6077cd27141a6edc5f0653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sun, 27 Aug 2023 17:28:31 +0200 Subject: [PATCH 06/23] feat(SmaPlugin): add total energy values --- .../Controllers/CurrentPowerController.cs | 6 ++++ .../Services/CurrentPowerService.cs | 10 +++++-- .../Services/EnergyMeterService.cs | 28 +++++++++++++++---- Plugins.SmaEnergymeter/SharedValues.cs | 15 ++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/Plugins.SmaEnergymeter/Controllers/CurrentPowerController.cs b/Plugins.SmaEnergymeter/Controllers/CurrentPowerController.cs index 0cfa53a92..07b83b274 100644 --- a/Plugins.SmaEnergymeter/Controllers/CurrentPowerController.cs +++ b/Plugins.SmaEnergymeter/Controllers/CurrentPowerController.cs @@ -18,5 +18,11 @@ public int GetPower() { return _currentPowerService.GetCurrentPower(); } + + [HttpGet] + public SharedValues GetAllValues() + { + return _currentPowerService.GetAllValues(); + } } } diff --git a/Plugins.SmaEnergymeter/Services/CurrentPowerService.cs b/Plugins.SmaEnergymeter/Services/CurrentPowerService.cs index 0fe5c8ce6..1aabbdc4b 100644 --- a/Plugins.SmaEnergymeter/Services/CurrentPowerService.cs +++ b/Plugins.SmaEnergymeter/Services/CurrentPowerService.cs @@ -14,6 +14,12 @@ public CurrentPowerService(ILogger logger, SharedValues sha public int GetCurrentPower() { _logger.LogTrace("{method}()", nameof(GetCurrentPower)); - return _sharedValues.Overage; + return _sharedValues.OverageW; } -} \ No newline at end of file + + public SharedValues GetAllValues() + { + _logger.LogTrace("{method}()", nameof(GetAllValues)); + return _sharedValues; + } +} diff --git a/Plugins.SmaEnergymeter/Services/EnergyMeterService.cs b/Plugins.SmaEnergymeter/Services/EnergyMeterService.cs index 3a67d8830..27afc7f11 100644 --- a/Plugins.SmaEnergymeter/Services/EnergyMeterService.cs +++ b/Plugins.SmaEnergymeter/Services/EnergyMeterService.cs @@ -55,21 +55,37 @@ public void StartLogging() var relevantValues = byteArray.Skip(28).Take(byteArray.Length - 27).ToArray(); var obisValues = ConvertArrayToObisDictionary(relevantValues); - var currentSupply = - Convert.ToDecimal(obisValues.First(v => v.Id == 1 && v.ValueType == ValueMode.Average).Value / 10.0); var currentOverage = Convert.ToDecimal(obisValues.First(v => v.Id == 2 && v.ValueType == ValueMode.Average).Value / 10.0); + var currentSupply = + Convert.ToDecimal(obisValues.First(v => v.Id == 1 && v.ValueType == ValueMode.Average).Value / 10.0); + + + var totalEnergyToGrid = Convert.ToDecimal(obisValues.First(v => v.Id == 2 && v.ValueType == ValueMode.Counter).Value / 3600.0); + var totalEnergyFromGrid = Convert.ToDecimal(obisValues.First(v => v.Id == 1 && v.ValueType == ValueMode.Counter).Value / 3600.0); + + _sharedValues.PowerFromGridW = (int) currentSupply; + _sharedValues.PowerToGridW = (int) currentOverage; + + _sharedValues.TotalEnergyToGridWh = totalEnergyToGrid; + _sharedValues.TotalEnergyFromGridWh = totalEnergyFromGrid; + + _sharedValues.LastValuesFrom = DateTime.UtcNow; + + _logger.LogTrace("current overage: {currentOverage} W", currentOverage); + _logger.LogTrace("current supply: {currentSupply} W", currentSupply); - _logger.LogTrace("current supply: {currentSupply}", currentSupply); - _logger.LogTrace("current overage: {currentOverage}", currentOverage); + _logger.LogTrace("Total energy to grid: {totalEnergyToGrid} W", totalEnergyToGrid); + _logger.LogTrace("Total energy from grid: {totalEnergyFromGrid} W", totalEnergyFromGrid); + if (currentSupply > 0) { - _sharedValues.Overage = (int)-currentSupply; + _sharedValues.OverageW = (int)-currentSupply; } else { - _sharedValues.Overage = (int)currentOverage; + _sharedValues.OverageW = (int)currentOverage; } } } diff --git a/Plugins.SmaEnergymeter/SharedValues.cs b/Plugins.SmaEnergymeter/SharedValues.cs index b0b9a6c79..5c2a2973e 100644 --- a/Plugins.SmaEnergymeter/SharedValues.cs +++ b/Plugins.SmaEnergymeter/SharedValues.cs @@ -2,5 +2,16 @@ public class SharedValues { - public int Overage { get; set; } -} \ No newline at end of file + public int OverageW { get; set; } + + public int PowerToGridW { get; set; } + public int PowerFromGridW { get; set; } + + public decimal TotalEnergyToGridWh { get; set; } + public decimal TotalEnergyFromGridWh { get; set; } + + public decimal TotalEnergyToGridkWh => TotalEnergyToGridWh / 1000; + public decimal TotalEnergyFromGridkWh => TotalEnergyFromGridWh / 1000; + + public DateTime LastValuesFrom { get; set; } +} From d185620f05f9f41212b88a19a657e40a86de1b41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Aug 2023 03:43:33 +0000 Subject: [PATCH 07/23] build(deps): Bump Microsoft.NET.Test.Sdk from 17.7.1 to 17.7.2 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.7.1 to 17.7.2. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.7.1...v17.7.2) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj index 24510bda8..ef3400cda 100644 --- a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj +++ b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj @@ -11,7 +11,7 @@ - + From d6b44ad858a8648509a2bac305218768f26d96bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Thu, 31 Aug 2023 14:46:12 +0200 Subject: [PATCH 08/23] fix(CurrentValuesService): set needed parenthesis --- Plugins.SolarEdge/Services/CurrentValuesService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins.SolarEdge/Services/CurrentValuesService.cs b/Plugins.SolarEdge/Services/CurrentValuesService.cs index 1c6eb3023..7c676fe1e 100644 --- a/Plugins.SolarEdge/Services/CurrentValuesService.cs +++ b/Plugins.SolarEdge/Services/CurrentValuesService.cs @@ -214,7 +214,7 @@ private void AddCloudApiValueToSharedValues(CloudApiValue cloudApiValue) return null; } //If there are already values there and there is no relevant car, call API everytime reset minutes are over. - if (_sharedValues.CloudApiValues.Count > 0 && numberOfRelevantCars < 1 && _sharedValues.CloudApiValues.MaxBy(v => v.Key).Key > DateTime.UtcNow - solarEdgeTooManyRequestsResetTime) + if (_sharedValues.CloudApiValues.Count > 0 && numberOfRelevantCars < 1 && (_sharedValues.CloudApiValues.MaxBy(v => v.Key).Key > (DateTime.UtcNow - solarEdgeTooManyRequestsResetTime))) { _logger.LogDebug("Prevent calling SolarEdge API as relevantCarCount is {relevantCarCount}", numberOfRelevantCars); return null; From 8545ca5e3954dc249906a94c25de068da62d1146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Thu, 31 Aug 2023 14:49:47 +0200 Subject: [PATCH 09/23] fix(CurrentValuesService): fix another parenthesis issue --- Plugins.SolarEdge/Services/CurrentValuesService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugins.SolarEdge/Services/CurrentValuesService.cs b/Plugins.SolarEdge/Services/CurrentValuesService.cs index 7c676fe1e..8cefd1a82 100644 --- a/Plugins.SolarEdge/Services/CurrentValuesService.cs +++ b/Plugins.SolarEdge/Services/CurrentValuesService.cs @@ -214,7 +214,9 @@ private void AddCloudApiValueToSharedValues(CloudApiValue cloudApiValue) return null; } //If there are already values there and there is no relevant car, call API everytime reset minutes are over. - if (_sharedValues.CloudApiValues.Count > 0 && numberOfRelevantCars < 1 && (_sharedValues.CloudApiValues.MaxBy(v => v.Key).Key > (DateTime.UtcNow - solarEdgeTooManyRequestsResetTime))) + if ((_sharedValues.CloudApiValues.Count > 0) + && numberOfRelevantCars < 1 + && (_sharedValues.CloudApiValues.MaxBy(v => v.Key).Key > (DateTime.UtcNow - solarEdgeTooManyRequestsResetTime))) { _logger.LogDebug("Prevent calling SolarEdge API as relevantCarCount is {relevantCarCount}", numberOfRelevantCars); return null; From 6e5b648270a96470c5652115b2b34924d94c1e08 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:44:09 +0000 Subject: [PATCH 10/23] build(deps): Bump Microsoft.EntityFrameworkCore.Sqlite Bumps [Microsoft.EntityFrameworkCore.Sqlite](https://github.com/dotnet/efcore) from 7.0.4 to 7.0.11. - [Release notes](https://github.com/dotnet/efcore/releases) - [Commits](https://github.com/dotnet/efcore/compare/v7.0.4...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.EntityFrameworkCore.Sqlite dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj | 2 +- TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj index 3eb5b507b..5eae1ea09 100644 --- a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj +++ b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj @@ -11,7 +11,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index 6106e6b48..64ebcbd63 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -40,7 +40,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all From ac4db4ef7864782f2b15058bc5cb5c958b776142 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:44:33 +0000 Subject: [PATCH 11/23] build(deps): Bump Microsoft.AspNetCore.Components.WebAssembly.DevServer Bumps [Microsoft.AspNetCore.Components.WebAssembly.DevServer](https://github.com/dotnet/aspnetcore) from 7.0.10 to 7.0.11. - [Release notes](https://github.com/dotnet/aspnetcore/releases) - [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md) - [Commits](https://github.com/dotnet/aspnetcore/compare/v7.0.10...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Components.WebAssembly.DevServer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj b/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj index 956c3edb9..54255b27f 100644 --- a/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj +++ b/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj @@ -19,7 +19,7 @@ - + From bc03ec890d7d8708870fa0b7c9adbe648d7f9c79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:44:42 +0000 Subject: [PATCH 12/23] build(deps): Bump Microsoft.AspNetCore.OpenApi from 7.0.10 to 7.0.11 Bumps [Microsoft.AspNetCore.OpenApi](https://github.com/dotnet/aspnetcore) from 7.0.10 to 7.0.11. - [Release notes](https://github.com/dotnet/aspnetcore/releases) - [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md) - [Commits](https://github.com/dotnet/aspnetcore/compare/v7.0.10...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.OpenApi dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Plugins.Solax/Plugins.Solax.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins.Solax/Plugins.Solax.csproj b/Plugins.Solax/Plugins.Solax.csproj index a85d443ce..be9411f73 100644 --- a/Plugins.Solax/Plugins.Solax.csproj +++ b/Plugins.Solax/Plugins.Solax.csproj @@ -8,7 +8,7 @@ - + From 85cb3334e0b9f598867e838bb532b9753de45495 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:44:51 +0000 Subject: [PATCH 13/23] build(deps): Bump Microsoft.AspNetCore.Components.WebAssembly.Server Bumps [Microsoft.AspNetCore.Components.WebAssembly.Server](https://github.com/dotnet/aspnetcore) from 7.0.10 to 7.0.11. - [Release notes](https://github.com/dotnet/aspnetcore/releases) - [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md) - [Commits](https://github.com/dotnet/aspnetcore/compare/v7.0.10...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Components.WebAssembly.Server dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index 6106e6b48..bb9418f97 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -34,7 +34,7 @@ - + all From 22a72720ae578e1c2bc4bfdadca726e3eb754dfe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 03:42:26 +0000 Subject: [PATCH 14/23] build(deps): Bump Npgsql.EntityFrameworkCore.PostgreSQL Bumps [Npgsql.EntityFrameworkCore.PostgreSQL](https://github.com/npgsql/efcore.pg) from 7.0.4 to 7.0.11. - [Release notes](https://github.com/npgsql/efcore.pg/releases) - [Commits](https://github.com/npgsql/efcore.pg/compare/v7.0.4...v7.0.11) --- updated-dependencies: - dependency-name: Npgsql.EntityFrameworkCore.PostgreSQL dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj | 2 +- TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj index 3eb5b507b..2c3918aa5 100644 --- a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj +++ b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj @@ -16,7 +16,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index 6106e6b48..374044709 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -48,7 +48,7 @@ - + From aab4a26a5db7ff6ff6f4d61f51a328c5228590bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 03:42:31 +0000 Subject: [PATCH 15/23] build(deps): Bump xunit.runner.visualstudio from 2.5.0 to 2.5.1 Bumps [xunit.runner.visualstudio](https://github.com/xunit/xunit) from 2.5.0 to 2.5.1. - [Commits](https://github.com/xunit/xunit/compare/2.5.0...2.5.1) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj index ef3400cda..9e9fd81db 100644 --- a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj +++ b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj @@ -16,7 +16,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From f504508e863d74f2cc92edabf85ff829ac8b9632 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:37:03 +0000 Subject: [PATCH 16/23] build(deps): Bump xunit from 2.5.0 to 2.5.1 Bumps [xunit](https://github.com/xunit/xunit) from 2.5.0 to 2.5.1. - [Commits](https://github.com/xunit/xunit/compare/2.5.0...2.5.1) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj index 9e9fd81db..c30a98ac4 100644 --- a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj +++ b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj @@ -15,7 +15,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 5ee0ffe9f304ee2edb28b52583716f9f17f940af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:37:40 +0000 Subject: [PATCH 17/23] build(deps): Bump MQTTnet from 4.2.1.781 to 4.3.1.873 Bumps [MQTTnet](https://github.com/dotnet/MQTTnet) from 4.2.1.781 to 4.3.1.873. - [Release notes](https://github.com/dotnet/MQTTnet/releases) - [Commits](https://github.com/dotnet/MQTTnet/compare/v4.2.1.781...v4.3.1.873) --- updated-dependencies: - dependency-name: MQTTnet dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index dcd5eeecd..faf463336 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -46,7 +46,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 63ba91e9a07103a9f0ad14e349fc5dcc964a743d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:37:51 +0000 Subject: [PATCH 18/23] build(deps): Bump Microsoft.EntityFrameworkCore.Design Bumps [Microsoft.EntityFrameworkCore.Design](https://github.com/dotnet/efcore) from 7.0.4 to 7.0.11. - [Release notes](https://github.com/dotnet/efcore/releases) - [Commits](https://github.com/dotnet/efcore/compare/v7.0.4...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.EntityFrameworkCore.Design dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj | 2 +- TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj index 2c3918aa5..bfdbff4d8 100644 --- a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj +++ b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj @@ -7,7 +7,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index dcd5eeecd..236f26243 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -36,7 +36,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 2dae5b9c808c4d6e2f586931badc3d9851e833d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:37:52 +0000 Subject: [PATCH 19/23] build(deps): Bump Microsoft.AspNetCore.Components.WebAssembly Bumps [Microsoft.AspNetCore.Components.WebAssembly](https://github.com/dotnet/aspnetcore) from 7.0.10 to 7.0.11. - [Release notes](https://github.com/dotnet/aspnetcore/releases) - [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md) - [Commits](https://github.com/dotnet/aspnetcore/compare/v7.0.10...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Components.WebAssembly dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj b/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj index 54255b27f..51506cd18 100644 --- a/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj +++ b/TeslaSolarCharger/Client/TeslaSolarCharger.Client.csproj @@ -18,7 +18,7 @@ - + From a41c0bf55cbfb9561530d9d743a8893f92713dfc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:44:06 +0000 Subject: [PATCH 20/23] build(deps): Bump Microsoft.AspNetCore.Mvc.NewtonsoftJson Bumps [Microsoft.AspNetCore.Mvc.NewtonsoftJson](https://github.com/dotnet/aspnetcore) from 7.0.10 to 7.0.11. - [Release notes](https://github.com/dotnet/aspnetcore/releases) - [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md) - [Commits](https://github.com/dotnet/aspnetcore/compare/v7.0.10...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Mvc.NewtonsoftJson dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index 6e5b5e199..428938dc9 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -35,7 +35,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 51b11c87de7223f8ddc014adb280c1630ce1313b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:44:56 +0000 Subject: [PATCH 21/23] build(deps): Bump Microsoft.EntityFrameworkCore.Tools Bumps [Microsoft.EntityFrameworkCore.Tools](https://github.com/dotnet/efcore) from 7.0.4 to 7.0.11. - [Release notes](https://github.com/dotnet/efcore/releases) - [Commits](https://github.com/dotnet/efcore/compare/v7.0.4...v7.0.11) --- updated-dependencies: - dependency-name: Microsoft.EntityFrameworkCore.Tools dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj index 4880ff410..5d0a1d8c7 100644 --- a/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj +++ b/TeslaSolarCharger.Model/TeslaSolarCharger.Model.csproj @@ -12,7 +12,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From f0d77cc0d704964bf9ee1c196196021622d7000a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Tue, 19 Sep 2023 00:39:09 +0200 Subject: [PATCH 22/23] refactor(chore): use fake it easy --- .../LatestTimeToReachSocUpdateService.cs | 10 +++--- .../TeslaSolarCharger.Tests.csproj | 21 +++++++----- TeslaSolarCharger.Tests/TestBase.cs | 34 ++++++++++++++----- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs b/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs index 71fbba876..d358c804b 100644 --- a/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs +++ b/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs @@ -1,4 +1,5 @@ using Autofac; +using FakeItEasy; using System; using TeslaSolarCharger.Shared.Contracts; using TeslaSolarCharger.Shared.Dtos.Settings; @@ -24,13 +25,10 @@ public void Correctly_Updates_LatestTimeToReachSoc(bool shouldIgnoreDate, DateTi LatestTimeToReachSoC = configuredDate, }; - var currentTimeProvider = Mock.Create( - new NamedParameter("dateTime", currentDate)); - Mock.Provide(currentTimeProvider); - - var latestTimeToReachSocUpdateService = Mock.Create(); + _fake.Provide(new FakeDateTimeProvider(currentDate)); + var latestTimeToReachSocUpdateService = _fake.Resolve(); latestTimeToReachSocUpdateService.UpdateCarConfiguration(carConfiguration); - + Assert.Equal(expectedDate, carConfiguration.LatestTimeToReachSoC); } diff --git a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj index c30a98ac4..2e43c3220 100644 --- a/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj +++ b/TeslaSolarCharger.Tests/TeslaSolarCharger.Tests.csproj @@ -8,15 +8,18 @@ - - - - - - - - - + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/TeslaSolarCharger.Tests/TestBase.cs b/TeslaSolarCharger.Tests/TestBase.cs index 66a197545..d7898f2be 100644 --- a/TeslaSolarCharger.Tests/TestBase.cs +++ b/TeslaSolarCharger.Tests/TestBase.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using Autofac; +using Autofac.Extras.FakeItEasy; using Autofac.Extras.Moq; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -12,6 +13,8 @@ using Serilog.Events; using TeslaSolarCharger.Model.Contracts; using TeslaSolarCharger.Model.EntityFramework; +using TeslaSolarCharger.Server.MappingExtensions; +using TeslaSolarCharger.Shared.Contracts; using TeslaSolarCharger.Shared.TimeProviding; using Xunit.Abstractions; @@ -24,6 +27,7 @@ public class TestBase : IDisposable protected readonly AutoMock Mock; private readonly TeslaSolarChargerContext _ctx; + protected readonly AutoFake _fake; protected ITeslaSolarChargerContext Context => _ctx; @@ -44,16 +48,28 @@ protected TestBase( {"ConfigFileLocation", "configs"}, {"CarConfigFilename", "carConfig.json"}, }; + var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(configDictionary!) - .Build() + .AddInMemoryCollection(configDictionary!) + .Build() ; - - Mock = AutoMock.GetLoose(cfg => - { - cfg.RegisterType(typeof(FakeDateTimeProvider)); - cfg.RegisterInstance(configuration).As(); - }); + + var currentFakeTime = new DateTime(2023, 2, 2, 8, 0, 0); + + _fake = new AutoFake(); + _fake.Provide(); + _fake.Provide(new FakeDateTimeProvider(currentFakeTime)); + _fake.Provide(configuration); + + Mock = AutoMock.GetLoose( + b => + { + b.Register((_, _) => Context); + b.Register((_, _) => _fake.Resolve()); + b.Register((_, _) => _fake.Resolve()); + b.RegisterType(); + //b.Register((_, _) => _fake.Resolve()); + }); // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); @@ -88,7 +104,7 @@ protected TestBase( //var autoMock = AutoMock.GetLoose(cfg => cfg.RegisterInstance(new TeslaSolarChargerContext(options)).As()); //_ctx = (TeslaSolarChargerContext) autoMock.Create(); - _ctx = (TeslaSolarChargerContext)Mock.Provide(new TeslaSolarChargerContext(options)); + _ctx = _fake.Provide(new TeslaSolarChargerContext(options)); _ctx.Database.EnsureCreated(); //_ctx.InitContextData(); _ctx.SaveChanges(); From 262a458b57d9e6321d09da80b20d9528226e076d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Tue, 19 Sep 2023 00:52:14 +0200 Subject: [PATCH 23/23] refactor(tests): remove resharper warnings --- .../Services/Server/ChargeTimeCalculationService.cs | 6 ++++-- .../Services/Server/LatestTimeToReachSocUpdateService.cs | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TeslaSolarCharger.Tests/Services/Server/ChargeTimeCalculationService.cs b/TeslaSolarCharger.Tests/Services/Server/ChargeTimeCalculationService.cs index f64811d91..ee9ec5948 100644 --- a/TeslaSolarCharger.Tests/Services/Server/ChargeTimeCalculationService.cs +++ b/TeslaSolarCharger.Tests/Services/Server/ChargeTimeCalculationService.cs @@ -150,7 +150,8 @@ public async Task Dont_Plan_Charging_If_Min_Soc_Reached(ChargeMode chargeMode) }; var chargeTimeCalculationService = Mock.Create(); - var chargingSlots = await chargeTimeCalculationService.PlanChargingSlots(car, currentDate).ConfigureAwait(false); + // ReSharper disable once UseConfigureAwaitFalse + var chargingSlots = await chargeTimeCalculationService.PlanChargingSlots(car, currentDate); Assert.Empty(chargingSlots); } @@ -210,7 +211,8 @@ public async Task Calculate_Correct_ChargeTimes_Without_Stock_Prices(ChargeMode }; var chargeTimeCalculationService = Mock.Create(); - var chargingSlots = await chargeTimeCalculationService.PlanChargingSlots(car, currentDate).ConfigureAwait(false); + // ReSharper disable once UseConfigureAwaitFalse + var chargingSlots = await chargeTimeCalculationService.PlanChargingSlots(car, currentDate); Assert.Single(chargingSlots); diff --git a/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs b/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs index d358c804b..468f96536 100644 --- a/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs +++ b/TeslaSolarCharger.Tests/Services/Server/LatestTimeToReachSocUpdateService.cs @@ -1,6 +1,4 @@ -using Autofac; -using FakeItEasy; -using System; +using System; using TeslaSolarCharger.Shared.Contracts; using TeslaSolarCharger.Shared.Dtos.Settings; using TeslaSolarCharger.Shared.TimeProviding;