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
+33 -20
View File
@@ -1,3 +1,5 @@
#region
using System.Globalization;
using System.Reactive.Concurrency;
using Microsoft.Extensions.Logging;
@@ -10,6 +12,8 @@ using ShowerMonitorManager.Interface;
using ShowerMonitorManager.Models;
using static ShowerMonitor.Models.ShowerMonitorConsts;
#endregion
namespace ShowerMonitorManager;
[NetDaemonApp]
@@ -69,7 +73,10 @@ public sealed class ShowerMonitorInit
{
await Task.Delay(TimeSpan.FromSeconds(3));
if (_options.CleanupEntitiesOnStartup) await _entityService.CleanupEntitiesAsync();
if (_options.CleanupEntitiesOnStartup)
{
await _entityService.CleanupEntitiesAsync();
}
await _entityService.CreateEntitiesAsync();
@@ -81,6 +88,7 @@ public sealed class ShowerMonitorInit
catch (Exception ex)
{
_logger.LogError(ex, "Error initializing ShowerMonitor");
throw;
}
}
@@ -99,28 +107,29 @@ public sealed class ShowerMonitorInit
private void ScheduleMidnightReset()
{
_scheduler.ScheduleCron("0 0 * * *", () =>
{
try
{
_logger.LogDebug("Midnight reset: clearing shower session counters");
_detectionService.ResetDailyCounters();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during midnight reset");
}
});
{
try
{
_logger.LogDebug("Midnight reset: clearing shower session counters");
_detectionService.ResetDailyCounters();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during midnight reset");
}
});
}
private void SubscribeToCleanupButton()
{
var cleanupButton = new Entity(_haContext, CleanupButtonEntityId);
cleanupButton.StateChanges()
.Subscribe(_ =>
{
_logger.LogDebug("Cleanup button pressed, removing all ShowerMonitor entities");
Task.Run(HandleCleanupAsync);
});
.Subscribe(_ =>
{
_logger.LogDebug("Cleanup button pressed, removing all ShowerMonitor entities");
Task.Run(HandleCleanupAsync);
});
}
private async Task HandleCleanupAsync()
@@ -144,6 +153,7 @@ public sealed class ShowerMonitorInit
if (_cleanedUp)
{
_logger.LogDebug("ShowerMonitor is cleaned up, skipping poll");
return;
}
@@ -157,7 +167,7 @@ public sealed class ShowerMonitorInit
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("Humidity sensor data unavailable (bathroom={Bathroom}, home={Home})",
bathroomHumidity, mainHomeHumidity);
bathroomHumidity, mainHomeHumidity);
}
return;
@@ -183,7 +193,7 @@ public sealed class ShowerMonitorInit
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("Poll: bathroom={Bath}%, home={Home}%, diff={Diff}%, state={State}",
bathroomHumidity.Value, mainHomeHumidity.Value, Math.Round(differential, 1), state);
bathroomHumidity.Value, mainHomeHumidity.Value, Math.Round(differential, 1), state);
}
}
catch (Exception ex)
@@ -196,7 +206,10 @@ public sealed class ShowerMonitorInit
{
var state = _haContext.GetState(entityId);
if (state?.State is null or "unavailable" or "unknown") return null;
if (state?.State is null or "unavailable" or "unknown")
{
return null;
}
return double.TryParse(state.State, CultureInfo.InvariantCulture, out var value) ? value : null;
}