Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1018

Merged
merged 7 commits into from
Dec 10, 2023
Merged

Develop #1018

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TeslaSolarCharger.Tests/Services/Server/SpotPriceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void Generates_Awattar_Url_With_DateTimeOffset()
Mock.Mock<IDateTimeProvider>()
.Setup(d => d.DateTimeOffSetNow())
.Returns(currentDate);
Mock.Mock<IConfigurationWrapper>()
.Setup(c => c.GetAwattarBaseUrl())
.Returns("https://api.awattar.de/v1/marketdata");

var endFutureMilliseconds = currentDate.AddHours(48).ToUnixTimeMilliseconds();

Expand All @@ -51,6 +54,9 @@ public void Generates_Awattar_Url_With_DateTimeOffset()
public void Generates_Awattar_Url_WithOut_DateTimeOffset()
{
var spotPriceService = Mock.Create<TeslaSolarCharger.Server.Services.SpotPriceService>();
Mock.Mock<IConfigurationWrapper>()
.Setup(c => c.GetAwattarBaseUrl())
.Returns("https://api.awattar.de/v1/marketdata");
var url = spotPriceService.GenerateAwattarUrl(null);
Assert.Equal("https://api.awattar.de/v1/marketdata", url);
}
Expand Down
17 changes: 17 additions & 0 deletions TeslaSolarCharger/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@

<PageTitle>Tesla Solar Charger</PageTitle>

@if(_serverTime != default)
{
if (_serverTime.Value is { Day: 24, Month: 12, Hour: > 15 } or { Day: 25, Month: 12 })
{
<div class="alert alert-info" role="alert">
Merry Christmas! &#127876; &#127877; &#127873;
</div>

}
if(_serverTime.Value is { Day: 31, Month: 12, Hour: > 15 } or { Day: 1, Month: 1})
{
<div class="alert alert-info" role="alert">
Happy New Year! &#127878; &#127881; &#127882;
</div>
}
}

<BackendIssueValidation></BackendIssueValidation>

@if (_pvValues != null)
Expand Down
7 changes: 5 additions & 2 deletions TeslaSolarCharger/Server/Services/SpotPriceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class SpotPriceService : ISpotPriceService
private readonly ILogger<SpotPriceService> _logger;
private readonly ITeslaSolarChargerContext _teslaSolarChargerContext;
private readonly IDateTimeProvider _dateTimeProvider;
private readonly IConfigurationWrapper _configurationWrapper;

public SpotPriceService(ILogger<SpotPriceService> logger, ITeslaSolarChargerContext teslaSolarChargerContext,
IDateTimeProvider dateTimeProvider)
IDateTimeProvider dateTimeProvider, IConfigurationWrapper configurationWrapper)
{
_logger = logger;
_teslaSolarChargerContext = teslaSolarChargerContext;
_dateTimeProvider = dateTimeProvider;
_configurationWrapper = configurationWrapper;
}

public async Task UpdateSpotPrices()
Expand Down Expand Up @@ -71,7 +73,8 @@ internal SpotPrice GenerateSpotPriceFromAwattarPrice(Datum value)

internal string GenerateAwattarUrl(DateTimeOffset? fromDate)
{
var url = "https://api.awattar.de/v1/marketdata";
var url = _configurationWrapper.GetAwattarBaseUrl();
//var url = "https://api.awattar.de/v1/marketdata";
if (fromDate != null)
{
var toDate = _dateTimeProvider.DateTimeOffSetNow().AddHours(48);
Expand Down
2 changes: 2 additions & 0 deletions TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public async Task StartCharging(int carId, int startAmp, CarStateEnum? carState)
await WakeUpCarIfNeeded(carId, carState).ConfigureAwait(false);

var id = await _teslamateContext.Cars.Where(c => c.Id == carId).Select(c => c.Eid).FirstAsync().ConfigureAwait(false);
await SetAmp(carId, startAmp).ConfigureAwait(false);

var result = await SendCommandToTeslaApi(id, _chargeStartComand).ConfigureAwait(false);
}

Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"UseFleetApi": false,
"FleetApiClientId": "f29f71d6285a-4873-8b6b-80f15854892e",
"BackendApiBaseUrl": "https://www.teslasolarcharger.de/api/",
"AwattarBaseUrl": "https://api.awattar.de/v1/marketdata",
"GridPriceProvider": {
"EnergyProvider": "FixedPrice",
"Octopus": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ public interface IConfigurationWrapper
bool UseFleetApi();
string BackendApiBaseUrl();
bool IsDevelopmentEnvironment();
string GetAwattarBaseUrl();
}
7 changes: 7 additions & 0 deletions TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
return path;
}

public string GetAwattarBaseUrl()
{
var environmentVariableName = "AwattarBaseUrl";
var value = GetNotNullableConfigurationValue<string>(environmentVariableName);
return value;
}

public bool AllowCors()
{
var environmentVariableName = "AllowCORS";
Expand All @@ -110,7 +117,7 @@
{
var environmentVariableName = "BackendApiBaseUrl";
var value = _configuration.GetValue<string>(environmentVariableName);
return value;

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

View workflow job for this annotation

GitHub Actions / Building TeslaSolarCharger image

Possible null reference return.
}

public bool IsDevelopmentEnvironment()
Expand Down
Loading