feat: add BatteryMonitor implementation with discovery, notification, and scheduling services
This commit is contained in:
@@ -318,7 +318,7 @@ public class NordPoolEntityServiceTests
|
||||
#region UpdateEntitiesAsync
|
||||
|
||||
private static EntityUpdateContext CreateDefaultContext(
|
||||
double currentPrice = 12.5,
|
||||
double currentPrice = 17.91,
|
||||
NordPoolPrice? todayPrice = null,
|
||||
NordPoolPrice? tomorrowPrice = null)
|
||||
{
|
||||
@@ -331,18 +331,18 @@ public class NordPoolEntityServiceTests
|
||||
UsingCachedData = false,
|
||||
TodayNordPoolPrice = todayPrice ?? new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
|
||||
},
|
||||
TomorrowNordPoolPrice = tomorrowPrice ?? new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 20.0 } }
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 18.71 } }
|
||||
},
|
||||
CheapestIntervals = [],
|
||||
ConfiguredHours = 1.0,
|
||||
ConfiguredHours = 2.0,
|
||||
ConfiguredIntervalCount = 4,
|
||||
ConfiguredPriceCap = 100.0,
|
||||
ConfiguredPriceCap = 25.0,
|
||||
SkipPriceCap = false,
|
||||
ConfiguredReadyBy = "06:00",
|
||||
ConfiguredReadyBy = "18:00",
|
||||
IsNowCheap = false,
|
||||
NextCheapIntervalStart = null
|
||||
};
|
||||
@@ -364,7 +364,7 @@ public class NordPoolEntityServiceTests
|
||||
|
||||
// Assert
|
||||
_entityManagerMock.Verify(em => em.SetEntityState("sensor.nordpool_last_update_time", It.IsAny<string>()), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState("sensor.nordpool_current_price", "12.50"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState("sensor.nordpool_current_price", "17.91"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState("sensor.nordpool_today_prices", "1"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState("sensor.nordpool_tomorrow_prices", "1"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState("sensor.nordpool_today_tomorrow_prices", It.Is<string>(s => s.Contains('-') && s.Contains(':'))), Times.Once);
|
||||
@@ -421,21 +421,21 @@ public class NordPoolEntityServiceTests
|
||||
public async Task UpdateEntitiesAsync_WithTodayAndTomorrowPrices_ShouldUpdateCombinedSensor()
|
||||
{
|
||||
// Arrange
|
||||
var todayStart = new DateTime(2025, 3, 16, 6, 0, 0, DateTimeKind.Utc);
|
||||
var tomorrowStart = new DateTime(2025, 3, 17, 6, 0, 0, DateTimeKind.Utc);
|
||||
var todayStart = new DateTime(2026, 3, 31, 6, 0, 0, DateTimeKind.Utc);
|
||||
var tomorrowStart = new DateTime(2026, 4, 1, 6, 0, 0, DateTimeKind.Utc);
|
||||
var todayPrice = new NordPoolPrice
|
||||
{
|
||||
Prices =
|
||||
[
|
||||
new NordPoolDayPrice { Start = todayStart.AddHours(2), End = todayStart.AddHours(2).AddMinutes(15), Price = 15.0 },
|
||||
new NordPoolDayPrice { Start = todayStart, End = todayStart.AddMinutes(15), Price = 10.0 }
|
||||
new NordPoolDayPrice { Start = todayStart.AddHours(2), End = todayStart.AddHours(2).AddMinutes(15), Price = 17.91 },
|
||||
new NordPoolDayPrice { Start = todayStart, End = todayStart.AddMinutes(15), Price = 12.50 }
|
||||
]
|
||||
};
|
||||
var tomorrowPrice = new NordPoolPrice
|
||||
{
|
||||
Prices =
|
||||
[
|
||||
new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 20.0 }
|
||||
new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }
|
||||
]
|
||||
};
|
||||
var context = CreateDefaultContext(todayPrice: todayPrice, tomorrowPrice: tomorrowPrice);
|
||||
@@ -467,7 +467,7 @@ public class NordPoolEntityServiceTests
|
||||
// Arrange
|
||||
var todayPrice = new NordPoolPrice
|
||||
{
|
||||
Prices = [new NordPoolDayPrice { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddMinutes(15), Price = 12.0 }]
|
||||
Prices = [new NordPoolDayPrice { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddMinutes(15), Price = 17.91 }]
|
||||
};
|
||||
var context = CreateDefaultContext(todayPrice: todayPrice, tomorrowPrice: new NordPoolPrice { Prices = [] });
|
||||
|
||||
@@ -496,7 +496,7 @@ public class NordPoolEntityServiceTests
|
||||
// Arrange
|
||||
var tomorrowPrice = new NordPoolPrice
|
||||
{
|
||||
Prices = [new NordPoolDayPrice { Start = DateTime.UtcNow.AddDays(1), End = DateTime.UtcNow.AddDays(1).AddMinutes(15), Price = 18.0 }]
|
||||
Prices = [new NordPoolDayPrice { Start = DateTime.UtcNow.AddDays(1), End = DateTime.UtcNow.AddDays(1).AddMinutes(15), Price = 18.71 }]
|
||||
};
|
||||
var context = CreateDefaultContext(todayPrice: new NordPoolPrice { Prices = [] }, tomorrowPrice: tomorrowPrice);
|
||||
|
||||
@@ -527,9 +527,9 @@ public class NordPoolEntityServiceTests
|
||||
{
|
||||
Prices = [new NordPoolDayPrice
|
||||
{
|
||||
Start = new DateTime(2026, 3, 19, 10, 0, 0, DateTimeKind.Utc),
|
||||
End = new DateTime(2026, 3, 19, 10, 15, 0, DateTimeKind.Utc),
|
||||
Price = 12.0
|
||||
Start = new DateTime(2026, 3, 31, 10, 0, 0, DateTimeKind.Utc),
|
||||
End = new DateTime(2026, 3, 31, 10, 15, 0, DateTimeKind.Utc),
|
||||
Price = 17.91
|
||||
}]
|
||||
};
|
||||
var context = CreateDefaultContext(todayPrice: todayPrice, tomorrowPrice: new NordPoolPrice { Prices = [] });
|
||||
@@ -555,21 +555,21 @@ public class NordPoolEntityServiceTests
|
||||
// Arrange
|
||||
const int intervalsPerDay = 96;
|
||||
const int haAttributeByteLimitBytes = 16_384;
|
||||
var todayStart = new DateTime(2026, 3, 19, 0, 0, 0, DateTimeKind.Utc);
|
||||
var tomorrowStart = new DateTime(2026, 3, 20, 0, 0, 0, DateTimeKind.Utc);
|
||||
var todayStart = new DateTime(2026, 3, 31, 0, 0, 0, DateTimeKind.Utc);
|
||||
var tomorrowStart = new DateTime(2026, 4, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
var todayPrices = Enumerable.Range(0, intervalsPerDay).Select(i => new NordPoolDayPrice
|
||||
{
|
||||
Start = todayStart.AddMinutes(i * NordPoolConsts.MinutesPerInterval),
|
||||
End = todayStart.AddMinutes((i + 1) * NordPoolConsts.MinutesPerInterval),
|
||||
Price = 5.0 + i * 0.1
|
||||
Price = 4.93 + i * 0.22
|
||||
}).ToList();
|
||||
|
||||
var tomorrowPrices = Enumerable.Range(0, intervalsPerDay).Select(i => new NordPoolDayPrice
|
||||
{
|
||||
Start = tomorrowStart.AddMinutes(i * NordPoolConsts.MinutesPerInterval),
|
||||
End = tomorrowStart.AddMinutes((i + 1) * NordPoolConsts.MinutesPerInterval),
|
||||
Price = 8.0 + i * 0.1
|
||||
Price = 5.50 + i * 0.22
|
||||
}).ToList();
|
||||
|
||||
object? capturedAttributes = null;
|
||||
|
||||
Reference in New Issue
Block a user