mirror of
https://github.com/rwinkhart/uni-nut.git
synced 2026-08-27 20:36:25 -04:00
Add "GetVar" function for checking the value of a specific variable (statelessly)
This commit is contained in:
@@ -36,8 +36,8 @@ func (c *Client) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
// GetListVar updates NutKeyValMap with the current status of all variables from <upsID>.
|
||||
func (c *Client) GetListVar(upsID string) error {
|
||||
// ListVar updates NutKeyValMap with the current status of all variables from <upsID>.
|
||||
func (c *Client) ListVar(upsID string) error {
|
||||
cmd := "LIST VAR \"" + upsID + "\""
|
||||
if err := c.write(cmd); err != nil {
|
||||
return err
|
||||
@@ -68,6 +68,20 @@ outer:
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVar returns the value of the specified variable for <upsID>.
|
||||
func (c *Client) GetVar(upsID, varName string) (string, error) {
|
||||
cmd := "GET VAR \"" + upsID + "\" \"" + varName + "\""
|
||||
if err := c.write(cmd); err != nil {
|
||||
return "", err
|
||||
}
|
||||
l, err := c.read()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
value := strings.Trim(strings.Join(strings.Split(l, " ")[3:], " "), "\"")
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// newClient wraps an existing net.Conn.
|
||||
func newClient(conn net.Conn) *Client {
|
||||
return &Client{conn, bufio.NewReader(conn)}
|
||||
|
||||
Reference in New Issue
Block a user