Add braces to single-statement guards and refactor NordPool price fetching

- Expand inline guard, return and logger blocks across the monitor services, init classes and tests
- Have INordPoolPriceService take a per-date fetch delegate and expose ParseAndAdjust, moving the HA fetch call into NordPoolInit so the service can be registered singleton
- Record the NordPool and boiler service lifetimes in AGENTS.md
- Drop the unused persisted-state argument from the boiler test data helper
This commit is contained in:
2026-12-01 11:59:31 +02:00
parent 24729ee267
commit 77458383d1
34 changed files with 336 additions and 93 deletions
+22 -4
View File
@@ -25,10 +25,12 @@ public class NordPoolInit
private readonly NordPoolOptions _options;
private readonly INordPoolPriceService _priceService;
private readonly IScheduler _scheduler;
private readonly Services _services;
private readonly TimeProvider _timeProvider;
public NordPoolInit(
Entities entities,
Services services,
IHaContext haContext,
ILogger<NordPoolInit> logger,
INordPoolPriceService priceService,
@@ -44,6 +46,7 @@ public class NordPoolInit
_priceService = priceService;
_entityService = entityService;
_scheduler = scheduler;
_services = services;
_cheapestIntervalsFinder = cheapestIntervalsFinder;
_boilerConfigProvider = boilerConfigProvider;
_options = options.Value;
@@ -115,10 +118,12 @@ public class NordPoolInit
var today = DateOnly.FromDateTime(nowCet);
if (_priceService.LastFetchedDate.HasValue && _priceService.LastFetchedDate.Value < today)
{
_priceService.RollOverPrices(today);
}
if (_priceService.ShouldFetchNewPrices(today)) await _priceService.FetchPricesAsync();
await _priceService.FetchPricesAsync(FetchPricesForDateAsync);
_priceService.UpdateCurrentPrice();
var boilerConfig = _boilerConfigProvider.GetCurrentConfiguration();
@@ -131,6 +136,20 @@ public class NordPoolInit
}
}
private async Task<NordPoolPrice> FetchPricesForDateAsync(DateOnly date)
{
var nordPoolPricesDto = await _services.Nordpool.GetPricesForDateAsync(
new NordpoolGetPricesForDateParameters
{
Areas = "LT",
ConfigEntry = NordPoolConsts.ConfigEntry,
Currency = "EUR",
Date = date
});
return _priceService.ParseAndAdjust(nordPoolPricesDto);
}
private void SubscribeToFetchPricesButton()
{
var button = new Entity(_haContext, NordPoolConsts.FetchPricesButtonEntityId);
@@ -157,8 +176,7 @@ public class NordPoolInit
return;
}
CheapestIntervals = _cheapestIntervalsFinder.FindCheapestIntervals(_priceService.TodayNordPoolPrice,
effectiveIntervalCount, effectivePriceCap, config.Deadline);
CheapestIntervals = _cheapestIntervalsFinder.FindCheapestIntervals(_priceService.TodayNordPoolPrice, effectiveIntervalCount, effectivePriceCap, config.Deadline);
}
catch (Exception ex)
{