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:
2026-12-01 12:33:31 +02:00
parent 77458383d1
commit f919d6b25b
115 changed files with 3115 additions and 1959 deletions
+20 -13
View File
@@ -1,3 +1,5 @@
#region
using LeakMonitor.Models;
using LeakMonitorManager.Interface;
using LeakMonitorManager.Models;
@@ -7,6 +9,8 @@ using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Entities;
#endregion
namespace LeakMonitorManager;
[NetDaemonApp]
@@ -42,12 +46,15 @@ public sealed class LeakMonitorInit
return Task.CompletedTask;
}
foreach (var sensorEntityId in _options.SensorEntityIds) SubscribeToLeakSensor(sensorEntityId);
foreach (var sensorEntityId in _options.SensorEntityIds)
{
SubscribeToLeakSensor(sensorEntityId);
}
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("LeakMonitor initialized, monitoring {Count} sensor(s)",
_options.SensorEntityIds.Length);
_options.SensorEntityIds.Length);
}
}
catch (Exception ex)
@@ -63,17 +70,17 @@ public sealed class LeakMonitorInit
var entity = new Entity(_haContext, sensorEntityId);
entity.StateChanges()
.Subscribe(change =>
{
try
{
HandleStateChange(sensorEntityId, change);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error handling state change for {SensorId}", sensorEntityId);
}
});
.Subscribe(change =>
{
try
{
HandleStateChange(sensorEntityId, change);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error handling state change for {SensorId}", sensorEntityId);
}
});
if (_logger.IsEnabled(LogLevel.Information))
{
@@ -1,9 +1,13 @@
#region
using LeakMonitorManager.Interface;
using LeakMonitorManager.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetDaemon.AppModel;
#endregion
namespace LeakMonitorManager;
public static class LeakMonitorServiceRegistration
@@ -11,10 +15,14 @@ public static class LeakMonitorServiceRegistration
public static void AddLeakMonitor(this IServiceCollection services, IConfiguration configuration)
{
var options = configuration
.GetSection(LeakMonitorOptions.SectionName)
.Get<LeakMonitorOptions>() ?? new LeakMonitorOptions();
.GetSection(LeakMonitorOptions.SectionName)
.Get<LeakMonitorOptions>() ??
new LeakMonitorOptions();
if (!options.Enabled) return;
if (!options.Enabled)
{
return;
}
services.AddNetDaemonApp<LeakMonitorInit>().AddScoped<ILeakNotificationService, LeakNotificationService>();
}
+42 -33
View File
@@ -1,3 +1,5 @@
#region
using System.Collections.Concurrent;
using LeakMonitor.Models;
using LeakMonitorManager.Interface;
@@ -6,6 +8,8 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetDaemon.HassModel;
#endregion
namespace LeakMonitorManager;
public sealed class LeakNotificationService(
@@ -14,7 +18,7 @@ public sealed class LeakNotificationService(
IOptions<LeakMonitorOptions> options,
TimeProvider timeProvider) : ILeakNotificationService
{
private readonly ConcurrentDictionary<string, DateTimeOffset> _lastNotificationTimes = new();
private readonly ConcurrentDictionary<string, DateTimeOffset> _lastNotificationTimes = new ConcurrentDictionary<string, DateTimeOffset>();
private readonly LeakMonitorOptions _options = options.Value;
public void SendLeakAlert(string sensorEntityId)
@@ -24,8 +28,8 @@ public sealed class LeakNotificationService(
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug(
"Skipping leak notification for {SensorId} -- within cooldown period",
sensorEntityId);
"Skipping leak notification for {SensorId} -- within cooldown period",
sensorEntityId);
}
return;
@@ -47,9 +51,9 @@ public sealed class LeakNotificationService(
var notificationId = BuildNotificationId(sensorEntityId);
haContext.CallService(
LeakMonitorConsts.PersistentNotificationDomain,
LeakMonitorConsts.PersistentNotificationDismissService,
data: new { notification_id = notificationId });
LeakMonitorConsts.PersistentNotificationDomain,
LeakMonitorConsts.PersistentNotificationDismissService,
data: new { notification_id = notificationId });
if (logger.IsEnabled(LogLevel.Information))
{
@@ -60,50 +64,55 @@ public sealed class LeakNotificationService(
private void SendMobilePushNotification(string message)
{
haContext.CallService(
LeakMonitorConsts.NotifyDomain,
LeakMonitorConsts.MobileAppService,
data: new
{
message,
title = LeakMonitorConsts.NotificationTitle,
data = new
{
push = new
{
sound = new
{
critical = 1,
volume = 1.0
}
}
}
});
LeakMonitorConsts.NotifyDomain,
LeakMonitorConsts.MobileAppService,
data: new
{
message,
title = LeakMonitorConsts.NotificationTitle,
data = new
{
push = new
{
sound = new
{
critical = 1,
volume = 1.0
}
}
}
});
}
private void CreatePersistentNotification(string notificationId, string message)
{
haContext.CallService(
LeakMonitorConsts.PersistentNotificationDomain,
LeakMonitorConsts.PersistentNotificationCreateService,
data: new
{
title = LeakMonitorConsts.NotificationTitle,
message,
notification_id = notificationId
});
LeakMonitorConsts.PersistentNotificationDomain,
LeakMonitorConsts.PersistentNotificationCreateService,
data: new
{
title = LeakMonitorConsts.NotificationTitle,
message,
notification_id = notificationId
});
}
private bool IsWithinCooldown(string sensorEntityId)
{
if (!_lastNotificationTimes.TryGetValue(sensorEntityId, out var lastTime)) return false;
if (!_lastNotificationTimes.TryGetValue(sensorEntityId, out var lastTime))
{
return false;
}
var cooldown = TimeSpan.FromMinutes(_options.NotificationCooldownMinutes);
return timeProvider.GetUtcNow() - lastTime < cooldown;
}
internal static string BuildNotificationId(string sensorEntityId)
{
var sanitized = sensorEntityId.Replace('.', '_');
return $"{LeakMonitorConsts.NotificationIdPrefix}{sanitized}";
}
}
@@ -1,5 +1,9 @@
#region
using LeakMonitor.Models;
#endregion
namespace LeakMonitorManager.Models;
public sealed class LeakMonitorOptions