diff --git a/nut.go b/nut.go index 9a41766..6de6715 100644 --- a/nut.go +++ b/nut.go @@ -36,8 +36,8 @@ func (c *Client) Close() error { return c.conn.Close() } -// GetListVar updates NutKeyValMap with the current status of all variables from . -func (c *Client) GetListVar(upsID string) error { +// ListVar updates NutKeyValMap with the current status of all variables from . +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 . +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)}