Skip to content

Commit

Permalink
Merge pull request #1601 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Nov 8, 2024
2 parents 701464d + 7161c4b commit 42ad569
Show file tree
Hide file tree
Showing 16 changed files with 507 additions and 134 deletions.
2 changes: 1 addition & 1 deletion Plugins.SmaEnergymeter/Plugins.SmaEnergymeter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
<PackageReference Include="Quartz" Version="3.13.0" />
<PackageReference Include="Quartz" Version="3.13.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
442 changes: 336 additions & 106 deletions TeslaSolarCharger/Client/Components/GenericInput.razor

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions TeslaSolarCharger/Client/Components/PowerBufferComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@using TeslaSolarCharger.Shared.Dtos
@using TeslaSolarCharger.Shared.Dtos.IndexRazor.PvValues

@inject HttpClient HttpClient
@inject ISnackbar Snackbar


@if(_displayValue && _pvValues != default)
{
<div style="max-width: 200px; margin: 0 auto;">
<GenericInput T="int?"
For="() => _pvValues.PowerBuffer"
PostfixButtonStartIcon="@Icons.Material.Filled.Save"
OnButtonClicked="UpdatePowerBuffer"></GenericInput>
</div>
}


@code {
private DtoPvValues? _pvValues;
private bool _displayValue;

protected override async Task OnInitializedAsync()
{
var result = await HttpClient.GetFromJsonAsync<DtoValue<bool>>("api/BaseConfiguration/AllowPowerBufferChangeOnHome").ConfigureAwait(false);
if(result == default)
{
return;
}
_displayValue = result.Value;
if(_displayValue)
{
_pvValues = await HttpClient.GetFromJsonAsync<DtoPvValues>("api/Index/GetPvValues").ConfigureAwait(false);
}

}

private async Task UpdatePowerBuffer()
{
if(_pvValues == default)
{
return;
}
var response = await HttpClient.GetAsync($"api/BaseConfiguration/UpdatePowerBuffer?powerBuffer={_pvValues.PowerBuffer ?? 0}").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
Snackbar.Add("Power Buffer updated", Severity.Success);
}
else
{
Snackbar.Add("Failed to update Power Buffer", Severity.Error);
}

}
}
23 changes: 0 additions & 23 deletions TeslaSolarCharger/Client/Components/PowerFlowComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@inject HttpClient HttpClient
@inject IConstants Constants
@inject ISnackbar Snackbar
@implements IDisposable

@if (_pvValues != default)
Expand Down Expand Up @@ -166,14 +165,6 @@
</svg>

</div>
if (_pvValues.PowerBuffer != default && _pvValues.PowerBuffer != 0)
{
<div style="max-width: 200px; margin: 0 auto;">
<GenericInput T="int?"
For="() => _pvValues.PowerBuffer"
OnValueChanged="newValue => UpdatePowerBuffer(newValue)"></GenericInput>
</div>
}
}


Expand Down Expand Up @@ -641,18 +632,4 @@
return homePower;
}

