Skip to content

Commit 4ce8f05

Browse files
committed
Fix for progress status
1 parent 5483ab3 commit 4ce8f05

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

command/ota/status.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func PrintOtaStatus(otaid, otaids, device string, cred *config.Credentials, limi
4444
res, err := otapi.GetOtaStatusByOtaID(otaid, limit, order)
4545
if err == nil && res != nil {
4646
feedback.PrintResult(otaapi.OtaStatusDetail{
47-
FirmwareSize: res.FirmwareSize,
47+
FirmwareSize: res.Ota.FirmwareSize,
4848
Ota: res.Ota,
4949
Details: res.States,
5050
})

internal/ota-api/dto.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package otaapi
1919

2020
import (
21+
"fmt"
2122
"strconv"
2223
"strings"
2324
"time"
@@ -31,22 +32,24 @@ const progressBarMultiplier = 2
3132

3233
type (
3334
OtaStatusResponse struct {
34-
FirmwareSize *int64 `json:"firmware_size,omitempty"`
35-
Ota Ota `json:"ota"`
36-
States []State `json:"states,omitempty"`
35+
Ota Ota `json:"ota"`
36+
States []State `json:"states,omitempty"`
3737
}
3838

3939
OtaStatusList struct {
4040
Ota []Ota `json:"ota"`
4141
}
4242

4343
Ota struct {
44-
ID string `json:"id,omitempty" yaml:"id,omitempty"`
45-
DeviceID string `json:"device_id,omitempty" yaml:"device_id,omitempty"`
46-
Status string `json:"status" yaml:"status"`
47-
StartedAt string `json:"started_at" yaml:"started_at"`
48-
EndedAt string `json:"ended_at,omitempty" yaml:"ended_at,omitempty"`
49-
ErrorReason string `json:"error_reason,omitempty" yaml:"error_reason,omitempty"`
44+
ID string `json:"id,omitempty" yaml:"id,omitempty"`
45+
DeviceID string `json:"device_id,omitempty" yaml:"device_id,omitempty"`
46+
Status string `json:"status" yaml:"status"`
47+
StartedAt string `json:"started_at" yaml:"started_at"`
48+
EndedAt string `json:"ended_at,omitempty" yaml:"ended_at,omitempty"`
49+
ErrorReason string `json:"error_reason,omitempty" yaml:"error_reason,omitempty"`
50+
FirmwareSize int64 `json:"firmware_size,omitempty"`
51+
MaxRetries int64 `json:"max_retries,omitempty"`
52+
RetryAttempt int64 `json:"retry_attempt,omitempty"`
5053
}
5154

5255
State struct {
@@ -57,7 +60,7 @@ type (
5760
}
5861

5962
OtaStatusDetail struct {
60-
FirmwareSize *int64 `json:"firmware_size,omitempty"`
63+
FirmwareSize int64 `json:"firmware_size,omitempty"`
6164
Ota Ota `json:"ota"`
6265
Details []State `json:"details,omitempty"`
6366
}
@@ -160,8 +163,8 @@ func (r OtaStatusDetail) String() string {
160163
t = table.New()
161164
t.SetHeader("Time", "Status", "Detail")
162165
fwSize := int64(0)
163-
if r.FirmwareSize != nil {
164-
fwSize = *r.FirmwareSize
166+
if r.FirmwareSize > 0 {
167+
fwSize = r.FirmwareSize
165168
}
166169
for _, s := range r.Details {
167170
stateData := formatStateData(s.State, s.StateData, fwSize, hasReachedFlashState(r.Details))
@@ -186,6 +189,7 @@ func formatStateData(state, data string, firmware_size int64, hasReceivedFlashSt
186189
if data == "" || data == "Unknown" {
187190
return ""
188191
}
192+
fmt.Println("State: ", state)
189193
if state == "fetch" {
190194
// This is the state 'fetch' of OTA progress. This contains a number that represents the number of bytes fetched
191195
actualDownloadedData, err := strconv.Atoi(data)

0 commit comments

Comments
 (0)