feat: add BatteryMonitor implementation with discovery, notification, and scheduling services
This commit is contained in:
@@ -9,7 +9,7 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
private const int IntervalDurationSeconds = MinutesPerInterval * 60;
|
||||
|
||||
private static readonly DateTime TestStart = new(2026, 3, 19, 10, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime TestStart = new(2026, 3, 31, 10, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime TestEnd = TestStart.AddMinutes(MinutesPerInterval);
|
||||
private static readonly long TestStartEpoch = new DateTimeOffset(TestStart).ToUnixTimeSeconds();
|
||||
private static readonly long TestEndEpoch = new DateTimeOffset(TestEnd).ToUnixTimeSeconds();
|
||||
@@ -17,19 +17,19 @@ public class CompactNordPoolDayPriceTests
|
||||
[Fact]
|
||||
public void FromDayPrice_ShouldConvertDateTimesToUnixEpochSeconds()
|
||||
{
|
||||
var dayPrice = new NordPoolDayPrice { Start = TestStart, End = TestEnd, Price = 12.35 };
|
||||
var dayPrice = new NordPoolDayPrice { Start = TestStart, End = TestEnd, Price = 17.91 };
|
||||
|
||||
var result = CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
result.Start.Should().Be(TestStartEpoch);
|
||||
result.End.Should().Be(TestEndEpoch);
|
||||
result.Price.Should().Be(12.35);
|
||||
result.Price.Should().Be(17.91);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenStartIsNull_ShouldUseZeroEpoch()
|
||||
{
|
||||
var dayPrice = new NordPoolDayPrice { Start = null, End = TestEnd, Price = 5.0 };
|
||||
var dayPrice = new NordPoolDayPrice { Start = null, End = TestEnd, Price = 8.96 };
|
||||
|
||||
var result = CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CompactNordPoolDayPriceTests
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenEndIsNull_ShouldUseZeroEpoch()
|
||||
{
|
||||
var dayPrice = new NordPoolDayPrice { Start = TestStart, End = null, Price = 5.0 };
|
||||
var dayPrice = new NordPoolDayPrice { Start = TestStart, End = null, Price = 8.96 };
|
||||
|
||||
var result = CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
@@ -51,9 +51,9 @@ public class CompactNordPoolDayPriceTests
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenDateTimeKindIsLocal_ShouldConvertToUtcWithoutThrowing()
|
||||
{
|
||||
var localStart = new DateTime(2026, 3, 19, 12, 0, 0, DateTimeKind.Local);
|
||||
var localEnd = new DateTime(2026, 3, 19, 12, 15, 0, DateTimeKind.Local);
|
||||
var dayPrice = new NordPoolDayPrice { Start = localStart, End = localEnd, Price = 10.0 };
|
||||
var localStart = new DateTime(2026, 3, 31, 12, 0, 0, DateTimeKind.Local);
|
||||
var localEnd = new DateTime(2026, 3, 31, 12, 15, 0, DateTimeKind.Local);
|
||||
var dayPrice = new NordPoolDayPrice { Start = localStart, End = localEnd, Price = 12.50 };
|
||||
|
||||
var act = () => CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
@@ -66,9 +66,9 @@ public class CompactNordPoolDayPriceTests
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenDateTimeKindIsUnspecified_ShouldConvertWithoutThrowing()
|
||||
{
|
||||
var unspecifiedStart = new DateTime(2026, 3, 19, 12, 0, 0, DateTimeKind.Unspecified);
|
||||
var unspecifiedEnd = new DateTime(2026, 3, 19, 12, 15, 0, DateTimeKind.Unspecified);
|
||||
var dayPrice = new NordPoolDayPrice { Start = unspecifiedStart, End = unspecifiedEnd, Price = 10.0 };
|
||||
var unspecifiedStart = new DateTime(2026, 3, 31, 12, 0, 0, DateTimeKind.Unspecified);
|
||||
var unspecifiedEnd = new DateTime(2026, 3, 31, 12, 15, 0, DateTimeKind.Unspecified);
|
||||
var dayPrice = new NordPoolDayPrice { Start = unspecifiedStart, End = unspecifiedEnd, Price = 12.50 };
|
||||
|
||||
var act = () => CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
@@ -92,12 +92,12 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
Start = TestStartEpoch,
|
||||
End = TestEndEpoch,
|
||||
Price = 12.35
|
||||
Price = 17.91
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(compact);
|
||||
|
||||
json.Should().Be($"[{TestStartEpoch},{TestEndEpoch},12.35]");
|
||||
json.Should().Be($"[{TestStartEpoch},{TestEndEpoch},17.91]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -122,7 +122,7 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
Start = TestStartEpoch,
|
||||
End = TestEndEpoch,
|
||||
Price = 12.35
|
||||
Price = 17.91
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(original);
|
||||
@@ -138,13 +138,13 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
var prices = new List<CompactNordPoolDayPrice>
|
||||
{
|
||||
new() { Start = TestStartEpoch, End = TestEndEpoch, Price = 10.0 },
|
||||
new() { Start = TestEndEpoch, End = TestEndEpoch + IntervalDurationSeconds, Price = 11.0 }
|
||||
new() { Start = TestStartEpoch, End = TestEndEpoch, Price = 12.50 },
|
||||
new() { Start = TestEndEpoch, End = TestEndEpoch + IntervalDurationSeconds, Price = 13.26 }
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(prices);
|
||||
|
||||
json.Should().Be($"[[{TestStartEpoch},{TestEndEpoch},10],[{TestEndEpoch},{TestEndEpoch + IntervalDurationSeconds},11]]");
|
||||
json.Should().Be($"[[{TestStartEpoch},{TestEndEpoch},12.5],[{TestEndEpoch},{TestEndEpoch + IntervalDurationSeconds},13.26]]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -184,16 +184,16 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
var prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = TestStart, End = TestEnd, Price = 10.0 },
|
||||
new() { Start = TestEnd, End = TestEnd.AddMinutes(MinutesPerInterval), Price = 11.0 }
|
||||
new() { Start = TestStart, End = TestEnd, Price = 12.50 },
|
||||
new() { Start = TestEnd, End = TestEnd.AddMinutes(MinutesPerInterval), Price = 13.26 }
|
||||
};
|
||||
|
||||
var result = prices.ToCompact();
|
||||
|
||||
result.Should().HaveCount(2);
|
||||
result[0].Start.Should().Be(TestStartEpoch);
|
||||
result[0].Price.Should().Be(10.0);
|
||||
result[1].Price.Should().Be(11.0);
|
||||
result[0].Price.Should().Be(12.50);
|
||||
result[1].Price.Should().Be(13.26);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -220,7 +220,7 @@ public class CompactNordPoolDayPriceTests
|
||||
public void SerializedSize_WithMaxEntries_ShouldBeUnderHaAttributeLimit()
|
||||
{
|
||||
const int haAttributeByteLimitBytes = 16_384;
|
||||
var dayStart = new DateTime(2026, 3, 19, 0, 0, 0, DateTimeKind.Utc);
|
||||
var dayStart = new DateTime(2026, 3, 31, 0, 0, 0, DateTimeKind.Utc);
|
||||
var prices = new List<NordPoolDayPrice>();
|
||||
|
||||
for (var i = 0; i < MaxExpectedPriceEntries; i++)
|
||||
@@ -230,7 +230,7 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
Start = start,
|
||||
End = start.AddMinutes(MinutesPerInterval),
|
||||
Price = 10.0 + i * 0.01
|
||||
Price = 4.93 + i * 0.22
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user