Innovenergy_trunk/csharp/lib/StatusApi/AcDevice.cs

36 lines
852 B
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
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!);
}
}