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,10 +1,10 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using BatteryMonitor.Models;
|
||||
using BatteryMonitorManager.Interface;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetDaemon.HassModel;
|
||||
using NetDaemon.HassModel.Entities;
|
||||
using BatteryMonitor.Models;
|
||||
using BatteryMonitorManager.Interface;
|
||||
|
||||
namespace BatteryMonitorManager;
|
||||
|
||||
@@ -24,11 +24,9 @@ public sealed class BatterySensorDiscoveryService(
|
||||
.ToList();
|
||||
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation(
|
||||
"Battery check: found {Count} sensors below {Threshold}%",
|
||||
lowBatterySensors.Count, thresholdPercent);
|
||||
}
|
||||
|
||||
return lowBatterySensors!;
|
||||
}
|
||||
@@ -36,9 +34,7 @@ public sealed class BatterySensorDiscoveryService(
|
||||
internal static bool IsBatterySensor(Entity entity)
|
||||
{
|
||||
if (!entity.EntityId.StartsWith(BatteryMonitorConsts.SensorDomainPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var deviceClass = GetJsonStringProperty(entity.EntityState?.AttributesJson, "device_class");
|
||||
|
||||
@@ -60,9 +56,8 @@ public sealed class BatterySensorDiscoveryService(
|
||||
if (state is null or "unavailable" or "unknown")
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.LogDebug("Skipping battery sensor {EntityId}: state is {State}", entity.EntityId, state ?? "null");
|
||||
}
|
||||
logger.LogDebug("Skipping battery sensor {EntityId}: state is {State}", entity.EntityId,
|
||||
state ?? "null");
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -70,17 +65,13 @@ public sealed class BatterySensorDiscoveryService(
|
||||
if (!double.TryParse(state, CultureInfo.InvariantCulture, out var batteryLevel))
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.LogDebug("Skipping battery sensor {EntityId}: unable to parse state '{State}'", entity.EntityId, state);
|
||||
}
|
||||
logger.LogDebug("Skipping battery sensor {EntityId}: unable to parse state '{State}'", entity.EntityId,
|
||||
state);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (batteryLevel >= thresholdPercent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (batteryLevel >= thresholdPercent) return null;
|
||||
|
||||
var friendlyName = GetJsonStringProperty(entity.EntityState?.AttributesJson, "friendly_name")
|
||||
?? entity.EntityId;
|
||||
@@ -95,13 +86,10 @@ public sealed class BatterySensorDiscoveryService(
|
||||
|
||||
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()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user