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:
@@ -666,10 +666,17 @@ def create_app(config: Config | None = None) -> Flask:
|
|||||||
with open(scan_files[0]) as f:
|
with open(scan_files[0]) as f:
|
||||||
scan = json.load(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")
|
db = app.config.get("DATABASE")
|
||||||
saved_floors = db.get_all_device_floors() if db else {}
|
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
|
# Enrich with distance estimates and saved floor assignments
|
||||||
for net in scan.get("wifi_networks", []):
|
for net in scan.get("wifi_networks", []):
|
||||||
net["estimated_distance_m"] = round(estimate_distance(net["rssi"]), 2)
|
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:
|
if "height_m" not in net:
|
||||||
net["height_m"] = None
|
net["height_m"] = None
|
||||||
|
|
||||||
|
# Filter out scanner devices and enrich BT devices
|
||||||
|
filtered_bt = []
|
||||||
for dev in scan.get("bluetooth_devices", []):
|
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)
|
dev["estimated_distance_m"] = round(estimate_distance(dev["rssi"], tx_power=-65), 2)
|
||||||
address = dev.get("address")
|
dev["floor"] = saved_floors.get(dev.get("address")) if dev.get("address") else dev.get("floor")
|
||||||
dev["floor"] = saved_floors.get(address) if address else dev.get("floor")
|
|
||||||
if "height_m" not in dev:
|
if "height_m" not in dev:
|
||||||
dev["height_m"] = None
|
dev["height_m"] = None
|
||||||
|
filtered_bt.append(dev)
|
||||||
|
scan["bluetooth_devices"] = filtered_bt
|
||||||
|
|
||||||
scan["gps"] = {
|
scan["gps"] = {
|
||||||
"lat": app.config["CURRENT_LAT"],
|
"lat": app.config["CURRENT_LAT"],
|
||||||
|
|||||||
Reference in New Issue
Block a user