Skip to content

Commit

Permalink
Merge pull request #2 from chroju/change-internal-implementation
Browse files Browse the repository at this point in the history
Change internal implementation
  • Loading branch information
chroju authored Jan 22, 2019
2 parents cf423c3 + 8256acb commit a2f33d5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- source
- run: go get github.com/mitchellh/gox
- run: go get github.com/tcnksm/ghr
- run: make build
- run: make crossbuild
- run: ${CIRCLE_WORKING_DIRECTORY}/.circleci/compress_binaries.sh
- run: ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME $CIRCLE_TAG pkg/

Expand All @@ -49,4 +49,4 @@ workflows:
tags:
only: /^v.*$/
branches:
ignore: /.*/
ignore: /.*/
18 changes: 9 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

[[constraint]]
branch = "master"
name = "github.com/chroju/go-nature-remo"
name = "github.com/tenntenn/natureremo"

[[constraint]]
name = "github.com/mitchellh/cli"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
BINARY_NAME=remo

build:
crossbuild:
$(GOBUILD) -os="linux darwin windows" -arch="386 amd64" -output "bin/remo_{{.OS}}_{{.Arch}}/{{.Dir}}"
clean:
$(GOCLEAN)
Expand Down
14 changes: 8 additions & 6 deletions commands/send.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package commands

import (
"context"
"fmt"

"github.com/fatih/color"

cloud "github.com/chroju/go-nature-remo/cloud"
"github.com/chroju/nature-remo-cli/configfile"
"github.com/mitchellh/cli"
"github.com/tenntenn/natureremo"
)

type SendCommand struct {
Expand All @@ -34,19 +35,19 @@ func (c *SendCommand) Run(args []string) int {
return 1
}

var signalID string
var toSendSignal *natureremo.Signal
for _, v := range appliances {
if v.Name == applianceName {
for _, signal := range v.Signals {
if signal.Name == signalName {
signalID = signal.ID
toSendSignal = signal
break
}
}
break
}
}
if signalID == "" {
if toSendSignal == nil {
c.UI.Error(color.RedString(fmt.Sprintf("Appliance '%s' - Signal '%s' is invalid", applianceName, signalName)))
return 1
}
Expand All @@ -57,8 +58,9 @@ func (c *SendCommand) Run(args []string) int {
return 1
}

client := cloud.NewClient(token)
if _, err := client.SendSignal(signalID); err != nil {
client := natureremo.NewClient(token)
ctx := context.Background()
if err := client.SignalService.Send(ctx, toSendSignal); err != nil {
c.UI.Error(err.Error())
return 1
}
Expand Down
11 changes: 7 additions & 4 deletions configfile/configfile.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package configfile

import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/user"
"path"

cloud "github.com/chroju/go-nature-remo/cloud"
"github.com/go-yaml/yaml"
"github.com/pkg/errors"
"github.com/tenntenn/natureremo"
)

type Appliance struct {
Name string
ID string
Signals []cloud.Signal
Signals []*natureremo.Signal
}

type Setting struct {
Expand Down Expand Up @@ -65,8 +66,10 @@ func (c *ConfigFile) SyncConfigFile(token string) error {
}
defer file.Close()

client := cloud.NewClient(token)
appliances, err := client.GetAppliances()
// client := cloud.NewClient(token)
client := natureremo.NewClient(token)
ctx := context.Background()
appliances, err := client.ApplianceService.GetAll(ctx)
if err != nil {
return fmt.Errorf("Failed to login")
}
Expand Down

0 comments on commit a2f33d5

Please sign in to comment.