Refactor services to use DI for IHaContext and TimeProvider

This commit is contained in:
2026-07-03 12:15:44 +03:00
parent 7f280bea7b
commit 2706a6b188
23 changed files with 146 additions and 374 deletions
@@ -20,7 +20,6 @@ public sealed class ShowerReplayRunner : IMonitorReplayRunner
private readonly ReplayDataSeries _dataSeries;
private readonly IShowerDetectionService _detectionService;
private readonly IExhaustFanControlService _fanControlService;
private readonly IHaContext _haContext;
private readonly ILogger<ShowerReplayRunner> _logger;
private readonly ReplayOptions _replayOptions;
private readonly ShowerMonitorOptions _showerOptions;
@@ -34,7 +33,6 @@ public sealed class ShowerReplayRunner : IMonitorReplayRunner
ReplayDataSeries dataSeries,
IShowerDetectionService detectionService,
IExhaustFanControlService fanControlService,
IHaContext haContext,
ILogger<ShowerReplayRunner> logger,
IOptions<ReplayOptions> replayOptions,
IOptions<ShowerMonitorOptions> showerOptions)
@@ -45,7 +43,6 @@ public sealed class ShowerReplayRunner : IMonitorReplayRunner
_dataSeries = dataSeries;
_detectionService = detectionService;
_fanControlService = fanControlService;
_haContext = haContext;
_logger = logger;
_replayOptions = replayOptions.Value;
_showerOptions = showerOptions.Value;
@@ -80,7 +77,7 @@ public sealed class ShowerReplayRunner : IMonitorReplayRunner
_dataSeries.AddPoint(MonitorName, "State", currentTime, (double)state);
_fanControlService.Evaluate(state, currentTime, _haContext);
_fanControlService.Evaluate(state, currentTime);
if (state != previousState)
{
@@ -177,11 +177,11 @@ public sealed class ReplayOrchestrationService
var detection = new ShowerMonitorManager.ShowerDetectionService(
rateCalc,
showerOpts);
var fan = new ExhaustFanControlService(showerOpts);
var fan = new ExhaustFanControlService(replayHaContext, showerOpts);
runners.Add(new ShowerReplayRunner(
historyTimeline, timeProvider, Timeline, DataSeries,
detection, fan, replayHaContext,
detection, fan,
_serviceProvider.GetRequiredService<ILogger<ShowerReplayRunner>>(),
replayOptions, showerOpts));
}