print line cleanup 2
This commit is contained in:
1 parent
91640964cd
commit
f00ba3fefc
3 files changed
+10
-10
No files matched your search
@@ -48,9 +48,9 @@ async def read_data(mac_address):
|
|||||||
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")
|
||||||
@@ -69,7 +69,6 @@ async def read_data(mac_address):
|
|||||||
hum = sensor_data[2]
|
hum = sensor_data[2]
|
||||||
|
|
||||||
print(f"-- Temperature: {temp:.1f}°C, Humidity: {hum}%")
|
print(f"-- Temperature: {temp:.1f}°C, Humidity: {hum}%")
|
||||||
print("")
|
|
||||||
return temp, hum
|
return temp, hum
|
||||||
|
|
||||||
def sensor_data_query(mac_list):
|
def sensor_data_query(mac_list):
|
||||||
|
|||||||
+7
-6
@@ -100,16 +100,16 @@ def update_cache() -> None:
|
|||||||
# Gets the MACs
|
# Gets the MACs
|
||||||
print("--- Starting update_cache loop ---")
|
print("--- Starting update_cache loop ---")
|
||||||
new_macs = scan_macs()
|
new_macs = scan_macs()
|
||||||
print(f"[Scanner] Updated cache, {len(_mac_cache)} unique MAC(s).")
|
|
||||||
print("Updating data for current MACs...")
|
|
||||||
# now that we have MACs, let's get sensor data
|
# now that we have MACs, let's get sensor data
|
||||||
|
print("Updating sensor data...")
|
||||||
sensor_data = None
|
sensor_data = None
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print(f"Aww fuck, no data :( - {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:")
|
||||||
for sensor_datum in sensor_data:
|
for sensor_datum in sensor_data:
|
||||||
print(f"MAC - {sensor_datum['name']} | temp - {sensor_datum['temp']} | humidity - {sensor_datum['humidity']}")
|
print(f"MAC - {sensor_datum['name']} | temp - {sensor_datum['temp']} | humidity - {sensor_datum['humidity']}")
|
||||||
for sensor in _sensors_cache:
|
for sensor in _sensors_cache:
|
||||||
@@ -123,15 +123,16 @@ def update_cache() -> None:
|
|||||||
|
|
||||||
# this helper function scans for MACs
|
# this helper function scans for MACs
|
||||||
def scan_macs():
|
def scan_macs():
|
||||||
|
print("Scanning for MACs:")
|
||||||
new_macs = asyncio.run(_scan_once())
|
new_macs = asyncio.run(_scan_once())
|
||||||
with _lock:
|
with _lock:
|
||||||
print("MACs found:")
|
|
||||||
for new_mac in new_macs:
|
for new_mac in new_macs:
|
||||||
print(f"{new_mac}")
|
print(f"{new_mac}")
|
||||||
new_sensor = Sensor(name=f"{new_mac}")
|
new_sensor = Sensor(name=f"{new_mac}")
|
||||||
if new_mac not in set(_mac_cache):
|
if new_mac not in set(_mac_cache):
|
||||||
_sensors_cache.append(new_sensor)
|
_sensors_cache.append(new_sensor)
|
||||||
_mac_cache.update(new_macs)
|
_mac_cache.update(new_macs)
|
||||||
|
print(f"Found {len(new_macs)} new MACs, total {len(_mac_cache)} MACs in cache.")
|
||||||
return new_macs
|
return new_macs
|
||||||
|
|
||||||
# return just the MACs
|
# return just the MACs
|
||||||
@@ -149,7 +150,7 @@ def get_sensor_details(friendly_date = False):
|
|||||||
if friendly_date:
|
if friendly_date:
|
||||||
first_seen = ts_to_pst_string(sensor.first_seen)
|
first_seen = ts_to_pst_string(sensor.first_seen)
|
||||||
last_seen = ts_to_pst_string(sensor.last_seen)
|
last_seen = ts_to_pst_string(sensor.last_seen)
|
||||||
print(f"Summary - {sensor.name}")
|
# print(f"Summary - {sensor.name}")
|
||||||
new_sensor = {
|
new_sensor = {
|
||||||
"name": sensor.name,
|
"name": sensor.name,
|
||||||
"first_seen": first_seen,
|
"first_seen": first_seen,
|
||||||
@@ -168,7 +169,7 @@ def get_sensor_details(friendly_date = False):
|
|||||||
def get_sensor_summary():
|
def get_sensor_summary():
|
||||||
sensor_list = []
|
sensor_list = []
|
||||||
for sensor in _sensors_cache:
|
for sensor in _sensors_cache:
|
||||||
print(f"Summary - {sensor.name}")
|
# print(f"Summary - {sensor.name}")
|
||||||
new_sensor = {
|
new_sensor = {
|
||||||
"name": sensor.name,
|
"name": sensor.name,
|
||||||
"comment": sensor.comment,
|
"comment": sensor.comment,
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ class Sensor:
|
|||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialise timestamps when the object is created."""
|
"""Initialise timestamps when the object is created."""
|
||||||
print(f"Instantiating new sensor object - {self.name}")
|
# print(f"Instantiating new sensor object - {self.name}")
|
||||||
ts = _current_timestamp()
|
ts = _current_timestamp()
|
||||||
self.first_seen = ts
|
self.first_seen = ts
|
||||||
self.last_seen = ts
|
self.last_seen = ts
|
||||||
|
|||||||
Reference in new issue
Block a user