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

53 lines
1.1 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 (
2018-09-19 13:00:08 +02:00
eventGetTestResults = "get test results"
eventTestResults = "test results"
2018-09-18 18:07:40 +02:00
)
// 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)
2018-09-19 13:00:08 +02:00
err = c.conn.On(eventTestResults, func(h *gosocketio.Channel, res *TestResults) {
2018-09-18 18:07:40 +02:00
results = res
2018-09-19 13:00:08 +02:00
c.conn.Off(eventTestResults)
2018-09-18 18:07:40 +02:00
wg.Done()
})
2018-09-19 13:00:08 +02:00
if err != nil {
return nil, errors.Wrapf(err, "error while binding to '%s' event", eventTestResults)
}
2018-09-18 18:07:40 +02:00
2018-09-19 13:00:08 +02:00
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)
2018-09-18 18:07:40 +02:00
}
2018-09-19 13:00:08 +02:00
c.logf("'%s' event sent", eventGetTestResults)
2018-09-18 18:07:40 +02:00
wg.Wait()
return results, err
}