blob: ecd075a5edb9daa47920cde9f2a2a3b123946829 (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
from discover import discover
import os
from logger import get_logger
import asyncio
logger = get_logger("Main")
# TODO - This is not tested yet as I only have one device.
# Needs mocking and testing in test_main.py
async def device_selection(devices):
print("\nPlease choose which device to use:")
for index, device in enumerate(devices, start=1):
print(f"{index}. {device['name']} - {device['address']}")
while True:
try:
choice = int(input("\nEnter the number of your choice: "))
if 1 <= choice <= len(devices):
return devices[choice - 1]
else:
logger.warning("Invalid selection.")
except ValueError:
logger.warning("Invalid selection.")
async def main(debug_flag=None):
# Discover
check_debug = debug_flag if debug_flag is not None else os.getenv("DEBUG", "FALSE").upper() == "TRUE"
if check_debug:
logger.info("Debug mode is enabled")
devices = await discover(debug=check_debug)
if not devices:
logger.error("No supported devices were found during discovery")
return
if len(devices) >= 2:
logger.info("There are multiple TP350S devices!")
device = await device_selection(devices)
else:
device = devices[0]
logger.info(f"Single device selected: {device['name']} - {device['address']}")
if __name__ == "__main__":
asyncio.run(main())
|