36 lines
852 B
C#
36 lines
852 B
C#
using System.Text.Json.Nodes;
|
|
|
|
namespace InnovEnergy.Lib.StatusApi;
|
|
|
|
|
|
public record AcDevice : IAcDevice
|
|
{
|
|
public IAcPhase[] Ac { get; init; } = Array.Empty<IAcPhase>();
|
|
public Double Frequency { get; init; }
|
|
public DeviceType Type { get; init; }
|
|
public String? Name { get; init; }
|
|
|
|
|
|
public JsonNode ToJson()
|
|
{
|
|
var json = new Dictionary<String, JsonNode>();
|
|
|
|
json[nameof(Type)] = Type.ToString()!;
|
|
json[nameof(Frequency)] = Frequency;
|
|
|
|
if (Name is not null)
|
|
json[nameof(Name)] = Name!;
|
|
|
|
|
|
if (Ac.Any())
|
|
{
|
|
json[nameof(Ac)] = new JsonArray(Ac.Select(p => p.ToJson()).ToArray());
|
|
}
|
|
|
|
json[nameof(Type)] = Type.ToString()!;
|
|
|
|
|
|
return new JsonObject(json!);
|
|
}
|
|
|
|
} |