Clear Qodana findings in monitor runtime code
- Guard logger calls with IsEnabled so value-type arguments are not boxed when the level is disabled - Make helper members static, narrow write-only properties to init or private get, and delete members no call site reaches - Flatten nested conditionals and convert if/else chains into switch and ternary form - Drop the unused *MonitorInit interfaces; NetDaemon instantiates the concrete app classes - Drop the unused IConfiguration parameter from AddNordPool and AddPowerMonitor, and the unused IEntityManager.CreateEntitiesAsync - Remove the ignored parameters of the boiler run-time tracker stub - Pin the NordPool DTO price mapping explicitly so the getter use is visible to static analysis - Fail Qodana on any finding and record the registration changes in AGENTS.md
This commit is contained in:
@@ -40,7 +40,10 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
|
||||
{
|
||||
if (IsWithinCooldownPeriod())
|
||||
{
|
||||
logger.LogDebug("Water ready cooldown active (since {Since}), suppressing turn-on", _waterReadySince);
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.LogDebug("Water ready cooldown active (since {Since}), suppressing turn-on", _waterReadySince);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +62,10 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
|
||||
{
|
||||
if (!_hasObservedHeating)
|
||||
{
|
||||
logger.LogDebug("Ignoring power reading ({PowerWatts}W) — boiler has not been observed heating yet", powerWatts.Value);
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.LogDebug("Ignoring power reading ({PowerWatts}W) — boiler has not been observed heating yet", powerWatts.Value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -74,15 +80,21 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
|
||||
|
||||
if (_consecutiveBelowThresholdCount < BoilerMonitorConsts.ConsecutiveReadingsRequired)
|
||||
{
|
||||
logger.LogDebug("Below-threshold reading {Count}/{Required} ({PowerWatts}W), waiting for confirmation",
|
||||
_consecutiveBelowThresholdCount, BoilerMonitorConsts.ConsecutiveReadingsRequired, powerWatts.Value);
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.LogDebug("Below-threshold reading {Count}/{Required} ({PowerWatts}W), waiting for confirmation",
|
||||
_consecutiveBelowThresholdCount, BoilerMonitorConsts.ConsecutiveReadingsRequired, powerWatts.Value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_waterReadySince ??= timeProvider.GetUtcNow();
|
||||
|
||||
logger.LogInformation("Water detected as ready after {Count} consecutive readings, cooldown active until shower or midnight reset", _consecutiveBelowThresholdCount);
|
||||
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;
|
||||
}
|
||||
@@ -132,13 +144,19 @@ public sealed class WaterReadyService(ILogger<WaterReadyService> logger, TimePro
|
||||
var todayMidnightUtc = new DateTimeOffset(timeProvider.GetUtcNow().Date, TimeSpan.Zero);
|
||||
if (waterReadySince < todayMidnightUtc)
|
||||
{
|
||||
logger.LogInformation("Persisted cooldown is from a previous day ({Since}), not restoring", waterReadySince);
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Persisted cooldown is from a previous day ({Since}), not restoring", waterReadySince);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_waterReadySince = waterReadySince;
|
||||
logger.LogInformation("Restored water ready cooldown from {Since}", waterReadySince);
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Restored water ready cooldown from {Since}", waterReadySince);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user