@@ 51,16 51,12 @@ func (client *Client) remoteStatus() *RemoteStatus {
log.Fatal(err)
}
- var connectedDevices []string
+ var sum float64
for key := range connections.List {
- if key != systemStatus.MyID {
- connectedDevices = append(connectedDevices, key)
+ if key == systemStatus.MyID {
+ continue
}
- }
-
- var sum float64
- for _, device := range connectedDevices {
- path := fmt.Sprintf("/rest/db/completion?device=%s", device)
+ path := fmt.Sprintf("/rest/db/completion?device=%s", key)
var status RemoteStatus
err = client.get(path, &status)
if err != nil {
@@ 70,11 66,11 @@ func (client *Client) remoteStatus() *RemoteStatus {
sum += status.Completion
}
- // Don't divide by zero
- if len(connectedDevices) == 0 {
+ // Don't divide by zero; list contains local device as well
+ if len(connections.List) == 1 {
totalStatus.Completion = 100
} else {
- totalStatus.Completion = sum / float64(len(connectedDevices))
+ totalStatus.Completion = sum / float64(len(connections.List)-1)
}
return &totalStatus