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:
2026-11-29 21:49:21 +02:00
parent 41ac93733e
commit cf8c9434c8
15 changed files with 173 additions and 206 deletions
@@ -1,5 +1,4 @@
using FluentAssertions; using FluentAssertions;
using BoilerMonitorManager.Models;
namespace BoilerMonitor.Manager.Tests; namespace BoilerMonitor.Manager.Tests;
@@ -447,8 +447,8 @@ public class BoilerMonitorEntityServiceTests
_entityManagerMock.Verify(em => em.SetEntityAttributes(WaterReadyEntityId, It.IsAny<object>()), Times.Once); _entityManagerMock.Verify(em => em.SetEntityAttributes(WaterReadyEntityId, It.IsAny<object>()), Times.Once);
} }
public static TheoryData<string> UntouchedByTransientResetEntityIds => new() public static TheoryData<string> UntouchedByTransientResetEntityIds =>
{ [
TodayRuntimeEntityId, TodayRuntimeEntityId,
SessionCountEntityId, SessionCountEntityId,
BudgetPercentageEntityId, BudgetPercentageEntityId,
@@ -459,7 +459,7 @@ public class BoilerMonitorEntityServiceTests
AutoManagementEntityId, AutoManagementEntityId,
ConfigPowerEntityId, ConfigPowerEntityId,
ConfigSwitchEntityId ConfigSwitchEntityId
}; ];
[Theory] [Theory]
[MemberData(nameof(UntouchedByTransientResetEntityIds))] [MemberData(nameof(UntouchedByTransientResetEntityIds))]
@@ -56,8 +56,7 @@ internal static class BoilerMonitorTestData
bool waterReady = false, bool waterReady = false,
string? boilerSwitchState = "on", string? boilerSwitchState = "on",
double? boilerPowerWatts = 0.0, double? boilerPowerWatts = 0.0,
DateTimeOffset? cooldownSince = null, DateTimeOffset? cooldownSince = null) =>
bool isNowCheap = true) =>
new() new()
{ {
TodayRunTime = todayRunTime ?? TimeSpan.FromHours(1), TodayRunTime = todayRunTime ?? TimeSpan.FromHours(1),
+1 -32
View File
@@ -577,7 +577,7 @@ public sealed class BoilerMonitorInit
string s => bool.TryParse(s, out var parsed) && parsed, string s => bool.TryParse(s, out var parsed) && parsed,
JsonElement { ValueKind: JsonValueKind.True } => true, JsonElement { ValueKind: JsonValueKind.True } => true,
JsonElement { ValueKind: JsonValueKind.False } => false, JsonElement { ValueKind: JsonValueKind.False } => false,
JsonElement jsonElement when jsonElement.ValueKind == JsonValueKind.String => JsonElement { ValueKind: JsonValueKind.String } jsonElement =>
bool.TryParse(jsonElement.GetString(), out var jsonParsed) && jsonParsed, bool.TryParse(jsonElement.GetString(), out var jsonParsed) && jsonParsed,
_ => false _ => false
}; };
@@ -602,35 +602,4 @@ public sealed class BoilerMonitorInit
return elapsed < WaterReadyNotificationCooldown; return elapsed < WaterReadyNotificationCooldown;
} }
private static DateTime? ReadAttributeDateTime(EntityState? entityState, string attributeName)
{
if (entityState?.Attributes is null)
{
return null;
}
try
{
if (entityState.Attributes is IDictionary<string, object> attributes && attributes.TryGetValue(attributeName, out var value))
{
var stringValue = value switch
{
string s => s,
JsonElement { ValueKind: JsonValueKind.String } jsonElement => jsonElement.GetString(),
_ => null
};
if (stringValue is not null && DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var parsed))
{
return parsed;
}
}
}
catch
{
// Attribute not found or not parseable
}
return null;
}
} }
@@ -304,30 +304,27 @@ public class CheapestIntervalsFinderTests
#region IsCurrentIntervalCheap #region IsCurrentIntervalCheap
public static TheoryData<string, int, CheapestIntervalResult[], bool> CurrentIntervalCases => new() [Fact]
public void IsCurrentIntervalCheap_ShouldMatchIntervalBounds()
{ {
{ "inside interval", 10 * Hour + 7 * 60, [Interval(10 * Hour, 10 * Hour + Quarter)], true }, // Arrange - xUnit cannot serialize CheapestIntervalResult rows, so the matrix is exercised in one test
{ "exactly at start", 10 * Hour, [Interval(10 * Hour, 10 * Hour + Quarter)], true },
{ "exactly at end", 10 * Hour + Quarter, [Interval(10 * Hour, 10 * Hour + Quarter)], false },
{ "outside all intervals", 12 * Hour, [Interval(10 * Hour, 10 * Hour + Quarter), Interval(14 * Hour, 14 * Hour + Quarter)], false },
{ "boundary between adjacent intervals", 10 * Hour + Quarter, [Interval(10 * Hour, 10 * Hour + Quarter, price: 8.96, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, price: 6.20, rank: 2)], true },
{ "unsorted intervals", 14 * Hour + 5 * 60, [Interval(14 * Hour, 14 * Hour + Quarter, price: 4.93, rank: 2), Interval(10 * Hour, 10 * Hour + Quarter, price: 6.20, rank: 1)], true },
{ "before first interval", 10 * Hour - 1, [Interval(10 * Hour, 10 * Hour + Quarter)], false },
{ "in gap between intervals", 10 * Hour + 2 * Quarter, [Interval(10 * Hour, 10 * Hour + Quarter), Interval(11 * Hour, 11 * Hour + Quarter)], false },
{ "middle of three consecutive intervals", 10 * Hour + Quarter + 5 * 60, [Interval(10 * Hour, 10 * Hour + Quarter, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, rank: 2), Interval(10 * Hour + 2 * Quarter, 10 * Hour + 3 * Quarter, rank: 3)], true },
{ "empty interval list", 12 * Hour, [], false }
};
[Theory]
[MemberData(nameof(CurrentIntervalCases))]
public void IsCurrentIntervalCheap_ShouldMatchIntervalBounds(
string scenario,
int nowSeconds,
CheapestIntervalResult[] intervals,
bool expected)
{
// Arrange
var sut = CreateSut(); var sut = CreateSut();
(string Scenario, int NowSeconds, CheapestIntervalResult[] Intervals, bool Expected)[] cases =
[
("inside interval", 10 * Hour + 7 * 60, [Interval(10 * Hour, 10 * Hour + Quarter)], true),
("exactly at start", 10 * Hour, [Interval(10 * Hour, 10 * Hour + Quarter)], true),
("exactly at end", 10 * Hour + Quarter, [Interval(10 * Hour, 10 * Hour + Quarter)], false),
("outside all intervals", 12 * Hour, [Interval(10 * Hour, 10 * Hour + Quarter), Interval(14 * Hour, 14 * Hour + Quarter)], false),
("boundary between adjacent intervals", 10 * Hour + Quarter, [Interval(10 * Hour, 10 * Hour + Quarter, price: 8.96, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, price: 6.20, rank: 2)], true),
("unsorted intervals", 14 * Hour + 5 * 60, [Interval(14 * Hour, 14 * Hour + Quarter, price: 4.93, rank: 2), Interval(10 * Hour, 10 * Hour + Quarter, price: 6.20, rank: 1)], true),
("before first interval", 10 * Hour - 1, [Interval(10 * Hour, 10 * Hour + Quarter)], false),
("in gap between intervals", 10 * Hour + 2 * Quarter, [Interval(10 * Hour, 10 * Hour + Quarter), Interval(11 * Hour, 11 * Hour + Quarter)], false),
("middle of three consecutive intervals", 10 * Hour + Quarter + 5 * 60, [Interval(10 * Hour, 10 * Hour + Quarter, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, rank: 2), Interval(10 * Hour + 2 * Quarter, 10 * Hour + 3 * Quarter, rank: 3)], true),
("empty interval list", 12 * Hour, [], false)
];
foreach (var (scenario, nowSeconds, intervals, expected) in cases)
{
var now = DayStart.AddSeconds(nowSeconds); var now = DayStart.AddSeconds(nowSeconds);
// Act // Act
@@ -336,6 +333,7 @@ public class CheapestIntervalsFinderTests
// Assert // Assert
result.Should().Be(expected, $"scenario: {scenario}"); result.Should().Be(expected, $"scenario: {scenario}");
} }
}
[Fact] [Fact]
public void IsCurrentIntervalCheap_WithGeneratedDay_ShouldBeTrueOnlyForSelectedQuarters() public void IsCurrentIntervalCheap_WithGeneratedDay_ShouldBeTrueOnlyForSelectedQuarters()
@@ -432,13 +432,17 @@ public class NordPoolEntityServiceTests
Times.Once); Times.Once);
} }
public static TheoryData<string, NordPoolPrice?, NordPoolPrice?, int> MergedPriceScenarios()
[Fact]
public async Task UpdateEntitiesAsync_WithMergedPriceScenarios_ShouldPublishSortedFilteredPrices()
{ {
var data = new TheoryData<string, NordPoolPrice?, NordPoolPrice?, int>(); // Arrange - xUnit cannot serialize NordPoolPrice rows, so the matrix is exercised in one test
var todayStart = new DateTime(2026, 3, 31, 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 tomorrowStart = new DateTime(2026, 4, 1, 6, 0, 0, DateTimeKind.Utc);
data.Add( (string Scenario, NordPoolPrice? TodayPrice, NordPoolPrice? TomorrowPrice, int ExpectedMergedCount)[] cases =
[
(
"today and tomorrow with null-start entry filtered", "today and tomorrow with null-start entry filtered",
new NordPoolPrice new NordPoolPrice
{ {
@@ -453,35 +457,25 @@ public class NordPoolEntityServiceTests
Prices = [new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }] Prices = [new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }]
}, },
2 2
); ),
(
data.Add(
"only today", "only today",
new NordPoolPrice { Prices = [new NordPoolDayPrice { Start = todayStart, End = todayStart.AddMinutes(15), Price = 17.91 }] }, new NordPoolPrice { Prices = [new NordPoolDayPrice { Start = todayStart, End = todayStart.AddMinutes(15), Price = 17.91 }] },
new NordPoolPrice { Prices = [] }, new NordPoolPrice { Prices = [] },
1 1
); ),
(
data.Add(
"only tomorrow", "only tomorrow",
new NordPoolPrice { Prices = [] }, new NordPoolPrice { Prices = [] },
new NordPoolPrice { Prices = [new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }] }, new NordPoolPrice { Prices = [new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }] },
1 1
); ),
("empty lists", new NordPoolPrice { Prices = [] }, new NordPoolPrice { Prices = [] }, 0),
("null lists", new NordPoolPrice { Prices = null }, new NordPoolPrice { Prices = null }, 0),
("null price objects", null, null, 0)
];
data.Add("empty lists", new NordPoolPrice { Prices = [] }, new NordPoolPrice { Prices = [] }, 0); foreach (var (scenario, todayPrice, tomorrowPrice, expectedMergedCount) in cases)
data.Add("null lists", new NordPoolPrice { Prices = null }, new NordPoolPrice { Prices = null }, 0);
data.Add("null price objects", null, null, 0);
return data;
}
[Theory]
[MemberData(nameof(MergedPriceScenarios))]
public async Task UpdateEntitiesAsync_WithMergedPriceScenarios_ShouldPublishSortedFilteredPrices(
string scenario,
NordPoolPrice? todayPrice,
NordPoolPrice? tomorrowPrice,
int expectedMergedCount)
{ {
// Arrange // Arrange
object? capturedAttributes = null; object? capturedAttributes = null;
@@ -511,6 +505,7 @@ public class NordPoolEntityServiceTests
prices.Select(p => p.Start).Should().BeInAscendingOrder(); prices.Select(p => p.Start).Should().BeInAscendingOrder();
type.GetProperty("prices_count")!.GetValue(attributes).Should().Be(expectedMergedCount); type.GetProperty("prices_count")!.GetValue(attributes).Should().Be(expectedMergedCount);
} }
}
[Fact] [Fact]
public async Task UpdateEntitiesAsync_TodayTomorrowPrices_ShouldUseCompactFormat() public async Task UpdateEntitiesAsync_TodayTomorrowPrices_ShouldUseCompactFormat()
@@ -667,39 +667,34 @@ public class NordPoolPriceServiceTests
#region ShouldFetchNewPrices #region ShouldFetchNewPrices
/// <summary> private static NordPoolPrice CreatePrices(params double?[] values) => new()
/// Scenarios that do not depend on the time of day (tomorrow's prices are published after 13:00,
/// so the "tomorrow missing" cases are covered separately below).
/// </summary>
public static TheoryData<string, DateOnly?, NordPoolPrice?, NordPoolPrice?, bool> ShouldFetchScenarios()
{
var data = new TheoryData<string, DateOnly?, NordPoolPrice?, NordPoolPrice?, bool>();
var today = DateOnly.FromDateTime(DateTime.Now);
static NordPoolPrice Prices(params double?[] values) => new()
{ {
Prices = [.. values.Select(price => new NordPoolDayPrice { Price = price })] Prices = [.. values.Select(price => new NordPoolDayPrice { Price = price })]
}; };
data.Add("no fetch date yet", null, Prices(12.50), Prices(18.71), true); /// <summary>
data.Add("last fetch was yesterday", today.AddDays(-1), Prices(12.50), Prices(18.71), true); /// Scenarios that do not depend on the time of day (tomorrow's prices are published after 13:00,
data.Add("last fetch date is in the future", today.AddDays(1), Prices(12.50), Prices(18.71), false); /// so the "tomorrow missing" cases are covered separately below). xUnit cannot serialize
data.Add("today prices are null", today, new NordPoolPrice { Prices = null }, Prices(18.71), true); /// <see cref="NordPoolPrice"/> rows, so the matrix runs inside a single test.
data.Add("today prices are empty", today, new NordPoolPrice { Prices = [] }, Prices(18.71), true); /// </summary>
data.Add("today and tomorrow prices present", today, Prices(12.50), Prices(18.71), false); [Fact]
data.Add("price values are null but entries exist", today, Prices((double?)null), Prices((double?)null), false); public void ShouldFetchNewPrices_ShouldMatchScenario()
data.Add("all price payloads are null", today, null, null, true); {
return data; var today = DateOnly.FromDateTime(DateTime.Now);
}
[Theory] (string Scenario, DateOnly? LastFetchedDate, NordPoolPrice? TodayPrice, NordPoolPrice? TomorrowPrice, bool Expected)[] cases =
[MemberData(nameof(ShouldFetchScenarios))] [
public void ShouldFetchNewPrices_ShouldMatchScenario( ("no fetch date yet", null, CreatePrices(12.50), CreatePrices(18.71), true),
string scenario, ("last fetch was yesterday", today.AddDays(-1), CreatePrices(12.50), CreatePrices(18.71), true),
DateOnly? lastFetchedDate, ("last fetch date is in the future", today.AddDays(1), CreatePrices(12.50), CreatePrices(18.71), false),
NordPoolPrice? todayPrice, ("today prices are null", today, new NordPoolPrice { Prices = null }, CreatePrices(18.71), true),
NordPoolPrice? tomorrowPrice, ("today prices are empty", today, new NordPoolPrice { Prices = [] }, CreatePrices(18.71), true),
bool expected) ("today and tomorrow prices present", today, CreatePrices(12.50), CreatePrices(18.71), false),
("price values are null but entries exist", today, CreatePrices((double?)null), CreatePrices((double?)null), false),
("all price payloads are null", today, null, null, true)
];
foreach (var (scenario, lastFetchedDate, todayPrice, tomorrowPrice, expected) in cases)
{ {
// Arrange // Arrange
_sut.LastFetchedDate = lastFetchedDate; _sut.LastFetchedDate = lastFetchedDate;
@@ -712,6 +707,7 @@ public class NordPoolPriceServiceTests
// Assert // Assert
result.Should().Be(expected, $"scenario: {scenario}"); result.Should().Be(expected, $"scenario: {scenario}");
} }
}
[Fact] [Fact]
public void ShouldFetchNewPrices_WhenTomorrowPricesAreNull_ShouldDependOnHourOfDay() public void ShouldFetchNewPrices_WhenTomorrowPricesAreNull_ShouldDependOnHourOfDay()
@@ -782,22 +778,18 @@ public class NordPoolPriceServiceTests
_sut.LastFetchedDate.Should().Be(today); _sut.LastFetchedDate.Should().Be(today);
} }
public static TheoryData<NordPoolPrice?> UnusableTomorrowPrices => new() /// <summary>
/// Rows are not serializable as theory data, so the three unusable payloads are exercised in one test.
/// </summary>
[Fact]
public void RollOverPrices_WithoutUsableTomorrowPrices_ShouldResetTodayToEmptyPrice()
{ {
{ null }, NordPoolPrice?[] unusablePrices = [null, new() { Prices = null }, new() { Prices = [] }];
{ new NordPoolPrice { Prices = null } },
{ new NordPoolPrice { Prices = [] } }
};
[Theory] foreach (var tomorrow in unusablePrices)
[MemberData(nameof(UnusableTomorrowPrices))]
public void RollOverPrices_WithoutUsableTomorrowPrices_ShouldResetTodayToEmptyPrice(NordPoolPrice? tomorrow)
{ {
// Arrange // Arrange
_sut.TodayNordPoolPrice = new NordPoolPrice _sut.TodayNordPoolPrice = new NordPoolPrice { Prices = [new() { Price = 12.50 }] };
{
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
};
_sut.TomorrowNordPoolPrice = tomorrow; _sut.TomorrowNordPoolPrice = tomorrow;
_sut.DayQuartersIndex = 42; _sut.DayQuartersIndex = 42;
var today = new DateOnly(2026, 4, 1); var today = new DateOnly(2026, 4, 1);
@@ -812,6 +804,7 @@ public class NordPoolPriceServiceTests
_sut.DayQuartersIndex.Should().Be(-1); _sut.DayQuartersIndex.Should().Be(-1);
_sut.LastFetchedDate.Should().Be(today); _sut.LastFetchedDate.Should().Be(today);
} }
}
[Fact] [Fact]
public void RollOverPrices_WhenBothPricesAreNull_ShouldNotThrow() public void RollOverPrices_WhenBothPricesAreNull_ShouldNotThrow()
+1 -1
View File
@@ -9,5 +9,5 @@ public class NordPoolDayPriceDto
[JsonPropertyName("end")] [JsonPropertyName("end")]
public string? End { get; init; } public string? End { get; init; }
[JsonPropertyName("price")] [JsonPropertyName("price")]
public double? Price { get; set; } public double? Price { get; init; }
} }
@@ -21,11 +21,11 @@ public class OtherPowerCalculationServiceTests
public static TheoryData<string, double, double[], double, string> CalculationCases => new() public static TheoryData<string, double, double[], double, string> CalculationCases => new()
{ {
{ "two devices", 341.97, [8.55, 36.93], 296.49, "ok" }, { "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 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" }, { "devices equal total", 100.0, [60.0, 40.0], 0.0, "ok" },
{ "zero power, no devices", 0.0, Array.Empty<double>(), 0.0, "ok" }, { "zero power, no devices", 0.0, [], 0.0, "ok" },
{ "negative total, no devices", -120.0, Array.Empty<double>(), 0.0, "device_sum_exceeds_total" }, { "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" }, { "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 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" } { "very small values", 0.5, [0.25], 0.25, "ok" }
@@ -43,7 +43,7 @@ public class OtherPowerCalculationServiceTests
// Arrange // Arrange
var sut = CreateSut(smoothingWindowSize: 1); var sut = CreateSut(smoothingWindowSize: 1);
var devices = deviceWatts 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); .ToDictionary(entry => entry.entityId, entry => entry.watts);
// Act // Act
@@ -312,7 +312,7 @@ public class PowerCostCalculationServiceTests
// Arrange // Arrange
const double pricePerKwh = 0.2; const double pricePerKwh = 0.2;
var timestamps = PowerMonitorTestData.CreateSampleTimestamps(PowerMonitorTestData.FixedDayStart, 96); var timestamps = PowerMonitorTestData.CreateSampleTimestamps(PowerMonitorTestData.FixedDayStart, 96);
var wattSamples = PowerMonitorTestData.CreatePowerSampleSeries(96); var wattSamples = PowerMonitorTestData.CreatePowerSampleSeries();
var expectedPerSlot = timestamps var expectedPerSlot = timestamps
.Select((_, index) => ExpectedCost(wattSamples[index], pricePerKwh)) .Select((_, index) => ExpectedCost(wattSamples[index], pricePerKwh))
.ToArray(); .ToArray();
@@ -74,6 +74,23 @@ public class PowerMonitorOptionsTests
second.PauseAndRestoreEntityIds.Should().BeEmpty(); 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] [Fact]
public void SectionName_ShouldBePowerMonitor() public void SectionName_ShouldBePowerMonitor()
{ {
@@ -336,7 +336,6 @@ public class PowerSensorDiscoveryServiceTests
{ {
// Arrange // Arrange
var entity = SetupEntity(entityId, deviceClass, unit, "Test"); var entity = SetupEntity(entityId, deviceClass, unit, "Test");
var sut = CreateSut();
// Act // Act
var result = PowerSensorDiscoveryService.IsPowerSensor(entity); var result = PowerSensorDiscoveryService.IsPowerSensor(entity);
@@ -351,7 +350,6 @@ public class PowerSensorDiscoveryServiceTests
// Arrange // Arrange
SetupEntitiesWithoutState("sensor.ghost_power"); SetupEntitiesWithoutState("sensor.ghost_power");
var entity = new Entity(_haContextMock.Object, "sensor.ghost_power"); var entity = new Entity(_haContextMock.Object, "sensor.ghost_power");
var sut = CreateSut();
// Act // Act
var result = PowerSensorDiscoveryService.IsPowerSensor(entity); var result = PowerSensorDiscoveryService.IsPowerSensor(entity);
@@ -15,7 +15,7 @@ public class HumidityRateCalculatorTests
public static TheoryData<string, int, double[], int[], double> RateCases => new() public static TheoryData<string, int, double[], int[], double> RateCases => new()
{ {
{ "no readings", 5, Array.Empty<double>(), Array.Empty<int>(), 0.0 }, { "no readings", 5, [], [], 0.0 },
{ "single reading", 5, [52.9], [0], 0.0 }, { "single reading", 5, [52.9], [0], 0.0 },
{ "rising humidity", 5, [52.9, 62.9], [0, 60], 10.0 }, { "rising humidity", 5, [52.9, 62.9], [0, 60], 10.0 },
{ "falling humidity", 5, [62.9, 52.9], [0, 120], -5.0 }, { "falling humidity", 5, [62.9, 52.9], [0, 120], -5.0 },
@@ -40,8 +40,8 @@ public sealed class ExhaustFanControlService(
break; break;
default: default:
// Unknown state: leave the fan untouched. // Every ShowerState member is handled above; fail loudly if one is added.
break; throw new ArgumentOutOfRangeException(nameof(state), state, "Unhandled shower state.");
} }
} }
} }
@@ -5,7 +5,6 @@ namespace ShowerMonitorManager.Interface;
public interface IShowerDetectionService public interface IShowerDetectionService
{ {
ShowerSession? CurrentSession { get; }
ShowerSession? LastCompletedSession { get; } ShowerSession? LastCompletedSession { get; }
int TodaySessionCount { get; } int TodaySessionCount { get; }
double LastRate { get; } double LastRate { get; }