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:
@@ -1,3 +1,5 @@
|
||||
#region
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetDaemon.HassModel;
|
||||
using NetDaemon.HassModel.Entities;
|
||||
@@ -5,13 +7,15 @@ using ShowerMonitor.Models.Enums;
|
||||
using ShowerMonitorManager.Interface;
|
||||
using ShowerMonitorManager.Models;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ShowerMonitorManager;
|
||||
|
||||
public sealed class ExhaustFanControlService(
|
||||
IHaContext haContext,
|
||||
IOptions<ShowerMonitorOptions> options) : IExhaustFanControlService
|
||||
{
|
||||
private readonly Lock _lock = new();
|
||||
private readonly Lock _lock = new Lock();
|
||||
private readonly ShowerMonitorOptions _options = options.Value;
|
||||
|
||||
private bool _fanTurnedOnByUs;
|
||||
@@ -27,16 +31,19 @@ public sealed class ExhaustFanControlService(
|
||||
case ShowerState.Suspected:
|
||||
TurnOnFanIfNeeded();
|
||||
_showerEndedAt = null;
|
||||
|
||||
break;
|
||||
|
||||
case ShowerState.Declining:
|
||||
case ShowerState.Completed:
|
||||
_showerEndedAt ??= timestamp;
|
||||
EvaluatePostShowerFanOff(timestamp);
|
||||
|
||||
break;
|
||||
|
||||
case ShowerState.Idle:
|
||||
EvaluatePostShowerFanOff(timestamp);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -67,10 +74,17 @@ public sealed class ExhaustFanControlService(
|
||||
|
||||
private void TurnOnFanIfNeeded()
|
||||
{
|
||||
if (_fanTurnedOnByUs) return;
|
||||
if (_fanTurnedOnByUs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fanState = haContext.GetState(_options.ExhaustFanEntityId)?.State;
|
||||
if (string.Equals(fanState, "on", StringComparison.OrdinalIgnoreCase)) return;
|
||||
|
||||
if (string.Equals(fanState, "on", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
haContext.CallService("switch", "turn_on", ServiceTarget.FromEntity(_options.ExhaustFanEntityId));
|
||||
_fanTurnedOnByUs = true;
|
||||
@@ -78,12 +92,18 @@ public sealed class ExhaustFanControlService(
|
||||
|
||||
private void EvaluatePostShowerFanOff(DateTimeOffset timestamp)
|
||||
{
|
||||
if (!_fanTurnedOnByUs || !_showerEndedAt.HasValue) return;
|
||||
if (!_fanTurnedOnByUs || !_showerEndedAt.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var elapsed = timestamp - _showerEndedAt.Value;
|
||||
var runAfterDuration = TimeSpan.FromMinutes(_options.FanRunAfterShowerMinutes);
|
||||
|
||||
if (elapsed < runAfterDuration) return;
|
||||
if (elapsed < runAfterDuration)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
haContext.CallService("switch", "turn_off", ServiceTarget.FromEntity(_options.ExhaustFanEntityId));
|
||||
_fanTurnedOnByUs = false;
|
||||
|
||||
Reference in New Issue
Block a user