using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Victron.VeDBus; using InnovEnergy.WireFormat.VictronV1; namespace InnovEnergy.VenusLogger.Parsers; public static class PvInverter { public static Maybe GetPvInverter(this IEnumerable 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("/Position"); } catch { return AcBusType.Unknown; } } } // numbers must match those used by Victron on DBus!