mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-02 10:09:09 +01:00
The first-run explainer offered "use the left side only" as the way to
avoid Zwift. That is the one puck Zwift actually locks. Picking it left
the rider on the 59-second restart loop, and — because
ZwiftClickV2RightSide.shouldAutoConnect required unlock-with-Zwift — it
also withheld the puck that needs nothing at all. Worse, with Zwift's
built-in keymap binding the right paddle to shiftUp and the left paddle
to shiftDown, the left side alone could only ever shift down. The
genuinely clean setup was reachable only by first choosing the mode it
was meant to replace, then tapping "Use the right side only" on the
right card.
So the option becomes right-side-only: no unlock ever, no restarts, and
the +/B remap the right card already applied so one puck covers both
shift directions. The cons now name the real price — no D-pad, so no
steering and no action bar.
Click V2 state is three modes now, not a boolean, and both connect gates
say so out loud. ClickLogic drives the left side's restart loop from a
single static timer that the right side's handshake cancels, so those
two can never be live together; that invariant used to be implied by one
gate and is now stated in both. Left-restart mode survives as the left
card's existing Select for riders who want the D-pad, just not as a
first-run choice.
The right card's shortcut delegates to the same policy rather than
keeping its own path, so both leave identical state: the left side held
back by the setting instead of pushed onto the ignored-devices list,
which is what lets "Set up again" undo it. Its confirmation copy moves
accordingly, and it stops offering itself once the left side is merely
listed rather than connected.
The remap sits in its own recordError guard. It needs a trainer app to
have been picked, and a mode the rider explicitly chose must not be left
half-written because an optional convenience could not run.
This also turns emulation_zwift_profiles_test's right-side case green:
it had been red since the gate landed, because e74c5920 fixed only the
isPending half of what was holding that side back.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
129 lines
5.2 KiB
Dart
129 lines
5.2 KiB
Dart
import 'package:bike_control/bluetooth/devices/bluetooth_device.dart';
|
|
import 'package:bike_control/bluetooth/devices/zwift/constants.dart';
|
|
import 'package:bike_control/bluetooth/devices/zwift/zwift_clickv2_left_side.dart';
|
|
import 'package:bike_control/bluetooth/devices/zwift/zwift_clickv2_right_side.dart';
|
|
import 'package:bike_control/bluetooth/devices/zwift/zwift_play.dart';
|
|
import 'package:bike_control/bluetooth/devices/zwift/zwift_play_fw2.dart';
|
|
import 'package:bike_control/bluetooth/emulation/emulation_profile.dart';
|
|
import 'package:bike_control/bluetooth/emulation/profiles/zwift_profiles.dart';
|
|
import 'package:bike_control/utils/actions/base_actions.dart';
|
|
import 'package:bike_control/utils/core.dart';
|
|
import 'package:bike_control/utils/keymap/apps/zwift.dart';
|
|
import 'package:bike_control/utils/keymap/buttons.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:prop/prop.dart' show propPrefs;
|
|
|
|
import 'harness/test_env.dart';
|
|
|
|
Future<void> main() async {
|
|
final env = await IntegrationEnv.setUp();
|
|
late StubActions stubActions;
|
|
|
|
core.connection.initialize();
|
|
|
|
setUp(() async {
|
|
await env.resetState();
|
|
// ZwiftClickV2 (and thus its left/right sides) reads `propPrefs` — a
|
|
// separate global from the `prop` package — on every button click
|
|
// (isLikelyUnlocked). IntegrationEnv.resetState() only wires up
|
|
// core.settings.prefs, not this second prefs instance (only
|
|
// Settings.init(), which production startup calls but the harness
|
|
// doesn't, does that). Initialize it here so Click V2 button presses
|
|
// don't hit a LateInitializationError.
|
|
propPrefs.initialize(core.settings.prefs);
|
|
// These tests exercise a *connected* Click V2's button/profile behaviour;
|
|
// which unlock mode the rider picked is orthogonal to that. env.resetState()
|
|
// starts from empty prefs, so both connect gates would otherwise hold the
|
|
// controller out of the queue -- connect() returns early, no BLE link
|
|
// opens, and the handshake write these tests wait for never arrives.
|
|
//
|
|
// Onboarding done clears ClickV2Onboarding.isPending for both sides.
|
|
// Unlock-with-Zwift is then the one mode in which BOTH sides connect, so
|
|
// the left- and right-side cases below can share this setUp; the other two
|
|
// modes each deliberately hold one side back.
|
|
await core.settings.setClickV2OnboardingDone(true);
|
|
await core.settings.setUnlockWithZwift(true);
|
|
stubActions = StubActions();
|
|
stubActions.supportedApp = Zwift();
|
|
core.actionHandler = stubActions;
|
|
core.emulation.reset();
|
|
core.emulation.attach(env.ble);
|
|
});
|
|
|
|
tearDown(() async {
|
|
await env.resetConnection();
|
|
});
|
|
|
|
/// Starts [profile], waits for detection as [T] and for the handshake write.
|
|
Future<EmulatedButton> connectAndFirstButton<T extends BluetoothDevice>(
|
|
EmulationProfile profile,
|
|
String deviceId, {
|
|
String? buttonLabel,
|
|
}) async {
|
|
final session = core.emulation.start(profile);
|
|
await core.connection.performScanning();
|
|
await IntegrationEnv.waitFor(
|
|
() => core.connection.devices.whereType<T>().isNotEmpty,
|
|
description: '$T in device list',
|
|
);
|
|
await IntegrationEnv.waitFor(
|
|
() => session.peripheral.writes.isNotEmpty,
|
|
description: '$T handshake write',
|
|
);
|
|
final buttons = session.inputs.whereType<EmulatedButton>();
|
|
return buttonLabel == null ? buttons.first : buttons.firstWhere((b) => b.label == buttonLabel);
|
|
}
|
|
|
|
Future<void> pressAndAssert(EmulatedButton button, ControllerButton expected) async {
|
|
button.onDown();
|
|
button.onUp();
|
|
await IntegrationEnv.waitFor(() => stubActions.performedActions.isNotEmpty, description: 'performed action');
|
|
expect(stubActions.performedActions.map((a) => a.button), contains(expected));
|
|
}
|
|
|
|
test('Zwift Play left: Nav Up press performs navigationUp', () async {
|
|
final button = await connectAndFirstButton<ZwiftPlay>(
|
|
zwiftPlayLeftProfile,
|
|
'emulated:zwift-play-left',
|
|
buttonLabel: 'Nav Up',
|
|
);
|
|
await pressAndAssert(button, ZwiftButtons.navigationUp);
|
|
});
|
|
|
|
test('Zwift Play right: Y press performs y', () async {
|
|
final button = await connectAndFirstButton<ZwiftPlay>(
|
|
zwiftPlayRightProfile,
|
|
'emulated:zwift-play-right',
|
|
buttonLabel: 'Y',
|
|
);
|
|
await pressAndAssert(button, ZwiftButtons.y);
|
|
});
|
|
|
|
test('Zwift Play FW2: SHFT_UP_R press performs shiftUpRight', () async {
|
|
final button = await connectAndFirstButton<ZwiftPlayFw2>(
|
|
zwiftPlayFw2Profile,
|
|
'emulated:zwift-play-fw2',
|
|
buttonLabel: 'SHFT_UP_R_BTN',
|
|
);
|
|
await pressAndAssert(button, ZwiftButtons.shiftUpRight);
|
|
});
|
|
|
|
test('Zwift Click V2 left side: UP press performs navigationUp', () async {
|
|
final button = await connectAndFirstButton<ZwiftClickV2LeftSide>(
|
|
zwiftClickV2LeftProfile,
|
|
'emulated:zwift-clickv2-left',
|
|
buttonLabel: 'UP_BTN',
|
|
);
|
|
await pressAndAssert(button, ZwiftButtons.navigationUp);
|
|
});
|
|
|
|
test('Zwift Click V2 right side: A press performs a', () async {
|
|
final button = await connectAndFirstButton<ZwiftClickV2RightSide>(
|
|
zwiftClickV2RightProfile,
|
|
'emulated:zwift-clickv2-right',
|
|
buttonLabel: 'A_BTN',
|
|
);
|
|
await pressAndAssert(button, ZwiftButtons.a);
|
|
});
|
|
}
|