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

52 lines
1.2 KiB
Go
Raw Normal View History

2018-09-18 18:07:40 +02:00
package reach
import (
"sync"
"forge.cadoles.com/Pyxis/golang-socketio"
"github.com/pkg/errors"
)
const (
// EventGetTestResults is a request for the ReachRS module's test results
EventGetTestResults = "get test results"
// EventTestResults is the response of the EventGetTestResults request
EventTestResults = "test results"
)
// TestResults are the ReachRS module's test results
type TestResults struct {
UBlox bool `json:"u-blox"`
STC bool `json:"stc"`
MPU bool `json:"mpu"`
Device string `json:"device"`
Lora bool `json:"lora"`
}
// TestResults returns the ReachRS module tests results
func (c *Client) TestResults() (*TestResults, error) {
var err error
var results *TestResults
var wg sync.WaitGroup
wg.Add(1)
c.conn.On(EventTestResults, func(h *gosocketio.Channel, res *TestResults) {
results = res
c.conn.On(EventTestResults, nil)
wg.Done()
})
c.logf("sending '%s' event", EventGetTestResults)
if err = c.conn.Emit(EventGetTestResults, nil); err != nil {
return nil, errors.Wrapf(err, "error while emitting '%s' event", EventGetTestResults)
}
c.logf("'%s' event sent", EventGetTestResults)
wg.Wait()
return results, err
}