36 lines
857 B
C#
36 lines
857 B
C#
|
using InnovEnergy.Lib.Utils;
|
||
|
|
||
|
namespace InnovEnergy.Lib.Devices.Battery250Up;
|
||
|
|
||
|
public class Battery250UpDevices
|
||
|
{
|
||
|
private readonly IReadOnlyList<Battery250UpDevice> _Devices;
|
||
|
|
||
|
public Battery250UpDevices(IReadOnlyList<Battery250UpDevice> devices) => _Devices = devices;
|
||
|
|
||
|
public Battery250UpRecords? Read()
|
||
|
{
|
||
|
var records = _Devices
|
||
|
.Select(TryRead)
|
||
|
.NotNull()
|
||
|
.ToList();
|
||
|
|
||
|
return Battery250UpRecords.FromBatteries(records);
|
||
|
}
|
||
|
|
||
|
private static Battery250UpRecord? TryRead(Battery250UpDevice d)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
return d.Read();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
Console.WriteLine($"Failed to read Battery node {d.SlaveId}\n{e.Message}");
|
||
|
// TODO: log
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|