From 86f8f2dfbe7a4d6ec3588dcc20a2e8f8c95a9e97 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 19 Mar 2026 16:24:40 +0200 Subject: [PATCH] feat: switch NordPool entity attributes to compact array serialization format Made-with: Cursor --- NordPool.Manager/NordPoolEntityService.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/NordPool.Manager/NordPoolEntityService.cs b/NordPool.Manager/NordPoolEntityService.cs index 35f862e..8776315 100644 --- a/NordPool.Manager/NordPoolEntityService.cs +++ b/NordPool.Manager/NordPoolEntityService.cs @@ -103,7 +103,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< await SetEntityStateSafe(TodayPricesEntityId, "0").ConfigureAwait(false); await SetEntityAttributesSafe(TodayPricesEntityId, new { - prices = Array.Empty(), + prices = Array.Empty(), friendly_name = "NordPool today prices", last_updated = (string?)null }).ConfigureAwait(false); @@ -114,7 +114,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< await SetEntityStateSafe(TomorrowPricesEntityId, "0").ConfigureAwait(false); await SetEntityAttributesSafe(TomorrowPricesEntityId, new { - prices = Array.Empty(), + prices = Array.Empty(), friendly_name = "NordPool tomorrow prices", last_updated = (string?)null }).ConfigureAwait(false); @@ -125,7 +125,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< await SetEntityStateSafe(TodayTomorrowPricesEntityId, "unknown").ConfigureAwait(false); await SetEntityAttributesSafe(TodayTomorrowPricesEntityId, new { - prices = Array.Empty(), + prices = Array.Empty(), prices_count = 0, friendly_name = "NordPool today and tomorrow prices", last_updated = (string?)null @@ -179,6 +179,14 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< var todayPricesCount = ctx.TodayNordPoolPrice?.Prices?.Count ?? 0; var tomorrowPricesCount = ctx.TomorrowNordPoolPrice?.Prices?.Count ?? 0; var mergedPrices = MergeTodayTomorrowPrices(ctx.TodayNordPoolPrice, ctx.TomorrowNordPoolPrice); + + if (mergedPrices.Count > NordPoolConsts.MaxExpectedPriceEntries) + { + logger.LogWarning( + "Merged price count ({Count}) exceeds expected maximum ({Max}). Attribute payload may be oversized", + mergedPrices.Count, NordPoolConsts.MaxExpectedPriceEntries); + } + var cheapestCount = ctx.CheapestIntervals?.Count ?? 0; logger.LogInformation("Updating nordpool_current_price with value: {Price} {Unit}", priceValue, ctx.UnitOfMeasurement); @@ -230,7 +238,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< await SetEntityStateSafe(TodayPricesEntityId, todayPricesCount.ToString()).ConfigureAwait(false); await SetEntityAttributesSafe(TodayPricesEntityId, new { - prices = ctx.TodayNordPoolPrice?.Prices ?? Array.Empty(), + prices = (ctx.TodayNordPoolPrice?.Prices).ToCompact(), friendly_name = "NordPool today prices", last_updated = timestamp }).ConfigureAwait(false); @@ -241,7 +249,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< await SetEntityStateSafe(TomorrowPricesEntityId, tomorrowPricesCount.ToString()).ConfigureAwait(false); await SetEntityAttributesSafe(TomorrowPricesEntityId, new { - prices = ctx.TomorrowNordPoolPrice?.Prices ?? Array.Empty(), + prices = (ctx.TomorrowNordPoolPrice?.Prices).ToCompact(), friendly_name = "NordPool tomorrow prices", last_updated = timestamp }).ConfigureAwait(false); @@ -252,7 +260,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger< await SetEntityStateSafe(TodayTomorrowPricesEntityId, updateTimeState).ConfigureAwait(false); await SetEntityAttributesSafe(TodayTomorrowPricesEntityId, new { - prices = mergedPrices, + prices = mergedPrices.ToCompact(), prices_count = mergedPrices.Count, friendly_name = "NordPool today and tomorrow prices", last_updated = timestamp