Files
Evergreen-Health/Evergreen.Health.Application/Health/Integrations/Ib43/Ib43PresenceAdapter.cs
T
2026-11-11 16:11:41 +08:00

25 lines
1.2 KiB
C#

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);
}
}
}