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
+54 -25
View File
@@ -13,22 +13,28 @@ before editing; it only records things that are easy to get wrong.
## Stack
- .NET 10 / C# 14 (`LangVersion=14.0`). `global.json` pins SDK `10.0.0` with
`rollForward=latestMajor` and `allowPrerelease=true`.
- .NET 10 / C# 14 (`LangVersion=14.0`, set per-csproj in the three
executable projects — `HomeAssistant.Server`, `HomeAssistant.McpServer`,
`HomeAssistant.HistoryReplay`; no `Directory.Build.props`). `global.json`
pins SDK `10.0.0` with `rollForward=latestMajor` and
`allowPrerelease=true`.
- NetDaemon v5 (NuGet `26.11.0`) apps run inside `HomeAssistant.Server`, the
only host / binary-deploy target. Solution file: `HomeAssistantSDK.sln`.
- Tests: xUnit + FluentAssertions + Moq. `Microsoft.Extensions.TimeProvider.Testing`
is used for time-based tests — prefer `FakeTimeProvider` over real time.
- AutoMapper 16 is used by `HomeAssistant.Server`. **A hardcoded license key
- AutoMapper 16.1.1 is used by `HomeAssistant.Server`. **A hardcoded license key
is committed in `HomeAssistant.Server/program.cs`** — do not move it to
settings, and do not log or echo it.
## Layout (non-obvious wiring)
- Each monitor follows a fixed 3-project pattern:
- `*.Models` — constants, enums, `*Options` (bound from
`appsettings.json` via `IOptions<>`).
- `*.Manager` — services + the `[NetDaemonApp]` entry `*Init.cs`.
- `*.Models` — entity/config interfaces, constants, enums.
- `*.Manager` — services, the `[NetDaemonApp]` entry `*Init.cs`, and
`*Options` (bound from `appsettings.json` via `IOptions<>`). Note:
`*Options` lives in `*.Manager/Models/`, **not** in the separate
`*.Models` project, for 6 of 7 monitors. Only `LightMonitor` puts
`LightMonitorOptions` in `LightMonitor.Models`.
- `*.Manager.Tests` — unit tests for the manager.
- Apps are **not** auto-discovered by the host. Each monitor exposes a
`Add<Name>Monitor(this IServiceCollection, IConfiguration)` extension in
@@ -36,24 +42,40 @@ before editing; it only records things that are easy to get wrong.
specific order. Adding a new monitor means: create the 3 projects, add a
`*ServiceRegistration.cs`, reference the projects from
`HomeAssistant.Server`, and wire `Add<Name>` + `Configure<*Options>` in
`program.cs`.
`program.cs`. **NordPool breaks the naming convention**: its extension is
`AddNordPool`, not `AddNordPoolMonitor`.
- `*ServiceRegistration.cs` honors an `Enabled` flag in the options and
no-ops (skips `AddNetDaemonApp`) when disabled. `PowerMonitor` ships
disabled by default in `appsettings.json`.
no-ops (skips `AddNetDaemonApp`) when disabled — for every monitor
**except NordPool**, which has no `Enabled` option and always registers.
`PowerMonitor` ships disabled by default in `appsettings.json`; all
others ship enabled.
- `HomeAssistant.Entities` holds the **generated** `HomeAssistantGenerated`
code (entity metadata sourced from
`HomeAssistant.Server/NetDaemonCodegen/{EntityMetaData,ServicesMetaData}.json`).
`program.cs` calls `AddHomeAssistantGenerated()`; the generated entities
are transient. Do not hand-edit generated files.
- `HomeAssistant.McpServer` is a separate stdio MCP server (ModelContextProtocol
NuGet) exposing HA tools. It is **not** referenced by the host; it runs
standalone via `dotnet run --project HomeAssistant.McpServer`. Cursor
wires it up in `.cursor/mcp.json` as the `homeassistant` MCP server.
- `program.cs` calls `Configure<*Options>` then `Add<Name>…` for each
monitor in this order: NordPool, Power, Boiler, Shower, Light, Battery,
Leak. Monitor service registrations (except `IBoilerConfigReader`,
`IEntityManager`, `TimeProvider.System`, which are in `program.cs`)
live inside each `*ServiceRegistration.cs`, not `program.cs`.
- `HomeAssistant.Models` is a thin shared model project (one file,
`EntityCreateModel.cs`) referenced by `HomeAssistant.Entities`. NetDaemon
MQTT extension lives here.
- `Mappings` is a class library holding AutoMapper profiles
(`GlobalMappingProfile`, `NordPoolMappingProfile` + `DateTimeTypeConverter`)
referenced by `HomeAssistant.Server`; wired in `program.cs` via
`config.AddProfile<…>()`. AutoMapper 16.1.1.
- `HomeAssistant.McpServer` is a separate stdio MCP server
(ModelContextProtocol NuGet 1.2.0) exposing HA tools. It is **not**
referenced by the host; it runs standalone via
`dotnet run --project HomeAssistant.McpServer`. It is wired as the
`homeassistant` MCP server in both `.cursor/mcp.json` (git-ignored) and
the committed `opencode.json` at the repo root.
- `HomeAssistant.HistoryReplay` is a Blazor debug web app that replays HA
history through monitor business logic with no side effects. See its own
README. Not deployed.
- `NordPool.Comminication` (sic — typo is intentional, keep it) is the
Nord Pool HTTP client project referenced by `NordPool.Manager`.
history through monitor business logic with no side effects. It
references a subset of monitors (Boiler, NordPool, Power, Shower, Light —
not Battery or Leak). See its own README. Not deployed.
## Critical DI rule
@@ -65,7 +87,10 @@ or app load fails with:
Verified-livable registrations (do not regress these to singleton):
- `Boiler`: `IBoilerMonitorEntityService` transient,
`IBoilerConfigReader` scoped (in `program.cs`).
`IBoilerControlService`/`IBoilerRunTimeTracker`/`IWaterReadyService`
singleton (no HA dep), `IBoilerConfigReader` scoped (registered directly
in `program.cs`, the only monitor service outside its
`*ServiceRegistration.cs`).
- `NordPool`: `INordPoolEntityService` transient, `INordPoolPriceService`
scoped, `INordPoolBoilerConfigProvider` scoped,
`ICheapestIntervalsFinder` singleton (no HA dep).
@@ -88,8 +113,8 @@ scoped.
## Live validation after monitor edits
`.cursor/rules/live-validation.mdc` (globs: all `*.Manager`/`*.Models` of
Boiler, Light, NordPool, Power, Shower, plus `HomeAssistant.McpServer`)
requires, after editing monitor runtime code:
Boiler, Light, NordPool, Power, Shower, plus `HomeAssistant.McpServer` —
**not** Battery or Leak) requires, after editing monitor runtime code:
1. `dotnet build` the affected project.
2. `RunSmokeTest` MCP tool from the `homeassistant` MCP server.
@@ -153,10 +178,14 @@ prints the reminder after publish.
`HumidityRateCalculator`). Keep both in sync when changing option names.
- `HomeAssistant.Server` references every monitor's `*.Manager` and
`*.Models` projects directly; `HomeAssistant.HistoryReplay` references a
subset. Adding a monitor to the replay tool requires a new project
reference there too.
subset (Boiler, NordPool, Power, Shower, Light). Adding a monitor to the
replay tool requires a new project reference there too.
- The repository folder name is misspelled `homeassistant-app-deamon`
(should be `daemon`). This is intentional/legacy — do not "fix" it in
paths; scripts and `.cursor/mcp.json` use `${workspaceFolder}`.
- `NordPool.Comminication` is also misspelled — keep it; the project
reference depends on the exact name.
paths; `opencode.json` and `.cursor/mcp.json` reference the workspace
folder by macro.
- Stale untracked folders `NordPool.Comminication/` and
`HomeAssistant.Infrastructure/` may appear on disk containing only
`obj/` build cruft. They are **not** in the solution, not committed to
git, and not referenced by any project. Do not treat them as real
projects; safe to delete.