diff --git a/.gitignore b/.gitignore index 9ab9220..4a5a818 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +.netatmo.yaml diff --git a/.netatmo.yaml.temp b/.netatmo.yaml.temp new file mode 100644 index 0000000..24843c9 --- /dev/null +++ b/.netatmo.yaml.temp @@ -0,0 +1,5 @@ +netatmo: + clientID: + clientSecret: + username: + password: diff --git a/cmd/humidity.go b/cmd/humidity.go index bf90029..6e2fad0 100644 --- a/cmd/humidity.go +++ b/cmd/humidity.go @@ -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" ) @@ -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 diff --git a/go.sum b/go.sum index fabcc26..f961190 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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=