|
11 | 11 |
|
12 | 12 | class PyObihai: |
13 | 13 |
|
14 | | - |
15 | | - def get_state(self, url, username, password) : |
| 14 | + def get_state(self, url, username, password): |
16 | 15 |
|
17 | 16 | server_origin = '{}://{}'.format('http', url) |
18 | 17 | url = urljoin(server_origin, DEFAULT_STATUS_PATH) |
19 | | - |
| 18 | + |
20 | 19 | services = dict() |
21 | 20 | try: |
22 | 21 | resp = requests.get(url, auth=requests.auth.HTTPDigestAuth(username,password), timeout=2) |
23 | 22 | root = xml.etree.ElementTree.fromstring(resp.text) |
24 | 23 | for models in root.iter('model'): |
25 | 24 | if models.attrib["reboot_req"]: |
26 | 25 | 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: |
30 | 29 | 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] |
33 | 32 | services[name] = state |
34 | 33 | 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] |
37 | 36 | 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] |
40 | 39 | services[name] = state |
41 | 40 | 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') |
44 | 43 | services["UpTime"] = state |
45 | 44 | except requests.exceptions.RequestException as e: |
46 | 45 | _LOGGER.error(e) |
47 | 46 | return services |
48 | 47 |
|
49 | | - def get_line_state(self, url, username, password) : |
50 | | - |
| 48 | + def get_line_state(self, url, username, password): |
| 49 | + |
51 | 50 | server_origin = '{}://{}'.format('http', url) |
52 | 51 | url = urljoin(server_origin, DEFAULT_LINE_PATH) |
53 | 52 | services = dict() |
54 | 53 | try: |
55 | 54 | resp = requests.get(url, auth=requests.auth.HTTPDigestAuth(username,password), timeout=2) |
56 | 55 | 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 |
63 | 63 | for x in o.findall("./parameter[@name='LastCallerInfo']/value"): |
64 | 64 | state = x.attrib.get('current') |
65 | | - services["Last Caller Info"] = state |
| 65 | + services[subtitle + " Last Caller Info"] = state |
66 | 66 | except requests.exceptions.RequestException as e: |
67 | 67 | _LOGGER.error(e) |
68 | 68 | return services |
69 | | - |
0 commit comments