Innovenergy_trunk/csharp/Lib/Devices/BatteryDeligreen/BatteryDeligreenDevices.cs

35 lines
870 B
C#

using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.Devices.BatteryDeligreen;
public class BatteryDeligreenDevices
{
private readonly IReadOnlyList<BatteryDeligreenDevice> _devices;
public BatteryDeligreenDevices(IReadOnlyList<BatteryDeligreenDevice> devices) => _devices = devices;
public BatteryDeligreenRecords? Read()
{
var records = _devices
.Select(TryRead)
.NotNull()
.ToList();
return BatteryDeligreenRecords.FromBatteries(records);
}
private static BatteryDeligreenRecord? TryRead(BatteryDeligreenDevice d)
{
try
{
return d.Reads().Result;
}
catch (Exception e)
{
Console.WriteLine($"Failed to read Battery node {d.SlaveId}\n{e.Message}");
// TODO: log
return null;
}
}
}