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:
@@ -13,7 +13,7 @@ using static ShowerMonitor.Models.ShowerMonitorConsts;
|
||||
namespace ShowerMonitorManager;
|
||||
|
||||
[NetDaemonApp]
|
||||
public sealed class ShowerMonitorInit : IShowerMonitorInit
|
||||
public sealed class ShowerMonitorInit
|
||||
{
|
||||
private readonly ILogger<ShowerMonitorInit> _logger;
|
||||
private readonly IHaContext _haContext;
|
||||
@@ -63,7 +63,7 @@ public sealed class ShowerMonitorInit : IShowerMonitorInit
|
||||
}
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
private async Task InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -88,11 +88,6 @@ public sealed class ShowerMonitorInit : IShowerMonitorInit
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CleanupEntitiesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _entityService.CleanupEntitiesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
private void SchedulePeriodicPolling()
|
||||
{
|
||||
var pollInterval = TimeSpan.FromSeconds(_options.PollIntervalSeconds);
|
||||
@@ -162,7 +157,11 @@ public sealed class ShowerMonitorInit : IShowerMonitorInit
|
||||
|
||||
if (!bathroomHumidity.HasValue || !mainHomeHumidity.HasValue)
|
||||
{
|
||||
_logger.LogDebug("Humidity sensor data unavailable (bathroom={Bathroom}, home={Home})", bathroomHumidity, mainHomeHumidity);
|
||||
if (_logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.LogDebug("Humidity sensor data unavailable (bathroom={Bathroom}, home={Home})", bathroomHumidity, mainHomeHumidity);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,19 +174,19 @@ public sealed class ShowerMonitorInit : IShowerMonitorInit
|
||||
var context = new ShowerMonitorUpdateContext
|
||||
{
|
||||
State = state,
|
||||
BathroomHumidity = bathroomHumidity.Value,
|
||||
MainHomeHumidity = mainHomeHumidity.Value,
|
||||
Differential = differential,
|
||||
HumidityRate = _detectionService.LastRate,
|
||||
TodaySessionCount = _detectionService.TodaySessionCount,
|
||||
LastCompletedSession = _detectionService.LastCompletedSession,
|
||||
CurrentSession = _detectionService.CurrentSession
|
||||
LastCompletedSession = _detectionService.LastCompletedSession
|
||||
};
|
||||
|
||||
await _entityService.UpdateEntitiesAsync(context);
|
||||
|
||||
_logger.LogDebug("Poll: bathroom={Bath}%, home={Home}%, diff={Diff}%, state={State}",
|
||||
bathroomHumidity.Value, mainHomeHumidity.Value, Math.Round(differential, 1), state);
|
||||
if (_logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.LogDebug("Poll: bathroom={Bath}%, home={Home}%, diff={Diff}%, state={State}",
|
||||
bathroomHumidity.Value, mainHomeHumidity.Value, Math.Round(differential, 1), state);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user