Clear the residual Qodana findings
- Drop the leftover unused using, parameter and date-time attribute reader - Merge the remaining enum guard into its pattern - Make the NordPool price DTO init-only - Replace the four non-serializable theory matrices with single tests that iterate the same rows, so xUnit can still report them - Replace Array.Empty with collection expressions and drop unused locals, redundant default arguments and duplicated tuple names - Throw from the unreachable shower default instead of an empty section - Cover the configurable PowerMonitor option overrides in a test so the init setters have a caller
This commit is contained in:
@@ -21,11 +21,11 @@ public class OtherPowerCalculationServiceTests
|
||||
public static TheoryData<string, double, double[], double, string> CalculationCases => new()
|
||||
{
|
||||
{ "two devices", 341.97, [8.55, 36.93], 296.49, "ok" },
|
||||
{ "no devices", 341.97, Array.Empty<double>(), 341.97, "ok" },
|
||||
{ "no devices", 341.97, [], 341.97, "ok" },
|
||||
{ "devices exceed total", 341.97, [200.0, 180.0], 0.0, "device_sum_exceeds_total" },
|
||||
{ "devices equal total", 100.0, [60.0, 40.0], 0.0, "ok" },
|
||||
{ "zero power, no devices", 0.0, Array.Empty<double>(), 0.0, "ok" },
|
||||
{ "negative total, no devices", -120.0, Array.Empty<double>(), 0.0, "device_sum_exceeds_total" },
|
||||
{ "zero power, no devices", 0.0, [], 0.0, "ok" },
|
||||
{ "negative total, no devices", -120.0, [], 0.0, "device_sum_exceeds_total" },
|
||||
{ "negative device reading", 100.0, [150.0, -40.0], 0.0, "device_sum_exceeds_total" },
|
||||
{ "very large values", 1_000_000.0, [250_000.0, 250_000.0], 500_000.0, "ok" },
|
||||
{ "very small values", 0.5, [0.25], 0.25, "ok" }
|
||||
@@ -43,7 +43,7 @@ public class OtherPowerCalculationServiceTests
|
||||
// Arrange
|
||||
var sut = CreateSut(smoothingWindowSize: 1);
|
||||
var devices = deviceWatts
|
||||
.Select((watts, index) => (entityId: $"sensor.device{index}_power", watts: watts))
|
||||
.Select((watts, index) => (entityId: $"sensor.device{index}_power", watts))
|
||||
.ToDictionary(entry => entry.entityId, entry => entry.watts);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -312,7 +312,7 @@ public class PowerCostCalculationServiceTests
|
||||
// Arrange
|
||||
const double pricePerKwh = 0.2;
|
||||
var timestamps = PowerMonitorTestData.CreateSampleTimestamps(PowerMonitorTestData.FixedDayStart, 96);
|
||||
var wattSamples = PowerMonitorTestData.CreatePowerSampleSeries(96);
|
||||
var wattSamples = PowerMonitorTestData.CreatePowerSampleSeries();
|
||||
var expectedPerSlot = timestamps
|
||||
.Select((_, index) => ExpectedCost(wattSamples[index], pricePerKwh))
|
||||
.ToArray();
|
||||
|
||||
@@ -74,6 +74,23 @@ public class PowerMonitorOptionsTests
|
||||
second.PauseAndRestoreEntityIds.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Options_ShouldAcceptConfiguredOverrides()
|
||||
{
|
||||
// Arrange - appsettings.json overrides these values, so the setters must stay writable.
|
||||
var options = new PowerMonitorOptions
|
||||
{
|
||||
PollIntervalSeconds = 1,
|
||||
AnomalyThresholdWatts = 250.0,
|
||||
HighPowerThresholdWatts = 5_500.0
|
||||
};
|
||||
|
||||
// Assert
|
||||
options.PollIntervalSeconds.Should().Be(1);
|
||||
options.AnomalyThresholdWatts.Should().Be(250.0);
|
||||
options.HighPowerThresholdWatts.Should().Be(5_500.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SectionName_ShouldBePowerMonitor()
|
||||
{
|
||||
|
||||
@@ -336,7 +336,6 @@ public class PowerSensorDiscoveryServiceTests
|
||||
{
|
||||
// Arrange
|
||||
var entity = SetupEntity(entityId, deviceClass, unit, "Test");
|
||||
var sut = CreateSut();
|
||||
|
||||
// Act
|
||||
var result = PowerSensorDiscoveryService.IsPowerSensor(entity);
|
||||
@@ -351,7 +350,6 @@ public class PowerSensorDiscoveryServiceTests
|
||||
// Arrange
|
||||
SetupEntitiesWithoutState("sensor.ghost_power");
|
||||
var entity = new Entity(_haContextMock.Object, "sensor.ghost_power");
|
||||
var sut = CreateSut();
|
||||
|
||||
// Act
|
||||
var result = PowerSensorDiscoveryService.IsPowerSensor(entity);
|
||||
|
||||
Reference in New Issue
Block a user