Skip to content

Commit

Permalink
Merge pull request #1003 from pkuehnel/feat/InstallationId
Browse files Browse the repository at this point in the history
feat(Index.razor): Display installation Id
  • Loading branch information
pkuehnel authored Dec 1, 2023
2 parents 411b014 + 75e223a commit 8758007
Show file tree
Hide file tree
Showing 16 changed files with 367 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public interface ITeslaSolarChargerContext
DatabaseFacade Database { get; }
DbSet<SpotPrice> SpotPrices { get; set; }
DbSet<TeslaToken> TeslaTokens { get; set; }
DbSet<TscConfiguration> TscConfigurations { get; set; }
void RejectChanges();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TeslaSolarCharger.Model.Entities.TeslaSolarCharger;

public class TscConfiguration
{
public int Id { get; set; }
public string Key { get; set; }
public string? Value { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TeslaSolarChargerContext : DbContext, ITeslaSolarChargerContext
public DbSet<PowerDistribution> PowerDistributions { get; set; } = null!;
public DbSet<SpotPrice> SpotPrices { get; set; } = null!;
public DbSet<TeslaToken> TeslaTokens { get; set; } = null!;
public DbSet<TscConfiguration> TscConfigurations { get; set; } = null!;

// ReSharper disable once UnassignedGetOnlyAutoProperty
public string DbPath { get; }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TeslaSolarCharger.Model.Migrations
{
/// <inheritdoc />
public partial class AddTscConfigurations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TscConfigurations",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Key = table.Column<string>(type: "TEXT", nullable: false),
Value = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TscConfigurations", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TscConfigurations");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("TeslaTokens");
});

modelBuilder.Entity("TeslaSolarCharger.Model.Entities.TeslaSolarCharger.TscConfiguration", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");

b.Property<string>("Key")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("Value")
.HasColumnType("TEXT");

b.HasKey("Id");

b.ToTable("TscConfigurations");
});

modelBuilder.Entity("TeslaSolarCharger.Model.Entities.TeslaSolarCharger.PowerDistribution", b =>
{
b.HasOne("TeslaSolarCharger.Model.Entities.TeslaSolarCharger.HandledCharge", "HandledCharge")
Expand Down
2 changes: 2 additions & 0 deletions TeslaSolarCharger.SharedBackend/Contracts/IConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface IConstants
/// Soc Difference needs to be higher than this value
/// </summary>
int MinimumSocDifference { get; }

string InstallationIdKey { get; }
}
2 changes: 2 additions & 0 deletions TeslaSolarCharger.SharedBackend/Values/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public class Constants : IConstants
public int MinSocLimit => 50;
public int DefaultOverage => -1000000;
public int MinimumSocDifference => 2;

public string InstallationIdKey => "InstallationId";
}
3 changes: 3 additions & 0 deletions TeslaSolarCharger/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ else
{
<p><em>Version: <a href="https://github.com/pkuehnel/TeslaSolarCharger/releases/tag/v@_version" target="_blank">@_version</a></em></p>
}
<div>@_installationId</div>
</div>


Expand Down Expand Up @@ -394,6 +395,7 @@ else
private string? _serverTimeZoneDisplayName;
private bool? _shouldDisplayApiRequestCounter;
private int? _apiRequestCount;
private string _installationId = "";

private Timer? _timer;

Expand All @@ -410,6 +412,7 @@ else
var dtoSolarChargerInstallation = await HttpClient.GetFromJsonAsync<DtoValue<bool>>("api/Hello/IsSolarEdgeInstallation").ConfigureAwait(false);
_isSolarEdgeInstallation = dtoSolarChargerInstallation?.Value;
_version = await HttpClient.GetStringAsync("api/Hello/ProductVersion").ConfigureAwait(false);
_installationId = await HttpClient.GetStringAsync("api/Hello/GetInstallationId").ConfigureAwait(false);
foreach (var carBaseState in _carBaseStates!)
{
_collapsedCarDetails.Add(carBaseState.CarId);
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/Contracts/ICoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface ICoreService
DtoValue<int> TeslaApiRequestsSinceStartup();
DtoValue<bool> ShouldDisplayApiRequestCounter();
Task<IEnumerable<Price>> GetPriceData(DateTimeOffset from, DateTimeOffset to);
Task<string> GetInstallationId();
}
3 changes: 3 additions & 0 deletions TeslaSolarCharger/Server/Controllers/HelloController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ public HelloController(ICoreService coreService)

[HttpGet]
public Task<IEnumerable<Price>> GetPriceData(DateTimeOffset from, DateTimeOffset to) => _coreService.GetPriceData(from, to);

[HttpGet]
public Task<string> GetInstallationId() => _coreService.GetInstallationId();
}
}
5 changes: 5 additions & 0 deletions TeslaSolarCharger/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TeslaSolarCharger.Server;
using TeslaSolarCharger.Server.Contracts;
using TeslaSolarCharger.Server.Scheduling;
using TeslaSolarCharger.Server.Services.Contracts;
using TeslaSolarCharger.Shared.Contracts;

var builder = WebApplication.CreateBuilder(args);
Expand Down Expand Up @@ -70,6 +71,10 @@
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);
logger.LogTrace("Installation Id: {installationId}", installationId);

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

Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static IServiceCollection AddMyDependencies(this IServiceCollection servi
.AddTransient<IChargeTimeCalculationService, ChargeTimeCalculationService>()
.AddTransient<ITeslaFleetApiService, TeslaFleetApiService>()
.AddTransient<ITeslamateApiService, TeslamateApiService>()
.AddTransient<ITscConfigurationService, TscConfigurationService>()
.AddSharedBackendDependencies();
if (useFleetApi)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TeslaSolarCharger.Server.Services.Contracts;

public interface ITscConfigurationService
{
Task<Guid> GetInstallationId();
}
Loading

0 comments on commit 8758007

Please sign in to comment.