Skip to content

Commit 8c422ab

Browse files
machugclaude
andcommitted
fix: use BLE adapter address for RAPT Pill device identity
The MAC bytes inside the RAPT payload change per broadcast and are not the device's stable identity. Use device.address from Bleak (the BLE adapter address) instead, so only one device appears. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 55bdf9d commit 8c422ab

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

backend/scanner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,19 @@ def _detection_callback(self, device, advertisement_data):
216216
temp_c = temp_raw / 128.0 - 273.15
217217
sg = gravity_raw / 1000.0
218218
battery_pct = battery_raw / 256.0
219-
mac_str = ":".join(f"{b:02X}" for b in mac_bytes)
219+
# Use the BLE adapter address as stable identifier, not the
220+
# payload MAC bytes which change per broadcast
221+
ble_addr = device.address.upper()
220222

221223
self._latest_rapt_reading = RAPTPillReading(
222-
mac=mac_str,
224+
mac=ble_addr,
223225
temp_c=round(temp_c, 2),
224226
sg=round(sg, 4),
225227
battery_percent=round(battery_pct, 1),
226228
rssi=advertisement_data.rssi,
227229
timestamp=datetime.now(timezone.utc),
228230
)
229-
print(f"BLE: Detected RAPT Pill ({mac_str}) - {temp_c:.1f}C, SG {sg:.4f}, Battery {battery_pct:.0f}%")
231+
print(f"BLE: Detected RAPT Pill ({ble_addr}) - {temp_c:.1f}C, SG {sg:.4f}, Battery {battery_pct:.0f}%")
230232
except Exception as e:
231233
logger.debug("Error parsing RAPT Pill packet: %s", e)
232234
return

0 commit comments

Comments
 (0)