Apply code formatting cleanup across monitor projects
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
This commit is contained in:
@@ -11,39 +11,69 @@ public sealed class ShowerDetectionService(
|
||||
IOptions<ShowerMonitorOptions> options)
|
||||
: IShowerDetectionService
|
||||
{
|
||||
private readonly ShowerMonitorOptions _options = options.Value;
|
||||
private readonly Lock _lock = new();
|
||||
private readonly ShowerMonitorOptions _options = options.Value;
|
||||
private ShowerSession? _currentSession;
|
||||
|
||||
private ShowerState _currentState = ShowerState.Idle;
|
||||
private ShowerSession? _currentSession;
|
||||
private ShowerSession? _lastCompletedSession;
|
||||
private int _todaySessionCount;
|
||||
private DateTimeOffset? _suspectedSince;
|
||||
private double _lastRate;
|
||||
private DateTimeOffset? _suspectedSince;
|
||||
private int _todaySessionCount;
|
||||
|
||||
public ShowerState CurrentState
|
||||
{
|
||||
get { lock (_lock) { return _currentState; } }
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _currentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ShowerSession? CurrentSession
|
||||
{
|
||||
get { lock (_lock) { return _currentSession; } }
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _currentSession;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ShowerSession? LastCompletedSession
|
||||
{
|
||||
get { lock (_lock) { return _lastCompletedSession; } }
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _lastCompletedSession;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int TodaySessionCount
|
||||
{
|
||||
get { lock (_lock) { return _todaySessionCount; } }
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _todaySessionCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double LastRate
|
||||
{
|
||||
get { lock (_lock) { return _lastRate; } }
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _lastRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ShowerState Evaluate(double bathroomHumidity, double mainHomeHumidity, DateTimeOffset timestamp)
|
||||
@@ -83,10 +113,7 @@ public sealed class ShowerDetectionService(
|
||||
var showerSuspected = rate >= _options.SpikeRateThreshold
|
||||
&& differential >= _options.MinDifferentialHumidity;
|
||||
|
||||
if (!showerSuspected)
|
||||
{
|
||||
return ShowerState.Idle;
|
||||
}
|
||||
if (!showerSuspected) return ShowerState.Idle;
|
||||
|
||||
_suspectedSince = timestamp;
|
||||
_currentSession = new ShowerSession
|
||||
@@ -111,17 +138,12 @@ public sealed class ShowerDetectionService(
|
||||
var confirmationWindow = TimeSpan.FromMinutes(_options.ConfirmationWindowMinutes);
|
||||
|
||||
if (_suspectedSince.HasValue && timestamp - _suspectedSince.Value >= confirmationWindow
|
||||
&& humidity >= _options.PeakHumidityThreshold
|
||||
&& differential >= _options.MinDifferentialHumidity)
|
||||
{
|
||||
&& 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();
|
||||
|
||||
@@ -141,10 +163,7 @@ public sealed class ShowerDetectionService(
|
||||
&& _currentSession.GetDuration(timestamp) >= maxDuration;
|
||||
var humidityRecovered = rate < 0 && differential < _options.MinDifferentialHumidity;
|
||||
|
||||
if (maxDurationReached || humidityRecovered)
|
||||
{
|
||||
return TransitionToDeclining();
|
||||
}
|
||||
if (maxDurationReached || humidityRecovered) return TransitionToDeclining();
|
||||
|
||||
return ShowerState.Active;
|
||||
}
|
||||
@@ -162,10 +181,7 @@ public sealed class ShowerDetectionService(
|
||||
var maxDurationReached = _currentSession is not null
|
||||
&& _currentSession.GetDuration(timestamp) >= maxDuration;
|
||||
|
||||
if (!maxDurationReached)
|
||||
{
|
||||
return ShowerState.Declining;
|
||||
}
|
||||
if (!maxDurationReached) return ShowerState.Declining;
|
||||
|
||||
CompleteSession(timestamp);
|
||||
|
||||
@@ -180,16 +196,13 @@ public sealed class ShowerDetectionService(
|
||||
private ShowerState TransitionToIdle()
|
||||
{
|
||||
rateCalculator.Reset();
|
||||
|
||||
|
||||
return ShowerState.Idle;
|
||||
}
|
||||
|
||||
private void CompleteSession(DateTimeOffset endTime)
|
||||
{
|
||||
if (_currentSession is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_currentSession is null) return;
|
||||
|
||||
_currentSession.EndTime = endTime;
|
||||
_lastCompletedSession = _currentSession;
|
||||
@@ -204,4 +217,4 @@ public sealed class ShowerDetectionService(
|
||||
_currentSession = null;
|
||||
_suspectedSince = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user