-
Notifications
You must be signed in to change notification settings - Fork 0
/
plantronics.py
75 lines (60 loc) · 2.15 KB
/
plantronics.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
import logging
from functions import get_http_result
class PLTDevice:
def __init__(self, spokes, uid):
self.host = "127.0.0.1"
self.port = "32017"
self.BaseURL = "http://" + self.host + ":" + self.port
self.AttachURL = self.BaseURL + "/Spokes/DeviceServices/Attach?uid=" + uid
self.attached = False
self.session = None
self.uid = uid
self.spokes = spokes
def attach(self):
r = get_http_result(self.AttachURL)
logging.info(r.text)
if r.json()["isError"] is False:
self.attached = True
self.session = r.json()["Result"]
def release(self):
self.ReleaseURL = (
self.spokes.BaseURL + "/Spokes/DeviceServices/Release?sess=" + self.session
)
r = get_http_result(self.ReleaseURL)
if r.json()["isError"] is False:
self.attached = False
self.session = None
def get_events(self, queue=0):
self.EventsURL = (
self.spokes.BaseURL
+ "/Spokes/DeviceServices/Events?sess="
+ self.session
+ "&queue="
+ str(queue)
)
r = get_http_result(self.EventsURL)
logging.info(r.json())
class Spokes:
def __init__(self):
self.host = "127.0.0.1"
self.port = "32017"
self.BaseURL = "http://" + self.host + ":" + self.port
self.DeviceInfoURL = self.BaseURL + "/Spokes/DeviceServices/Info"
self.CallManagerURL = self.BaseURL + "/Spokes/CallServices/CallManagerState"
self.deviceInfo = None
self.callManagerInfo = None
def get_device_info(self):
r = get_http_result(self.DeviceInfoURL)
if r.json()["isError"] is True:
logging.warn(r.json()["Err"]["Description"])
else:
self.deviceInfo = r.json()
return self.deviceInfo
def get_callmanager_state(self):
r = get_http_result(self.CallManagerURL)
if r.json()["isError"] is True:
logging.warn(r.json()["Err"]["Description"])
else:
self.callManagerInfo = r.json()
return self.callManagerInfo