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:
@@ -1,3 +1,5 @@
|
||||
#region
|
||||
|
||||
using System.Globalization;
|
||||
using BatteryMonitor.Models;
|
||||
using BatteryMonitorManager;
|
||||
@@ -8,12 +10,14 @@ using NetDaemon.HassModel;
|
||||
using NetDaemon.HassModel.Entities;
|
||||
using static BatteryMonitor.Manager.Tests.BatteryMonitorTestData;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace BatteryMonitor.Manager.Tests;
|
||||
|
||||
public class BatterySensorDiscoveryServiceTests
|
||||
{
|
||||
private readonly Mock<IHaContext> _haContextMock = new();
|
||||
private readonly Mock<ILogger<BatterySensorDiscoveryService>> _loggerMock = new();
|
||||
private readonly Mock<IHaContext> _haContextMock = new Mock<IHaContext>();
|
||||
private readonly Mock<ILogger<BatterySensorDiscoveryService>> _loggerMock = new Mock<ILogger<BatterySensorDiscoveryService>>();
|
||||
|
||||
private BatterySensorDiscoveryService CreateSut()
|
||||
{
|
||||
@@ -42,10 +46,10 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_ShouldFindLowBatteryDevices()
|
||||
{
|
||||
SetupEntities(
|
||||
Battery("sensor.bathroom_battery", "3", "Bathroom Battery"),
|
||||
Battery("sensor.bedroom_battery", "80", "Bedroom Battery"),
|
||||
Battery("sensor.boiler_temp_battery", "2", "Boiler Temp Battery")
|
||||
);
|
||||
Battery("sensor.bathroom_battery", "3", "Bathroom Battery"),
|
||||
Battery("sensor.bedroom_battery", "80", "Bedroom Battery"),
|
||||
Battery("sensor.boiler_temp_battery", "2", "Boiler Temp Battery")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -70,9 +74,9 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_ShouldExcludePersonalDevices(string excludedEntityId, string friendlyName)
|
||||
{
|
||||
SetupEntities(
|
||||
Battery("sensor.bathroom_battery", "2", "Bathroom Battery"),
|
||||
Battery(excludedEntityId, "1", friendlyName)
|
||||
);
|
||||
Battery("sensor.bathroom_battery", "2", "Bathroom Battery"),
|
||||
Battery(excludedEntityId, "1", friendlyName)
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -89,12 +93,12 @@ public class BatterySensorDiscoveryServiceTests
|
||||
[InlineData("sensorx.bathroom_battery", "battery")]
|
||||
[InlineData("switch.bathroom_battery", "battery")]
|
||||
public void DiscoverLowBatterySensors_ShouldIgnoreEntitiesThatAreNotBatterySensors(string entityId,
|
||||
string? deviceClass)
|
||||
string? deviceClass)
|
||||
{
|
||||
SetupEntities(
|
||||
Sensor(entityId, deviceClass, "2", "Ignored Entity"),
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
Sensor(entityId, deviceClass, "2", "Ignored Entity"),
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -108,9 +112,9 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_ShouldSkipUnusableStates(string? state)
|
||||
{
|
||||
SetupEntities(
|
||||
Battery("sensor.bathroom_battery", state, "Bathroom Battery"),
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
Battery("sensor.bathroom_battery", state, "Bathroom Battery"),
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -123,10 +127,10 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_WhenEntityStateIsNull_ShouldSkipSensor()
|
||||
{
|
||||
SetupEntities(
|
||||
new EntitySpec
|
||||
{ EntityId = "sensor.bathroom_battery", FriendlyName = "Bathroom Battery", HasState = false },
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
new EntitySpec
|
||||
{ EntityId = "sensor.bathroom_battery", FriendlyName = "Bathroom Battery", HasState = false },
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -137,8 +141,9 @@ public class BatterySensorDiscoveryServiceTests
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ThresholdBoundaryRows), MemberType = typeof(BatteryMonitorTestData))]
|
||||
public void DiscoverLowBatterySensors_ShouldApplyStrictThresholdBoundary(int thresholdPercent, string state,
|
||||
bool expectedIncluded)
|
||||
public void DiscoverLowBatterySensors_ShouldApplyStrictThresholdBoundary(int thresholdPercent,
|
||||
string state,
|
||||
bool expectedIncluded)
|
||||
{
|
||||
SetupEntities(Battery("sensor.boundary_battery", state, "Boundary Battery"));
|
||||
|
||||
@@ -147,7 +152,10 @@ public class BatterySensorDiscoveryServiceTests
|
||||
|
||||
result.Should().HaveCount(expectedIncluded ? 1 : 0);
|
||||
|
||||
if (!expectedIncluded) return;
|
||||
if (!expectedIncluded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
result[0].EntityId.Should().Be("sensor.boundary_battery");
|
||||
result[0].BatteryLevel.Should().Be(double.Parse(state, CultureInfo.InvariantCulture));
|
||||
@@ -157,9 +165,9 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_WhenNoBatterySensors_ShouldReturnEmpty()
|
||||
{
|
||||
SetupEntities(
|
||||
Sensor("sensor.temperature", "temperature", "22", "Temperature"),
|
||||
Sensor("switch.some_switch", null, "on", "Switch")
|
||||
);
|
||||
Sensor("sensor.temperature", "temperature", "22", "Temperature"),
|
||||
Sensor("switch.some_switch", null, "on", "Switch")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -171,10 +179,10 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_WhenAllAboveThreshold_ShouldReturnEmpty()
|
||||
{
|
||||
SetupEntities(
|
||||
Battery("sensor.bathroom_battery", "5", "Bathroom Battery"),
|
||||
Battery("sensor.bedroom_battery", "50", "Bedroom Battery"),
|
||||
Battery("sensor.boiler_temp_battery", "100", "Boiler Temp Battery")
|
||||
);
|
||||
Battery("sensor.bathroom_battery", "5", "Bathroom Battery"),
|
||||
Battery("sensor.bedroom_battery", "50", "Bedroom Battery"),
|
||||
Battery("sensor.boiler_temp_battery", "100", "Boiler Temp Battery")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -198,9 +206,9 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_WithDuplicateSensorIds_ShouldReportEachOccurrence()
|
||||
{
|
||||
SetupEntities(
|
||||
Battery("sensor.duplicate_battery", "2", "Duplicate Battery"),
|
||||
Battery("sensor.duplicate_battery", "2", "Duplicate Battery")
|
||||
);
|
||||
Battery("sensor.duplicate_battery", "2", "Duplicate Battery"),
|
||||
Battery("sensor.duplicate_battery", "2", "Duplicate Battery")
|
||||
);
|
||||
|
||||
var sut = CreateSut();
|
||||
var result = sut.DiscoverLowBatterySensors(BatteryMonitorConsts.DefaultBatteryThresholdPercent);
|
||||
@@ -250,8 +258,10 @@ public class BatterySensorDiscoveryServiceTests
|
||||
|
||||
result.Should().HaveCount(7);
|
||||
result.Select(s => s.BatteryLevel).Should().Equal(Enumerable.Range(0, 7).Select(i => (double)i));
|
||||
result.Select(s => s.FriendlyName).Should()
|
||||
.OnlyContain(name => name.StartsWith("Generated Battery", StringComparison.Ordinal));
|
||||
|
||||
result.Select(s => s.FriendlyName)
|
||||
.Should()
|
||||
.OnlyContain(name => name.StartsWith("Generated Battery", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user