forked from AceCentre/RelayKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll_devname.py
33 lines (24 loc) · 861 Bytes
/
poll_devname.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
from time import sleep, time
from pathlib import Path
from notifypy import Notify
from relaykeysclient import RelayKeysClient
client = RelayKeysClient(url="http://127.0.0.1:5383/")
def send_devname_notification(device_name):
notification = Notify()
notification.application_name = "Relaykeys"
notification.title = ""
notification.icon = str(Path(__file__).resolve().parent / "resources" / "logo.png")
notification.message = "Connected to {}.".format(device_name)
notification.send()
polling_start_timestamp = time()
timeout_sec = 40
while True:
if time() - polling_start_timestamp > timeout_sec:
break # timeout
ret = client.ble_cmd("devname")
if 'result' in ret:
devname = ret["result"]
if devname != 'NONE':
send_devname_notification(devname)
break
sleep(2)