Refactor boiler control and price logic: Introduce PriceConsts, improve BoilerAction handling with switch, and update namespaces for better structure.
This commit is contained in:
@@ -2,7 +2,7 @@ using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NordPoolManager;
|
||||
using NordPoolManager.Models;
|
||||
using NordPoolManager.Models.Enums;
|
||||
|
||||
namespace NordPool.Manager.Tests;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NordPoolManager.Interface;
|
||||
using NordPoolManager.Models;
|
||||
using NordPoolManager.Models.Enums;
|
||||
|
||||
namespace NordPoolManager;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NordPoolManager.Models;
|
||||
using NordPoolManager.Models.Enums;
|
||||
|
||||
namespace NordPoolManager.Interface;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace NordPoolManager.Models;
|
||||
namespace NordPoolManager.Models.Consts;
|
||||
|
||||
public static class ConversionConsts
|
||||
{
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace NordPoolManager.Models.Consts;
|
||||
|
||||
public static class PriceConsts
|
||||
{
|
||||
public const int MaxDailyIntervals = 96;
|
||||
public const int IntervalsPerHour = 4;
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace NordPoolManager.Models;
|
||||
namespace NordPoolManager.Models.Enums;
|
||||
|
||||
public enum BoilerAction
|
||||
{
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging;
|
||||
using NordPool.Models;
|
||||
using NordPool.Models.Dtos;
|
||||
using NordPoolManager.Interface;
|
||||
using NordPoolManager.Models;
|
||||
using NordPoolManager.Models.Consts;
|
||||
|
||||
namespace NordPoolManager;
|
||||
|
||||
@@ -49,8 +49,7 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
|
||||
LastUpdatedDate = DateTime.UtcNow;
|
||||
LastFetchedDate = today;
|
||||
|
||||
logger.LogInformation(
|
||||
"Prices ready for today ({Today}). Today prices count: {TodayCount}, Tomorrow prices count: {TomorrowCount}",
|
||||
logger.LogInformation("Prices ready for today ({Today}). Today prices count: {TodayCount}, Tomorrow prices count: {TomorrowCount}",
|
||||
today, TodayNordPoolPrice?.Prices?.Count ?? 0, TomorrowNordPoolPrice?.Prices?.Count ?? 0);
|
||||
}
|
||||
|
||||
@@ -149,7 +148,7 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
|
||||
LastFetchedDate = today;
|
||||
}
|
||||
|
||||
internal async Task<NordPoolPrice> GetNordPoolPriceAsync(DateOnly date)
|
||||
private async Task<NordPoolPrice> GetNordPoolPriceAsync(DateOnly date)
|
||||
{
|
||||
var nordPoolPricesDto = await _nordPoolServices.GetPricesForDateAsync(
|
||||
new NordpoolGetPricesForDateParameters
|
||||
|
||||
Reference in New Issue
Block a user