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
@@ -45,7 +45,10 @@ public sealed class BoilerMonitorEntityService(
try
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Creating/re-registering MQTT entity: {EntityId}", entity.EntityId);
}
await entityManager.CreateEntityAsync(entity).ConfigureAwait(false);
}
catch (Exception ex)
@@ -144,9 +147,12 @@ public sealed class BoilerMonitorEntityService(
!TryParseEntityInt(sessionCountState, out var sessionCount))
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation(
"No valid persisted BoilerMonitor state found in HA entities (runtime={Runtime}, sessions={Sessions})",
runtimeState, sessionCountState);
}
return null;
}
@@ -159,10 +165,12 @@ public sealed class BoilerMonitorEntityService(
};
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation(
"Restored persisted BoilerMonitor state: runtime={Runtime}, sessions={Sessions}, skipPriceCap={SkipPriceCap}, budgetOverride={BudgetOverride}",
persisted.AccumulatedRunTime, persisted.SessionCount, persisted.SkipPriceCapState,
persisted.BudgetOverrideState);
}
return persisted;
}
@@ -200,7 +208,10 @@ public sealed class BoilerMonitorEntityService(
DateTimeStyles.RoundtripKind, out var parsed))
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Read persisted cooldown timestamp: {CooldownSince}", parsed);
}
return parsed;
}
}
@@ -500,7 +511,9 @@ public sealed class BoilerMonitorEntityService(
{
await entityManager.SetEntityState(entityId, state).ConfigureAwait(false);
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Successfully set state for {EntityId}: {State}", entityId, state);
}
}
catch (Exception ex)
{
@@ -514,7 +527,9 @@ public sealed class BoilerMonitorEntityService(
{
await entityManager.SetEntityAttributes(entityId, attributes).ConfigureAwait(false);
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Successfully set attributes for {EntityId}", entityId);
}
}
catch (Exception ex)
{