Skip to content

Commit ee5ca1f

Browse files
committed
Refactored list_clients.
1 parent 8476758 commit ee5ca1f

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

nut2.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def list_clients(self, ups=None):
221221
The result is a dictionary containing 'key->val' pairs of
222222
'UPSName' and a list of clients.
223223
"""
224-
logging.debug("list_clients from server")
224+
logging.debug("list_clients from '%s'...", ups or "server")
225225

226226
if ups and (ups not in self.list_ups()):
227227
raise PyNUTError("%s is not a valid UPS" % ups)
@@ -235,17 +235,16 @@ def list_clients(self, ups=None):
235235
raise PyNUTError(result.replace("\n", ""))
236236

237237
result = self._srv_handler.read_until("END LIST CLIENTS\n")
238-
ups_dict = {}
239238

239+
clients = {}
240240
for line in result.split("\n"):
241-
if line[:6] == "CLIENT":
242-
host, ups = line[7:].split(' ')
243-
ups.replace(' ', '')
244-
if not ups in ups_dict:
245-
ups_dict[ups] = []
246-
ups_dict[ups].append(host)
241+
if line.startswith("CLIENT"):
242+
host, ups = line[len("CLIENT "):].split(' ')[:2]
243+
if not ups in clients:
244+
clients[ups] = []
245+
clients[ups].append(host)
247246

248-
return ups_dict
247+
return clients
249248

250249
def list_rw_vars(self, ups=""):
251250
"""Get a list of all writable vars from the selected UPS.

0 commit comments

Comments
 (0)