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
@@ -24,15 +24,15 @@ public class OtherPowerCalculationServiceTests
var sut = CreateSut(smoothingWindowSize: 1);
var devices = new Dictionary<string, double>
{
["sensor.device_a_power"] = 500,
["sensor.device_b_power"] = 300
["sensor.sonoff_100215c534_power"] = 8.55,
["sensor.sonoff_10018909cb_power"] = 36.93
};
var result = sut.Calculate(1000, devices);
var result = sut.Calculate(341.97, devices);
result.TotalPowerWatts.Should().Be(1000);
result.KnownDevicesSumWatts.Should().Be(800);
result.RawOtherPowerWatts.Should().Be(200);
result.TotalPowerWatts.Should().Be(341.97);
result.KnownDevicesSumWatts.Should().BeApproximately(45.48, 0.01);
result.RawOtherPowerWatts.Should().BeApproximately(296.49, 0.01);
result.DataQuality.Should().Be("ok");
}
@@ -42,11 +42,11 @@ public class OtherPowerCalculationServiceTests
var sut = CreateSut(smoothingWindowSize: 1);
var devices = new Dictionary<string, double>
{
["sensor.device_a_power"] = 800,
["sensor.device_b_power"] = 500
["sensor.sonoff_100215c534_power"] = 200.0,
["sensor.sonoff_10018909cb_power"] = 180.0
};
var result = sut.Calculate(1000, devices);
var result = sut.Calculate(341.97, devices);
result.RawOtherPowerWatts.Should().Be(0);
result.SmoothedOtherPowerWatts.Should().Be(0);
@@ -59,9 +59,9 @@ public class OtherPowerCalculationServiceTests
var sut = CreateSut(smoothingWindowSize: 1);
var devices = new Dictionary<string, double>();
var result = sut.Calculate(1500, devices);
var result = sut.Calculate(341.97, devices);
result.RawOtherPowerWatts.Should().Be(1500);
result.RawOtherPowerWatts.Should().Be(341.97);
result.KnownDevicesSumWatts.Should().Be(0);
}
@@ -71,15 +71,15 @@ public class OtherPowerCalculationServiceTests
var sut = CreateSut(smoothingWindowSize: 1);
var devices = new Dictionary<string, double>
{
["sensor.a"] = 100,
["sensor.b"] = 200
["sensor.sonoff_100215c534_power"] = 8.55,
["sensor.sonoff_10018909cb_power"] = 36.93
};
var result = sut.Calculate(500, devices);
var result = sut.Calculate(341.97, devices);
result.DevicePowerReadings.Should().HaveCount(2);
result.DevicePowerReadings["sensor.a"].Should().Be(100);
result.DevicePowerReadings["sensor.b"].Should().Be(200);
result.DevicePowerReadings["sensor.sonoff_100215c534_power"].Should().Be(8.55);
result.DevicePowerReadings["sensor.sonoff_10018909cb_power"].Should().Be(36.93);
}
#endregion
@@ -92,12 +92,12 @@ public class OtherPowerCalculationServiceTests
var sut = CreateSut(smoothingWindowSize: 4);
var devices = new Dictionary<string, double>();
var result1 = sut.Calculate(1000, devices);
result1.SmoothedOtherPowerWatts.Should().BeApproximately(1000, 0.1);
var result1 = sut.Calculate(341.97, devices);
result1.SmoothedOtherPowerWatts.Should().BeApproximately(341.97, 0.1);
var result2 = sut.Calculate(500, devices);
result2.SmoothedOtherPowerWatts.Should().BeLessThan(1000);
result2.SmoothedOtherPowerWatts.Should().BeGreaterThan(500);
var result2 = sut.Calculate(115.0, devices);
result2.SmoothedOtherPowerWatts.Should().BeLessThan(341.97);
result2.SmoothedOtherPowerWatts.Should().BeGreaterThan(115.0);
}
[Fact]
@@ -109,10 +109,10 @@ public class OtherPowerCalculationServiceTests
PowerCalculationResult? result = null;
for (var i = 0; i < 50; i++)
{
result = sut.Calculate(300, devices);
result = sut.Calculate(200.0, devices);
}
result!.SmoothedOtherPowerWatts.Should().BeApproximately(300, 0.1);
result!.SmoothedOtherPowerWatts.Should().BeApproximately(200.0, 0.1);
}
#endregion
@@ -124,13 +124,13 @@ public class OtherPowerCalculationServiceTests
{
var sut = CreateSut(smoothingWindowSize: 10);
var devices = new Dictionary<string, double>();
sut.Calculate(1000, devices);
sut.Calculate(1000, devices);
sut.Calculate(341.97, devices);
sut.Calculate(341.97, devices);
sut.Reset();
var result = sut.Calculate(100, devices);
var result = sut.Calculate(115.0, devices);
result.SmoothedOtherPowerWatts.Should().BeApproximately(100, 0.1);
result.SmoothedOtherPowerWatts.Should().BeApproximately(115.0, 0.1);
}
#endregion