Apply code formatting cleanup across monitor projects

- Reindent appsettings.json and the MSBuild project files
- Collapse single-statement guard blocks and tidy using and member order
- Normalize XML doc indentation and file endings
- Reorder BatteryMonitor test-data helpers and move the exclusion tests into
  their own region
- Carry the same formatting through the boiler config, control, entity and
  test files
This commit is contained in:
2026-11-30 11:52:06 +02:00
parent cf8c9434c8
commit 24729ee267
165 changed files with 2513 additions and 2470 deletions
@@ -9,9 +9,9 @@ using static BoilerMonitor.Models.BoilerMonitorConsts;
namespace BoilerMonitor.Manager.Tests;
/// <summary>
/// Shared, deterministic fixtures used by the BoilerMonitor tests: config/options builders,
/// entity-state sets, parse samples and a fixed clock. Keeping them here avoids copy-pasted
/// setup and makes every timestamp/DST assertion independent of the real clock.
/// Shared, deterministic fixtures used by the BoilerMonitor tests: config/options builders,
/// entity-state sets, parse samples and a fixed clock. Keeping them here avoids copy-pasted
/// setup and makes every timestamp/DST assertion independent of the real clock.
/// </summary>
internal static class BoilerMonitorTestData
{
@@ -21,30 +21,36 @@ internal static class BoilerMonitorTestData
/// <summary>Fixed "now" (UTC) used by every time based test.</summary>
public static readonly DateTimeOffset BaseTime = new(2026, 3, 31, 12, 0, 0, TimeSpan.Zero);
public static FakeTimeProvider CreateTimeProvider(DateTimeOffset? utcNow = null) =>
new(utcNow ?? BaseTime);
public static FakeTimeProvider CreateTimeProvider(DateTimeOffset? utcNow = null)
{
return new FakeTimeProvider(utcNow ?? BaseTime);
}
public static BoilerMonitorConfig CreateConfig(
string? boilerPowerEntityId = PowerEntityId,
string? boilerSwitchEntityId = SwitchEntityId,
int? pollIntervalSeconds = DefaultPollIntervalSeconds,
double? heatingPowerThresholdWatts = DefaultHeatingPowerThresholdWatts) =>
new()
double? heatingPowerThresholdWatts = DefaultHeatingPowerThresholdWatts)
{
return new BoilerMonitorConfig
{
BoilerPowerEntityId = boilerPowerEntityId,
BoilerSwitchEntityId = boilerSwitchEntityId,
PollIntervalSeconds = pollIntervalSeconds,
HeatingPowerThresholdWatts = heatingPowerThresholdWatts
};
}
public static BoilerMonitorOptions CreateOptions(
bool enabled = true,
bool cleanupEntitiesOnStartup = true) =>
new()
bool cleanupEntitiesOnStartup = true)
{
return new BoilerMonitorOptions
{
Enabled = enabled,
CleanupEntitiesOnStartup = cleanupEntitiesOnStartup
};
}
public static BoilerMonitorUpdateContext CreateUpdateContext(
TimeSpan? todayRunTime = null,
@@ -56,8 +62,9 @@ internal static class BoilerMonitorTestData
bool waterReady = false,
string? boilerSwitchState = "on",
double? boilerPowerWatts = 0.0,
DateTimeOffset? cooldownSince = null) =>
new()
DateTimeOffset? cooldownSince = null)
{
return new BoilerMonitorUpdateContext
{
TodayRunTime = todayRunTime ?? TimeSpan.FromHours(1),
RemainingTime = remainingTime ?? TimeSpan.FromHours(1),
@@ -68,33 +75,43 @@ internal static class BoilerMonitorTestData
WaterReady = waterReady,
BoilerSwitchState = boilerSwitchState,
BoilerPowerWatts = boilerPowerWatts,
CooldownSince = cooldownSince,
CooldownSince = cooldownSince
};
}
/// <summary>
/// The four entity states <c>ReadPersistedState</c> reads, with valid defaults.
/// A null value means the entity does not exist in Home Assistant.
/// The four entity states <c>ReadPersistedState</c> reads, with valid defaults.
/// A null value means the entity does not exist in Home Assistant.
/// </summary>
public static Dictionary<string, string?> CreatePersistedEntityStates(
string? todayRuntime = "7200",
string? sessionCount = "3",
string? skipPriceCap = "OFF",
string? budgetOverride = "OFF") =>
new()
string? budgetOverride = "OFF")
{
return new Dictionary<string, string?>
{
[TodayRuntimeEntityId] = todayRuntime,
[SessionCountEntityId] = sessionCount,
[SkipPriceCapEntityId] = skipPriceCap,
[BudgetOverrideEntityId] = budgetOverride
};
}
public static EntityState CreateEntityState(string state) => new() { State = state };
public static EntityState CreateEntityState(string state)
{
return new EntityState { State = state };
}
public static EntityState CreateEntityStateWithAttributes(IReadOnlyDictionary<string, object?> attributes) =>
new() { State = "yes", AttributesJson = JsonSerializer.SerializeToElement(attributes) };
public static EntityState CreateEntityStateWithAttributes(IReadOnlyDictionary<string, object?> attributes)
{
return new EntityState { State = "yes", AttributesJson = JsonSerializer.SerializeToElement(attributes) };
}
public static EntityState CreateWaterReadyEntityStateWithCooldown(object? cooldownSince) =>
CreateEntityStateWithAttributes(new Dictionary<string, object?> { ["cooldown_since"] = cooldownSince });
public static EntityState CreateWaterReadyEntityStateWithCooldown(object? cooldownSince)
{
return CreateEntityStateWithAttributes(new Dictionary<string, object?> { ["cooldown_since"] = cooldownSince });
}
extension(Mock<IHaContext> haContextMock)
{
@@ -107,13 +124,15 @@ internal static class BoilerMonitorTestData
}
}
public void SetupEntityState(string entityId, EntityState? entityState) =>
public void SetupEntityState(string entityId, EntityState? entityState)
{
haContextMock.Setup(h => h.GetState(entityId)).Returns(entityState);
}
}
/// <summary>
/// Entity-state samples for the today-runtime sensor: valid values with the expected
/// <see cref="TimeSpan"/>, plus unavailable/negative/overflow values that must be rejected.
/// Entity-state samples for the today-runtime sensor: valid values with the expected
/// <see cref="TimeSpan" />, plus unavailable/negative/overflow values that must be rejected.
/// </summary>
public static TheoryData<string?, TimeSpan?> RuntimeStateSamples()
{
@@ -141,11 +160,10 @@ internal static class BoilerMonitorTestData
data.Add("-1", null);
data.Add("-0.001", null);
return data;
}
/// <summary>
/// Entity-state samples for the session-count sensor, including the int boundaries.
/// Entity-state samples for the session-count sensor, including the int boundaries.
/// </summary>
public static TheoryData<string?, int?> SessionCountStateSamples()
{
@@ -168,12 +186,11 @@ internal static class BoilerMonitorTestData
data.Add("2147483648", null);
data.Add("1e3", null);
return data;
}
/// <summary>
/// Water-ready detection samples around the heating threshold, including negative,
/// zero, exact-boundary, huge and NaN readings.
/// Water-ready detection samples around the heating threshold, including negative,
/// zero, exact-boundary, huge and NaN readings.
/// </summary>
public static TheoryData<string, double, bool> PowerReadingSamples()
{
@@ -188,11 +205,10 @@ internal static class BoilerMonitorTestData
data.Add("maximum", double.MaxValue, false);
data.Add("not-a-number", double.NaN, true);
return data;
}
/// <summary>
/// Elapsed-time sweep showing that the water-ready cooldown never expires on its own.
/// Elapsed-time sweep showing that the water-ready cooldown never expires on its own.
/// </summary>
public static TheoryData<TimeSpan> GeneratedElapsedTimes()
{
@@ -207,12 +223,11 @@ internal static class BoilerMonitorTestData
data.Add(TimeSpan.FromHours(48));
data.Add(TimeSpan.FromHours(168));
return data;
}
/// <summary>
/// Cooldown restore samples around the UTC-midnight cut-off, including DST start/end
/// timestamps carrying non-zero offsets.
/// Cooldown restore samples around the UTC-midnight cut-off, including DST start/end
/// timestamps carrying non-zero offsets.
/// </summary>
public static TheoryData<string, DateTimeOffset, DateTimeOffset, bool> CooldownRestoreSamples()
{
@@ -259,9 +274,10 @@ internal static class BoilerMonitorTestData
false
);
return data;
}
private static DateTimeOffset TodayMidnight() =>
new(BaseTime.Date, TimeSpan.Zero);
}
private static DateTimeOffset TodayMidnight()
{
return new DateTimeOffset(BaseTime.Date, TimeSpan.Zero);
}
}