37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using NordPoolManager.Interface;
|
|
using NordPoolManager.Models;
|
|
|
|
namespace NordPoolManager;
|
|
|
|
public class BoilerControlService(ILogger<BoilerControlService> logger) : IBoilerControlService
|
|
{
|
|
private const string SwitchOnState = "on";
|
|
|
|
public BoilerAction DetermineAction(bool isNowCheap, bool waterReady, string? currentSwitchState)
|
|
{
|
|
var isCurrentlyOn = string.Equals(currentSwitchState, SwitchOnState, StringComparison.OrdinalIgnoreCase);
|
|
var shouldBeOn = isNowCheap && !waterReady;
|
|
|
|
if (shouldBeOn && !isCurrentlyOn)
|
|
{
|
|
logger.LogInformation("Boiler should turn ON — cheap interval active, water not ready (current state: {State})", currentSwitchState);
|
|
|
|
return BoilerAction.TurnOn;
|
|
}
|
|
|
|
if (!shouldBeOn && isCurrentlyOn)
|
|
{
|
|
var reason = waterReady ? "water is already ready" : "not in a cheap interval";
|
|
|
|
logger.LogInformation("Boiler should turn OFF — {Reason} (current state: {State})", reason, currentSwitchState);
|
|
|
|
return BoilerAction.TurnOff;
|
|
}
|
|
|
|
logger.LogDebug("Boiler state unchanged: {State} (cheap={Cheap}, waterReady={WaterReady})", currentSwitchState, isNowCheap, waterReady);
|
|
|
|
return BoilerAction.NoChange;
|
|
}
|
|
}
|