Update
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetDaemon.HassModel;
|
||||
using NetDaemon.HassModel.Entities;
|
||||
@@ -8,23 +7,14 @@ using ShowerMonitorManager.Models;
|
||||
|
||||
namespace ShowerMonitorManager;
|
||||
|
||||
public sealed class ExhaustFanControlService : IExhaustFanControlService
|
||||
public sealed class ExhaustFanControlService(IOptions<ShowerMonitorOptions> options) : IExhaustFanControlService
|
||||
{
|
||||
private readonly ILogger<ExhaustFanControlService> _logger;
|
||||
private readonly ShowerMonitorOptions _options;
|
||||
private readonly ShowerMonitorOptions _options = options.Value;
|
||||
private readonly Lock _lock = new();
|
||||
|
||||
private bool _fanTurnedOnByUs;
|
||||
private DateTimeOffset? _showerEndedAt;
|
||||
|
||||
public ExhaustFanControlService(
|
||||
ILogger<ExhaustFanControlService> logger,
|
||||
IOptions<ShowerMonitorOptions> options)
|
||||
{
|
||||
_logger = logger;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public void Evaluate(ShowerState state, DateTimeOffset timestamp, IHaContext haContext)
|
||||
{
|
||||
lock (_lock)
|
||||
@@ -57,7 +47,6 @@ public sealed class ExhaustFanControlService : IExhaustFanControlService
|
||||
if (_fanTurnedOnByUs)
|
||||
{
|
||||
haContext.CallService("switch", "turn_off", ServiceTarget.FromEntity(_options.ExhaustFanEntityId));
|
||||
_logger.LogInformation("Exhaust fan turned OFF during reset (was turned on by shower detection)");
|
||||
}
|
||||
|
||||
_fanTurnedOnByUs = false;
|
||||
@@ -80,7 +69,6 @@ public sealed class ExhaustFanControlService : IExhaustFanControlService
|
||||
|
||||
haContext.CallService("switch", "turn_on", ServiceTarget.FromEntity(_options.ExhaustFanEntityId));
|
||||
_fanTurnedOnByUs = true;
|
||||
_logger.LogInformation("Exhaust fan turned ON by shower detection");
|
||||
}
|
||||
|
||||
private void EvaluatePostShowerFanOff(DateTimeOffset timestamp, IHaContext haContext)
|
||||
@@ -101,6 +89,5 @@ public sealed class ExhaustFanControlService : IExhaustFanControlService
|
||||
haContext.CallService("switch", "turn_off", ServiceTarget.FromEntity(_options.ExhaustFanEntityId));
|
||||
_fanTurnedOnByUs = false;
|
||||
_showerEndedAt = null;
|
||||
_logger.LogInformation("Exhaust fan turned OFF after post-shower run period ({Duration})", runAfterDuration);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user