Enable PowerMonitor limit enforcement and prune unused boiler/replay code

PowerMonitor now ships enabled with power-limit enforcement settings: watt limit, recovery and cooldown windows, and switch-off plus pause/restore entity lists.

Remove the unused BoilerRunTimeTracker, its DI registration and tests, the StatusCleanedUp constant, and the boiler replay runner; simplify BoilerConfigReader, control-service logging and entity parsing. Switch CostAccumulator to System.Threading.Lock, update the Shower exhaust fan service and tests, drop the legacy HistoryReplay/McpServer sources and reporting tooling, and expand AGENTS.md with the current project wiring and DI notes.
This commit is contained in:
2026-11-29 13:58:08 +02:00
parent f176a1b8fc
commit f0bbd4f10b
98 changed files with 306 additions and 4737 deletions
@@ -1,6 +1,4 @@
using BoilerMonitor.Models;
using BoilerMonitorManager;
using BoilerMonitorManager.Models;
using FluentAssertions;
using HomeAssistant.Entities.Interfaces;
using Microsoft.Extensions.Logging;
@@ -1,254 +0,0 @@
using FluentAssertions;
using BoilerMonitorManager;
namespace BoilerMonitor.Manager.Tests;
public class BoilerRunTimeTrackerTests
{
private readonly BoilerRunTimeTracker _sut = new();
#region RecordPollResult
[Fact]
public void RecordPollResult_WhenHeating_ShouldAccumulateRunTime()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(true, interval);
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.FromSeconds(90));
}
[Fact]
public void RecordPollResult_WhenNotHeating_ShouldNotAccumulate()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(false, interval);
_sut.RecordPollResult(false, interval);
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.Zero);
}
[Fact]
public void RecordPollResult_WhenHeatingStarts_ShouldIncrementSessionCount()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
var snapshot = _sut.GetSnapshot();
snapshot.SessionCount.Should().Be(1);
}
[Fact]
public void RecordPollResult_ContinuousHeating_ShouldCountAsOneSession()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(true, interval);
var snapshot = _sut.GetSnapshot();
snapshot.SessionCount.Should().Be(1);
}
[Fact]
public void RecordPollResult_HeatingStopsAndRestarts_ShouldCountAsTwoSessions()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(false, interval);
_sut.RecordPollResult(true, interval);
var snapshot = _sut.GetSnapshot();
snapshot.SessionCount.Should().Be(2);
}
[Fact]
public void RecordPollResult_MultipleSessions_ShouldAccumulateCorrectly()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(false, interval);
_sut.RecordPollResult(true, interval);
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.FromSeconds(90));
snapshot.SessionCount.Should().Be(2);
}
[Fact]
public void RecordPollResult_WhenHeating_ShouldSetIsInSessionTrue()
{
_sut.RecordPollResult(true, TimeSpan.FromSeconds(30));
var snapshot = _sut.GetSnapshot();
snapshot.IsInSession.Should().BeTrue();
}
[Fact]
public void RecordPollResult_WhenNotHeating_ShouldSetIsInSessionFalse()
{
_sut.RecordPollResult(true, TimeSpan.FromSeconds(30));
_sut.RecordPollResult(false, TimeSpan.FromSeconds(30));
var snapshot = _sut.GetSnapshot();
snapshot.IsInSession.Should().BeFalse();
}
#endregion
#region Reset
[Fact]
public void Reset_ShouldClearAllState()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
_sut.RecordPollResult(true, interval);
_sut.Reset();
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.Zero);
snapshot.SessionCount.Should().Be(0);
snapshot.IsInSession.Should().BeFalse();
}
[Fact]
public void Reset_AfterReset_ShouldAccumulateFromZero()
{
var interval = TimeSpan.FromSeconds(30);
_sut.RecordPollResult(true, interval);
_sut.Reset();
_sut.RecordPollResult(true, interval);
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.FromSeconds(30));
snapshot.SessionCount.Should().Be(1);
}
#endregion
#region RestoreFromSnapshot
[Fact]
public void RestoreFromSnapshot_ShouldSetAccumulatedRunTimeAndSessionCount()
{
// Arrange
var runTime = TimeSpan.FromMinutes(45);
const int sessionCount = 3;
// Act
_sut.RestoreFromSnapshot(runTime, sessionCount);
// Assert
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(runTime);
snapshot.SessionCount.Should().Be(sessionCount);
snapshot.IsInSession.Should().BeFalse();
}
[Fact]
public void RestoreFromSnapshot_ShouldOverwriteExistingState()
{
// Arrange
_sut.RecordPollResult(true, TimeSpan.FromSeconds(30));
_sut.RecordPollResult(true, TimeSpan.FromSeconds(30));
var restoredRunTime = TimeSpan.FromHours(2);
const int restoredSessions = 5;
// Act
_sut.RestoreFromSnapshot(restoredRunTime, restoredSessions);
// Assert
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(restoredRunTime);
snapshot.SessionCount.Should().Be(restoredSessions);
}
[Fact]
public void RestoreFromSnapshot_ShouldAllowFurtherAccumulationFromRestoredState()
{
// Arrange
var restoredRunTime = TimeSpan.FromMinutes(30);
const int restoredSessions = 2;
var pollInterval = TimeSpan.FromSeconds(30);
_sut.RestoreFromSnapshot(restoredRunTime, restoredSessions);
// Act
_sut.RecordPollResult(true, pollInterval);
// Assert
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(restoredRunTime + pollInterval);
snapshot.SessionCount.Should().Be(restoredSessions + 1);
}
[Fact]
public void RestoreFromSnapshot_WithZeroValues_ShouldSetToZero()
{
// Arrange
_sut.RecordPollResult(true, TimeSpan.FromSeconds(30));
// Act
_sut.RestoreFromSnapshot(TimeSpan.Zero, 0);
// Assert
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.Zero);
snapshot.SessionCount.Should().Be(0);
}
#endregion
#region Thread safety
[Fact]
public async Task RecordPollResult_ConcurrentCalls_ShouldNotCorruptState()
{
var interval = TimeSpan.FromSeconds(1);
const int iterationsPerThread = 1000;
const int threadCount = 4;
var tasks = Enumerable.Range(0, threadCount).Select(_ => Task.Run(() =>
{
for (var i = 0; i < iterationsPerThread; i++)
{
_sut.RecordPollResult(true, interval);
}
})).ToArray();
await Task.WhenAll(tasks);
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.FromSeconds(iterationsPerThread * threadCount));
}
#endregion
#region GetSnapshot
[Fact]
public void GetSnapshot_Initial_ShouldReturnZeroState()
{
var snapshot = _sut.GetSnapshot();
snapshot.AccumulatedRunTime.Should().Be(TimeSpan.Zero);
snapshot.SessionCount.Should().Be(0);
snapshot.IsInSession.Should().BeFalse();
}
#endregion
}