1111
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using Evergreen.Health.Application.Health.Sleep;
|
||||
|
||||
namespace Evergreen.Health.Application.Health.Integrations.Ib43;
|
||||
|
||||
public sealed record Ib43SavedBed(string BindingId, string Side);
|
||||
public sealed record Ib43SavedReport(int MatchedCount, IReadOnlyList<Ib43SavedBed> ActiveBeds);
|
||||
|
||||
internal static class Ib43PresenceAdapter
|
||||
{
|
||||
public static void Publish(IBedPresenceSink sink, Ib43Binding device, Ib43Report report,
|
||||
IReadOnlyList<Ib43SavedBed> beds, Guid connectionId, CancellationToken connectionToken)
|
||||
{
|
||||
if (sink == null || !report.Accepted || report.Issues.Count != 0) return;
|
||||
foreach (var bed in beds)
|
||||
{
|
||||
if (bed.Side is not ("left" or "right") ||
|
||||
!report.Readings.TryGetValue(bed.Side + ".presence", out var presence) ||
|
||||
presence.Source != "ibNew" || presence.Value is not (0 or 1)) continue;
|
||||
sink.Observe(new(bed.BindingId, device.ProductKey, device.SerialNumber,
|
||||
bed.Side == "left" ? BedSide.Left : BedSide.Right, device.Simulation,
|
||||
presence.Value == 0 ? BedPresence.Empty : BedPresence.Occupied, presence.ReceivedAt, connectionId), connectionToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user