Skip to content

Commit

Permalink
feat(chore): decide if to use beta endpoints based on version number
Browse files Browse the repository at this point in the history
  • Loading branch information
pkuehnel committed Feb 8, 2025
1 parent d580010 commit 7f2148e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions TeslaSolarCharger/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ async Task DoStartupStuff(WebApplication webApplication, ILogger<Program> logger
}
}



var tscConfigurationService = webApplication.Services.GetRequiredService<ITscConfigurationService>();
var installationId = await tscConfigurationService.GetInstallationId().ConfigureAwait(false);
var backendApiService = webApplication.Services.GetRequiredService<IBackendApiService>();
var version = await backendApiService.GetCurrentVersion().ConfigureAwait(false);
if (version != default && version.Contains('-'))
{
settings.IsPreRelease = true;
}
LogContext.PushProperty("InstallationId", installationId);
LogContext.PushProperty("Version", version);

Expand Down
1 change: 0 additions & 1 deletion TeslaSolarCharger/Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"ShouldUseFakeSolarValues": true,
"IgnoreSslErrors": true,
"BleBaseUrl": "http://raspible:7210/",
"UseBetaEndpoints": true,
"GridPriceProvider": {
"EnergyProvider": "Tibber",
"Octopus": {
Expand Down
1 change: 0 additions & 1 deletion TeslaSolarCharger/Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"FleetTelemetryApiUrl": "wss://api.fleet-telemetry.solar4car.com/ws?",
"BetaFleetTelemetryApiUrl": "wss://beta.api.fleet-telemetry.solar4car.com/ws?",
"BackendPasswordDefaultLength": 25,
"UseBetaEndpoints": false,
"GridPriceProvider": {
"EnergyProvider": "FixedPrice",
"Octopus": {
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Shared/Dtos/Contracts/ISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public interface ISettings
string? ChargePricesUpdateText { get; set; }
DateTime StartupTime { get; set; }
int LastPvDemoCase { get; set; }
bool IsPreRelease { get; set; }
}
2 changes: 2 additions & 0 deletions TeslaSolarCharger/Shared/Dtos/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public class Settings : ISettings

public string? ChargePricesUpdateText { get; set; }
public int LastPvDemoCase { get; set; }

public bool IsPreRelease { get; set; }
}
9 changes: 5 additions & 4 deletions TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Configuration;
using TeslaSolarCharger.Shared.Contracts;
using TeslaSolarCharger.Shared.Dtos.BaseConfiguration;
using TeslaSolarCharger.Shared.Dtos.Contracts;
Expand Down Expand Up @@ -209,9 +210,9 @@ public bool SendTeslaApiStatsToBackend()
public string BackendApiBaseUrl()
{
var environmentVariableName = "BackendApiBaseUrl";
var useBetaEndpoints = configuration.GetValue<bool>("UseBetaEndpoints");
if (useBetaEndpoints)
if (settings.IsPreRelease)
{
logger.LogInformation("Use beta endpoints as is prerelease");
environmentVariableName = "Beta" + environmentVariableName;
}
var value = configuration.GetValue<string>(environmentVariableName);
Expand All @@ -221,9 +222,9 @@ public string BackendApiBaseUrl()
public string FleetTelemetryApiUrl()
{
var environmentVariableName = "FleetTelemetryApiUrl";
var useBetaEndpoints = configuration.GetValue<bool>("UseBetaEndpoints");
if (useBetaEndpoints)
if (settings.IsPreRelease)
{
logger.LogInformation("Use beta endpoints as is prerelease");
environmentVariableName = "Beta" + environmentVariableName;
}
var value = configuration.GetValue<string>(environmentVariableName);
Expand Down

0 comments on commit 7f2148e

Please sign in to comment.