Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions omronconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ def serial_to_mac(serial: str) -> str:
return ":".join(values[5:2:-1] + values[2::-1])


def ble_local_name_to_mac(local_name: str) -> str:
# e.g. blesmart_0001020828ffb210aaa4 to 28:FF:B2:10:AA:A4
# OMRON encodes the MAC as the last 12 hex chars of the BLE local name.
# Mirrors the BLE-scan derivation in omramin.omron_ble_scan.
name = (local_name or "").strip()
mac_hex = name[-12:].upper()
if len(mac_hex) != 12 or not all(c in "0123456789ABCDEF" for c in mac_hex):
return ""
return ":".join(mac_hex[i : i + 2] for i in range(0, 12, 2))


def convert_weight_to_kg(weight: T.Union[int, float], unit: int) -> float:
if unit == WeightUnit.G:
return weight / 1000
Expand Down Expand Up @@ -833,6 +844,14 @@ def get_registered_devices(self, days: T.Optional[int] = 30) -> T.Optional[list[
continue

macAddress = attrs.get("macAddress", "").strip()
if not macAddress:
# EU/NA v2 responses omit macAddress; OMRON encodes the MAC in the
# BLE local name (blesmart_<...>) and falls back to deviceSerialID.
macAddress = ble_local_name_to_mac(attrs.get("deviceLocalName", ""))
if not macAddress:
serial = attrs.get("deviceSerialID", "")
if serial:
macAddress = serial_to_mac(serial)
if not macAddress:
L.debug(f"Skipping device without MAC address: {attrs.get('name', 'unknown')}")
continue
Expand Down