From 7fcb4796fd540f22ed70e58192932cf4ecd0e0a8 Mon Sep 17 00:00:00 2001 From: jjchen01 Date: Mon, 30 Mar 2026 16:15:46 +0800 Subject: [PATCH] robot status --- internal/clients/platform/platform.go | 27 +++++++++++++++++++++++---- internal/commands/robot.go | 10 ++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/internal/clients/platform/platform.go b/internal/clients/platform/platform.go index d9f402a..a2229ab 100644 --- a/internal/clients/platform/platform.go +++ b/internal/clients/platform/platform.go @@ -40,12 +40,31 @@ func NewClient() (*Client, error) { }, nil } +// Battery represents battery status +type Battery struct { + Level int `json:"level"` + Charging bool `json:"charging"` +} + +// RobotStatus represents the robot's current status +type RobotStatus struct { + RobotID string `json:"robot_id"` + Battery Battery `json:"battery"` + Timestamp int64 `json:"timestamp"` +} + +// LocalTimestamp returns the timestamp converted to local time +func (r *RobotStatus) LocalTimestamp() time.Time { + return time.Unix(r.Timestamp, 0).Local() +} + // RobotResponse represents a robot in the API response type RobotResponse struct { - ID string `json:"id"` - Model string `json:"model"` - Type string `json:"type"` - Name string `json:"name"` + ID string `json:"id"` + Model string `json:"model"` + Type string `json:"type"` + Name string `json:"name"` + Status *RobotStatus `json:"status,omitempty"` } // ListResponse is a generic list response diff --git a/internal/commands/robot.go b/internal/commands/robot.go index 3f6fb1a..3b90529 100644 --- a/internal/commands/robot.go +++ b/internal/commands/robot.go @@ -233,6 +233,16 @@ func showRobotStatus(robotID string) error { fmt.Printf("Model: %s\n", robot.Model) fmt.Printf("Type: %s\n", robot.Type) + if robot.Status != nil { + fmt.Printf("\nStatus:\n") + fmt.Printf(" Battery: %d%%", robot.Status.Battery.Level) + if robot.Status.Battery.Charging { + fmt.Printf(" (charging)") + } + fmt.Printf("\n") + fmt.Printf(" Last Updated: %s\n", robot.Status.LocalTimestamp().Format("2006-01-02 15:04:05")) + } + return nil }