33 lines
890 B
C#
33 lines
890 B
C#
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!);
|
|
}
|
|
} |