feat: switch NordPool entity attributes to compact array serialization format
Made-with: Cursor
This commit is contained in:
@@ -103,7 +103,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
|
|||||||
await SetEntityStateSafe(TodayPricesEntityId, "0").ConfigureAwait(false);
|
await SetEntityStateSafe(TodayPricesEntityId, "0").ConfigureAwait(false);
|
||||||
await SetEntityAttributesSafe(TodayPricesEntityId, new
|
await SetEntityAttributesSafe(TodayPricesEntityId, new
|
||||||
{
|
{
|
||||||
prices = Array.Empty<NordPoolDayPrice>(),
|
prices = Array.Empty<CompactNordPoolDayPrice>(),
|
||||||
friendly_name = "NordPool today prices",
|
friendly_name = "NordPool today prices",
|
||||||
last_updated = (string?)null
|
last_updated = (string?)null
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
@@ -114,7 +114,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
|
|||||||
await SetEntityStateSafe(TomorrowPricesEntityId, "0").ConfigureAwait(false);
|
await SetEntityStateSafe(TomorrowPricesEntityId, "0").ConfigureAwait(false);
|
||||||
await SetEntityAttributesSafe(TomorrowPricesEntityId, new
|
await SetEntityAttributesSafe(TomorrowPricesEntityId, new
|
||||||
{
|
{
|
||||||
prices = Array.Empty<NordPoolDayPrice>(),
|
prices = Array.Empty<CompactNordPoolDayPrice>(),
|
||||||
friendly_name = "NordPool tomorrow prices",
|
friendly_name = "NordPool tomorrow prices",
|
||||||
last_updated = (string?)null
|
last_updated = (string?)null
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
@@ -125,7 +125,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
|
|||||||
await SetEntityStateSafe(TodayTomorrowPricesEntityId, "unknown").ConfigureAwait(false);
|
await SetEntityStateSafe(TodayTomorrowPricesEntityId, "unknown").ConfigureAwait(false);
|
||||||
await SetEntityAttributesSafe(TodayTomorrowPricesEntityId, new
|
await SetEntityAttributesSafe(TodayTomorrowPricesEntityId, new
|
||||||
{
|
{
|
||||||
prices = Array.Empty<NordPoolDayPrice>(),
|
prices = Array.Empty<CompactNordPoolDayPrice>(),
|
||||||
prices_count = 0,
|
prices_count = 0,
|
||||||
friendly_name = "NordPool today and tomorrow prices",
|
friendly_name = "NordPool today and tomorrow prices",
|
||||||
last_updated = (string?)null
|
last_updated = (string?)null
|
||||||
@@ -179,6 +179,14 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
|
|||||||
var todayPricesCount = ctx.TodayNordPoolPrice?.Prices?.Count ?? 0;
|
var todayPricesCount = ctx.TodayNordPoolPrice?.Prices?.Count ?? 0;
|
||||||
var tomorrowPricesCount = ctx.TomorrowNordPoolPrice?.Prices?.Count ?? 0;
|
var tomorrowPricesCount = ctx.TomorrowNordPoolPrice?.Prices?.Count ?? 0;
|
||||||
var mergedPrices = MergeTodayTomorrowPrices(ctx.TodayNordPoolPrice, ctx.TomorrowNordPoolPrice);
|
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;
|
var cheapestCount = ctx.CheapestIntervals?.Count ?? 0;
|
||||||
|
|
||||||
logger.LogInformation("Updating nordpool_current_price with value: {Price} {Unit}", priceValue, ctx.UnitOfMeasurement);
|
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 SetEntityStateSafe(TodayPricesEntityId, todayPricesCount.ToString()).ConfigureAwait(false);
|
||||||
await SetEntityAttributesSafe(TodayPricesEntityId, new
|
await SetEntityAttributesSafe(TodayPricesEntityId, new
|
||||||
{
|
{
|
||||||
prices = ctx.TodayNordPoolPrice?.Prices ?? Array.Empty<NordPoolDayPrice>(),
|
prices = (ctx.TodayNordPoolPrice?.Prices).ToCompact(),
|
||||||
friendly_name = "NordPool today prices",
|
friendly_name = "NordPool today prices",
|
||||||
last_updated = timestamp
|
last_updated = timestamp
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
@@ -241,7 +249,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
|
|||||||
await SetEntityStateSafe(TomorrowPricesEntityId, tomorrowPricesCount.ToString()).ConfigureAwait(false);
|
await SetEntityStateSafe(TomorrowPricesEntityId, tomorrowPricesCount.ToString()).ConfigureAwait(false);
|
||||||
await SetEntityAttributesSafe(TomorrowPricesEntityId, new
|
await SetEntityAttributesSafe(TomorrowPricesEntityId, new
|
||||||
{
|
{
|
||||||
prices = ctx.TomorrowNordPoolPrice?.Prices ?? Array.Empty<NordPoolDayPrice>(),
|
prices = (ctx.TomorrowNordPoolPrice?.Prices).ToCompact(),
|
||||||
friendly_name = "NordPool tomorrow prices",
|
friendly_name = "NordPool tomorrow prices",
|
||||||
last_updated = timestamp
|
last_updated = timestamp
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
@@ -252,7 +260,7 @@ public sealed class NordPoolEntityService(IEntityManager entityManager, ILogger<
|
|||||||
await SetEntityStateSafe(TodayTomorrowPricesEntityId, updateTimeState).ConfigureAwait(false);
|
await SetEntityStateSafe(TodayTomorrowPricesEntityId, updateTimeState).ConfigureAwait(false);
|
||||||
await SetEntityAttributesSafe(TodayTomorrowPricesEntityId, new
|
await SetEntityAttributesSafe(TodayTomorrowPricesEntityId, new
|
||||||
{
|
{
|
||||||
prices = mergedPrices,
|
prices = mergedPrices.ToCompact(),
|
||||||
prices_count = mergedPrices.Count,
|
prices_count = mergedPrices.Count,
|
||||||
friendly_name = "NordPool today and tomorrow prices",
|
friendly_name = "NordPool today and tomorrow prices",
|
||||||
last_updated = timestamp
|
last_updated = timestamp
|
||||||
|
|||||||
Reference in New Issue
Block a user