Skip to content

Commit

Permalink
Correct AnalogRead in sparkCoreAdaptor
Browse files Browse the repository at this point in the history
It now returns an int instead of float64, since the interface is
expecting that.
  • Loading branch information
Javier Cervantes committed Sep 15, 2014
1 parent 96918d3 commit 1fc6195
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions platforms/spark/spark_core_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package spark
import (
"encoding/json"
"fmt"
"github.com/hybridgroup/gobot"
"io/ioutil"
"net/http"
"net/url"

"github.com/hybridgroup/gobot"
)

type SparkCoreAdaptor struct {
Expand Down Expand Up @@ -38,7 +39,7 @@ func (s *SparkCoreAdaptor) Finalize() bool {
return true
}

func (s *SparkCoreAdaptor) AnalogRead(pin string) float64 {
func (s *SparkCoreAdaptor) AnalogRead(pin string) int {
params := url.Values{
"params": {pin},
"access_token": {s.AccessToken},
Expand All @@ -48,7 +49,7 @@ func (s *SparkCoreAdaptor) AnalogRead(pin string) float64 {

resp, err := s.postToSpark(url, params)
if err == nil {
return resp["return_value"].(float64)
return int(resp["return_value"].(float64))
}

return 0
Expand Down
7 changes: 4 additions & 3 deletions platforms/spark/spark_core_adaptor_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package spark

import (
"github.com/hybridgroup/gobot"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/hybridgroup/gobot"
)

// HELPERS
Expand Down Expand Up @@ -104,7 +105,7 @@ func TestSparkCoreAdaptorAnalogRead(t *testing.T) {

a.setAPIServer(testServer.URL)

gobot.Assert(t, a.AnalogRead("A1"), 5.2)
gobot.Assert(t, a.AnalogRead("A1"), 5)

testServer.Close()

Expand All @@ -114,7 +115,7 @@ func TestSparkCoreAdaptorAnalogRead(t *testing.T) {
})
defer testServer.Close()

gobot.Assert(t, a.AnalogRead("A1"), float64(0))
gobot.Assert(t, a.AnalogRead("A1"), 0)

}

Expand Down

0 comments on commit 1fc6195

Please sign in to comment.