Apply code formatting cleanup across the monitor projects

- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests
- Expand single-statement guards and loops into braced blocks
- Realign wrapped method arguments, chained calls and continuations
- Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty`
- Flatten the boiler config expression and reindent the remaining touched files
This commit is contained in:
2026-12-01 12:33:31 +02:00
parent 77458383d1
commit f919d6b25b
115 changed files with 3115 additions and 1959 deletions
+32 -15
View File
@@ -1,9 +1,13 @@
#region
using Microsoft.Extensions.Options;
using ShowerMonitor.Models;
using ShowerMonitor.Models.Enums;
using ShowerMonitorManager.Interface;
using ShowerMonitorManager.Models;
#endregion
namespace ShowerMonitorManager;
public sealed class ShowerDetectionService(
@@ -11,7 +15,7 @@ public sealed class ShowerDetectionService(
IOptions<ShowerMonitorOptions> options)
: IShowerDetectionService
{
private readonly Lock _lock = new();
private readonly Lock _lock = new Lock();
private readonly ShowerMonitorOptions _options = options.Value;
private ShowerSession? _currentSession;
@@ -85,6 +89,7 @@ public sealed class ShowerDetectionService(
lock (_lock)
{
_lastRate = rate;
_currentState = _currentState switch
{
ShowerState.Idle => EvaluateIdle(rate, differential, bathroomHumidity, timestamp),
@@ -110,12 +115,15 @@ public sealed class ShowerDetectionService(
private ShowerState EvaluateIdle(double rate, double differential, double humidity, DateTimeOffset timestamp)
{
var showerSuspected = rate >= _options.SpikeRateThreshold
&& differential >= _options.MinDifferentialHumidity;
var showerSuspected = rate >= _options.SpikeRateThreshold && differential >= _options.MinDifferentialHumidity;
if (!showerSuspected) return ShowerState.Idle;
if (!showerSuspected)
{
return ShowerState.Idle;
}
_suspectedSince = timestamp;
_currentSession = new ShowerSession
{
StartTime = timestamp,
@@ -137,15 +145,17 @@ public sealed class ShowerDetectionService(
var confirmationWindow = TimeSpan.FromMinutes(_options.ConfirmationWindowMinutes);
if (_suspectedSince.HasValue && timestamp - _suspectedSince.Value >= confirmationWindow
&& humidity >= _options.PeakHumidityThreshold
&& differential >= _options.MinDifferentialHumidity)
if (_suspectedSince.HasValue && timestamp - _suspectedSince.Value >= confirmationWindow && humidity >= _options.PeakHumidityThreshold && differential >= _options.MinDifferentialHumidity)
{
return ShowerState.Active;
}
var showerAbandoned = rate < 0 && differential < _options.MinDifferentialHumidity;
if (!showerAbandoned) return ShowerState.Suspected;
if (!showerAbandoned)
{
return ShowerState.Suspected;
}
CompleteSessionCleanup();
@@ -161,11 +171,13 @@ public sealed class ShowerDetectionService(
}
var maxDuration = TimeSpan.FromMinutes(_options.MaxShowerDurationMinutes);
var maxDurationReached = _currentSession is not null
&& _currentSession.GetDuration(timestamp) >= maxDuration;
var maxDurationReached = _currentSession is not null && _currentSession.GetDuration(timestamp) >= maxDuration;
var humidityRecovered = rate < 0 && differential < _options.MinDifferentialHumidity;
if (maxDurationReached || humidityRecovered) return TransitionToDeclining();
if (maxDurationReached || humidityRecovered)
{
return TransitionToDeclining();
}
return ShowerState.Active;
}
@@ -180,10 +192,12 @@ public sealed class ShowerDetectionService(
}
var maxDuration = TimeSpan.FromMinutes(_options.MaxShowerDurationMinutes);
var maxDurationReached = _currentSession is not null
&& _currentSession.GetDuration(timestamp) >= maxDuration;
var maxDurationReached = _currentSession is not null && _currentSession.GetDuration(timestamp) >= maxDuration;
if (!maxDurationReached) return ShowerState.Declining;
if (!maxDurationReached)
{
return ShowerState.Declining;
}
CompleteSession(timestamp);
@@ -204,7 +218,10 @@ public sealed class ShowerDetectionService(
private void CompleteSession(DateTimeOffset endTime)
{
if (_currentSession is null) return;
if (_currentSession is null)
{
return;
}
_currentSession.EndTime = endTime;
_lastCompletedSession = _currentSession;