mirror of
https://github.com/rwinkhart/uni-nut.git
synced 2026-09-05 16:37:15 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42b80c18ad | ||
|
|
e15cb96069 |
@@ -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,24 @@ 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
|
||||
}
|
||||
lSplit := strings.Split(l, " ")
|
||||
if len(lSplit) < 4 {
|
||||
return "", fmt.Errorf("invalid response to GET VAR; check your UPS ID")
|
||||
}
|
||||
value := strings.Trim(strings.Join(lSplit[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