private async Task UpdatePowerBuffer(int? newValue)
{
var response = await HttpClient.GetAsync($"api/BaseConfiguration/UpdatePowerBuffer?powerBuffer={newValue ?? 0}").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
Snackbar.Add("Power Buffer updated", Severity.Success);
}
else
{
Snackbar.Add("Failed to update Power Buffer", Severity.Error);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Lysando.LabStorageV2.UiHelper.Wrapper.Contracts;

public interface IJavaScriptWrapper
{
Task<bool> SetFocusToElementById(string elementId);
Task<bool> RemoveFocusFromElementById(string elementId);
Task OpenUrlInNewTab(string url);
Task<bool> IsIosDevice();
}
54 changes: 54 additions & 0 deletions TeslaSolarCharger/Client/Helper/JavaScriptWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Lysando.LabStorageV2.UiHelper.Wrapper.Contracts;
using Microsoft.JSInterop;

namespace Lysando.LabStorageV2.UiHelper.Wrapper;

public class JavaScriptWrapper(IJSRuntime jsRuntime) : IJavaScriptWrapper
{
/// <summary>
/// Sets the focus to an element with a specific ID
/// </summary>
/// <param name="elementId">ID to set the focus on</param>
/// <returns>Was the ID set successfully</returns>
public async Task<bool> SetFocusToElementById(string elementId)
{
try
{
return await jsRuntime.InvokeAsync<bool>("setFocus", elementId);
}
catch (Exception)
{
return false;
}
}

public async Task<bool> RemoveFocusFromElementById(string elementId)
{
try
{
return await jsRuntime.InvokeAsync<bool>("removeFocus", elementId);
}
catch (Exception)
{
return false;
}
}

public async Task OpenUrlInNewTab(string url)
{
await jsRuntime.InvokeVoidAsync("openInNewTab", url);
}

public async Task<bool> IsIosDevice()
{
try
{
var device = await jsRuntime.InvokeAsync<string>("detectDevice");
return device == "iOS";
}
catch (Exception)
{
return false;
}
}
}
8 changes: 5 additions & 3 deletions TeslaSolarCharger/Client/Pages/BaseConfiguration.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/BaseConfiguration"
@page "/BaseConfiguration"
@using System.Globalization
@using TeslaSolarCharger.Client.Helper.Contracts
@using TeslaSolarCharger.Shared.Dtos.BaseConfiguration
Expand Down Expand Up @@ -153,11 +153,13 @@ else
<InputComponent ValueId="powerBuffer"
LabelText="Power Buffer"
UnitText="W"
HelpText="Set values higher than 0 to always have some overage (power to grid). Set values lower than 0 to always consume some power from the grid. Note: The power buffer you see on the home page is replaced with this value after a TSC restart. Do only change this value if you want a permanent change. Frequent Base Configuration changes are not recommended. If you can not see a power buffer value on the homepage, set the power buffer here to 1 as on the homepage it is only displayed if different from zero.">
HelpText="Set values higher than 0 to always have some overage (power to grid). Set values lower than 0 to always consume some power from the grid.">
<InputFragment>
<InputNumber id="powerBuffer" @bind-Value="_dtoBaseConfiguration.PowerBuffer" placeholder=" " class="form-control" />
</InputFragment>
</InputComponent>

<GenericInput For="() => _dtoBaseConfiguration.AllowPowerBufferChangeOnHome"></GenericInput>

<InputComponent ValueId="homeBatteryMinSoc"
LabelText="Home Battery Minimum SoC"
Expand Down Expand Up @@ -241,7 +243,7 @@ else
UnitText="min"
HelpText="">
<InputFragment>
<InputNumber id="minutesUntilSwitchOn" @bind-Value="_dtoBaseConfiguration.MinutesUntilSwitchOff" class="form-control" placeholder=" "/>
<InputNumber id="minutesUntilSwitchOff" @bind-Value="_dtoBaseConfiguration.MinutesUntilSwitchOff" class="form-control" placeholder=" " />
</InputFragment>
</InputComponent>
<hr/>
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<LoggedErrorsComponent></LoggedErrorsComponent>

<PowerFlowComponent></PowerFlowComponent>
<PowerBufferComponent></PowerBufferComponent>


@if (_carBaseStates == null || _carBaseSettings == null)
Expand Down
3 changes: 3 additions & 0 deletions TeslaSolarCharger/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Lysando.LabStorageV2.UiHelper.Wrapper;
using Lysando.LabStorageV2.UiHelper.Wrapper.Contracts;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor;
Expand All @@ -21,6 +23,7 @@
builder.Services.AddScoped<INodePatternTypeHelper, NodePatternTypeHelper>();
builder.Services.AddScoped<IDateTimeProvider, DateTimeProvider>();
builder.Services.AddScoped<IDialogHelper, DialogHelper>();
builder.Services.AddScoped<IJavaScriptWrapper, JavaScriptWrapper>();
builder.Services.AddScoped<IHttpClientHelper, HttpClientHelper>();
builder.Services.AddSingleton<ToolTipTextKeys>();
builder.Services.AddSharedDependencies();
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<script src="js/fileDownload.js"></script>
<script src="js/textAreaLineCount.js"></script>
<script src="js/copyToClipboard.js"></script>
<script src="js/javaScriptWrapperFunctions.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
Expand Down
30 changes: 30 additions & 0 deletions TeslaSolarCharger/Client/wwwroot/js/javaScriptWrapperFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function setFocus(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.focus();
return true;
}
return false;
}

