did stuff idk i'm cooked

This commit is contained in:
2024-06-22 22:37:24 +02:00
parent 2b1c12f273
commit 961fba65be
13 changed files with 53 additions and 24 deletions

View File

@@ -1,2 +1,5 @@
bluepy
pyyaml
pyyaml
bs4
lxml
requests

View File

@@ -14,12 +14,10 @@ class Data:
def parse_data(self, val):
data_bytes = [int(val[i:i + 2], 16) for i in range(0, len(val), 2)]
if data_bytes[8] > 127: data_bytes[8] -= 256
if data_bytes[8] > 127:
print(data_bytes)
data_bytes[8] -= 256
self.timestamp = datetime.now().astimezone().replace(microsecond=0).isoformat()
self.mac = ":".join(["{:02X}".format(data_bytes[i]) for i in range(2, 8)])
self.mac = ":".join(["{:02X}".format(data_bytes[i]) for i in range(2, 8)]).upper()
self.temperature = (data_bytes[8] * 256 + data_bytes[9]) / 10
self.humidity = data_bytes[10]
self.battery_percent = data_bytes[11]

View File

@@ -20,6 +20,5 @@ def get_devices():
return devices_list
def get_device(dev):
return next((d for d in get_devices() if d.mac == dev.addr.upper()), None)

View File

@@ -2,7 +2,7 @@ from bluepy.btle import DefaultDelegate
from bluepy.btle import Scanner
from data_class import Data
from devices import get_devices as get_device_from_config
from devices import get_device
# This is the list, where the responses will be stored from the `handleDiscovery`
devices = []
@@ -20,7 +20,7 @@ class ScanDelegate(DefaultDelegate):
data_obj = Data(val)
if self.is_atc_device(dev, data_obj):
device_from_config = self.get_device(dev)
device_from_config = get_device(dev)
devices.append([dev, data_obj, device_from_config])
@staticmethod
@@ -35,17 +35,13 @@ class ScanDelegate(DefaultDelegate):
for device in devices:
if str(device[0].addr) == str(dev.addr): return False
device_from_config = self.get_device(dev)
device_from_config = get_device(dev)
try:print(f"Device: {dev.addr.upper()} ({dev.addrType}), RSSI: {dev.rssi} dB, Room: {device_from_config.room}")
except:print(f"Device: {dev.addr.upper()} ({dev.addrType}), RSSI: {dev.rssi} dB, Room: ?")
print(f'\tTemp: {data_obj.temperature}°C, Humid: {data_obj.humidity}%, Batt: {data_obj.battery_percent}%\n')
return True
@staticmethod
def get_device(dev):
return next((d for d in get_device_from_config() if d.mac == dev.addr.upper()), None)
def cleanup():
global devices

1
python/src/log_data.py Normal file
View File

@@ -0,0 +1 @@
# TODO

View File

@@ -1,7 +1,5 @@
from discovery import start_discovery
from data_class import Data
from loop import start_loop
from time import sleep
devices = start_discovery()

1
python/src/mqtt.py Normal file
View File

@@ -0,0 +1 @@
# TODO