diff --git a/api/client.go b/api/client.go index 397a919..f98d231 100644 --- a/api/client.go +++ b/api/client.go @@ -299,6 +299,25 @@ func (c *Client) ReadAnyMessage() (*Message, error) { return &msg, nil } +// SendAction sends an action to the server. +func (c *Client) SendAction(actionName string) (*Message, error) { + token := generateRequestToken() + + action := Action{ + ActionName: actionName, + Login: *c.email, + PasswordHash: *c.resourcePasswordHash, + RequestToken: token, + } + + err := c.mainConn.WriteJSON(action) + if err != nil { + return nil, fmt.Errorf("failed to write action %s: %v", action.ActionName, err) + } + + return c.ReadMessage(action.ActionName, token) +} + // SendEvent sends an event containing value to the cell. // // Events are named "Xevents" in F&Home's terminology. diff --git a/cmd/fhome/commands.go b/cmd/fhome/commands.go index 0636461..36be84a 100644 --- a/cmd/fhome/commands.go +++ b/cmd/fhome/commands.go @@ -126,6 +126,33 @@ var configCommand = cli.Command{ log.Println() } } else if c.Bool("glance") { + // We want to see real values of the system resources. + // To do that we need to send "statustouches" action and + // wait for its response. + + // Send "statustouches" event. + _, err := client.SendAction(api.ActionStatusTouches) + if err != nil { + return fmt.Errorf("failed to send action: %v", err) + } + + msg, err := client.ReadMessage(api.ActionStatusTouchesChanged, "") + if err != nil { + slog.Error("failed to read message", slog.Any("error", err)) + return err + } + + var resp api.StatusTouchesChangedResponse + + err = json.Unmarshal(msg.Raw, &resp) + if err != nil { + slog.Error("failed to unmarshal message", slog.Any("error", err)) + return err + } + + cellValue := resp.Response.CellValues + printCellData(&cellValue, config) + cells := []struct { Name string Value int