print line cleanup 3
This commit is contained in:
1 parent
f00ba3fefc
commit
55f30af700
2 files changed
+8
-10
No files matched your search
@@ -26,14 +26,14 @@ async def read_data(mac_address):
|
|||||||
device = next((d for d in devices if d.address.lower() == mac_address.lower()), None)
|
device = next((d for d in devices if d.address.lower() == mac_address.lower()), None)
|
||||||
if device:
|
if device:
|
||||||
# print(f"BleakScanner device variable loaded - {device.name}")
|
# print(f"BleakScanner device variable loaded - {device.name}")
|
||||||
print(f"-- Found device: {device.name} ({device.address})")
|
print(f"-- Found device: {device.name} ({device.address})")
|
||||||
fail_count = 0
|
fail_count = 0
|
||||||
# else:
|
# else:
|
||||||
# print("BleakScanner device not loaded yet")
|
# print("BleakScanner device not loaded yet")
|
||||||
fail_count = fail_count - 1
|
fail_count = fail_count - 1
|
||||||
|
|
||||||
if not device:
|
if not device:
|
||||||
print(f"!! Device with MAC {mac_address} not found")
|
print(f"!! Device with MAC {mac_address} not found")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Connect to the device
|
# Connect to the device
|
||||||
@@ -43,14 +43,14 @@ async def read_data(mac_address):
|
|||||||
success = False
|
success = False
|
||||||
# Check if Mi service is available
|
# Check if Mi service is available
|
||||||
|
|
||||||
print("?? Waiting on client to connect...")
|
print("-- Waiting on client to connect...")
|
||||||
while not client.is_connected:
|
while not client.is_connected:
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
while not success:
|
while not success:
|
||||||
try:
|
try:
|
||||||
print("..Client connected, getting services")
|
print(".. Client connected, getting services")
|
||||||
services = client.services
|
services = client.services
|
||||||
print("..Services acquired, loading uuid matches")
|
print(".. Services acquired, loading uuid matches")
|
||||||
mi_service = next((s for s in services if s.uuid.lower() == MI_SERVICE_UUID.lower()), None)
|
mi_service = next((s for s in services if s.uuid.lower() == MI_SERVICE_UUID.lower()), None)
|
||||||
success = True
|
success = True
|
||||||
#print("uuid matches loaded")
|
#print("uuid matches loaded")
|
||||||
@@ -68,7 +68,7 @@ async def read_data(mac_address):
|
|||||||
temp = temp / 100
|
temp = temp / 100
|
||||||
hum = sensor_data[2]
|
hum = sensor_data[2]
|
||||||
|
|
||||||
print(f"-- Temperature: {temp:.1f}°C, Humidity: {hum}%")
|
print(f"-- Temperature: {temp:.1f}°C, Humidity: {hum}%")
|
||||||
return temp, hum
|
return temp, hum
|
||||||
|
|
||||||
def sensor_data_query(mac_list):
|
def sensor_data_query(mac_list):
|
||||||
|
|||||||
+2
-4
@@ -36,8 +36,7 @@ def save_state() -> None:
|
|||||||
try:
|
try:
|
||||||
with open(STATE_FILE, "wb") as f:
|
with open(STATE_FILE, "wb") as f:
|
||||||
pickle.dump(state, f, protocol=pickle.HIGHEST_PROTOCOL)
|
pickle.dump(state, f, protocol=pickle.HIGHEST_PROTOCOL)
|
||||||
if debug_output:
|
print("[Scanner] State persisted to", STATE_FILE)
|
||||||
print("[Scanner] State persisted to", STATE_FILE)
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
# Don't crash the app – just log the error
|
# Don't crash the app – just log the error
|
||||||
print("[Scanner] Warning: could not persist state:", exc)
|
print("[Scanner] Warning: could not persist state:", exc)
|
||||||
@@ -58,8 +57,7 @@ def load_state() -> None:
|
|||||||
_mac_cache.update(state.get("mac_cache", []))
|
_mac_cache.update(state.get("mac_cache", []))
|
||||||
global _sensors_cache
|
global _sensors_cache
|
||||||
_sensors_cache = state.get("sensors", [])
|
_sensors_cache = state.get("sensors", [])
|
||||||
if debug_output:
|
print("[Scanner] Loaded state from", STATE_FILE)
|
||||||
print("[Scanner] Loaded state from", STATE_FILE)
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print("[Scanner] Warning: could not load state:", exc)
|
print("[Scanner] Warning: could not load state:", exc)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user