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
@@ -3,4 +3,4 @@ namespace LightMonitorManager.Interface;
public interface ILightControlService
{
void TurnOnLight();
}
}
@@ -3,4 +3,4 @@ namespace LightMonitorManager.Interface;
public interface IPresenceService
{
bool IsAnyoneHome();
}
}
+3 -9
View File
@@ -1,9 +1,9 @@
using LightMonitor.Models;
using LightMonitorManager.Interface;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Entities;
using LightMonitor.Models;
using LightMonitorManager.Interface;
namespace LightMonitorManager;
@@ -22,9 +22,7 @@ public sealed class LightControlService(
if (!string.Equals(sunState, LightMonitorConsts.SunBelowHorizon, StringComparison.OrdinalIgnoreCase))
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Sun is not below horizon (state={SunState}), skipping light turn on", sunState);
}
return;
}
@@ -34,9 +32,7 @@ public sealed class LightControlService(
if (string.Equals(lightState, LightMonitorConsts.LightOnState, StringComparison.OrdinalIgnoreCase))
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Light {EntityId} is already on, skipping", _options.LightEntityId);
}
return;
}
@@ -44,8 +40,6 @@ public sealed class LightControlService(
haContext.CallService("light", "turn_on", ServiceTarget.FromEntity(_options.LightEntityId));
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Light {EntityId} turned ON (dark outside + person home)", _options.LightEntityId);
}
}
}
}
@@ -8,19 +8,19 @@
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>LightMonitor.Manager.Tests</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>LightMonitor.Manager.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HomeAssistant.Entities\HomeAssistant.Entities.csproj" />
<ProjectReference Include="..\LightMonitor.Models\LightMonitor.Models.csproj" />
<ProjectReference Include="..\HomeAssistant.Entities\HomeAssistant.Entities.csproj"/>
<ProjectReference Include="..\LightMonitor.Models\LightMonitor.Models.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="11.0.0" />
<PackageReference Include="NetDaemon.HassModel" Version="26.43.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="11.0.0"/>
<PackageReference Include="NetDaemon.HassModel" Version="26.43.1"/>
</ItemGroup>
</Project>
+20 -29
View File
@@ -1,10 +1,10 @@
using LightMonitor.Models;
using LightMonitorManager.Interface;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Entities;
using LightMonitor.Models;
using LightMonitorManager.Interface;
namespace LightMonitorManager;
@@ -12,10 +12,10 @@ namespace LightMonitorManager;
public sealed class LightMonitorInit
{
private readonly IHaContext _haContext;
private readonly ILogger<LightMonitorInit> _logger;
private readonly IPresenceService _presenceService;
private readonly ILightControlService _lightControlService;
private readonly ILogger<LightMonitorInit> _logger;
private readonly LightMonitorOptions _options;
private readonly IPresenceService _presenceService;
public LightMonitorInit(
IHaContext haContext,
@@ -41,9 +41,8 @@ public sealed class LightMonitorInit
SubscribeToPersonStateChanges();
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("LightMonitor initialized with {PersonCount} tracked persons", _options.PersonEntityIds.Length);
}
_logger.LogInformation("LightMonitor initialized with {PersonCount} tracked persons",
_options.PersonEntityIds.Length);
}
catch (Exception ex)
{
@@ -61,27 +60,20 @@ public sealed class LightMonitorInit
{
try
{
if (!string.Equals(e.New?.State, LightMonitorConsts.SunBelowHorizon, StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!string.Equals(e.New?.State, LightMonitorConsts.SunBelowHorizon,
StringComparison.OrdinalIgnoreCase)) return;
if (IsRecoveryTransition(e.Old?.State))
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Sun state recovered from {OldState}, ignoring", e.Old?.State);
}
return;
}
_logger.LogInformation("Sun went below horizon, checking if anyone is home");
if (_presenceService.IsAnyoneHome())
{
_lightControlService.TurnOnLight();
}
if (_presenceService.IsAnyoneHome()) _lightControlService.TurnOnLight();
}
catch (Exception ex)
{
@@ -100,25 +92,21 @@ public sealed class LightMonitorInit
{
try
{
if (!string.Equals(e.New?.State, LightMonitorConsts.PersonHomeState, StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!string.Equals(e.New?.State, LightMonitorConsts.PersonHomeState,
StringComparison.OrdinalIgnoreCase)) return;
if (IsRecoveryTransition(e.Old?.State))
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Person {EntityId} state recovered from {OldState}, ignoring", personEntityId, e.Old?.State);
}
_logger.LogInformation("Person {EntityId} state recovered from {OldState}, ignoring",
personEntityId, e.Old?.State);
return;
}
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Person {EntityId} arrived home, checking if it is dark", personEntityId);
}
_logger.LogInformation("Person {EntityId} arrived home, checking if it is dark",
personEntityId);
_lightControlService.TurnOnLight();
}
@@ -130,5 +118,8 @@ public sealed class LightMonitorInit
}
}
private static bool IsRecoveryTransition(string? oldState) => oldState is null or LightMonitorConsts.UnavailableState or LightMonitorConsts.UnknownState;
}
private static bool IsRecoveryTransition(string? oldState)
{
return oldState is null or LightMonitorConsts.UnavailableState or LightMonitorConsts.UnknownState;
}
}
@@ -1,8 +1,8 @@
using LightMonitor.Models;
using LightMonitorManager.Interface;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetDaemon.AppModel;
using LightMonitorManager.Interface;
namespace LightMonitorManager;
@@ -14,15 +14,12 @@ public static class LightMonitorServiceRegistration
.GetSection(LightMonitorOptions.SectionName)
.Get<LightMonitorOptions>() ?? new LightMonitorOptions();
if (!options.Enabled)
{
return services;
}
if (!options.Enabled) return services;
services.AddNetDaemonApp<LightMonitorInit>()
.AddScoped<IPresenceService, PresenceService>()
.AddScoped<ILightControlService, LightControlService>();
.AddScoped<IPresenceService, PresenceService>()
.AddScoped<ILightControlService, LightControlService>();
return services;
}
}
}
+9 -16
View File
@@ -1,15 +1,15 @@
using LightMonitor.Models;
using LightMonitorManager.Interface;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetDaemon.HassModel;
using LightMonitor.Models;
using LightMonitorManager.Interface;
namespace LightMonitorManager;
public sealed class PresenceService(
IHaContext haContext,
ILogger<PresenceService> logger,
IOptions<LightMonitorOptions> options) : IPresenceService
IHaContext haContext,
ILogger<PresenceService> logger,
IOptions<LightMonitorOptions> options) : IPresenceService
{
private readonly LightMonitorOptions _options = options.Value;
@@ -20,23 +20,16 @@ public sealed class PresenceService(
var state = haContext.GetState(personEntityId);
if (state?.State is null or LightMonitorConsts.UnavailableState or LightMonitorConsts.UnknownState)
{
continue;
}
if (!string.Equals(state.State, LightMonitorConsts.PersonHomeState, StringComparison.OrdinalIgnoreCase))
{
continue;
}
if (!string.Equals(state.State, LightMonitorConsts.PersonHomeState,
StringComparison.OrdinalIgnoreCase)) continue;
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Person {EntityId} is home", personEntityId);
}
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("Person {EntityId} is home", personEntityId);
return true;
}
return false;
}
}
}