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

33 lines
995 B
C#

using System.Collections.Immutable;
using InnovEnergy.Lib.Victron.VeDBus;
namespace InnovEnergy.VenusLogger.Parsers;
using VeProps = ImmutableDictionary<String, VeProperty>;
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<ServiceProperties> 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);
}
}