This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/reach/test_results.go

54 lines
1.1 KiB
Go

package reach
import (
"sync"
"forge.cadoles.com/Pyxis/golang-socketio"
"github.com/pkg/errors"
)
const (
eventGetTestResults = "get test results"
eventTestResults = "test results"
)
// TestResults are the ReachRS module's test results
//
type TestResults struct {
Device string `json:"device"`
Lora bool `json:"lora"`
MPU bool `json:"mpu"`
STC bool `json:"stc"`
UBlox bool `json:"u-blox"`
}
// TestResults returns the ReachRS module tests results
func (u *Updater) TestResults() (*TestResults, error) {
var err error
var results *TestResults
var wg sync.WaitGroup
wg.Add(1)
err = u.conn.On(eventTestResults, func(h *gosocketio.Channel, res *TestResults) {
results = res
u.conn.Off(eventTestResults)
wg.Done()
})
if err != nil {
return nil, errors.Wrapf(err, "error while binding to '%s' event", eventTestResults)
}
u.logf("sending '%s' event", eventGetTestResults)
if err = u.conn.Emit(eventGetTestResults, nil); err != nil {
return nil, errors.Wrapf(err, "error while emitting '%s' event", eventGetTestResults)
}
u.logf("'%s' event sent", eventGetTestResults)
wg.Wait()
return results, err
}