File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
4462type 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
Original file line number Diff line number Diff 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 ("\n Status:\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
You can’t perform that action at this time.
0 commit comments