Skip to content

Commit

Permalink
Humidity (#6)
Browse files Browse the repository at this point in the history
* Add humidity command

* Update .gitignore
  • Loading branch information
mortenberg80 authored Jan 22, 2021
1 parent 4cc335d commit 0033cad
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

.netatmo.yaml
5 changes: 5 additions & 0 deletions .netatmo.yaml.temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
netatmo:
clientID: <CLIENT_ID>
clientSecret: <CLIENT_SECRET>
username: <USERNAME>
password: <PASSWORD>
41 changes: 39 additions & 2 deletions cmd/humidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ package cmd

import (
"fmt"
netatmo2 "github.com/mariusbreivik/netatmo/api/netatmo"
"github.com/mariusbreivik/netatmo/internal/netatmo"
"github.com/spf13/viper"
"github.com/ttacon/chalk"

"github.com/spf13/cobra"
)
Expand All @@ -27,14 +31,47 @@ var humidityCmd = &cobra.Command{
Short: "read humidity data from netatmo station",
Long: `read humidity data from netatmo station`,
Example: "netatmo humidity",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("humidity called")
RunE: func(cmd *cobra.Command, args []string) error {
netatmoClient, err := netatmo.NewClient(netatmo.Config{
ClientID: viper.GetString("netatmo.clientID"),
ClientSecret: viper.GetString("netatmo.clientSecret"),
Username: viper.GetString("netatmo.username"),
Password: viper.GetString("netatmo.password"),
})

if err != nil {
return err
}

if indoor {
printIndoorHumidity(netatmoClient.GetStationData())
} else if outdoor {
printOutdoorHumidity(netatmoClient.GetStationData())
} else {
fmt.Println(cmd.UsageString())
}

return nil
},
}

func printOutdoorHumidity(stationData netatmo2.StationData) {
fmt.Println("Station name: ", stationData.Body.Devices[0].StationName)
fmt.Println("Humidity outdoor:", chalk.Blue, stationData.Body.Devices[0].Modules[0].DashboardData.Humidity, chalk.Reset)

}

func printIndoorHumidity(stationData netatmo2.StationData) {
fmt.Println("Station name: ", stationData.Body.Devices[0].StationName)
fmt.Println("Humidity indoor:", chalk.Red, stationData.Body.Devices[0].DashboardData.Humidity, chalk.Reset)
}

func init() {
rootCmd.AddCommand(humidityCmd)

humidityCmd.Flags().BoolVarP(&indoor, "indoor", "i", false, "netatmo humidity -i|--indoor")
humidityCmd.Flags().BoolVarP(&outdoor, "outdoor", "o", false, "netatmo humidity -o|--outdoor")

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -261,6 +262,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
Expand Down Expand Up @@ -460,6 +462,7 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Expand Down

0 comments on commit 0033cad

Please sign in to comment.