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,3 +1,5 @@
#region
using System.Globalization;
using System.Text.Json;
using BatteryMonitor.Models;
@@ -5,6 +7,8 @@ using Moq;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Entities;
#endregion
namespace BatteryMonitor.Manager.Tests;
/// <summary>
@@ -20,7 +24,7 @@ internal static class BatteryMonitorTestData
/// (threshold, state, expected) rows straddling the strict <c>level &lt; threshold</c>
/// boundary, including zero/negative thresholds and int min/max thresholds.
/// </summary>
public static TheoryData<int, string, bool> ThresholdBoundaryRows { get; } = new()
public static TheoryData<int, string, bool> ThresholdBoundaryRows { get; } = new TheoryData<int, string, bool>
{
{ 5, "4", true },
{ 5, "5", false },
@@ -59,7 +63,7 @@ internal static class BatteryMonitorTestData
"unknown",
"UNAVAILABLE",
"UNKNOWN",
"",
string.Empty,
" ",
"\t",
"not_a_number",
@@ -85,8 +89,10 @@ internal static class BatteryMonitorTestData
}
/// <summary>A sensor with an arbitrary (or missing) device class.</summary>
public static EntitySpec Sensor(string entityId, string? deviceClass, string? state,
string? friendlyName = DefaultFriendlyName)
public static EntitySpec Sensor(string entityId,
string? deviceClass,
string? state,
string? friendlyName = DefaultFriendlyName)
{
return new EntitySpec
{
@@ -101,9 +107,15 @@ internal static class BatteryMonitorTestData
{
var attributes = new Dictionary<string, object?>(StringComparer.Ordinal);
if (spec.DeviceClass is not null) attributes["device_class"] = spec.DeviceClass;
if (spec.DeviceClass is not null)
{
attributes["device_class"] = spec.DeviceClass;
}
if (spec.FriendlyName is not null) attributes["friendly_name"] = spec.FriendlyName;
if (spec.FriendlyName is not null)
{
attributes["friendly_name"] = spec.FriendlyName;
}
return new EntityState
{
@@ -122,7 +134,10 @@ internal static class BatteryMonitorTestData
foreach (var spec in entities)
{
if (spec.HasState) haContextMock.Setup(h => h.GetState(spec.EntityId)).Returns(CreateEntityState(spec));
if (spec.HasState)
{
haContextMock.Setup(h => h.GetState(spec.EntityId)).Returns(CreateEntityState(spec));
}
entityList.Add(new Entity(haContextMock.Object, spec.EntityId));
}
@@ -159,10 +174,10 @@ internal static class BatteryMonitorTestData
return
[
.. Enumerable.Range(0, count)
.Select(i => Battery(
$"sensor.generated_battery_{i:D3}",
i.ToString(CultureInfo.InvariantCulture),
$"Generated Battery {i:D3}"))
.Select(i => Battery(
$"sensor.generated_battery_{i:D3}",
i.ToString(CultureInfo.InvariantCulture),
$"Generated Battery {i:D3}"))
];
}
@@ -175,10 +190,10 @@ internal static class BatteryMonitorTestData
return
[
.. Enumerable.Range(0, count)
.Select(i => CreateSensorInfo(
$"sensor.generated_{i:D3}",
i * 37 % 101,
$"Generated Device {i:D3}"))
.Select(i => CreateSensorInfo(
$"sensor.generated_{i:D3}",
i * 37 % 101,
$"Generated Device {i:D3}"))
];
}
@@ -202,7 +217,7 @@ internal static class BatteryMonitorTestData
data.Add("sensor.boiler_temp_battery", false);
data.Add("sensor.aquarium_leak_sensor_battery", false);
data.Add("sensor.temperature", false);
data.Add("", false);
data.Add(string.Empty, false);
data.Add(" ", false);
return data;