feat(train): the Loop's live heart rate in a recording (ADR 0030, D41)

A recording with a Loop set up reads its heart rate through Polar's SDK
while no strap sends: the strap first, the Loop where there is none or
while it is lost. The SDK is one for the process, held by the open
app's bridge and by the recording service, so that the band stays
connected with the app gone; the app reopening finds it connected. The
recording file gains `loop` state lines; the rate is kept alone, as `h`
lines, and the Record sheet names the source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-28 21:32:13 +01:00
commit fa7680821d
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -1052,17 +1052,19 @@ void main() {
File file() => File('${folder.path}/recording.txt');
/// Train on a device that records, signed in, its clock at [now]'s.
Future<void> startRecording(WidgetTester tester) => start(
tester,
usedBefore: true,
recording: (
platform: platform,
file: file(),
straps: DeviceStore(File('${folder.path}/strap.json')),
rowers: DeviceStore(File('${folder.path}/rower.json')),
),
workouts: workouts,
);
Future<void> startRecording(WidgetTester tester, {PolarLoop? loop}) =>
start(
tester,
usedBefore: true,
recording: (
platform: platform,
file: file(),
straps: DeviceStore(File('${folder.path}/strap.json')),
rowers: DeviceStore(File('${folder.path}/rower.json')),
),
workouts: workouts,
loop: loop,
);
/// Lets [seconds] pass, the screen following.
Future<void> pass(WidgetTester tester, [int seconds = 1]) async {
@ -1356,6 +1358,39 @@ void main() {
expect(find.text('Strap lost'), findsOneWidget);
});
});
testWidgets("with a Loop and no strap, the Loop's heart rate is "
'recorded and shown (D41)', (tester) async {
// A band set up before, not started: nothing is asked of it here.
LoopStore(
File('${folder.path}/loop.json'),
).save(const KnownLoop(id: 'A1', name: 'Polar Loop A1'));
final loop = PolarLoop(
FakeLoopPlatform(),
LoopStore(File('${folder.path}/loop.json')),
ProfileRepository(MemoryProfileGateway(), keys, person: 'alice'),
days: DayRepository(MemoryDayGateway(), keys, person: 'alice'),
workouts: workouts,
backgroundLines: File('${folder.path}/loop_days.txt'),
);
await withClock(Clock.fixed(at), () async {
await startRecording(tester, loop: loop);
await tester.tap(find.text('Record'));
await tester.pumpAndSettle();
expect(find.text('From the Polar Loop'), findsOneWidget);
await tester.tap(find.text('Start'));
await pass(tester, 2);
expect(platform.started.single.loop, 'A1');
expect(platform.started.single.strap, isNull);
platform
..write('loop @ connected')
..write('h @ 118');
await pass(tester);
expect(find.text('118'), findsOneWidget);
});
});
});
group('on the rower (D28)', () {
const rower = FoundDevice(