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:
2026-11-29 21:42:43 +02:00
parent 17774b40b8
commit 41ac93733e
65 changed files with 545 additions and 459 deletions
+7 -4
View File
@@ -167,8 +167,11 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
}
var cheapestCount = ctx.CheapestIntervals?.Count ?? 0;
logger.LogInformation("Updating sensor.nordpool_cheapest_intervals with {Count} intervals, is_now_cheap={IsNow}", cheapestCount, ctx.IsNowCheap);
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Updating sensor.nordpool_cheapest_intervals with {Count} intervals, is_now_cheap={IsNow}", cheapestCount, ctx.IsNowCheap);
}
var updateTasks = new[]
{
@@ -273,9 +276,9 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
}
}
internal ICollection<NordPoolEntity> GetInitEntitiesList(string? unitOfMeasurement)
internal static ICollection<NordPoolEntity> GetInitEntitiesList(string? unitOfMeasurement)
{
var currentPriceEntityId = NordPoolConsts.CurrentPriceEntityId;
const string currentPriceEntityId = NordPoolConsts.CurrentPriceEntityId;
var currentPriceDomainSeparator = currentPriceEntityId.IndexOf('.', StringComparison.Ordinal);
var currentPriceDomain = currentPriceEntityId[..currentPriceDomainSeparator];
var currentPriceObjectId = currentPriceEntityId[(currentPriceDomainSeparator + 1)..];
+53 -39
View File
@@ -28,13 +28,21 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
if ((TodayNordPoolPrice?.Prices == null || TodayNordPoolPrice.Prices.Count == 0) && ShouldFetchNewPrices(today))
{
logger.LogInformation("Fetching today's prices from API for CET date: {Today}", today);
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Fetching today's prices from API for CET date: {Today}", today);
}
TodayNordPoolPrice = await FetchPricesForDateWithRetryAsync(today, "today");
}
if ((TomorrowNordPoolPrice?.Prices == null || TomorrowNordPoolPrice.Prices.Count == 0) && ShouldFetchNewPrices(today.AddDays(1)))
{
logger.LogInformation("Fetching tomorrow's prices from API for CET date: {Tomorrow}", today.AddDays(1));
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Fetching tomorrow's prices from API for CET date: {Tomorrow}", today.AddDays(1));
}
TomorrowNordPoolPrice = await FetchPricesForDateWithRetryAsync(today.AddDays(1), "tomorrow");
}
@@ -46,30 +54,35 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
{
var index = GetTimeQuarterIndex(DateTime.UtcNow);
logger.LogDebug("Current time quarter index: {Index}, Total prices available: {Count}", index, TodayNordPoolPrice?.Prices?.Count ?? 0);
if (DayQuartersIndex != index)
if (logger.IsEnabled(LogLevel.Debug))
{
if (TodayNordPoolPrice?.Prices != null && TodayNordPoolPrice.Prices.Count > index)
{
var price = TodayNordPoolPrice.Prices[index].Price;
logger.LogDebug("Current time quarter index: {Index}, Total prices available: {Count}", index, TodayNordPoolPrice?.Prices?.Count ?? 0);
}
if (price.HasValue)
{
CurrentPrice = price.Value;
}
else
{
logger.LogWarning("Price at index {Index} is null", index);
}
if (DayQuartersIndex == index)
{
return;
}
if (TodayNordPoolPrice?.Prices != null && TodayNordPoolPrice.Prices.Count > index)
{
var price = TodayNordPoolPrice.Prices[index].Price;
if (price.HasValue)
{
CurrentPrice = price.Value;
}
else
{
logger.LogWarning("Cannot get price for index {Index}. Prices is null: {IsNull}, Prices count: {Count}", index, TodayNordPoolPrice?.Prices == null, TodayNordPoolPrice?.Prices?.Count ?? 0);
logger.LogWarning("Price at index {Index} is null", index);
}
DayQuartersIndex = index;
}
else
{
logger.LogWarning("Cannot get price for index {Index}. Prices is null: {IsNull}, Prices count: {Count}", index, TodayNordPoolPrice?.Prices == null, TodayNordPoolPrice?.Prices?.Count ?? 0);
}
DayQuartersIndex = index;
}
public double GetCurrentPrice()
@@ -94,17 +107,14 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
return true;
}
if (TomorrowNordPoolPrice?.Prices == null || TomorrowNordPoolPrice.Prices.Count == 0)
if (TomorrowNordPoolPrice?.Prices is { Count: > 0 })
{
var currentHour = DateTime.Now.Hour;
if (currentHour >= 13)
{
return true;
}
return false;
}
return false;
var currentHour = DateTime.Now.Hour;
return currentHour >= 13;
}
public void RollOverPrices(DateOnly today)
@@ -172,27 +182,31 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
return priceResult != null ? mapper.Map<NordPoolPriceResultDto, NordPoolPrice>(priceResult) : new NordPoolPrice();
}
internal NordPoolPrice AdjustedNordPoolPrice(NordPoolPrice todayNordPoolPrice)
internal static NordPoolPrice AdjustedNordPoolPrice(NordPoolPrice todayNordPoolPrice)
{
var recalculatedPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice>()
};
if (todayNordPoolPrice.Prices != null)
if (todayNordPoolPrice.Prices is null)
{
foreach (var price in todayNordPoolPrice.Prices)
return recalculatedPrice;
}
foreach (var price in todayNordPoolPrice.Prices)
{
if (price.Price is null)
{
if (price.Price != null)
{
recalculatedPrice.Prices.Add(new NordPoolDayPrice
{
Start = price.Start,
End = price.End,
Price = PriceCorrection(price.Price.Value)
});
}
continue;
}
recalculatedPrice.Prices.Add(new NordPoolDayPrice
{
Start = price.Start,
End = price.End,
Price = PriceCorrection(price.Price.Value)
});
}
return recalculatedPrice;
@@ -1,4 +1,3 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetDaemon.AppModel;
using NordPoolManager.Interface;
@@ -7,7 +6,7 @@ namespace NordPoolManager;
public static class NordPoolServiceRegistration
{
public static IServiceCollection AddNordPool(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection AddNordPool(this IServiceCollection services)
{
services
.AddNetDaemonApp<NordPoolInit>()