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
@@ -37,15 +37,63 @@ public class PowerSensorDiscoveryServiceTests
}
private void SetupEntities(
params (string EntityId, string? DeviceClass, string? Unit, string? FriendlyName)[] entities) =>
params (string EntityId, string? DeviceClass, string? Unit, string? FriendlyName)[] entities)
{
_haContextMock
.Setup(h => h.GetAllEntities())
.Returns([.. entities.Select(entity => SetupEntity(entity.EntityId, entity.DeviceClass, entity.Unit, entity.FriendlyName))]);
.Returns([
.. entities.Select(entity =>
SetupEntity(entity.EntityId, entity.DeviceClass, entity.Unit, entity.FriendlyName))
]);
}
private void SetupEntitiesWithoutState(params string[] entityIds) =>
private void SetupEntitiesWithoutState(params string[] entityIds)
{
_haContextMock
.Setup(h => h.GetAllEntities())
.Returns([.. entityIds.Select(entityId => new Entity(_haContextMock.Object, entityId))]);
}
#region ExtractDeviceName
[Theory]
[InlineData("sensor.sonoff_1002230e32_power", "sonoff_1002230e32")]
[InlineData("sensor.sonoff_100215c534_power", "sonoff_100215c534")]
[InlineData("sensor.tv_power", "tv")]
[InlineData("sensor.temp_power", "temp")]
[InlineData("sensor.power", "power")]
[InlineData("sensor.TV_POWER", "TV")]
[InlineData("sensor.boiler_output_power", "boiler_output")]
[InlineData("sensor.temperature", "temperature")]
[InlineData("tv_power", "tv")]
[InlineData("sensor.", "")]
public void ExtractDeviceName_ShouldStripDomainAndPowerSuffix(string entityId, string expected)
{
PowerSensorDiscoveryService.ExtractDeviceName(entityId).Should().Be(expected);
}
#endregion
#region GlobToRegex
[Theory]
[InlineData("sensor.nordpool_*", "sensor.nordpool_current_price", true)]
[InlineData("sensor.nordpool_*", "sensor.tv_power", false)]
[InlineData("sensor.nordpool_*", "SENSOR.NORDPOOL_CURRENT_PRICE", true)]
[InlineData("sensor.powermonitor_*", "sensor.powermonitor_other_power", true)]
[InlineData("*_power", "sensor.sonoff_100215c534_power", true)]
[InlineData("*_power", "sensor.sonoff_100215c534_energy", false)]
[InlineData("sensor.tv_power", "sensor.tv_power", true)]
[InlineData("sensor.tv_power", "sensor.tv_power_2", false)]
[InlineData("sensor.?.power", "sensor.a.power", false)]
[InlineData("*", "anything at all", true)]
public void GlobToRegex_ShouldMatchCorrectly(string glob, string input, bool expected)
{
var regex = PowerSensorDiscoveryService.GlobToRegex(glob);
regex.IsMatch(input).Should().Be(expected);
}
#endregion
#region Discovery
@@ -96,7 +144,7 @@ public class PowerSensorDiscoveryServiceTests
(PowerMonitorTestData.MainMeterEntityId, "power", "W", "Total Home Power Usage"),
("sensor.tv_power", "power", "W", "TV Power"));
var sut = CreateSut(mainMeterEntityId: string.Empty);
var sut = CreateSut(string.Empty);
// Act
var result = sut.DiscoverDeviceSensors();
@@ -271,47 +319,6 @@ public class PowerSensorDiscoveryServiceTests
#endregion
#region ExtractDeviceName
[Theory]
[InlineData("sensor.sonoff_1002230e32_power", "sonoff_1002230e32")]
[InlineData("sensor.sonoff_100215c534_power", "sonoff_100215c534")]
[InlineData("sensor.tv_power", "tv")]
[InlineData("sensor.temp_power", "temp")]
[InlineData("sensor.power", "power")]
[InlineData("sensor.TV_POWER", "TV")]
[InlineData("sensor.boiler_output_power", "boiler_output")]
[InlineData("sensor.temperature", "temperature")]
[InlineData("tv_power", "tv")]
[InlineData("sensor.", "")]
public void ExtractDeviceName_ShouldStripDomainAndPowerSuffix(string entityId, string expected)
{
PowerSensorDiscoveryService.ExtractDeviceName(entityId).Should().Be(expected);
}
#endregion
#region GlobToRegex
[Theory]
[InlineData("sensor.nordpool_*", "sensor.nordpool_current_price", true)]
[InlineData("sensor.nordpool_*", "sensor.tv_power", false)]
[InlineData("sensor.nordpool_*", "SENSOR.NORDPOOL_CURRENT_PRICE", true)]
[InlineData("sensor.powermonitor_*", "sensor.powermonitor_other_power", true)]
[InlineData("*_power", "sensor.sonoff_100215c534_power", true)]
[InlineData("*_power", "sensor.sonoff_100215c534_energy", false)]
[InlineData("sensor.tv_power", "sensor.tv_power", true)]
[InlineData("sensor.tv_power", "sensor.tv_power_2", false)]
[InlineData("sensor.?.power", "sensor.a.power", false)]
[InlineData("*", "anything at all", true)]
public void GlobToRegex_ShouldMatchCorrectly(string glob, string input, bool expected)
{
var regex = PowerSensorDiscoveryService.GlobToRegex(glob);
regex.IsMatch(input).Should().Be(expected);
}
#endregion
#region IsPowerSensor
[Theory]
@@ -359,4 +366,4 @@ public class PowerSensorDiscoveryServiceTests
}
#endregion
}
}