From 3a748ba5c565aa8897e4b79041a983c7cff13388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sat, 27 Jan 2024 18:33:30 +0100 Subject: [PATCH 1/7] fix(TeslaFleetApiService): remove unnecessary char --- TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs index 4a53c8ef4..a569f567c 100644 --- a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs +++ b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs @@ -75,7 +75,7 @@ public class TeslaFleetApiService( private DtoFleetApiRequest VehicleRequest => new() { - RequestUrl = $"", + RequestUrl = "", NeedsProxy = false, }; From 80148633abb96dfcfcacd7ed6ccd1e17997c4b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Mon, 29 Jan 2024 17:56:50 +0100 Subject: [PATCH 2/7] feat(Program): log to seq --- .../DbConnectionStringHelper.cs | 5 ++-- TeslaSolarCharger/Server/Program.cs | 19 ++++++++++----- .../Services/Contracts/IBackendApiService.cs | 1 + .../Server/TeslaSolarCharger.Server.csproj | 1 + .../Server/appsettings.Development.json | 11 ++++++++- TeslaSolarCharger/Server/appsettings.json | 23 +++++++++---------- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/TeslaSolarCharger.Model/EntityFramework/DbConnectionStringHelper.cs b/TeslaSolarCharger.Model/EntityFramework/DbConnectionStringHelper.cs index dd097870d..26278b9f3 100644 --- a/TeslaSolarCharger.Model/EntityFramework/DbConnectionStringHelper.cs +++ b/TeslaSolarCharger.Model/EntityFramework/DbConnectionStringHelper.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using TeslaSolarCharger.Model.Contracts; using TeslaSolarCharger.Shared.Contracts; @@ -31,7 +31,8 @@ public string GetTeslaMateConnectionString() public string GetTeslaSolarChargerDbPath() { _logger.LogTrace("{method}()", nameof(GetTeslaSolarChargerDbPath)); - var connectionString = $"Data Source={_configurationWrapper.SqliteFileFullName()};Pooling=False"; + var filePath = _configurationWrapper.SqliteFileFullName(); + var connectionString = $"Data Source={filePath};Pooling=False"; return connectionString; } } diff --git a/TeslaSolarCharger/Server/Program.cs b/TeslaSolarCharger/Server/Program.cs index 538bbef51..4df189466 100644 --- a/TeslaSolarCharger/Server/Program.cs +++ b/TeslaSolarCharger/Server/Program.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using Serilog; +using Serilog.Context; using TeslaSolarCharger.GridPriceProvider; using TeslaSolarCharger.Model.Contracts; using TeslaSolarCharger.Server; @@ -44,6 +45,11 @@ var app = builder.Build(); +Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(app.Services.GetRequiredService()) + .Enrich.FromLogContext() + .CreateLogger(); + //Do nothing before these lines as BaseConfig.json is created here. This results in breaking new installations! var logger = app.Services.GetRequiredService>(); @@ -56,16 +62,21 @@ await baseConfigurationConverter.ConvertAllEnvironmentVariables().ConfigureAwait(false); await baseConfigurationConverter.ConvertBaseConfigToV1_0().ConfigureAwait(false); - var coreService = app.Services.GetRequiredService(); - coreService.LogVersion(); //Do nothing before these lines as database is created here. var teslaSolarChargerContext = app.Services.GetRequiredService(); await teslaSolarChargerContext.Database.MigrateAsync().ConfigureAwait(false); + var tscConfigurationService = app.Services.GetRequiredService(); + var installationId = await tscConfigurationService.GetInstallationId().ConfigureAwait(false); var backendApiService = app.Services.GetRequiredService(); + var version = await backendApiService.GetCurrentVersion().ConfigureAwait(false); + LogContext.PushProperty("InstallationId", installationId); + LogContext.PushProperty("Version", version); + await backendApiService.PostInstallationInformation("Startup").ConfigureAwait(false); + var coreService = app.Services.GetRequiredService(); await coreService.BackupDatabaseIfNeeded().ConfigureAwait(false); var life = app.Services.GetRequiredService(); @@ -74,10 +85,6 @@ coreService.KillAllServices().GetAwaiter().GetResult(); }); - var tscConfigurationService = app.Services.GetRequiredService(); - var installationId = await tscConfigurationService.GetInstallationId().ConfigureAwait(false); - logger.LogInformation("Installation Id: {installationId}", installationId); - var chargingCostService = app.Services.GetRequiredService(); await chargingCostService.DeleteDuplicatedHandleCharges().ConfigureAwait(false); diff --git a/TeslaSolarCharger/Server/Services/Contracts/IBackendApiService.cs b/TeslaSolarCharger/Server/Services/Contracts/IBackendApiService.cs index e8e79b497..b53cc9d6b 100644 --- a/TeslaSolarCharger/Server/Services/Contracts/IBackendApiService.cs +++ b/TeslaSolarCharger/Server/Services/Contracts/IBackendApiService.cs @@ -7,4 +7,5 @@ public interface IBackendApiService Task> StartTeslaOAuth(string locale, string baseUrl); Task PostInstallationInformation(string reason); Task PostErrorInformation(string source, string methodName, string message, string? stackTrace = null); + Task GetCurrentVersion(); } diff --git a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj index 92f4f511a..1e6ee379a 100644 --- a/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj +++ b/TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj @@ -54,6 +54,7 @@ + diff --git a/TeslaSolarCharger/Server/appsettings.Development.json b/TeslaSolarCharger/Server/appsettings.Development.json index 9fabe6703..f1ebbf654 100644 --- a/TeslaSolarCharger/Server/appsettings.Development.json +++ b/TeslaSolarCharger/Server/appsettings.Development.json @@ -1,7 +1,8 @@ { "Serilog": { "Using": [ - "Serilog.Sinks.Console" + "Serilog.Sinks.Console", + "Serilog.Sinks.Seq" ], "MinimumLevel": { "Default": "Verbose", @@ -19,6 +20,14 @@ "Args": { "outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Level:u3} {SourceContext}] {Message:lj}{NewLine}{Exception}" } + }, + { + "Name": "Seq", + "Args": { + "serverUrl": "https://www.teslasolarcharger.de/seq-logging", + "restrictedToMinimumLevel": "Warning", + "outputTemplate": "[{Timestamp:dd-MMM-yyyy HH:mm:ss.fff} {Level:u3} {SourceContext} {InstallationId} {Version}] {Message:lj}{NewLine}{Exception}" + } } ], "Enrich": [ diff --git a/TeslaSolarCharger/Server/appsettings.json b/TeslaSolarCharger/Server/appsettings.json index d3bf5944f..872107bc0 100644 --- a/TeslaSolarCharger/Server/appsettings.json +++ b/TeslaSolarCharger/Server/appsettings.json @@ -1,7 +1,8 @@ { "Serilog": { "Using": [ - "Serilog.Sinks.Console" + "Serilog.Sinks.Console", + "Serilog.Sinks.Seq" ], "MinimumLevel": { "Default": "Debug", @@ -22,17 +23,15 @@ "Args": { "outputTemplate": "[{Timestamp:dd-MMM-yyyy HH:mm:ss.fff} {Level:u3} {SourceContext}] {Message:lj}{NewLine}{Exception}" } - } //, - //{ - // "Name": "File", - // "Args": { - // "outputTemplate": "[{Timestamp:dd-MMM-yyyy HH:mm:ss.fff} {Level:u3} {SourceContext}] {Message:lj}{NewLine}{Exception}", - // "path": "configs/log.txt", - // "rollingIntervall": "Day", - // "rollOnFileSizeLimit": true, - // "retainedFileCountLimit": 7 - // } - //} + }, + { + "Name": "Seq", + "Args": { + "serverUrl": "https://www.teslasolarcharger.de/seq-logging", + "restrictedToMinimumLevel": "Warning", + "outputTemplate": "[{Timestamp:dd-MMM-yyyy HH:mm:ss.fff} {Level:u3} {SourceContext} {InstallationId} {Version}] {Message:lj}{NewLine}{Exception}" + } + } ], "Enrich": [ "FromLogContext" From a39da2152b8bee6fa61843d9e7b44e9ef2b9eb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Mon, 29 Jan 2024 18:01:01 +0100 Subject: [PATCH 3/7] fix(ConfigJsonService): use TeslaMateCarId as primary identifier --- TeslaSolarCharger/Server/Services/ConfigJsonService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TeslaSolarCharger/Server/Services/ConfigJsonService.cs b/TeslaSolarCharger/Server/Services/ConfigJsonService.cs index 4da74150d..282eb3696 100644 --- a/TeslaSolarCharger/Server/Services/ConfigJsonService.cs +++ b/TeslaSolarCharger/Server/Services/ConfigJsonService.cs @@ -243,7 +243,7 @@ public async Task AddCarsToTscDatabase() var carsToManage = _settings.Cars.Where(c => c.CarConfiguration.ShouldBeManaged == true).ToList(); foreach (var car in carsToManage) { - var databaseCar = await _teslaSolarChargerContext.Cars.FirstOrDefaultAsync(c => c.Id == car.Id).ConfigureAwait(false); + var databaseCar = await _teslaSolarChargerContext.Cars.FirstOrDefaultAsync(c => c.TeslaMateCarId == car.Id).ConfigureAwait(false); if (databaseCar != default) { continue; @@ -251,7 +251,6 @@ public async Task AddCarsToTscDatabase() databaseCar = new Model.Entities.TeslaSolarCharger.Car() { - Id = car.Id, TeslaMateCarId = car.Id, }; _teslaSolarChargerContext.Cars.Add(databaseCar); From f82d2256e32b12c929d9bcd17c22098e35b6a4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Mon, 29 Jan 2024 18:03:20 +0100 Subject: [PATCH 4/7] feat(CICD): use fixcarid tag --- .github/workflows/alphaRelease.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/alphaRelease.yml b/.github/workflows/alphaRelease.yml index 58fcf48c3..1cbccca09 100644 --- a/.github/workflows/alphaRelease.yml +++ b/.github/workflows/alphaRelease.yml @@ -53,7 +53,7 @@ jobs: file: ./TeslaSolarCharger/Server/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: pkuehnel/teslasolarcharger:alpha + tags: pkuehnel/teslasolarcharger:fixcarid SmaEnergymeterPlugin: name: Building SMAPlugin Image From 55f17ad9998d952e3453d8d8eb1103df3bcd0d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Mon, 29 Jan 2024 22:51:44 +0100 Subject: [PATCH 5/7] feat(README): add transferred data --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5795674c5..024054c08 100644 --- a/README.md +++ b/README.md @@ -1035,3 +1035,4 @@ As the new Tesla Fleet API requires a domain and external Token creation from ve - Your access code is used to get the access token from Tesla (Note: the token itself is only stored locally in your TSC installation. It is only transferred via my server, but the token only exists in memory on the server itself. It is not stored in a database or log file) - Your installation ID (GUID) is at the bottom of the page. Do not post this GUID in public forums, as it is used to deliver the Tesla access token to your installation. Note: There is only a five-minute time window between requesting and providing the token using the installation ID. After these 5 minutes, all requests are blocked.) - Your installed version. +- Error and warning logs From 3e4cc1d48e1f923241067cbfb43edcaf7286080e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Mon, 29 Jan 2024 22:52:03 +0100 Subject: [PATCH 6/7] Revert "feat(CICD): use fixcarid tag" This reverts commit f82d2256e32b12c929d9bcd17c22098e35b6a4db. --- .github/workflows/alphaRelease.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/alphaRelease.yml b/.github/workflows/alphaRelease.yml index 1cbccca09..58fcf48c3 100644 --- a/.github/workflows/alphaRelease.yml +++ b/.github/workflows/alphaRelease.yml @@ -53,7 +53,7 @@ jobs: file: ./TeslaSolarCharger/Server/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: pkuehnel/teslasolarcharger:fixcarid + tags: pkuehnel/teslasolarcharger:alpha SmaEnergymeterPlugin: name: Building SMAPlugin Image From 9b0e9a6ed3d806a6e712b3b85355e39fe7e24a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Mon, 29 Jan 2024 22:55:42 +0100 Subject: [PATCH 7/7] feat(PvValueService): log inverter power below 0 as information --- TeslaSolarCharger/Server/Services/PvValueService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeslaSolarCharger/Server/Services/PvValueService.cs b/TeslaSolarCharger/Server/Services/PvValueService.cs index 06f64d63c..aa1f565f7 100644 --- a/TeslaSolarCharger/Server/Services/PvValueService.cs +++ b/TeslaSolarCharger/Server/Services/PvValueService.cs @@ -98,7 +98,7 @@ public async Task UpdatePvValues() patternType, xmlAttributeHeaderName, xmlAttributeHeaderValue, xmlAttributeValueName).ConfigureAwait(false); if (inverterPower < 0) { - _logger.LogWarning("Inverterpower is below 0: {inverterPower}, using -1 for further purposes", inverterPower); + _logger.LogInformation("Inverterpower is below 0: {inverterPower}, using -1 for further purposes", inverterPower); inverterPower = -1; } _settings.InverterPower = inverterPower;