From 31fae754761ea525c82ce1adf4cd698178651b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Fri, 8 Dec 2023 09:34:09 +0100 Subject: [PATCH 1/4] feat(SpotPriceService): add base AwattarURL to appsettings.json --- .../Services/Server/SpotPriceService.cs | 3 +++ TeslaSolarCharger/Server/Services/SpotPriceService.cs | 7 +++++-- TeslaSolarCharger/Server/appsettings.json | 1 + .../Shared/Contracts/IConfigurationWrapper.cs | 1 + TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs | 7 +++++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs b/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs index 67947e69f..70797974a 100644 --- a/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs +++ b/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs @@ -39,6 +39,9 @@ public void Generates_Awattar_Url_With_DateTimeOffset() Mock.Mock() .Setup(d => d.DateTimeOffSetNow()) .Returns(currentDate); + Mock.Mock() + .Setup(c => c.GetAwattarBaseUrl()) + .Returns("https://api.awattar.de/v1/marketdata"); var endFutureMilliseconds = currentDate.AddHours(48).ToUnixTimeMilliseconds(); diff --git a/TeslaSolarCharger/Server/Services/SpotPriceService.cs b/TeslaSolarCharger/Server/Services/SpotPriceService.cs index d9754c668..2b63a724e 100644 --- a/TeslaSolarCharger/Server/Services/SpotPriceService.cs +++ b/TeslaSolarCharger/Server/Services/SpotPriceService.cs @@ -12,13 +12,15 @@ public class SpotPriceService : ISpotPriceService private readonly ILogger _logger; private readonly ITeslaSolarChargerContext _teslaSolarChargerContext; private readonly IDateTimeProvider _dateTimeProvider; + private readonly IConfigurationWrapper _configurationWrapper; public SpotPriceService(ILogger logger, ITeslaSolarChargerContext teslaSolarChargerContext, - IDateTimeProvider dateTimeProvider) + IDateTimeProvider dateTimeProvider, IConfigurationWrapper configurationWrapper) { _logger = logger; _teslaSolarChargerContext = teslaSolarChargerContext; _dateTimeProvider = dateTimeProvider; + _configurationWrapper = configurationWrapper; } public async Task UpdateSpotPrices() @@ -71,7 +73,8 @@ internal SpotPrice GenerateSpotPriceFromAwattarPrice(Datum value) internal string GenerateAwattarUrl(DateTimeOffset? fromDate) { - var url = "https://api.awattar.de/v1/marketdata"; + var url = _configurationWrapper.GetAwattarBaseUrl(); + //var url = "https://api.awattar.de/v1/marketdata"; if (fromDate != null) { var toDate = _dateTimeProvider.DateTimeOffSetNow().AddHours(48); diff --git a/TeslaSolarCharger/Server/appsettings.json b/TeslaSolarCharger/Server/appsettings.json index 386519662..ad2703489 100644 --- a/TeslaSolarCharger/Server/appsettings.json +++ b/TeslaSolarCharger/Server/appsettings.json @@ -62,6 +62,7 @@ "UseFleetApi": false, "FleetApiClientId": "f29f71d6285a-4873-8b6b-80f15854892e", "BackendApiBaseUrl": "https://www.teslasolarcharger.de/api/", + "AwattarBaseUrl": "https://api.awattar.de/v1/marketdata", "GridPriceProvider": { "EnergyProvider": "FixedPrice", "Octopus": { diff --git a/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs b/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs index e23caf90f..d2c679ca8 100644 --- a/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs +++ b/TeslaSolarCharger/Shared/Contracts/IConfigurationWrapper.cs @@ -90,4 +90,5 @@ public interface IConfigurationWrapper bool UseFleetApi(); string BackendApiBaseUrl(); bool IsDevelopmentEnvironment(); + string GetAwattarBaseUrl(); } diff --git a/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs b/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs index 3582e8a88..0aad5d1ab 100644 --- a/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs +++ b/TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs @@ -92,6 +92,13 @@ internal string ConfigFileDirectory() return path; } + public string GetAwattarBaseUrl() + { + var environmentVariableName = "AwattarBaseUrl"; + var value = GetNotNullableConfigurationValue(environmentVariableName); + return value; + } + public bool AllowCors() { var environmentVariableName = "AllowCORS"; From cea8ddee8bcb9e593f92133c859afae317664c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Fri, 8 Dec 2023 09:59:54 +0100 Subject: [PATCH 2/4] fix(Tests): Mock Awattar Base Url --- TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs b/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs index 70797974a..ceb5840e5 100644 --- a/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs +++ b/TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs @@ -54,6 +54,9 @@ public void Generates_Awattar_Url_With_DateTimeOffset() public void Generates_Awattar_Url_WithOut_DateTimeOffset() { var spotPriceService = Mock.Create(); + Mock.Mock() + .Setup(c => c.GetAwattarBaseUrl()) + .Returns("https://api.awattar.de/v1/marketdata"); var url = spotPriceService.GenerateAwattarUrl(null); Assert.Equal("https://api.awattar.de/v1/marketdata", url); } From db58d29f3b417054e47a2d11506ea2f11a8767aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Fri, 8 Dec 2023 10:12:54 +0100 Subject: [PATCH 3/4] feat(TeslaFleetApiService): set correct current before charge start --- TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs index d5ff11b52..a3cb3dfa8 100644 --- a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs +++ b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs @@ -71,6 +71,8 @@ public async Task StartCharging(int carId, int startAmp, CarStateEnum? carState) await WakeUpCarIfNeeded(carId, carState).ConfigureAwait(false); var id = await _teslamateContext.Cars.Where(c => c.Id == carId).Select(c => c.Eid).FirstAsync().ConfigureAwait(false); + await SetAmp(carId, startAmp).ConfigureAwait(false); + var result = await SendCommandToTeslaApi(id, _chargeStartComand).ConfigureAwait(false); } From 4ffb15fa41d5efcb1dc08ed4340c213942d7fed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Fri, 8 Dec 2023 22:12:28 +0100 Subject: [PATCH 4/4] feat(IndexRazor): update info texts --- TeslaSolarCharger/Client/Pages/Index.razor | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TeslaSolarCharger/Client/Pages/Index.razor b/TeslaSolarCharger/Client/Pages/Index.razor index 529372702..775f082b0 100644 --- a/TeslaSolarCharger/Client/Pages/Index.razor +++ b/TeslaSolarCharger/Client/Pages/Index.razor @@ -17,6 +17,23 @@ Tesla Solar Charger +@if(_serverTime != default) +{ + if (_serverTime.Value is { Day: 24, Month: 12, Hour: > 15 } or { Day: 25, Month: 12 }) + { + + + } + if(_serverTime.Value is { Day: 31, Month: 12, Hour: > 15 } or { Day: 1, Month: 1}) + { + + } +} + @if (_pvValues != null)