Innovenergy_trunk/csharp/app/VenusLogger/Parsers/PvInverter.cs

51 lines
1.2 KiB
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
using InnovEnergy.Lib.Utils;
using InnovEnergy.Lib.Victron.VeDBus;
using InnovEnergy.WireFormat.VictronV1;
namespace InnovEnergy.VenusLogger.Parsers;
public static class PvInverter
{
public static Maybe<Device> GetPvInverter(this IEnumerable<ServiceProperties> services, AcBusType busType)
{
var pvInverters = services
.Where(sp => sp.GetBusType() == busType)
.TrySelect(GetPvInverter)
.ToList();
if (pvInverters.Count < 2)
return pvInverters.FirstOrDefault().Maybe();
return new Device
{
Type = DeviceType.PvInverter,
Devices = { pvInverters }
};
}
private static Device GetPvInverter(ServiceProperties sp)
{
return new Device
{
Type = DeviceType.PvInverter,
Phases = { sp.Properties.GetAcPhases() }
};
}
private static AcBusType GetBusType(this ServiceProperties service)
{
try
{
return (AcBusType) service.Properties.GetProperty<Int32>("/Position");
}
catch
{
return AcBusType.Unknown;
}
}
}
// numbers must match those used by Victron on DBus!