diff --git a/NordPool.Manager.Tests/CompactNordPoolDayPriceTests.cs b/NordPool.Manager.Tests/CompactNordPoolDayPriceTests.cs index e7adc41..7c84aea 100644 --- a/NordPool.Manager.Tests/CompactNordPoolDayPriceTests.cs +++ b/NordPool.Manager.Tests/CompactNordPoolDayPriceTests.cs @@ -188,4 +188,38 @@ public class CompactNordPoolDayPriceTests result.Should().BeEmpty(); } + + [Fact] + public void SerializedSize_WithMaxEntries_ShouldBeUnderHaAttributeLimit() + { + const int maxEntries = 192; + const int haAttributeByteLimitBytes = 16_384; + var dayStart = new DateTime(2026, 3, 19, 0, 0, 0, DateTimeKind.Utc); + var prices = new List(); + + for (var i = 0; i < maxEntries; i++) + { + var start = dayStart.AddMinutes(i * MinutesPerInterval); + prices.Add(new NordPoolDayPrice + { + Start = start, + End = start.AddMinutes(MinutesPerInterval), + Price = 10.0 + i * 0.01 + }); + } + + var compactPrices = prices.ToCompact(); + var attributePayload = new + { + prices = compactPrices, + prices_count = compactPrices.Count, + friendly_name = "NordPool today and tomorrow prices", + last_updated = DateTime.UtcNow.ToString("O") + }; + var json = JsonSerializer.Serialize(attributePayload); + var byteCount = System.Text.Encoding.UTF8.GetByteCount(json); + + byteCount.Should().BeLessThan(haAttributeByteLimitBytes, + $"serialized attribute payload is {byteCount} bytes, exceeding HA's {haAttributeByteLimitBytes}-byte limit"); + } }