#region using Microsoft.Extensions.Time.Testing; using NetDaemon.HassModel.Entities; using ShowerMonitor.Models; using ShowerMonitorManager.Models; #endregion namespace ShowerMonitor.Manager.Tests; /// /// Shared, deterministic fixtures for the shower monitor tests. /// Keeping options, fan states and sample series here avoids copy-pasted setup /// across test classes and keeps every timestamp independent of the wall clock. /// internal static class ShowerMonitorTestData { /// Fixed base time used by all timestamp-sensitive tests. private static readonly DateTimeOffset BaseTimestamp = new DateTimeOffset(2026, 1, 15, 12, 0, 0, TimeSpan.Zero); /// Creates a fake clock positioned at unless overridden. public static FakeTimeProvider CreateTimeProvider(DateTimeOffset? start = null) { return new FakeTimeProvider(start ?? BaseTimestamp); } /// /// Builds monitor options from the production defaults, overriding only the /// values a test cares about. /// public static ShowerMonitorOptions CreateOptions( string exhaustFanEntityId = ShowerMonitorConsts.ExhaustFanEntityId, int? fanRunAfterShowerMinutes = null, double spikeRateThreshold = ShowerMonitorConsts.DefaultSpikeRateThreshold, double minDifferentialHumidity = ShowerMonitorConsts.DefaultMinDifferentialHumidity, double peakHumidityThreshold = ShowerMonitorConsts.DefaultPeakHumidityThreshold, int confirmationWindowMinutes = ShowerMonitorConsts.DefaultConfirmationWindowMinutes, double recoveryDifferentialThreshold = ShowerMonitorConsts.DefaultRecoveryDifferentialThreshold, int? maxShowerDurationMinutes = null, int rateWindowSize = ShowerMonitorConsts.DefaultRateWindowSize) { return new ShowerMonitorOptions { ExhaustFanEntityId = exhaustFanEntityId, FanRunAfterShowerMinutes = fanRunAfterShowerMinutes ?? (int)ShowerMonitorConsts.DefaultFanRunAfterShower.TotalMinutes, SpikeRateThreshold = spikeRateThreshold, MinDifferentialHumidity = minDifferentialHumidity, PeakHumidityThreshold = peakHumidityThreshold, ConfirmationWindowMinutes = confirmationWindowMinutes, RecoveryDifferentialThreshold = recoveryDifferentialThreshold, MaxShowerDurationMinutes = maxShowerDurationMinutes ?? (int)ShowerMonitorConsts.DefaultMaxShowerDuration.TotalMinutes, RateWindowSize = rateWindowSize }; } /// Creates the HA state payload for the exhaust fan. public static EntityState FanState(string? state) { return new EntityState { State = state }; } /// Builds a sample series from (humidity, offset-in-seconds) pairs. public static IReadOnlyList CreateHumiditySeries( params (double Humidity, int OffsetSeconds)[] samples) { return [ .. samples.Select(sample => new HumiditySample(sample.Humidity, TimeSpan.FromSeconds(sample.OffsetSeconds))) ]; } /// /// Generates evenly spaced samples along a constant humidity slope, useful for /// exercising every window size against a known rate. /// public static IReadOnlyList CreateLinearHumiditySeries( double startHumidity, double ratePerMinute, int sampleCount, int intervalSeconds = 60) { return [ .. Enumerable.Range(0, sampleCount) .Select(i => new HumiditySample( startHumidity + ratePerMinute * i * intervalSeconds / 60.0, TimeSpan.FromSeconds(i * intervalSeconds))) ]; } /// A humidity sample with its offset from a test's base timestamp. public readonly record struct HumiditySample(double Humidity, TimeSpan Offset); }