Skip to content

Commit 92c65db

Browse files
authored
Fix line status for multiple ports
1 parent 75c49db commit 92c65db

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

pyobihai/__init__.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,58 @@
1111

1212
class PyObihai:
1313

14-
15-
def get_state(self, url, username, password) :
14+
def get_state(self, url, username, password):
1615

1716
server_origin = '{}://{}'.format('http', url)
1817
url = urljoin(server_origin, DEFAULT_STATUS_PATH)
19-
18+
2019
services = dict()
2120
try:
2221
resp = requests.get(url, auth=requests.auth.HTTPDigestAuth(username,password), timeout=2)
2322
root = xml.etree.ElementTree.fromstring(resp.text)
2423
for models in root.iter('model'):
2524
if models.attrib["reboot_req"]:
2625
services["Reboot Required"] = models.attrib["reboot_req"]
27-
for o in root.findall("object") :
28-
name = o.attrib.get('name')
29-
if 'Service Status' in name :
26+
for o in root.findall("object"):
27+
name = o.attrib.get('name')
28+
if 'Service Status' in name:
3029
if 'OBiTALK Service Status' in name:
31-
for e in o.findall("./parameter[@name='Status']/value") :
32-
state = e.attrib.get('current').split()[0] # take the first word
30+
for e in o.findall("./parameter[@name='Status']/value"):
31+
state = e.attrib.get('current').split()[0]
3332
services[name] = state
3433
else:
35-
for e in o.findall("./parameter[@name='Status']/value") :
36-
state = e.attrib.get('current').split()[0] # take the first word
34+
for e in o.findall("./parameter[@name='Status']/value"):
35+
state = e.attrib.get('current').split()[0]
3736
if state != 'Service':
38-
for x in o.findall("./parameter[@name='CallState']/value") :
39-
state = x.attrib.get('current').split()[0] # take the first word
37+
for x in o.findall("./parameter[@name='CallState']/value"):
38+
state = x.attrib.get('current').split()[0]
4039
services[name] = state
4140
if 'Product Information' in name:
42-
for e in o.findall("./parameter[@name='UpTime']/value") :
43-
state = e.attrib.get('current') # take the first word
41+
for e in o.findall("./parameter[@name='UpTime']/value"):
42+
state = e.attrib.get('current')
4443
services["UpTime"] = state
4544
except requests.exceptions.RequestException as e:
4645
_LOGGER.error(e)
4746
return services
4847

49-
def get_line_state(self, url, username, password) :
50-
48+
def get_line_state(self, url, username, password):
49+
5150
server_origin = '{}://{}'.format('http', url)
5251
url = urljoin(server_origin, DEFAULT_LINE_PATH)
5352
services = dict()
5453
try:
5554
resp = requests.get(url, auth=requests.auth.HTTPDigestAuth(username,password), timeout=2)
5655
root = xml.etree.ElementTree.fromstring(resp.text)
57-
for o in root.findall("object") :
58-
name = o.attrib.get('name')
59-
if 'Port Status' in name :
60-
for e in o.findall("./parameter[@name='State']/value") :
61-
state = e.attrib.get('current')# take the whole string
62-
services[name] = state
56+
for o in root.findall("object"):
57+
name = o.attrib.get('name')
58+
subtitle = o.attrib.get('subtitle')
59+
if 'Port Status' in name:
60+
for e in o.findall("./parameter[@name='State']/value"):
61+
state = e.attrib.get('current')
62+
services[subtitle] = state
6363
for x in o.findall("./parameter[@name='LastCallerInfo']/value"):
6464
state = x.attrib.get('current')
65-
services["Last Caller Info"] = state
65+
services[subtitle + " Last Caller Info"] = state
6666
except requests.exceptions.RequestException as e:
6767
_LOGGER.error(e)
6868
return services
69-

0 commit comments

Comments
 (0)