@@ -157,6 +157,17 @@ def list_ups(self):
157157
158158 return ups_dict
159159
160+ def description (self , ups ):
161+ """Returns the description for a given UPS."""
162+ logging .debug ("description called..." )
163+
164+ self ._srv_handler .write ("GET UPSDESC %s\n " % ups )
165+ result = self ._srv_handler .read_until ("\n " , self ._timeout )
166+ try :
167+ return result .split ('"' )[1 ].strip ()
168+ except IndexError :
169+ raise PyNUTError (result .replace ("\n " , "" ))
170+
160171 def list_vars (self , ups = "" ):
161172 """Get all available vars from the specified UPS.
162173
@@ -275,7 +286,7 @@ def list_rw_vars(self, ups=""):
275286
276287 return rw_vars
277288
278- def set_var (self , ups = "" , var = "" , value = "" ):
289+ def set_var (self , ups , var , value ):
279290 """Set a variable to the specified value on selected UPS.
280291
281292 The variable must be a writable value (cf list_rw_vars) and you
@@ -288,7 +299,48 @@ def set_var(self, ups="", var="", value=""):
288299 if result != "OK\n " :
289300 raise PyNUTError (result .replace ("\n " , "" ))
290301
291- def run_command (self , ups = "" , command = "" ):
302+ def get_var (self , ups , var ):
303+ """Get the value of a variable."""
304+ logging .debug ("get_var called..." )
305+
306+ self ._srv_handler .write ("GET VAR %s %s\n " % (ups , var ))
307+ result = self ._srv_handler .read_until ("\n " , self ._timeout )
308+ try :
309+ # result = 'VAR %s %s "%s"' % (ups, var, value)
310+ return result .split ('"' )[1 ].strip ()
311+ except IndexError :
312+ raise PyNUTError (result .replace ("\n " , "" ))
313+
314+ # Alias for convenience
315+ def get (self , ups , var ):
316+ """Get the value of a variable (alias for get_var)."""
317+ return self .get_var (ups , var )
318+
319+ def var_description (self , ups , var ):
320+ """Get a variable's description."""
321+ logging .debug ("var_description called..." )
322+
323+ self ._srv_handler .write ("GET DESC %s %s\n " % (ups , var ))
324+ result = self ._srv_handler .read_until ("\n " , self ._timeout )
325+ try :
326+ # result = 'DESC %s %s "%s"' % (ups, var, description)
327+ return result .split ('"' )[1 ].strip ()
328+ except IndexError :
329+ raise PyNUTError (result .replace ("\n " , "" ))
330+
331+ def command_description (self , ups , command ):
332+ """Get a command's description."""
333+ logging .debug ("command_description called..." )
334+
335+ self ._srv_handler .write ("GET CMDDESC %s %s\n " % (ups , command ))
336+ result = self ._srv_handler .read_until ("\n " , self ._timeout )
337+ try :
338+ # result = 'CMDDESC %s %s "%s"' % (ups, command, description)
339+ return result .split ('"' )[1 ].strip ()
340+ except IndexError :
341+ raise PyNUTError (result .replace ("\n " , "" ))
342+
343+ def run_command (self , ups , command ):
292344 """Send a command to the specified UPS."""
293345 logging .debug ("run_command called..." )
294346
@@ -312,6 +364,20 @@ def fsd(self, ups=""):
312364 if result != "OK FSD-SET\n " :
313365 raise PyNUTError (result .replace ("\n " , "" ))
314366
367+ def num_logins (self , ups = "" ):
368+ """Send GET NUMLOGINS command to get the number of users logged
369+ into a given UPS.
370+ """
371+ logging .debug ("num_logins called on '%s'..." , ups )
372+
373+ self ._srv_handler .write ("GET NUMLOGINS %s\n " % ups )
374+ result = self ._srv_handler .read_until ("\n " , self ._timeout )
375+ try :
376+ # result = "NUMLOGINS %s %s\n" % (ups, int(numlogins))
377+ return int (result .split (' ' )[2 ].strip ())
378+ except (ValueError , IndexError ):
379+ raise PyNUTError (result .replace ("\n " , "" ))
380+
315381 def help (self ):
316382 """Send HELP command."""
317383 logging .debug ("HELP called..." )
0 commit comments