Skip to content

Commit

Permalink
Merge pull request #1097 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Jan 29, 2024
2 parents a832ec1 + 980bc97 commit f8e1319
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using TeslaSolarCharger.Model.Contracts;
using TeslaSolarCharger.Shared.Contracts;

Expand Down Expand Up @@ -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;
}
}
19 changes: 13 additions & 6 deletions TeslaSolarCharger/Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Serilog;
using Serilog.Context;
using TeslaSolarCharger.GridPriceProvider;
using TeslaSolarCharger.Model.Contracts;
using TeslaSolarCharger.Server;
Expand Down Expand Up @@ -44,6 +45,11 @@

var app = builder.Build();

Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(app.Services.GetRequiredService<IConfiguration>())
.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<ILogger<Program>>();
Expand All @@ -56,16 +62,21 @@
await baseConfigurationConverter.ConvertAllEnvironmentVariables().ConfigureAwait(false);
await baseConfigurationConverter.ConvertBaseConfigToV1_0().ConfigureAwait(false);

var coreService = app.Services.GetRequiredService<ICoreService>();
coreService.LogVersion();

//Do nothing before these lines as database is created here.
var teslaSolarChargerContext = app.Services.GetRequiredService<ITeslaSolarChargerContext>();
await teslaSolarChargerContext.Database.MigrateAsync().ConfigureAwait(false);

var tscConfigurationService = app.Services.GetRequiredService<ITscConfigurationService>();
var installationId = await tscConfigurationService.GetInstallationId().ConfigureAwait(false);
var backendApiService = app.Services.GetRequiredService<IBackendApiService>();
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<ICoreService>();
await coreService.BackupDatabaseIfNeeded().ConfigureAwait(false);

var life = app.Services.GetRequiredService<IHostApplicationLifetime>();
Expand All @@ -74,10 +85,6 @@
coreService.KillAllServices().GetAwaiter().GetResult();
});

var tscConfigurationService = app.Services.GetRequiredService<ITscConfigurationService>();
var installationId = await tscConfigurationService.GetInstallationId().ConfigureAwait(false);
logger.LogInformation("Installation Id: {installationId}", installationId);

var chargingCostService = app.Services.GetRequiredService<IChargingCostService>();
await chargingCostService.DeleteDuplicatedHandleCharges().ConfigureAwait(false);

Expand Down
3 changes: 1 addition & 2 deletions TeslaSolarCharger/Server/Services/ConfigJsonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,14 @@ 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;
}

databaseCar = new Model.Entities.TeslaSolarCharger.Car()
{
Id = car.Id,
TeslaMateCarId = car.Id,
};
_teslaSolarChargerContext.Cars.Add(databaseCar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface IBackendApiService
Task<DtoValue<string>> StartTeslaOAuth(string locale, string baseUrl);
Task PostInstallationInformation(string reason);
Task PostErrorInformation(string source, string methodName, string message, string? stackTrace = null);
Task<string?> GetCurrentVersion();
}
2 changes: 1 addition & 1 deletion TeslaSolarCharger/Server/Services/PvValueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class TeslaFleetApiService(

private DtoFleetApiRequest VehicleRequest => new()
{
RequestUrl = $"",
RequestUrl = "",
NeedsProxy = false,
};

Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
11 changes: 10 additions & 1 deletion TeslaSolarCharger/Server/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Serilog": {
"Using": [
"Serilog.Sinks.Console"
"Serilog.Sinks.Console",
"Serilog.Sinks.Seq"
],
"MinimumLevel": {
"Default": "Verbose",
Expand All @@ -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": [
Expand Down
23 changes: 11 additions & 12 deletions TeslaSolarCharger/Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Serilog": {
"Using": [
"Serilog.Sinks.Console"
"Serilog.Sinks.Console",
"Serilog.Sinks.Seq"
],
"MinimumLevel": {
"Default": "Debug",
Expand All @@ -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"
Expand Down

0 comments on commit f8e1319

Please sign in to comment.