Skip to content

Commit 7a43c0d

Browse files
authored
Merge pull request #11 from menloresearch/main
robot status
2 parents 5899577 + 7fcb479 commit 7a43c0d

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

internal/clients/platform/platform.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,31 @@ func NewClient() (*Client, error) {
4040
}, nil
4141
}
4242

43+
// Battery represents battery status
44+
type Battery struct {
45+
Level int `json:"level"`
46+
Charging bool `json:"charging"`
47+
}
48+
49+
// RobotStatus represents the robot's current status
50+
type RobotStatus struct {
51+
RobotID string `json:"robot_id"`
52+
Battery Battery `json:"battery"`
53+
Timestamp int64 `json:"timestamp"`
54+
}
55+
56+
// LocalTimestamp returns the timestamp converted to local time
57+
func (r *RobotStatus) LocalTimestamp() time.Time {
58+
return time.Unix(r.Timestamp, 0).Local()
59+
}
60+
4361
// RobotResponse represents a robot in the API response
4462
type RobotResponse struct {
45-
ID string `json:"id"`
46-
Model string `json:"model"`
47-
Type string `json:"type"`
48-
Name string `json:"name"`
63+
ID string `json:"id"`
64+
Model string `json:"model"`
65+
Type string `json:"type"`
66+
Name string `json:"name"`
67+
Status *RobotStatus `json:"status,omitempty"`
4968
}
5069

5170
// ListResponse is a generic list response

internal/commands/robot.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ func showRobotStatus(robotID string) error {
233233
fmt.Printf("Model: %s\n", robot.Model)
234234
fmt.Printf("Type: %s\n", robot.Type)
235235

236+
if robot.Status != nil {
237+
fmt.Printf("\nStatus:\n")
238+
fmt.Printf(" Battery: %d%%", robot.Status.Battery.Level)
239+
if robot.Status.Battery.Charging {
240+
fmt.Printf(" (charging)")
241+
}
242+
fmt.Printf("\n")
243+
fmt.Printf(" Last Updated: %s\n", robot.Status.LocalTimestamp().Format("2006-01-02 15:04:05"))
244+
}
245+
236246
return nil
237247
}
238248

0 commit comments

Comments
 (0)