diff --git a/src/Client/NetDaemon.HassClient.Tests/HelperTest/ProgressiveTimoutTests.cs b/src/Client/NetDaemon.HassClient.Tests/HelperTest/ProgressiveTimoutTests.cs index d4a7c3896..bd1d5dd4a 100644 --- a/src/Client/NetDaemon.HassClient.Tests/HelperTest/ProgressiveTimoutTests.cs +++ b/src/Client/NetDaemon.HassClient.Tests/HelperTest/ProgressiveTimoutTests.cs @@ -22,6 +22,8 @@ public void TestProgressiveTimeoutInputChecksThrows() Assert.Throws(() => new ProgressiveTimeout(TimeSpan.Zero, TimeSpan.FromSeconds(100), 2.0)); // Check that max timeout is greater than start timeout Assert.Throws(() => new ProgressiveTimeout(TimeSpan.FromSeconds(100), TimeSpan.FromSeconds(99), 2.0)); + // Check that max timeout is not same as start timeout + Assert.Throws(() => new ProgressiveTimeout(TimeSpan.FromSeconds(100), TimeSpan.FromSeconds(100), 2.0)); // Check that increase factor is greater than 1 Assert.Throws(() => new ProgressiveTimeout(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(100), 1.0)); } diff --git a/src/Client/NetDaemon.HassClient/Internal/Helpers/ProgressiveTimeout.cs b/src/Client/NetDaemon.HassClient/Internal/Helpers/ProgressiveTimeout.cs index 8207dc143..02c8ca9f7 100644 --- a/src/Client/NetDaemon.HassClient/Internal/Helpers/ProgressiveTimeout.cs +++ b/src/Client/NetDaemon.HassClient/Internal/Helpers/ProgressiveTimeout.cs @@ -12,14 +12,9 @@ public class ProgressiveTimeout public ProgressiveTimeout(TimeSpan initialTimeout, TimeSpan maxTimeout, double increaseFactor) { - if (initialTimeout <= TimeSpan.Zero) - throw new ArgumentOutOfRangeException(nameof(initialTimeout), "Initial timeout must be greater than zero."); - - if (maxTimeout < initialTimeout) - throw new ArgumentOutOfRangeException(nameof(maxTimeout), "Max timeout must be greater than or equal to initial timeout."); - - if (increaseFactor <= 1) - throw new ArgumentOutOfRangeException(nameof(increaseFactor), "Increase factor must be greater than 1."); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(initialTimeout, TimeSpan.Zero, nameof(initialTimeout)); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(maxTimeout, initialTimeout, nameof(maxTimeout)); + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(increaseFactor, 1, nameof(increaseFactor)); _initialTimeout = initialTimeout; _maxTimeout = maxTimeout;