feat: migrate boiler control implementation to BoilerMonitor namespace and add budget handling logic

This commit is contained in:
Marius
2026-03-24 15:29:59 +02:00
parent c4015277a3
commit 11c2574235
61 changed files with 3250 additions and 728 deletions
@@ -43,23 +43,36 @@ internal sealed class CompactNordPoolDayPriceConverter : JsonConverter<CompactNo
public override CompactNordPoolDayPrice Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException("Expected start of array.");
}
if (!reader.Read() || reader.TokenType != JsonTokenType.Number)
{
throw new JsonException("Expected number for Start at position 0.");
}
var start = reader.GetInt64();
if (!reader.Read() || reader.TokenType != JsonTokenType.Number)
{
throw new JsonException("Expected number for End at position 1.");
}
var end = reader.GetInt64();
if (!reader.Read() || (reader.TokenType != JsonTokenType.Number && reader.TokenType != JsonTokenType.Null))
{
throw new JsonException("Expected number or null for Price at position 2.");
}
double? price = reader.TokenType == JsonTokenType.Null ? null : reader.GetDouble();
reader.Read();
if (reader.TokenType != JsonTokenType.EndArray)
{
throw new JsonException("Expected end of array.");
}
return new CompactNordPoolDayPrice { Start = start, End = end, Price = price };
}
@@ -71,9 +84,13 @@ internal sealed class CompactNordPoolDayPriceConverter : JsonConverter<CompactNo
writer.WriteNumberValue(value.End);
if (value.Price.HasValue)
{
writer.WriteNumberValue(value.Price.Value);
}
else
{
writer.WriteNullValue();
}
writer.WriteEndArray();
}
+16 -2
View File
@@ -9,14 +9,28 @@ public static class NordPoolConsts
/// </summary>
public const int MinutesPerInterval = 15;
/// <summary>
/// Number of 15-minute intervals in one hour.
/// </summary>
public const int IntervalsPerHour = 4;
/// <summary>
/// Maximum number of 15-minute intervals in a single day (96 = 24h * 4).
/// </summary>
public const int MaxDailyIntervals = 96;
/// <summary>
/// Maximum expected price entries when today and tomorrow are both available
/// (96 intervals per day x 2 days). Used for logging a warning if exceeded.
/// </summary>
public const int MaxExpectedPriceEntries = 192;
public const string DeviceIdentifier = "nordpool";
public const string DeviceName = "NordPool";
public const string DeviceManufacturer = "HomeAssistant App Daemon";
/// <summary>
/// Power threshold in watts below which the boiler is considered to have finished heating (water ready).
/// Home Assistant entity id for the Nord Pool current price sensor published by this integration.
/// </summary>
public const double WaterReadyPowerThresholdWatts = 5.0;
public const string CurrentPriceEntityId = "sensor.nordpool_current_price";
}
+3 -10
View File
@@ -1,15 +1,8 @@
using System.Text.Json.Serialization;
namespace NordPool.Models;
public class NordPoolDayPrice
{
[JsonPropertyName("start")]
public DateTime? Start { get; set; }
[JsonPropertyName("end")]
public DateTime? End { get; set; }
[JsonPropertyName("price")]
public double? Price { get; set; }
public DateTime? Start { get; init; }
public DateTime? End { get; init; }
public double? Price { get; init; }
}
@@ -5,7 +5,9 @@ public static class NordPoolDayPriceExtensions
public static List<CompactNordPoolDayPrice> ToCompact(this IEnumerable<NordPoolDayPrice>? prices)
{
if (prices is null)
{
return [];
}
return prices.Select(CompactNordPoolDayPrice.FromDayPrice).ToList();
}
+28 -5
View File
@@ -1,13 +1,21 @@
using HomeAssistant.Models;
using HomeAssistant.Models;
using NetDaemon.Extensions.MqttEntityManager;
namespace NordPool.Models;
public class NordPoolEntity : EntityCreateModel
{
public string Domain { get; set; } // example: sensor
public string Identifier { get; set; } // example: name of the sensor
public string Name { get; set; } // friendly name for UI
private static readonly object DeviceBlock = new
{
identifiers = new[] { NordPoolConsts.DeviceIdentifier },
name = NordPoolConsts.DeviceName,
model = NordPoolConsts.DeviceName,
manufacturer = NordPoolConsts.DeviceManufacturer
};
public string Domain { get; set; }
public string Identifier { get; set; }
public string Name { get; set; }
public NordPoolEntity(string domain, string identifier, string name)
{
@@ -20,7 +28,22 @@ public class NordPoolEntity : EntityCreateModel
{
UniqueId = EntityId,
Name = Name
};
AdditionalConfig = new { device = DeviceBlock };
}
/// <summary>
/// Creates an AdditionalConfig that merges custom properties with the NordPool device block.
/// Use this when an entity needs extra config beyond the default device assignment.
/// </summary>
public static object CreateAdditionalConfig(object extraProperties)
{
var extras = extraProperties.GetType().GetProperties()
.ToDictionary(p => p.Name, p => p.GetValue(extraProperties));
extras["device"] = DeviceBlock;
return extras;
}
}