summaryrefslogtreecommitdiffstats
path: root/src/discover.py
blob: e2351b38434308969bebe3f62fb0bdec275f1c83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import asyncio
from bleak import BleakScanner
import os

async def discover(debug=False):
    try:
        devices = await BleakScanner.discover()
        if debug:
            return [{"name": device.name, "address": device.address} for device in devices]
        else:
            return [
                {"name": device.name, "address": device.address}
                for device in devices
                if device.name and "TP350S" in device.name
            ]
    except Exception:
        return []

async def main():
    check_debug = os.getenv("DEBUG", "FALSE").upper() == "TRUE"
    if check_debug:
        print("DEBUG MODE ENABLED")
    devices = await discover(debug=check_debug)

    print(devices)

if __name__ == "__main__":
    asyncio.run(main())
git.ajschof.me — hosted by ajschofield — powered by cgit