feat: switch NordPool entity attributes to compact array serialization format

Made-with: Cursor
This commit is contained in:
Marius
2026-03-19 16:24:40 +02:00
parent 0f146150f7
commit 86f8f2dfbe
+14 -6
View File
@@ -103,7 +103,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
await SetEntityStateSafe(TodayPricesEntityId, "0").ConfigureAwait(false);
await SetEntityAttributesSafe(TodayPricesEntityId, new
{
prices = Array.Empty<NordPoolDayPrice>(),
prices = Array.Empty<CompactNordPoolDayPrice>(),
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<NordPoolDayPrice>(),
prices = Array.Empty<CompactNordPoolDayPrice>(),
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<NordPoolDayPrice>(),
prices = Array.Empty<CompactNordPoolDayPrice>(),
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<NordPoolDayPrice>(),
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<NordPoolDayPrice>(),
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