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
14 changes: 12 additions & 2 deletions omronconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ class OmronDevice:
category: T.Optional[DeviceCategory] = None
user: int = 1
enabled: bool = True
# Kii's deviceSerialID is 8 bytes; the BLE MAC we store/display is only 6,
# so macaddr<->serial is a lossy round-trip (see serial_to_mac/ble_mac_to_serial).
# When the server hands us the real serial directly (get_registered_devices),
# we keep it here so `serial` doesn't have to reconstruct a wrong value.
real_serial: T.Optional[str] = None

def __post_init__(self) -> None:
if not isinstance(self.category, DeviceCategory):
Expand All @@ -335,7 +340,7 @@ def __post_init__(self) -> None:

@property
def serial(self) -> str:
return ble_mac_to_serial(self.macaddr)
return self.real_serial or ble_mac_to_serial(self.macaddr)

def to_dict(self) -> dict:
result = asdict(self)
Expand Down Expand Up @@ -566,6 +571,7 @@ def unique_devices(sync_list):
name=f"{device['deviceModel']}:{device['userNumberInDevice']}",
macaddr=serial_to_mac(device["deviceSerialID"]),
user=int(device["userNumberInDevice"]),
real_serial=device["deviceSerialID"],
)
result.append(ocDev)

Expand All @@ -579,11 +585,15 @@ def get_measurements(
"containCorrectedDataFlag": 1,
"containAllDataTypeFlag": 1,
"deviceCategory": device.category,
# Required by the backend for it to actually return measureList data —
# omitting it yields a 200 OK with deviceModelList: null every time,
# even for a valid device/date range. `name` is always stored as
# "<deviceModel>:<userNumberInDevice>" (see get_registered_devices).
"deviceModel": device.name.rsplit(":", 1)[0],
"deviceSerialID": device.serial,
"userNumberInDevice": int(device.user),
"searchDateFrom": searchDateFrom if searchDateFrom >= 0 else 0,
"searchDateTo": int(U.utcnow().timestamp() * 1000) if searchDateTo <= 0 else searchDateTo,
# "deviceModel": "OGSC", "HBF-xxx", ...
}

r = self._client.post(
Expand Down