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
@@ -41,8 +41,11 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
if (IsWithinCooldownPeriod())
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Water ready cooldown active (since {Since}), suppressing turn-on",
_waterReadySince);
}
return true;
}
}
@@ -56,8 +59,10 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
if (!_hasObservedHeating)
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Ignoring power reading ({PowerWatts}W) — boiler has not been observed heating yet",
powerWatts.Value);
}
return false;
}
@@ -73,10 +78,12 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
if (_consecutiveBelowThresholdCount < BoilerMonitorConsts.ConsecutiveReadingsRequired)
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug(
"Below-threshold reading {Count}/{Required} ({PowerWatts}W), waiting for confirmation",
_consecutiveBelowThresholdCount, BoilerMonitorConsts.ConsecutiveReadingsRequired,
powerWatts.Value);
}
return false;
}
@@ -84,9 +91,11 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
_waterReadySince ??= timeProvider.GetUtcNow();
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation(
"Water detected as ready after {Count} consecutive readings, cooldown active until shower or midnight reset",
_consecutiveBelowThresholdCount);
}
return true;
}
@@ -135,15 +144,19 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
if (waterReadySince < todayMidnightUtc)
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Persisted cooldown is from a previous day ({Since}), not restoring",
waterReadySince);
}
return;
}
_waterReadySince = waterReadySince;
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Restored water ready cooldown from {Since}", waterReadySince);
}
}
}