Refactor boiler control and price logic: Introduce PriceConsts, improve BoilerAction handling with switch, and update namespaces for better structure.
This commit is contained in:
@@ -7,7 +7,8 @@ using NetDaemon.Extensions.Scheduler;
|
||||
using NordPool.Models;
|
||||
using NordPoolManager.Interface;
|
||||
using NordPoolManager.Models;
|
||||
using static NordPoolManager.Models.BoilerAction;
|
||||
using NordPoolManager.Models.Consts;
|
||||
using static NordPoolManager.Models.Enums.BoilerAction;
|
||||
|
||||
namespace NordPoolManager;
|
||||
|
||||
@@ -239,7 +240,7 @@ public class NordPoolInit : INordPoolInit
|
||||
{
|
||||
var boilerConfig = ReadBoilerConfig();
|
||||
var effectivePriceCap = boilerConfig.SkipPriceCap ? double.MaxValue : boilerConfig.PriceCap;
|
||||
var effectiveIntervalCount = boilerConfig.SkipPriceCap ? 96 : boilerConfig.IntervalCount;
|
||||
var effectiveIntervalCount = boilerConfig.SkipPriceCap ? PriceConsts.MaxDailyIntervals : boilerConfig.IntervalCount;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -279,11 +280,12 @@ public class NordPoolInit : INordPoolInit
|
||||
var boilerConfig = new BoilerConfig();
|
||||
|
||||
var dailyHours = BoilerDailyHoursEntity.State ?? 1.0;
|
||||
var intervalCount = (int)(dailyHours * 4);
|
||||
|
||||
var intervalCount = (int)(dailyHours * PriceConsts.IntervalsPerHour);
|
||||
|
||||
if (intervalCount <= 0)
|
||||
{
|
||||
intervalCount = 4;
|
||||
intervalCount = PriceConsts.IntervalsPerHour;
|
||||
}
|
||||
|
||||
boilerConfig.IntervalCount = intervalCount;
|
||||
@@ -348,13 +350,20 @@ public class NordPoolInit : INordPoolInit
|
||||
|
||||
var boilerAction = _boilerControlService.DetermineAction(isNowCheap, waterReady, boilerSwitchState);
|
||||
|
||||
if (boilerAction == TurnOn)
|
||||
switch (boilerAction)
|
||||
{
|
||||
BoilerSwitchEntity.TurnOn();
|
||||
}
|
||||
else if (boilerAction == TurnOff)
|
||||
{
|
||||
BoilerSwitchEntity.TurnOff();
|
||||
case TurnOn:
|
||||
BoilerSwitchEntity.TurnOn();
|
||||
|
||||
break;
|
||||
case TurnOff:
|
||||
BoilerSwitchEntity.TurnOff();
|
||||
|
||||
break;
|
||||
case NoChange:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var context = new EntityUpdateContext
|
||||
|
||||
Reference in New Issue
Block a user