Apply code formatting cleanup across the monitor projects

- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests
- Expand single-statement guards and loops into braced blocks
- Realign wrapped method arguments, chained calls and continuations
- Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty`
- Flatten the boiler config expression and reindent the remaining touched files
This commit is contained in:
2026-12-01 12:33:31 +02:00
parent 77458383d1
commit f919d6b25b
115 changed files with 3115 additions and 1959 deletions
@@ -1,9 +1,13 @@
#region
using System.Text.Json;
using PowerMonitor.Models;
using PowerMonitorManager;
using PowerMonitorManager.Models;
using PowerMonitorManager.Models.Consts;
#endregion
namespace PowerMonitor.Manager.Tests;
/// <summary>
@@ -21,11 +25,11 @@ internal static class PowerMonitorTestData
public const string AutoManagementEntityId = "switch.boilermonitor_auto_management";
public const string MainMeterEntityId = "sensor.sonoff_100267d63f_power";
public static readonly DateTime FixedNow = new(2026, 3, 17, 10, 0, 0);
public static readonly DateTime FixedNow = new DateTime(2026, 3, 17, 10, 0, 0);
public static readonly DateTime FixedDayStart = new(2026, 3, 17, 0, 0, 0);
public static readonly DateTime FixedDayStart = new DateTime(2026, 3, 17, 0, 0, 0);
public static readonly DateTimeOffset FixedUtcNow = new(2026, 3, 17, 8, 0, 0, TimeSpan.Zero);
public static readonly DateTimeOffset FixedUtcNow = new DateTimeOffset(2026, 3, 17, 8, 0, 0, TimeSpan.Zero);
/// <summary>
/// Two-device reading set used by the cost calculation tests.
@@ -107,13 +111,14 @@ internal static class PowerMonitorTestData
string priceSource = "live")
{
var readings = deviceReadings ?? CreateDeviceReadings();
var deviceCosts = readings
.Select((reading, index) => (reading.Key, Snapshot: CreateCostSnapshot(
0.0005 * (index + 1),
0.002 * (index + 1),
0.03 * (index + 1),
0.9 * (index + 1))))
.ToDictionary(entry => entry.Key, entry => entry.Snapshot);
.Select((reading, index) => (reading.Key, Snapshot: CreateCostSnapshot(
0.0005 * (index + 1),
0.002 * (index + 1),
0.03 * (index + 1),
0.9 * (index + 1))))
.ToDictionary(entry => entry.Key, entry => entry.Snapshot);
return new PowerUpdateContext
{
@@ -143,21 +148,22 @@ internal static class PowerMonitorTestData
};
configure?.Invoke(options);
return options;
}
public static PowerMonitorOptions CreateLimitEnforcementOptions(Action<PowerMonitorOptions>? configure = null)
{
return CreateOptions(options =>
{
options.EnforceLimitEnabled = true;
options.PowerLimitWatts = PowerMonitorConsts.DefaultPowerLimitWatts;
options.RecoverySeconds = PowerMonitorConsts.DefaultRecoverySeconds;
options.LimitCooldownSeconds = PowerMonitorConsts.DefaultLimitCooldownSeconds;
options.EnforceSwitchOffEntityIds = [BoilerSwitchEntityId];
options.PauseAndRestoreEntityIds = [AutoManagementEntityId];
configure?.Invoke(options);
});
{
options.EnforceLimitEnabled = true;
options.PowerLimitWatts = PowerMonitorConsts.DefaultPowerLimitWatts;
options.RecoverySeconds = PowerMonitorConsts.DefaultRecoverySeconds;
options.LimitCooldownSeconds = PowerMonitorConsts.DefaultLimitCooldownSeconds;
options.EnforceSwitchOffEntityIds = [BoilerSwitchEntityId];
options.PauseAndRestoreEntityIds = [AutoManagementEntityId];
configure?.Invoke(options);
});
}
public static PowerSensorInfo CreateSensor(
@@ -182,11 +188,20 @@ internal static class PowerMonitorTestData
{
var attributes = new Dictionary<string, object?>();
if (deviceClass is not null) attributes["device_class"] = deviceClass;
if (deviceClass is not null)
{
attributes["device_class"] = deviceClass;
}
if (unitOfMeasurement is not null) attributes["unit_of_measurement"] = unitOfMeasurement;
if (unitOfMeasurement is not null)
{
attributes["unit_of_measurement"] = unitOfMeasurement;
}
if (friendlyName is not null) attributes["friendly_name"] = friendlyName;
if (friendlyName is not null)
{
attributes["friendly_name"] = friendlyName;
}
return JsonSerializer.SerializeToElement(attributes);
}
@@ -200,7 +215,7 @@ internal static class PowerMonitorTestData
return
[
.. Enumerable.Range(0, count)
.Select(i => Math.Round(50.0 + i * 37.5 + i % 7 * 0.5, 2))
.Select(i => Math.Round(50.0 + i * 37.5 + i % 7 * 0.5, 2))
];
}
@@ -212,7 +227,7 @@ internal static class PowerMonitorTestData
return
[
.. Enumerable.Range(0, count)
.Select(i => Math.Round(0.08 + i * 0.03 + i % 5 * 0.0125, 4))
.Select(i => Math.Round(0.08 + i * 0.03 + i % 5 * 0.0125, 4))
];
}
@@ -223,7 +238,7 @@ internal static class PowerMonitorTestData
return
[
.. Enumerable.Range(0, prices.Count)
.Select(hour => (dayStart.AddHours(hour), prices[hour]))
.Select(hour => (dayStart.AddHours(hour), prices[hour]))
];
}
@@ -232,7 +247,7 @@ internal static class PowerMonitorTestData
return
[
.. Enumerable.Range(0, count)
.Select(i => start.AddMinutes(i * intervalMinutes))
.Select(i => start.AddMinutes(i * intervalMinutes))
];
}
}