using System.Collections.Immutable; using InnovEnergy.Lib.Victron.VeDBus; namespace InnovEnergy.VenusLogger.Parsers; using VeProps = ImmutableDictionary; public record VenusSettings(Boolean HasAcOutBus, Boolean HasDcSystem); public static class Settings { private static VenusSettings DefaultSettings { get; } = new VenusSettings(true, true); public static VenusSettings GetSettings(this IEnumerable services) { return services .Where(VeService.IsSettingsService) .Select(s=>s.Properties) .Select(GetSettings) .FirstOrDefault(DefaultSettings); } private static VenusSettings GetSettings(this VeProps props) { var hasAcOut = props.TryGetProperty("/Settings/SystemSetup/HasAcOutSystem", true); var hasDcSystem = props.TryGetProperty("/Settings/SystemSetup/HasDcSystem", true); return new VenusSettings(hasAcOut, hasDcSystem); } }