64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System.Text.Json;
|
|
using InnovEnergy.Lib.Utils;
|
|
using static InnovEnergy.Lib.Units.Units;
|
|
|
|
namespace InnovEnergy.Lib.StatusApi;
|
|
|
|
public abstract record DeviceStatus
|
|
{
|
|
private static readonly JsonSerializerOptions JsonSerializerOptions;
|
|
|
|
static DeviceStatus()
|
|
{
|
|
JsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
|
JsonConverters.ForEach(JsonSerializerOptions.Converters.Add); // how stupid is that?!!
|
|
}
|
|
|
|
public String DeviceType => GetType()
|
|
.Generate(t => t.BaseType!)
|
|
.First(t => t.IsAbstract)
|
|
.Name
|
|
.Replace("Status", "");
|
|
|
|
public String ToJson() => JsonSerializer.Serialize(this, GetType(), JsonSerializerOptions);
|
|
}
|
|
|
|
|
|
// public static class Program
|
|
// {
|
|
// public static void Main(string[] args)
|
|
// {
|
|
// var x = new ThreePhasePvInverterStatus
|
|
// {
|
|
// Ac = new()
|
|
// {
|
|
// Frequency = 50,
|
|
// L1 = new()
|
|
// {
|
|
// Current = 10,
|
|
// Voltage = 10,
|
|
// Phi = 0,
|
|
// },
|
|
// L2 = new()
|
|
// {
|
|
// Current = 52,
|
|
// Voltage = 220,
|
|
// Phi = Angle.Pi / 2,
|
|
// },
|
|
// L3 = new()
|
|
// {
|
|
// Current = 158,
|
|
// Voltage = 454,
|
|
// Phi = Angle.Pi / 3,
|
|
// },
|
|
// },
|
|
// Strings = new DcBus[]
|
|
// {
|
|
// new() { Current = 10, Voltage = 22 },
|
|
// new() { Current = 12, Voltage = 33 },
|
|
// }
|
|
// };
|
|
//
|
|
// var s = x.ToJson();
|
|
// }
|
|
// } |