1818package otaapi
1919
2020import (
21- "fmt"
2221 "strconv"
2322 "strings"
2423 "time"
6261 OtaStatusDetail struct {
6362 FirmwareSize int64 `json:"firmware_size,omitempty"`
6463 MaxRetries int64 `json:"max_retries,omitempty"`
65- RetryAttempt int64 `json:"retry_attempt,omitempty"`
64+ RetryAttempt int64 `json:"retry_attempt,omitempty"`
6665 Ota Ota `json:"ota"`
6766 Details []State `json:"details,omitempty"`
6867 }
@@ -96,7 +95,7 @@ func (r OtaStatusList) String() string {
9695 line := []any {r .DeviceID , r .ID , r .MapStatus (), formatHumanReadableTs (r .StartedAt ), formatHumanReadableTs (r .EndedAt )}
9796 if hasErrorReason {
9897 line = append (line , r .ErrorReason )
99- line = append (line , r .RetryAttempt )
98+ line = append (line , strconv . FormatInt ( r .RetryAttempt , 10 ) )
10099 }
101100 t .AddRow (line ... )
102101 }
@@ -120,7 +119,7 @@ func (r Ota) String() string {
120119 hasErrorReason := r .ErrorReason != ""
121120
122121 if hasErrorReason {
123- t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" )
122+ t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" , "Retry Attempt" )
124123 } else {
125124 t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" )
126125 }
@@ -129,6 +128,7 @@ func (r Ota) String() string {
129128 line := []any {r .DeviceID , r .ID , r .MapStatus (), formatHumanReadableTs (r .StartedAt ), formatHumanReadableTs (r .EndedAt )}
130129 if hasErrorReason {
131130 line = append (line , r .ErrorReason )
131+ line = append (line , strconv .FormatInt (r .RetryAttempt , 10 ))
132132 }
133133 t .AddRow (line ... )
134134
@@ -147,7 +147,7 @@ func (r OtaStatusDetail) String() string {
147147 hasErrorReason := r .Ota .ErrorReason != ""
148148
149149 if hasErrorReason {
150- t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" )
150+ t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" , "Retry Attempt" )
151151 } else {
152152 t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" )
153153 }
@@ -156,23 +156,41 @@ func (r OtaStatusDetail) String() string {
156156 line := []any {r .Ota .DeviceID , r .Ota .ID , r .Ota .MapStatus (), formatHumanReadableTs (r .Ota .StartedAt ), formatHumanReadableTs (r .Ota .EndedAt )}
157157 if hasErrorReason {
158158 line = append (line , r .Ota .ErrorReason )
159+ line = append (line , strconv .FormatInt (r .RetryAttempt , 10 ))
159160 }
160161 t .AddRow (line ... )
161162
162163 output := t .Render ()
163164
164165 // Add details
166+ containsFlashState := false
167+ firstTS := ""
165168 if len (r .Details ) > 0 {
166169 t = table .New ()
167170 t .SetHeader ("Time" , "Status" , "Detail" )
168171 fwSize := int64 (0 )
169172 if r .FirmwareSize > 0 {
170173 fwSize = r .FirmwareSize
171174 }
175+ for _ , s := range r .Details {
176+ if upperCaseFirst (s .State ) == "Flash" {
177+ containsFlashState = true
178+ }
179+ if firstTS == "" {
180+ firstTS = formatHumanReadableTs (s .Timestamp )
181+ }
182+ }
183+ if ! containsFlashState && ! hasErrorReason {
184+ t .AddRow (firstTS , "Flash" , "" )
185+ if fwSize > 0 {
186+ t .AddRow (firstTS , "Fetch" , formatStateData ("fetch" , strconv .Itoa (int (fwSize )), fwSize , true ))
187+ }
188+ }
172189 for _ , s := range r .Details {
173190 stateData := formatStateData (s .State , s .StateData , fwSize , hasReachedFlashState (r .Details ))
174191 t .AddRow (formatHumanReadableTs (s .Timestamp ), upperCaseFirst (s .State ), stateData )
175192 }
193+
176194 output += "\n Details:\n " + t .Render ()
177195 }
178196
@@ -192,7 +210,6 @@ func formatStateData(state, data string, firmware_size int64, hasReceivedFlashSt
192210 if data == "" || data == "Unknown" {
193211 return ""
194212 }
195- fmt .Println ("State: " , state )
196213 if state == "fetch" {
197214 // This is the state 'fetch' of OTA progress. This contains a number that represents the number of bytes fetched
198215 actualDownloadedData , err := strconv .Atoi (data )
0 commit comments