Replaces the copy-pasted "first non-loopback IPv4" interface selection
with prop's AdvertisedAddressPicker (prefers the real LAN interface over
VPN tunnels, virtualization bridges and link-local adapters) and bumps
the prop submodule with the DirCon TCP/mDNS hardening: reconnect
supersede, socket onError handling, port-bind fallback with
actually-bound-port advertising, dual-stack listener.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add test/integration with platform fakes installed at the plugin seams
(UniversalBle.setInstance, NsdPlatformInterface.instance); everything
above them — Connection, device classification, protocol parsers, press
state machine, keymaps, ProxyDevice — is the real code:
- controller_connection_test: scan→classification (Zwift Click/Ride via
manufacturer data, Di2 via service UUID, FTMS trainer→ProxyDevice,
ignored names/devices), connect lifecycle (device-info reads, battery,
RideOn handshake, subscriptions), drops, dedupe, forget list.
- controller_button_chain_test: byte-accurate BLE notifications through
the full reaction chain — single/double/long press, trigger remapping,
duplicate-frame dedupe, unmapped-button error surfacing, multi-button
Ride presses.
- virtual_shifting_connection_logic_test: retrofit-mode defaults (WiFi /
BT-wins / proxy for power meters), auto-connect consent gating,
in-place "No connection" disconnect + in-place reconnect, WiFi trainer
discovery rules (found/lost/connected-survives-flap, self-exclusion),
and an end-to-end Click-press → real action pipeline → gear shift.
Protocol-level coverage (DirCon over real TCP, BLE peripheral) lives in
the prop submodule's own tests — no prop internals in this repo.
Bug fix found by these tests: Connection.disconnect(keepInList: true)
was defeated — UniversalBle.disconnect resolves only after the platform
disconnect event, so the still-attached connectionStream listener
re-entered disconnect() without keepInList and dropped the device,
orphaning the object the open details page holds (the exact bug
0db8cf0c addressed). Guarded via _inPlaceDisconnects.
Also update stale tests to current behavior: sim-mode shifts return
Ignored since e0e4494d (handled by the bridge, not forwarded, logged
neutrally), ControllerButton.initials direction arrows, and skip the
third BC2 state-machine test consistently with its siblings.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The _detachLogged teardown helper now reports failures via the app's
recordError (console in debug + crash persistence), matching the
convention used elsewhere (e.g. ZwiftClickV2.detach), instead of a bare
debugPrint.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
After an in-place "No connection" disconnect, selecting Virtual Shifting
again reconnected the BLE upstream but the connect never completed:
device.isConnected stayed false and the card hung on "connecting".
The listener that flips isConnected (and drives the handshake to
completion) is created only in _connect(), which runs once via the
auto-connect queue at app start. The first manual connect reuses that
listener; disconnect cancels it (so a BLE drop doesn't fire
auto-reconnect); the second manual connect via startProxy() had no
listener and never re-ran _connect.
Route the in-place reconnect through a new Connection.connectDevice()
wrapper over _connect, re-attaching the action / connection-state
listeners — the same path the working auto-connect uses — instead of
calling ProxyDevice.startProxy() directly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The "No connection" picker entry disconnects without leaving the details
page, but Connection.disconnect(forget: false) removed the ProxyDevice
from the registry (isResetting is false). The open page kept the now
orphaned object: rediscovery built a *new* ProxyDevice while the page
still pointed at the old one, so selecting Virtual Shifting again
reconnected a device absent from bluetoothDevices — its BLE notifications
were rejected ("Device not found") and the connection was force-dropped.
Add a keepInList flag to disconnect; the in-place "No connection" path
passes it so the same device object stays registered (and its scan
result is retained to avoid a churned duplicate) and remains
reconnectable on the same card. The Disconnect buttons, which pop the
page, keep the default removing behaviour.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- ConnectionCard: "No connection" shows "Not connected" instead of the
bridge connect instruction; switching modes keeps the bridge accordion
mounted with inline progress (drops the "Connecting in ... mode"
placeholder card).
- proxy_device_details: stable keys on ConnectionCard / LiveMetricsSection
/ MiniWorkoutCard. On (dis)connect, conditional siblings toggle both
above (FTMS warning) and below (gear/settings/VS-notice) these widgets,
trapping the unkeyed ones in Flutter's reconciliation middle and
remounting them — which collapsed the accordion and rebuilt the page.
- ProxyDevice: re-establish the emulator-state bindings on every
(re)connect (_rebindEmulatorState in startProxy). The in-place
"No connection" disconnect detaches them on a reused ProxyDevice, so
reconnecting Virtual Shifting left the UI stuck on "connecting" while
the emulator was actually connected.
- ProxyDevice.disconnect/switchRetrofitMode/handleServices: await the
emulator stops so mDNS/TCP is torn down before reporting disconnected,
and log the previously swallowed detach errors.
- connection.dart: log the discovered device name instead of its runtime
type.
- Bump prop for the awaited mDNS teardown.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Brings the BLE peripheral-mode migration to universal_ble 2.0.0 into the
WiFi DirCon trainer-discovery branch and bumps universal_ble to the latest
fork commit (ref: changes, 2.0.0).
Conflict resolutions:
- prop submodule: merged the universal_ble 2.0 transporter migration with
the WiFi DirCon TrainerTransport refactor; kept the '0x' short-UUID
normalisation on startAdvertising. Updated BleCharacteristic call sites
to the new 3-arg (uuid, properties, descriptors) constructor.
- obc_ble_emulator.dart: took the PeripheralServer / universal_ble 2.0
write-handler migration; kept the richer Error(button:) context on
sendAction (using _currentDeviceId, the migrated connection tracker).
- unlock.dart: kept the main.dart import.
- pubspec.yaml: kept version 6.0.0+135; took ref: changes for universal_ble.
Pre-existing prop test failures (composite/dircon/fitness serviceUUIDs) are
unchanged by this merge — they fail identically on the pre-merge branch.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Settings.trainerAppListenable fires from setTrainerApp.
- Connection.initialize listens and restarts ftmsEmulator + each
ProxyDevice's _proxyEmulator so the new advertisement name (e.g.
"Zwift Hub" for Rouvy) appears on the wire without reconnect.
- ProxyDevice.restartProxyEmulator no-ops in VS mode (ftmsEmulator
handles itself).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ProxyDevice sets trainerApp / isTrial / deviceName callbacks on the
emulator instead of computing the name itself. ProxyDevice.advertisementName
now reads through emulator.advertisementName. startServer no longer
takes the name as a parameter.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
handleServices builds both ProxyBikeDefinition and
FitnessBikeDefinition up front and attaches to the right emulator
based on retrofit mode. ProxyDevice provides advertisementName +
mdnsTxt to ftmsEmulator/_proxyEmulator via the new startServer
parameters. Drops DirconEmulator state mirroring that's no longer
needed. ZwiftClickV2 no longer calls startServer (click-alone
path removed per prop strip). UI consumers route through
ProxyDevice.advertisementName and device.retrofitMode.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
handleServices was always driving _proxyEmulator.startServer, even
when the saved mode for the trainer was wifi or bluetooth. The
per-instance proxy emulator now only starts in proxy mode; for VS
modes the FBD attaches to the shared ftmsEmulator, mirroring what
switchRetrofitMode does for mid-session swaps.
isUnlocked / alreadyUnlocked / waiting notifiers + the vendor message
capture move to ZwiftClickV2. ftmsEmulator.setScanResult and
handleServices are no longer called from the click flow. The unlock
page binds to widget.device's notifiers. The prefs-based unlock check
is renamed isPersistedUnlocked to avoid shadowing the new live notifier.
ftmsEmulator is now the single emulator for Virtual Shifting traffic
across all trainers and the Click V2. ProxyDevice keeps a per-instance
emulator only for proxy mode (each proxy trainer advertises its own
mDNS identity). ZwiftClickV2 attaches its def to ftmsEmulator directly.
ProxyDevice exposes its own state ValueListenables (isStartedListenable,
isConnectedListenable, retrofitMode, localAddress) that mirror the active
emulator, so UI bindings survive mode swaps. setRetrofitMode and
switchRetrofitMode live on ProxyDevice and migrate the FBD between
proxy/shared emulators.
Removes companionProvider, refreshCompanions, and the click-def
internal seeding in DirconEmulator.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ZwiftClickV2 no longer tracks which emulator hosts its definition or
listens for trainer arrival/departure. Instead:
- ProxyDevice installs an emulator.companionProvider that returns click
defs for any connected ZwiftClickV2 at start time.
- ZwiftClickV2.handleServices builds the def, asks running trainer
emulators to refreshCompanions, or starts the standalone if no
trainer is running.
- ProxyDevice.disconnect migrates the click def back to the standalone
so the Click stays usable after a trainer goes away.
Removes EmulatorRegistry singleton, the rebind handler, and the
sharedTrainerEmulator listener.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ZwiftClickDefinition is now attached to the resolved DirconEmulator at
Click-connect time, regardless of whether the unlock page is open:
- No trainer → ZwiftClickV2.handleServices starts the standalone so
Zwift / Rouvy see BikeControl-as-Click as soon as the user plugs the
Click in.
- Trainer present → click def attaches to the trainer's emulator; the
trainer's existing peripheral advertises both services via the
composite, so Zwift auto-subscribes to the Click service when it
pairs with the trainer.
unlock.dart no longer drives the standalone's lifecycle; it just
listens to the shared unlock notifiers.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- unlock.dart now seeds ftmsEmulator.scanResult before calling
startServer, so the unlock page works when the Click is bound to the
trainer's emulator (and never told the standalone about itself).
Also guards the startServer call behind isStarted.value to avoid
double-starting.
- ZwiftClickV2 attach/detach call sites now wrap their futures in
catchError(recordError, context: '...') per the project's
feedback_record_error rule.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ZwiftClickV2.handleServices / _onSharedTrainerChanged were calling
setScanResult and handleServices on whichever DirconEmulator the
registry resolved to — corrupting the trainer's mDNS advertisement
(which reads scanResult.deviceId + scanResult.services for its TXT
record) and breaking subsequent _createDefinitionAndTransporter
rebuilds whenever a trainer was the resolve target.
The Click's hardware identity already lives inside the
ZwiftClickDefinition (services / device constructor args). Only the
standalone ftmsEmulator should learn the Click as its primary device.
When a smart trainer is connected, the Click V2's ZwiftClickDefinition
attaches to the trainer's emulator so Zwift/Rouvy pair once and see
both services. When no trainer is connected, falls back to the
standalone ftmsEmulator (existing unlock path). Trainer arrival /
departure while the Click is connected rebinds the definition.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Lets companion devices (Zwift Click V2) attach their definitions to
the trainer's emulator instead of using a separate one. The registry
slot is reclaimed by ProxyDevice's emulator on construction and
released on teardown.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ZwiftClickV2 uses this to find the trainer's DirconEmulator at connect
time and attach its ZwiftClickDefinition there, falling back to the
standalone emulator only when no trainer is connected.
activeDefinition now returns the CompositeBleDefinition; consumers
that need the FitnessBikeDefinition specifically use the fitnessBike
convenience getter. Bumps prop submodule to pick up the composite
machinery.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Drop bluetooth_low_energy. Move OBC BLE emulator, Zwift emulator, and
the remote mouse / keyboard pairing flows onto a new PeripheralServer
wrapper around UniversalBlePeripheral that routes per-characteristic
read/write handlers, so multiple peripheral instances coexist without
clobbering universal_ble's process-wide handlers.
Also: onValueChange callback gains a timestamp param (v1.0.0 breaking
change), PeripheralManager().showAppSettings() → openAppSettings(),
UUID.short(0x12) → literal UUID, and prop submodule bumped to the
matching universal_ble peripheral rewrite.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>