function removeFocus(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.blur();
return true;
}
return false;
}

function openInNewTab(url) {
window.open(url, '_blank');
}

function detectDevice() {
var ua = navigator.userAgent || navigator.vendor || window.opera;
// iOS detection
if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) {
return "iOS";
}
return "Other";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class BaseConfigurationController(
[HttpGet]
public Task<DtoBaseConfiguration> GetBaseConfiguration() => configurationWrapper.GetBaseConfigurationAsync();

[HttpGet]
public DtoValue<bool> AllowPowerBufferChangeOnHome() => new(configurationWrapper.AllowPowerBufferChangeOnHome());

[HttpPut]
public Task UpdateBaseConfiguration([FromBody] DtoBaseConfiguration baseConfiguration) =>
service.UpdateBaseConfigurationAsync(baseConfiguration);
Expand Down
2 changes: 1 addition & 1 deletion TeslaSolarCharger/Server/TeslaSolarCharger.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<PackageReference Include="MQTTnet" Version="4.3.7.1207" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
<PackageReference Include="Quartz" Version="3.13.0" />
<PackageReference Include="Quartz" Version="3.13.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ public interface IConfigurationWrapper
TimeSpan BleUsageStopAfterError();
bool UseTeslaMateIntegration();
string FleetTelemetryApiUrl();
bool AllowPowerBufferChangeOnHome();
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class BaseConfigurationBase
public int MinutesUntilSwitchOff { get; set; } = 5;
[Required]
public int PowerBuffer { get; set; } = 0;
[HelperText("If enabled, the configured power buffer is displayed on the home screen, including the option to directly change it. Note: The values you set on the home screen will be overwritten on every TSC restart. To set a permanent power buffer, use the field above.")]
public bool AllowPowerBufferChangeOnHome { get; set; }
public string? CurrentPowerToGridJsonPattern { get; set; }
public decimal CurrentPowerToGridCorrectionFactor { get; set; } = 1;
public string? CurrentInverterPowerJsonPattern { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public string FleetTelemetryApiUrl()
return value;

Check warning on line 212 in TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs

View workflow job for this annotation

GitHub Actions / Building TeslaSolarCharger image

Possible null reference return.

Check warning on line 212 in TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs

View workflow job for this annotation

GitHub Actions / Release (linux-arm64)

Possible null reference return.

Check warning on line 212 in TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs

View workflow job for this annotation

GitHub Actions / Release (win-x64)

Possible null reference return.

Check warning on line 212 in TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs

View workflow job for this annotation

GitHub Actions / Release (linux-x64)

Possible null reference return.

Check warning on line 212 in TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs

View workflow job for this annotation

GitHub Actions / Release (linux-arm)

Possible null reference return.

Check warning on line 212 in TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs

View workflow job for this annotation

GitHub Actions / Release (linux-arm)

Possible null reference return.
}

public bool AllowPowerBufferChangeOnHome()
{
return GetBaseConfiguration().AllowPowerBufferChangeOnHome;
}

public bool IsDevelopmentEnvironment()
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Expand Down

0 comments on commit 42ad569

Please sign in to comment.