fix: filter scanner BT MACs in API responses

- /api/latest now filters out devices matching peer bt_mac
- Prevents scanner devices from appearing in scan results

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
User
2026-02-01 18:09:06 +01:00
parent 579cea57dc
commit 9fc7c65454

View File

@@ -666,10 +666,17 @@ def create_app(config: Config | None = None) -> Flask:
with open(scan_files[0]) as f:
scan = json.load(f)
# Get saved floor assignments from database
# Get saved floor assignments and scanner BT MACs from database
db = app.config.get("DATABASE")
saved_floors = db.get_all_device_floors() if db else {}
# Get scanner BT MACs to filter out
scanner_bt_macs = set()
if db:
for peer in db.get_peers():
if peer.get("bt_mac"):
scanner_bt_macs.add(peer["bt_mac"].upper())
# Enrich with distance estimates and saved floor assignments
for net in scan.get("wifi_networks", []):
net["estimated_distance_m"] = round(estimate_distance(net["rssi"]), 2)
@@ -678,12 +685,18 @@ def create_app(config: Config | None = None) -> Flask:
if "height_m" not in net:
net["height_m"] = None
# Filter out scanner devices and enrich BT devices
filtered_bt = []
for dev in scan.get("bluetooth_devices", []):
address = dev.get("address", "").upper()
if address in scanner_bt_macs:
continue # Skip scanner devices
dev["estimated_distance_m"] = round(estimate_distance(dev["rssi"], tx_power=-65), 2)
address = dev.get("address")
dev["floor"] = saved_floors.get(address) if address else dev.get("floor")
dev["floor"] = saved_floors.get(dev.get("address")) if dev.get("address") else dev.get("floor")
if "height_m" not in dev:
dev["height_m"] = None
filtered_bt.append(dev)
scan["bluetooth_devices"] = filtered_bt
scan["gps"] = {
"lat": app.config["CURRENT_LAT"],