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,10 +1,14 @@
|
||||
using HomeAssistant.Entities.Interfaces;
|
||||
#region
|
||||
|
||||
using HomeAssistant.Entities.Interfaces;
|
||||
using HomeAssistant.Models;
|
||||
using HomeAssistantGenerated;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetDaemon.Extensions.MqttEntityManager;
|
||||
using NetDaemon.HassModel;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace HomeAssistant.Entities;
|
||||
|
||||
public class EntityManager(
|
||||
@@ -53,12 +57,14 @@ public class EntityManager(
|
||||
var rootTopic = BuildRootTopic(entityId, mqttConfiguration.Value.DiscoveryPrefix);
|
||||
|
||||
foreach (var suffix in CleanupTopicSuffixes)
|
||||
{
|
||||
haContext.CallService("mqtt", "publish", null, new MqttPublishParameters
|
||||
{
|
||||
Topic = $"{rootTopic}/{suffix}",
|
||||
Payload = string.Empty,
|
||||
Retain = true
|
||||
});
|
||||
}
|
||||
|
||||
// IHaContext.CallService is fire-and-forget; the calls are queued in order on the HA websocket.
|
||||
return Task.CompletedTask;
|
||||
@@ -67,11 +73,12 @@ public class EntityManager(
|
||||
private static string BuildRootTopic(string entityId, string discoveryPrefix)
|
||||
{
|
||||
var separatorIndex = entityId.IndexOf('.');
|
||||
|
||||
if (separatorIndex <= 0 || separatorIndex == entityId.Length - 1)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Entity id '{entityId}' is not in the 'domain.object_id' format.",
|
||||
nameof(entityId));
|
||||
$"Entity id '{entityId}' is not in the 'domain.object_id' format.",
|
||||
nameof(entityId));
|
||||
}
|
||||
|
||||
var domain = entityId[..separatorIndex];
|
||||
|
||||
Reference in New Issue
Block a user