remove tre from scanner.py, add test routine

This commit is contained in:
matt committed 2026-10-14 06:51:04 -07:00
1 parent 0bfcde0f64
commit 3c1c3ed432
3 files changed
+12 -17

No files matched your search

+2 -2
View File
@@ -27,8 +27,8 @@ def ble_scan_job():
run_counter = run_counter + 1 run_counter = run_counter + 1
"""Runs in the background, calls the async scanner.""" """Runs in the background, calls the async scanner."""
update_cache() update_cache()
#if run_counter > 9: if run_counter > 9:
# run_command run_counter = 0
# --- API ------------------------------------------------------------- # --- API -------------------------------------------------------------
+8 -9
View File
@@ -32,11 +32,10 @@ from bleak import BleakClient, BleakScanner
MI_SERVICE_UUID = "ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6" MI_SERVICE_UUID = "ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"
TEMP_CHAR_UUID = "ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6" TEMP_CHAR_UUID = "ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6"
SCAN_TIMEOUT = 5.0 # seconds to scan for each MAC SCAN_TIMEOUT = 10.0 # seconds to scan for each MAC
CONNECT_TIMEOUT = 10.0 CONNECT_TIMEOUT = 20.0
READ_TIMEOUT = 2.0 READ_TIMEOUT = 5.0
SERVICE_DISCOVERY_TIMEOUT = 5.0 SERVICE_DISCOVERY_TIMEOUT = 10.0
_lock = asyncio.Lock()
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Logging # Logging
@@ -192,10 +191,9 @@ def read_data_sync(mac: str) -> Optional[SensorReading]:
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Original helper functions - unchanged # Original helper functions
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
def sensor_data_query(mac_list: List[str]) -> List[dict]: def sensor_data_query(mac_list: List[str]) -> List[dict]:
"""Legacy function; returns a list of dicts like the original code."""
result = [] result = []
for mac in mac_list: for mac in mac_list:
try: try:
@@ -212,7 +210,6 @@ def sensor_data_query(mac_list: List[str]) -> List[dict]:
def test(test_count = 0) -> None: def test(test_count = 0) -> None:
"""Legacy test harness - identical to your original script."""
# first test scanner # first test scanner
test_loop_count = 0 test_loop_count = 0
found_macs = scan_macs() found_macs = scan_macs()
@@ -226,7 +223,9 @@ def test(test_count = 0) -> None:
"A4:C1:38:24:15:B0", "A4:C1:38:24:15:B0",
"A4:C1:38:D7:8D:26", "A4:C1:38:D7:8D:26",
] ]
print("Testing concurrent scan...")
multi_test_results = read_multiple(mac_list)
print(json.dumps(multi_test_results, indent=2))
print("Starting BLE test...") print("Starting BLE test...")
print(" Scanning MACs:") print(" Scanning MACs:")
for mac in mac_list: for mac in mac_list:
+2 -6
View File
@@ -71,7 +71,6 @@ load_state()
r = redis.Redis(host=bind_ip, port=redis_port) r = redis.Redis(host=bind_ip, port=redis_port)
def update_redis(data): def update_redis(data):
# push data to redis
# Publish to the Redis channel that the WS server is listening on # Publish to the Redis channel that the WS server is listening on
r.publish('temp_hum', json.dumps(data)) r.publish('temp_hum', json.dumps(data))
if debug_output: if debug_output:
@@ -89,11 +88,8 @@ def update_cache() -> None:
# now that we have MACs, let's get sensor data # now that we have MACs, let's get sensor data
print("Updating sensor data...") print("Updating sensor data...")
sensor_data = None sensor_data = None
try: sensor_data = sensor_data_query(new_macs)
sensor_data = sensor_data_query(new_macs) # print(sensor_data)
# print(sensor_data)
except Exception as e:
print(f"Aww fuck, no data :( - {e}")
# now we update the data in the sensor objects # now we update the data in the sensor objects
print("Sensor data collected:") print("Sensor data collected:")
for sensor_datum in sensor_data: for sensor_datum in sensor_data: