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
@@ -13,15 +13,13 @@ namespace PowerMonitorManager;
public sealed class PowerSensorDiscoveryService : IPowerSensorDiscoveryService
{
private readonly IHaContext _haContext;
private readonly PowerMonitorOptions _options;
private readonly ILogger<PowerSensorDiscoveryService> _logger;
private readonly Regex[] _exclusionPatterns;
private readonly IHaContext _haContext;
private readonly ILogger<PowerSensorDiscoveryService> _logger;
private readonly PowerMonitorOptions _options;
private volatile IReadOnlyList<PowerSensorInfo> _currentDeviceSensors = [];
public IReadOnlyList<PowerSensorInfo> CurrentDeviceSensors => _currentDeviceSensors;
public PowerSensorDiscoveryService(
IHaContext haContext,
IOptions<PowerMonitorOptions> options,
@@ -33,6 +31,8 @@ public sealed class PowerSensorDiscoveryService : IPowerSensorDiscoveryService
_exclusionPatterns = [.. _options.ExcludedSensorPatterns.Select(GlobToRegex)];
}
public IReadOnlyList<PowerSensorInfo> CurrentDeviceSensors => _currentDeviceSensors;
public IReadOnlyList<PowerSensorInfo> DiscoverDeviceSensors()
{
var allEntities = _haContext.GetAllEntities();
@@ -53,26 +53,19 @@ public sealed class PowerSensorDiscoveryService : IPowerSensorDiscoveryService
_currentDeviceSensors = powerSensors;
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Discovered {Count} power sensors (excluded main meter: {MainMeter}, exclusion patterns: {PatternCount})",
_logger.LogInformation(
"Discovered {Count} power sensors (excluded main meter: {MainMeter}, exclusion patterns: {PatternCount})",
powerSensors.Count, _options.MainMeterEntityId, _exclusionPatterns.Length);
}
return powerSensors;
}
internal static bool IsPowerSensor(Entity entity)
{
if (!entity.EntityId.StartsWith("sensor.", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (!entity.EntityId.StartsWith("sensor.", StringComparison.OrdinalIgnoreCase)) return false;
var attributes = entity.EntityState?.AttributesJson;
if (attributes is null)
{
return false;
}
if (attributes is null) return false;
var deviceClass = GetJsonStringProperty(attributes.Value, "device_class");
var unit = GetJsonStringProperty(attributes.Value, "unit_of_measurement");
@@ -117,10 +110,7 @@ public sealed class PowerSensorDiscoveryService : IPowerSensorDiscoveryService
private static string? GetJsonStringProperty(JsonElement? element, string propertyName)
{
if (element is null)
{
return null;
}
if (element is null) return null;
return element.Value.TryGetProperty(propertyName, out var value)
? value.GetString()
@@ -132,4 +122,4 @@ public sealed class PowerSensorDiscoveryService : IPowerSensorDiscoveryService
var regexPattern = "^" + Regex.Escape(globPattern).Replace("\\*", ".*") + "$";
return new Regex(regexPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
}
}