Innovenergy_trunk/csharp/lib/StatusApi/Inverter.cs

33 lines
890 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 Inverter : IInverter
{
public IAcPhase[] Ac { get; init; }
public Double Frequency { get; init; }
public IPhase Dc { 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(Dc.Current)] = Dc.Current;
json[nameof(Dc.Voltage)] = Dc.Voltage;
return new JsonObject(json!);
}
}