feat: add BatteryMonitor implementation with discovery, notification, and scheduling services

This commit is contained in:
Marius
2026-04-01 10:55:33 +03:00
parent 11c2574235
commit 6e4d684359
114 changed files with 22820 additions and 527 deletions
@@ -40,7 +40,7 @@ public class NordPoolPriceServiceTests
public void GetTimeQuarterIndex_ShouldReturnCorrectIndex(int hour, int minute, int expectedIndex)
{
// Arrange
var testDate = new DateTime(2026, 2, 3, hour, minute, 0, DateTimeKind.Utc);
var testDate = new DateTime(2026, 3, 31, hour, minute, 0, DateTimeKind.Utc);
// Act
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
@@ -58,7 +58,7 @@ public class NordPoolPriceServiceTests
public void GetTimeQuarterIndex_ShouldHandleAllHoursCorrectly(int hour, int minute, int expectedIndex)
{
// Arrange
var testDate = new DateTime(2026, 2, 3, hour, minute, 0, DateTimeKind.Utc);
var testDate = new DateTime(2026, 3, 31, hour, minute, 0, DateTimeKind.Utc);
// Act
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
@@ -71,7 +71,7 @@ public class NordPoolPriceServiceTests
public void GetTimeQuarterIndex_AtExactMidnight_ShouldReturnIndex4()
{
// Arrange
var testDate = new DateTime(2026, 2, 3, 0, 0, 0, DateTimeKind.Utc);
var testDate = new DateTime(2026, 3, 31, 0, 0, 0, DateTimeKind.Utc);
// Act
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
@@ -84,7 +84,7 @@ public class NordPoolPriceServiceTests
public void GetTimeQuarterIndex_AtEndOfDay_ShouldReturnIndex95()
{
// Arrange
var testDate = new DateTime(2026, 2, 3, 22, 45, 0, DateTimeKind.Utc);
var testDate = new DateTime(2026, 3, 31, 22, 45, 0, DateTimeKind.Utc);
// Act
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
@@ -97,8 +97,8 @@ public class NordPoolPriceServiceTests
public void GetTimeQuarterIndex_WithSeconds_ShouldIgnoreSeconds()
{
// Arrange
var withoutSeconds = new DateTime(2026, 2, 3, 12, 0, 0, DateTimeKind.Utc);
var withSeconds = new DateTime(2026, 2, 3, 12, 0, 59, DateTimeKind.Utc);
var withoutSeconds = new DateTime(2026, 3, 31, 12, 0, 0, DateTimeKind.Utc);
var withSeconds = new DateTime(2026, 3, 31, 12, 0, 59, DateTimeKind.Utc);
// Act
var result1 = NordPoolPriceService.GetTimeQuarterIndex(withoutSeconds);
@@ -117,7 +117,7 @@ public class NordPoolPriceServiceTests
{
for (var minute = 0; minute < 60; minute += 15)
{
var date = new DateTime(2026, 2, 3, hour, minute, 0, DateTimeKind.Utc);
var date = new DateTime(2026, 3, 31, hour, minute, 0, DateTimeKind.Utc);
var index = NordPoolPriceService.GetTimeQuarterIndex(date);
indices.Add(index);
}
@@ -285,9 +285,9 @@ public class NordPoolPriceServiceTests
{
Prices = new List<NordPoolDayPrice>
{
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 100.0 },
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = 200.0 },
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 150.0 }
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 },
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = 148.0 },
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 215.0 }
}
};
@@ -297,9 +297,9 @@ public class NordPoolPriceServiceTests
// Assert
result.Should().NotBeNull();
result.Prices.Should().HaveCount(3);
result.Prices![0].Price.Should().BeApproximately(12.1, 0.01);
result.Prices![1].Price.Should().BeApproximately(24.2, 0.01);
result.Prices![2].Price.Should().BeApproximately(18.15, 0.01);
result.Prices![0].Price.Should().BeApproximately(9.80, 0.01);
result.Prices![1].Price.Should().BeApproximately(17.91, 0.01);
result.Prices![2].Price.Should().BeApproximately(26.02, 0.01);
}
[Fact]
@@ -310,9 +310,9 @@ public class NordPoolPriceServiceTests
{
Prices = new List<NordPoolDayPrice>
{
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 100.0 },
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 },
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = null },
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 150.0 }
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 215.0 }
}
};
@@ -344,14 +344,14 @@ public class NordPoolPriceServiceTests
public void AdjustedNordPoolPrice_ShouldPreserveDateTimes()
{
// Arrange
var startTime = new DateTime(2026, 2, 3, 10, 0, 0, DateTimeKind.Utc);
var endTime = new DateTime(2026, 2, 3, 11, 0, 0, DateTimeKind.Utc);
var startTime = new DateTime(2026, 3, 31, 10, 0, 0, DateTimeKind.Utc);
var endTime = new DateTime(2026, 3, 31, 11, 0, 0, DateTimeKind.Utc);
var inputPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice>
{
new() { Start = startTime, End = endTime, Price = 100.0 }
new() { Start = startTime, End = endTime, Price = 81.0 }
}
};
@@ -408,7 +408,7 @@ public class NordPoolPriceServiceTests
{
Prices = new List<NordPoolDayPrice>
{
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 100.0 }
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 }
}
};
@@ -416,7 +416,7 @@ public class NordPoolPriceServiceTests
var result = _sut.AdjustedNordPoolPrice(inputPrice);
// Assert
inputPrice.Prices[0].Price.Should().Be(100.0);
inputPrice.Prices[0].Price.Should().Be(81.0);
result.Prices.Should().NotBeSameAs(inputPrice.Prices);
}
@@ -437,7 +437,7 @@ public class NordPoolPriceServiceTests
{
Start = now.AddMinutes(i * 15),
End = now.AddMinutes((i + 1) * 15),
Price = 10.0 + i
Price = 5.0 + i * 0.22
});
}
@@ -494,17 +494,17 @@ public class NordPoolPriceServiceTests
var prices = new List<NordPoolDayPrice>();
for (var i = 0; i < 96; i++)
prices.Add(new NordPoolDayPrice { Price = 42.0 + i });
prices.Add(new NordPoolDayPrice { Price = 4.0 + i * 0.23 });
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
_sut.DayQuartersIndex = expectedIndex;
_sut.CurrentPrice = 99.99;
_sut.CurrentPrice = 17.91;
// Act
var result = _sut.UpdateCurrentPrice();
// Assert
result.Should().Be(99.99);
result.Should().Be(17.91);
}
[Fact]
@@ -516,14 +516,14 @@ public class NordPoolPriceServiceTests
prices.Add(new NordPoolDayPrice { Price = null });
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
_sut.CurrentPrice = 55.0;
_sut.CurrentPrice = 17.91;
_sut.DayQuartersIndex = -1;
// Act
var result = _sut.UpdateCurrentPrice();
// Assert
result.Should().Be(55.0);
result.Should().Be(17.91);
}
[Fact]
@@ -532,7 +532,7 @@ public class NordPoolPriceServiceTests
// Arrange
var prices = new List<NordPoolDayPrice>();
for (var i = 0; i < 96; i++)
prices.Add(new NordPoolDayPrice { Price = 10.0 + i });
prices.Add(new NordPoolDayPrice { Price = 5.0 + i * 0.22 });
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
_sut.DayQuartersIndex = -1;
@@ -566,7 +566,7 @@ public class NordPoolPriceServiceTests
_sut.LastFetchedDate = today.AddDays(-1);
_sut.TodayNordPoolPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
};
// Act
@@ -585,7 +585,7 @@ public class NordPoolPriceServiceTests
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = null };
_sut.TomorrowNordPoolPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
};
// Act
@@ -604,7 +604,7 @@ public class NordPoolPriceServiceTests
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = new List<NordPoolDayPrice>() };
_sut.TomorrowNordPoolPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
};
// Act
@@ -622,11 +622,11 @@ public class NordPoolPriceServiceTests
_sut.LastFetchedDate = today;
_sut.TodayNordPoolPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
};
_sut.TomorrowNordPoolPrice = new NordPoolPrice
{
Prices = new List<NordPoolDayPrice> { new() { Price = 20.0 } }
Prices = new List<NordPoolDayPrice> { new() { Price = 18.71 } }
};
// Act