24729ee267
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using HomeAssistant.Models;
|
|
using NetDaemon.Extensions.MqttEntityManager;
|
|
|
|
namespace NordPool.Models;
|
|
|
|
public class NordPoolEntity : EntityCreateModel
|
|
{
|
|
private static readonly object DeviceBlock = new
|
|
{
|
|
identifiers = new[] { NordPoolConsts.DeviceIdentifier },
|
|
name = NordPoolConsts.DeviceName,
|
|
model = NordPoolConsts.DeviceName,
|
|
manufacturer = NordPoolConsts.DeviceManufacturer
|
|
};
|
|
|
|
public NordPoolEntity(string domain, string identifier, string name)
|
|
{
|
|
Domain = domain;
|
|
Identifier = identifier;
|
|
EntityId = $"{Domain}.{Identifier}";
|
|
Name = string.IsNullOrWhiteSpace(name) ? identifier : name;
|
|
|
|
Options = new EntityCreationOptions
|
|
{
|
|
UniqueId = EntityId,
|
|
Name = Name
|
|
};
|
|
|
|
AdditionalConfig = new { device = DeviceBlock };
|
|
}
|
|
|
|
public string Domain { get; }
|
|
public string Identifier { get; }
|
|
public string Name { get; }
|
|
|
|
/// <summary>
|
|
/// Creates an AdditionalConfig that merges custom properties with the NordPool device block.
|
|
/// Use this when an entity needs extra config beyond the default device assignment.
|
|
/// </summary>
|
|
public static object CreateAdditionalConfig(object extraProperties)
|
|
{
|
|
var extras = extraProperties.GetType().GetProperties()
|
|
.ToDictionary(p => p.Name, p => p.GetValue(extraProperties));
|
|
|
|
extras["device"] = DeviceBlock;
|
|
|
|
return extras;
|
|
}
|
|
} |