Add shared test data builders and Qodana configuration
- Extract per-monitor *TestData helper classes and rework tests to use them - Add boiler run-time tracker abstraction (implementation pending) - Drop unused NordPool init/update-result types and stale PLAN.md - Add qodana.yaml with the inspection set to keep the analysis focused
This commit is contained in:
@@ -15,7 +15,7 @@ using NordPoolManager.Models;
|
||||
namespace NordPoolManager;
|
||||
|
||||
[NetDaemonApp]
|
||||
public class NordPoolInit : INordPoolInit
|
||||
public class NordPoolInit
|
||||
{
|
||||
private readonly ILogger<NordPoolInit> _logger;
|
||||
private readonly IHaContext _haContext;
|
||||
@@ -57,7 +57,31 @@ public class NordPoolInit : INordPoolInit
|
||||
|
||||
_ = InitializeAndScheduleAsync();
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||
|
||||
if (_options.CleanupEntitiesOnStartup)
|
||||
{
|
||||
await _entityService.CleanupEntitiesAsync();
|
||||
}
|
||||
|
||||
await _entityService.CreateEntitiesAsync(UnitOfMeasurement);
|
||||
await _entityService.ResetEntitiesAsync();
|
||||
await Task.Delay(TimeSpan.FromSeconds(10));
|
||||
|
||||
await UpdatePricesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error initializing NordPool prices");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitializeAndScheduleAsync()
|
||||
{
|
||||
try
|
||||
@@ -72,41 +96,6 @@ public class NordPoolInit : INordPoolInit
|
||||
}
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||
|
||||
await _priceService.FetchPricesAsync();
|
||||
|
||||
if (_options.CleanupEntitiesOnStartup)
|
||||
{
|
||||
await _entityService.CleanupEntitiesAsync();
|
||||
}
|
||||
|
||||
await _entityService.CreateEntitiesAsync(UnitOfMeasurement);
|
||||
await _entityService.ResetEntitiesAsync();
|
||||
await Task.Delay(TimeSpan.FromSeconds(10));
|
||||
|
||||
var currentPrice = _priceService.UpdateCurrentPrice();
|
||||
|
||||
if (currentPrice == 0)
|
||||
{
|
||||
_logger.LogWarning("Current price is 0, which may indicate an issue with price retrieval");
|
||||
}
|
||||
|
||||
var boilerConfig = _boilerConfigProvider.GetCurrentConfiguration();
|
||||
UpdateCheapestIntervals(boilerConfig);
|
||||
await UpdateEntitiesAsync(boilerConfig);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error initializing NordPool prices");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SchedulePeriodicUpdates()
|
||||
{
|
||||
var now = _timeProvider.GetLocalNow();
|
||||
@@ -143,7 +132,6 @@ public class NordPoolInit : INordPoolInit
|
||||
var boilerConfig = _boilerConfigProvider.GetCurrentConfiguration();
|
||||
UpdateCheapestIntervals(boilerConfig);
|
||||
await UpdateEntitiesAsync(boilerConfig);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -158,36 +146,10 @@ public class NordPoolInit : INordPoolInit
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
_logger.LogInformation("Fetch prices button pressed, triggering manual NordPool price update");
|
||||
Task.Run(HandleFetchPricesAsync);
|
||||
Task.Run(UpdatePricesAsync);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task HandleFetchPricesAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Manual fetch: forcing fresh NordPool price retrieval");
|
||||
|
||||
await _priceService.FetchPricesAsync();
|
||||
_priceService.UpdateCurrentPrice();
|
||||
|
||||
var boilerConfig = _boilerConfigProvider.GetCurrentConfiguration();
|
||||
UpdateCheapestIntervals(boilerConfig);
|
||||
await UpdateEntitiesAsync(boilerConfig);
|
||||
|
||||
_logger.LogInformation("Manual fetch and update completed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during manual NordPool price fetch");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CleanupEntitiesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _entityService.CleanupEntitiesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
private void UpdateCheapestIntervals(BoilerConfig config)
|
||||
{
|
||||
var effectivePriceCap = config.SkipPriceCap ? double.MaxValue : config.PriceCap;
|
||||
@@ -215,14 +177,14 @@ public class NordPoolInit : INordPoolInit
|
||||
private async Task UpdateEntitiesAsync(BoilerConfig boilerConfig)
|
||||
{
|
||||
var cetTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
||||
var nowCet = TimeZoneInfo.ConvertTime(_timeProvider.GetUtcNow(), cetTimeZone).DateTime;
|
||||
var todayCet = DateOnly.FromDateTime(nowCet);
|
||||
var currentDateTime = nowCet;
|
||||
var currentDateTime = TimeZoneInfo.ConvertTime(_timeProvider.GetUtcNow(), cetTimeZone).DateTime;
|
||||
var todayCet = DateOnly.FromDateTime(currentDateTime);
|
||||
|
||||
var configuredHours = (double)boilerConfig.IntervalCount / NordPoolConsts.IntervalsPerHour;
|
||||
var configuredReadyBy = boilerConfig.Deadline.TimeOfDay.ToString(@"hh\:mm", CultureInfo.InvariantCulture);
|
||||
|
||||
var isNowCheap = CheapestIntervals != null && _cheapestIntervalsFinder.IsCurrentIntervalCheap(CheapestIntervals, currentDateTime);
|
||||
|
||||
var nextCheapInterval = CheapestIntervals?
|
||||
.Where(i => i.Start > currentDateTime)
|
||||
.OrderBy(i => i.Start)
|
||||
|
||||
Reference in New Issue
Block a user