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:
@@ -1,3 +1,5 @@
|
||||
#region
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
@@ -13,6 +15,8 @@ using NordPoolManager.Interface;
|
||||
using PowerMonitorManager.Interface;
|
||||
using ShowerMonitorManager.Interface;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace HomeAssistantServer;
|
||||
|
||||
[NetDaemonApp]
|
||||
@@ -50,23 +54,24 @@ public sealed class MqttRecreateApp
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
|
||||
await _mqttEntityManager.CreateAsync(
|
||||
RecreateButtonEntityId,
|
||||
new EntityCreationOptions
|
||||
{
|
||||
UniqueId = RecreateButtonEntityId,
|
||||
Name = "Recreate all MQTT entities"
|
||||
},
|
||||
new
|
||||
{
|
||||
icon = "mdi:refresh",
|
||||
device = new
|
||||
{
|
||||
identifiers = AppDaemonIdentifiers,
|
||||
name = "AppDaemon",
|
||||
model = "AppDaemon",
|
||||
manufacturer = "HomeAssistant App Daemon"
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
RecreateButtonEntityId,
|
||||
new EntityCreationOptions
|
||||
{
|
||||
UniqueId = RecreateButtonEntityId,
|
||||
Name = "Recreate all MQTT entities"
|
||||
},
|
||||
new
|
||||
{
|
||||
icon = "mdi:refresh",
|
||||
device = new
|
||||
{
|
||||
identifiers = AppDaemonIdentifiers,
|
||||
name = "AppDaemon",
|
||||
model = "AppDaemon",
|
||||
manufacturer = "HomeAssistant App Daemon"
|
||||
}
|
||||
})
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
@@ -74,12 +79,13 @@ public sealed class MqttRecreateApp
|
||||
}
|
||||
|
||||
var button = new Entity(_haContext, RecreateButtonEntityId);
|
||||
|
||||
button.StateChanges()
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
_logger.LogInformation("Recreate-all button pressed, recreating all MQTT entities");
|
||||
Task.Run(HandleRecreateAsync);
|
||||
});
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
_logger.LogInformation("Recreate-all button pressed, recreating all MQTT entities");
|
||||
Task.Run(HandleRecreateAsync);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -107,9 +113,11 @@ public sealed class MqttRecreateApp
|
||||
private async Task RecreateNordPoolAsync()
|
||||
{
|
||||
var entityService = _serviceProvider.GetService<INordPoolEntityService>();
|
||||
|
||||
if (entityService is null)
|
||||
{
|
||||
_logger.LogDebug("NordPool entity service not registered (disabled), skipping");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,9 +140,11 @@ public sealed class MqttRecreateApp
|
||||
private async Task RecreateBoilerMonitorAsync()
|
||||
{
|
||||
var entityService = _serviceProvider.GetService<IBoilerMonitorEntityService>();
|
||||
|
||||
if (entityService is null)
|
||||
{
|
||||
_logger.LogDebug("BoilerMonitor entity service not registered (disabled), skipping");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,9 +165,11 @@ public sealed class MqttRecreateApp
|
||||
private async Task RecreateShowerMonitorAsync()
|
||||
{
|
||||
var entityService = _serviceProvider.GetService<IShowerMonitorEntityService>();
|
||||
|
||||
if (entityService is null)
|
||||
{
|
||||
_logger.LogDebug("ShowerMonitor entity service not registered (disabled), skipping");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -177,9 +189,11 @@ public sealed class MqttRecreateApp
|
||||
private async Task RecreatePowerMonitorAsync()
|
||||
{
|
||||
var entityService = _serviceProvider.GetService<IPowerMonitorEntityService>();
|
||||
|
||||
if (entityService is null)
|
||||
{
|
||||
_logger.LogDebug("PowerMonitor entity service not registered (disabled), skipping");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,14 +216,13 @@ public sealed class MqttRecreateApp
|
||||
try
|
||||
{
|
||||
var state = _haContext.GetState(NordPoolPriceEntityId);
|
||||
|
||||
if (state?.Attributes is IDictionary<string, object> attributes &&
|
||||
attributes.TryGetValue("unit_of_measurement", out var value))
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
string s => s,
|
||||
JsonElement { ValueKind: JsonValueKind.String } je => je.GetString(),
|
||||
_ => null
|
||||
string s => s, JsonElement { ValueKind: JsonValueKind.String } je => je.GetString(), _ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user