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
@@ -1,3 +1,5 @@
#region
using System.Globalization;
using HomeAssistant.Entities.Interfaces;
using Microsoft.Extensions.Logging;
@@ -7,6 +9,8 @@ using ShowerMonitorManager.Interface;
using ShowerMonitorManager.Models;
using static ShowerMonitor.Models.ShowerMonitorConsts;
#endregion
namespace ShowerMonitorManager;
public sealed class ShowerMonitorEntityService(
@@ -30,17 +34,18 @@ public sealed class ShowerMonitorEntityService(
cancellationToken.ThrowIfCancellationRequested();
var entities = GetAllEntities();
var createTasks = entities.Select(async entity =>
{
try
{
await entityManager.CreateEntityAsync(entity).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to create MQTT entity: {EntityId}", entity.EntityId);
}
});
{
try
{
await entityManager.CreateEntityAsync(entity).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to create MQTT entity: {EntityId}", entity.EntityId);
}
});
await Task.WhenAll(createTasks).ConfigureAwait(false);
}
@@ -79,6 +84,7 @@ public sealed class ShowerMonitorEntityService(
catch (Exception ex)
{
logger.LogError(ex, "Error cleaning up ShowerMonitor entities");
throw;
}
}
@@ -140,60 +146,76 @@ public sealed class ShowerMonitorEntityService(
private async Task UpdateDifferentialAsync(double differential, string timestamp)
{
await SetEntityStateSafe(DifferentialEntityId,
Math.Round(differential, 1).ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
Math.Round(differential, 1).ToString(CultureInfo.InvariantCulture))
.ConfigureAwait(false);
await SetEntityAttributesSafe(DifferentialEntityId, new
{
unit_of_measurement = "%",
friendly_name = "Bathroom differential humidity",
last_updated = timestamp
}).ConfigureAwait(false);
{
unit_of_measurement = "%",
friendly_name = "Bathroom differential humidity",
last_updated = timestamp
})
.ConfigureAwait(false);
}
private async Task UpdateHumidityRateAsync(double rate, string timestamp)
{
await SetEntityStateSafe(HumidityRateEntityId, Math.Round(rate, 2).ToString(CultureInfo.InvariantCulture))
.ConfigureAwait(false);
.ConfigureAwait(false);
await SetEntityAttributesSafe(HumidityRateEntityId, new
{
unit_of_measurement = "%/min",
friendly_name = "Humidity rate of change",
last_updated = timestamp
}).ConfigureAwait(false);
{
unit_of_measurement = "%/min",
friendly_name = "Humidity rate of change",
last_updated = timestamp
})
.ConfigureAwait(false);
}
private async Task UpdateTodaySessionCountAsync(int count, string timestamp)
{
await SetEntityStateSafe(TodaySessionCountEntityId, count.ToString(CultureInfo.InvariantCulture))
.ConfigureAwait(false);
.ConfigureAwait(false);
await SetEntityAttributesSafe(TodaySessionCountEntityId, new
{
friendly_name = "Showers today",
last_updated = timestamp
}).ConfigureAwait(false);
{
friendly_name = "Showers today",
last_updated = timestamp
})
.ConfigureAwait(false);
}
private async Task UpdateLastShowerAsync(ShowerSession? session, string timestamp)
{
if (session is null) return;
if (session is null)
{
return;
}
var durationSeconds = (int)session.Duration.TotalSeconds;
await SetEntityStateSafe(LastShowerDurationEntityId, durationSeconds.ToString(CultureInfo.InvariantCulture))
.ConfigureAwait(false);
.ConfigureAwait(false);
await SetEntityAttributesSafe(LastShowerDurationEntityId, new
{
formatted = FormatDuration(session.Duration),
peak_humidity = session.PeakHumidity,
friendly_name = "Last shower duration",
last_updated = timestamp
}).ConfigureAwait(false);
{
formatted = FormatDuration(session.Duration),
peak_humidity = session.PeakHumidity,
friendly_name = "Last shower duration",
last_updated = timestamp
})
.ConfigureAwait(false);
await SetEntityStateSafe(LastShowerTimeEntityId,
session.StartTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)).ConfigureAwait(false);
session.StartTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture))
.ConfigureAwait(false);
await SetEntityAttributesSafe(LastShowerTimeEntityId, new
{
friendly_name = "Last shower time",
last_updated = timestamp
}).ConfigureAwait(false);
{
friendly_name = "Last shower time",
last_updated = timestamp
})
.ConfigureAwait(false);
}
private async Task SetEntityStateSafe(string entityId, string state)