fix: derive device MAC from BLE local name on EU/NA v2 API - #23
fix: derive device MAC from BLE local name on EU/NA v2 API#23rencsaridogan wants to merge 3 commits into
Conversation
OMRON's EU/NA v2 init-user response does not include a `macAddress` field for registered devices, so `get_registered_devices` dropped every device via the "skip device without MAC address" guard, leaving the device list empty even when the account had active devices. OMRON encodes the MAC in the BLE local name (e.g. `blesmart_0001020828ffb210aaa4` -> `28:FF:B2:10:AA:A4`), the same value the Bluetooth scanner derives. Fall back to that local name, then to `deviceSerialID` via `serial_to_mac`, before skipping. The derivation matches `omramin.omron_ble_scan`, so the resulting MAC is consistent with BLE discovery and manual `add --macaddr`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a CHANGELOG entry for the macAddress-derivation fix and a README troubleshooting subsection for the "omron list shows no devices" symptom (region mismatch, not-yet-synced, and the --debug inspection tip). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rencsaridogan
left a comment
There was a problem hiding this comment.
Reviewed the discovery change. The approach is sound: v2 matches measurements by userNumberInDevice, so deriving the MAC purely as a stable config identifier is safe, and reusing the omron_ble_scan last-12-hex rule keeps it consistent with BLE discovery and manual add --macaddr. Two non-blocking notes inline.
Unrelated drive-by noticed while reading (not part of this PR): the v2 unknown-category branch logs device.get('deviceModel'), but in the v2 loop deviceModel lives under attributes (attrs), so that warning always prints None. Pre-existing — mentioning since it's nearby.
- ble_local_name_to_mac: require a BLESMART_ prefix so an unrelated
deviceLocalName that merely ends in 12 hex chars can't yield a bogus MAC.
- get_registered_devices: uppercase the resolved MAC so every discovery
path (API macAddress, BLE local name, serial fallback) produces the same
string for a device, avoiding case-sensitive mismatches on dedup/lookup.
- Fix the v2 unknown-category warning to log the inferred deviceModel
instead of device.get('deviceModel'), which was always None in the v2
loop (deviceModel lives under attributes).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Review feedback addressed in f39fff1:
Re-verified against the real |
Problem
On the EU/NA v2 API,
omron list/ device discovery returns no devices even when the OMRON account has active, registered devices. The account authenticates fine; the device list just comes back empty.Root cause
OmronConnect2.get_registered_devicesreads the MAC only fromattributes.macAddress:The EU/NA v2
init-userresponse does not include amacAddressfield. The MAC is instead encoded in the BLE local name, e.g.:So every device hit the
continueguard and was silently dropped.Fix
Before giving up, fall back to deriving the MAC from the BLE local name (last 12 hex chars), then from
deviceSerialIDvia the existingserial_to_mac:ble_local_name_to_mac()mirrors the exact derivation already used byomramin.omron_ble_scan(last 12 hex of theBLEsmart_name), so the resulting MAC is identical to what BLE discovery and manualadd --macaddrproduce.macAddress-> BLE local name ->deviceSerialID.The MAC is only used as a config identifier (v2 matches measurements by
userNumberInDevice, not MAC), so this restores discovery without affecting sync matching.Verification
On an EU (NL) account whose v2 response omitted
macAddress:omron list-> "No devices found in OMRON Connect"omron list-> device found with MAC28:FF:B2:10:AA:A4, andsynctransfers weigh-ins to Garmin end-to-end.Additionally, the real
get_registered_devicescode path was driven with cannedEU/NA v2 responses (offline, no credentials) alongside helper unit checks — 9/9 passed:
ble_local_name_to_mac("blesmart_0001020828ffb210aaa4")->28:FF:B2:10:AA:A4, identical to the rule inomramin.omron_ble_scan(last 12 hex, uppercase)"")get_registered_devicesnow discovers a device whose v2 attributes have nomacAddress(previously dropped by the skip-guard)macAddressis present it is used unchangedserial_to_mac(deviceSerialID)when neithermacAddressnor a usable local name is presentisActive: 0) are still skippedomron listfound the device andsynctransferred weigh-ins to Garmin Connect