-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_bridge_infos.py
56 lines (41 loc) · 1.62 KB
/
example_bridge_infos.py
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
48
49
50
51
52
53
54
55
56
"""Read out information from multiple Bridges
This Script connects to all available Bridges and prints out the Battery Level
as well as the hardware and Firmware Version.
"""
import asyncio
from gravitraxconnect import gravitrax_bridge as gb
finished = asyncio.Event()
async def main():
"""Connect to all available Bridges and read out information
"""
try:
bridges = [gb.Bridge()]
gb.logger.disabled = False
index = 0
gb.log_print("Searching for Bridge")
while await bridges[index].connect(timeout=10, try_reconnect=False):
gb.log_print("Searching for more Bridges")
new_bridge = gb.Bridge()
bridges.append(new_bridge)
index += 1
bridges.pop()
gb.log_print(f"{len(bridges)} Bridges found")
for bridge in bridges:
gb.log_print(await bridge.request_battery_string(), bridge=bridge)
# Getting the Firmware and Hardware Version from the Member variables
# that are set after connecting to the bridge
gb.log_print(f"Firmware: {bridge.firmware} Hardware: {bridge.hardware}")
# Requesting the current Firmware/ Hardware Version from the Bridge
if (await bridge.request_bridge_info())[0] >= 14:
gb.log_print("Firmware 14 or newer is used")
await bridge.disconnect()
gb.log_print("Press Enter to close")
input()
except asyncio.CancelledError:
return
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
gb.log_print("Program finished")