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:
@@ -1,11 +1,11 @@
|
||||
using System.Globalization;
|
||||
using BatteryMonitor.Models;
|
||||
using BatteryMonitorManager;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NetDaemon.HassModel;
|
||||
using NetDaemon.HassModel.Entities;
|
||||
using BatteryMonitor.Models;
|
||||
using BatteryMonitorManager;
|
||||
using static BatteryMonitor.Manager.Tests.BatteryMonitorTestData;
|
||||
|
||||
namespace BatteryMonitor.Manager.Tests;
|
||||
@@ -25,6 +25,17 @@ public class BatterySensorDiscoveryServiceTests
|
||||
ConfigureHaContext(_haContextMock, entities);
|
||||
}
|
||||
|
||||
#region IsExcludedDevice
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ExcludedEntityIdRows), MemberType = typeof(BatteryMonitorTestData))]
|
||||
public void IsExcludedDevice_ShouldCorrectlyIdentifyExclusions(string entityId, bool expected)
|
||||
{
|
||||
BatterySensorDiscoveryService.IsExcludedDevice(entityId).Should().Be(expected);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Discovery
|
||||
|
||||
[Fact]
|
||||
@@ -77,7 +88,8 @@ public class BatterySensorDiscoveryServiceTests
|
||||
[InlineData("sensor.no_device_class", null)]
|
||||
[InlineData("sensorx.bathroom_battery", "battery")]
|
||||
[InlineData("switch.bathroom_battery", "battery")]
|
||||
public void DiscoverLowBatterySensors_ShouldIgnoreEntitiesThatAreNotBatterySensors(string entityId, string? deviceClass)
|
||||
public void DiscoverLowBatterySensors_ShouldIgnoreEntitiesThatAreNotBatterySensors(string entityId,
|
||||
string? deviceClass)
|
||||
{
|
||||
SetupEntities(
|
||||
Sensor(entityId, deviceClass, "2", "Ignored Entity"),
|
||||
@@ -111,7 +123,8 @@ public class BatterySensorDiscoveryServiceTests
|
||||
public void DiscoverLowBatterySensors_WhenEntityStateIsNull_ShouldSkipSensor()
|
||||
{
|
||||
SetupEntities(
|
||||
new EntitySpec { EntityId = "sensor.bathroom_battery", FriendlyName = "Bathroom Battery", HasState = false },
|
||||
new EntitySpec
|
||||
{ EntityId = "sensor.bathroom_battery", FriendlyName = "Bathroom Battery", HasState = false },
|
||||
Battery("sensor.bedroom_battery", "3", "Bedroom Battery")
|
||||
);
|
||||
|
||||
@@ -124,7 +137,8 @@ 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"));
|
||||
|
||||
@@ -133,10 +147,7 @@ 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));
|
||||
@@ -239,7 +250,8 @@ 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
|
||||
@@ -279,15 +291,4 @@ public class BatterySensorDiscoveryServiceTests
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsExcludedDevice
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ExcludedEntityIdRows), MemberType = typeof(BatteryMonitorTestData))]
|
||||
public void IsExcludedDevice_ShouldCorrectlyIdentifyExclusions(string entityId, bool expected)
|
||||
{
|
||||
BatterySensorDiscoveryService.IsExcludedDevice(entityId).Should().Be(expected);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user