5777e641f6
- Extract per-monitor *TestData helper classes and rework tests to use them - Add boiler run-time tracker abstraction (implementation pending) - Drop unused NordPool init/update-result types and stale PLAN.md - Add qodana.yaml with the inspection set to keep the analysis focused
53 lines
2.0 KiB
C#
53 lines
2.0 KiB
C#
using System.Globalization;
|
|
using BoilerMonitor.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
using NetDaemon.HassModel;
|
|
using static BoilerMonitor.Models.BoilerMonitorConsts;
|
|
using static NordPool.Models.NordPoolConsts;
|
|
|
|
namespace BoilerMonitorManager;
|
|
|
|
public sealed class BoilerConfigReader(IHaContext haContext, ILogger<BoilerConfigReader> logger) : IBoilerConfigReader
|
|
{
|
|
private const double DefaultDailyHours = 1.0;
|
|
|
|
public BoilerConfig ReadConfig()
|
|
{
|
|
var dailyHoursState = haContext.GetState(BoilerDailyHoursEntityId)?.State;
|
|
var dailyHours = double.TryParse(dailyHoursState, NumberStyles.Any, CultureInfo.InvariantCulture, out var dh) ? dh : DefaultDailyHours;
|
|
|
|
var intervalCount = (int)(dailyHours * IntervalsPerHour);
|
|
|
|
if (intervalCount <= 0)
|
|
{
|
|
intervalCount = IntervalsPerHour;
|
|
}
|
|
|
|
var priceCapState = haContext.GetState(BoilerPriceCapEntityId)?.State;
|
|
var priceCap = double.TryParse(priceCapState, NumberStyles.Any, CultureInfo.InvariantCulture, out var pc) && pc > 0 ? pc : double.MaxValue;
|
|
|
|
var deadline = DateTime.Today.AddDays(1);
|
|
var readyByState = haContext.GetState(BoilerReadyByEntityId)?.State;
|
|
|
|
if (!string.IsNullOrEmpty(readyByState) && TimeSpan.TryParse(readyByState, CultureInfo.InvariantCulture, out var readyByTime))
|
|
{
|
|
deadline = DateTime.Today.Add(readyByTime);
|
|
}
|
|
|
|
var skipPriceCapState = haContext.GetState(SkipPriceCapEntityId)?.State;
|
|
var skipPriceCap = string.Equals(skipPriceCapState, SwitchOnState, StringComparison.OrdinalIgnoreCase);
|
|
|
|
logger.LogDebug("Boiler config: intervals={Intervals}, priceCap={Cap}, skipPriceCap={Skip}, deadline={Deadline}", intervalCount, priceCap, skipPriceCap, deadline);
|
|
|
|
var config = new BoilerConfig
|
|
{
|
|
IntervalCount = intervalCount,
|
|
PriceCap = priceCap,
|
|
Deadline = deadline,
|
|
SkipPriceCap = skipPriceCap
|
|
};
|
|
|
|
return config;
|
|
}
|
|
}
|