Skip to content

fix: derive device MAC from BLE local name on EU/NA v2 API - #23

Open
rencsaridogan wants to merge 3 commits into
bugficks:masterfrom
rencsaridogan:fix/eu-v2-device-discovery-macaddress
Open

fix: derive device MAC from BLE local name on EU/NA v2 API#23
rencsaridogan wants to merge 3 commits into
bugficks:masterfrom
rencsaridogan:fix/eu-v2-device-discovery-macaddress

Conversation

@rencsaridogan

@rencsaridogan rencsaridogan commented Jun 29, 2026

Copy link
Copy Markdown

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_devices reads the MAC only from attributes.macAddress:

macAddress = attrs.get("macAddress", "").strip()
if not macAddress:
    L.debug(f"Skipping device without MAC address: ...")
    continue

The EU/NA v2 init-user response does not include a macAddress field. The MAC is instead encoded in the BLE local name, e.g.:

"deviceLocalName": "blesmart_0001020828ffb210aaa4"   ->  28:FF:B2:10:AA:A4
"deviceSerialID":  "<serial>"

So every device hit the continue guard 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 deviceSerialID via the existing serial_to_mac:

  • New helper ble_local_name_to_mac() mirrors the exact derivation already used by omramin.omron_ble_scan (last 12 hex of the BLEsmart_ name), so the resulting MAC is identical to what BLE discovery and manual add --macaddr produce.
  • v2 discovery order: 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:

  • Before: omron list -> "No devices found in OMRON Connect"
  • After: omron list -> device found with MAC 28:FF:B2:10:AA:A4, and sync transfers weigh-ins to Garmin end-to-end.

Additionally, the real get_registered_devices code path was driven with canned
EU/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 in omramin.omron_ble_scan (last 12 hex, uppercase)
  • Helper rejects empty / too-short / non-hex local names (returns "")
  • get_registered_devices now discovers a device whose v2 attributes have no macAddress (previously dropped by the skip-guard)
  • No regression: when macAddress is present it is used unchanged
  • Falls back to serial_to_mac(deviceSerialID) when neither macAddress nor a usable local name is present
  • Inactive devices (isActive: 0) are still skipped
  • Module imports cleanly
  • Live end-to-end on an EU (NL) account: omron list found the device and sync transferred weigh-ins to Garmin Connect

rencsaridogan and others added 2 commits June 29, 2026 10:36
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 rencsaridogan left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread omronconnect.py
Comment thread omronconnect.py
- 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>
@rencsaridogan

Copy link
Copy Markdown
Author

Review feedback addressed in f39fff1:

  • MAC case consistency — the resolved MAC is now uppercased once after the fallback chain, so the API macAddress, BLE-local-name, and serial_to_mac paths all agree. ✅ resolved
  • Prefix guardble_local_name_to_mac now requires a BLESMART_ prefix before deriving. ✅ resolved
  • Drive-by (v2 unknown-category log) — now logs the inferred deviceModel instead of device.get('deviceModel') (which was always None in the v2 loop). ✅ fixed

Re-verified against the real get_registered_devices path with canned v2 responses — 11/11 checks pass, now including: non-BLESMART_ names rejected, lowercase API macAddress normalized to uppercase, and serial fallback normalized to uppercase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant