Skip to content

Commit

Permalink
Pressure command (#15)
Browse files Browse the repository at this point in the history
* Pressure command

* Pressure command
  • Loading branch information
skrashevich authored Aug 30, 2021
1 parent 8a21805 commit 119637d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
75 changes: 75 additions & 0 deletions cmd/pressure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"
"math"

netatmo2 "github.com/mariusbreivik/netatmo/api/netatmo"
"github.com/mariusbreivik/netatmo/internal/netatmo"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/ttacon/chalk"
)

// pressure2Cmd represents the pressure command
var pressureCmd = &cobra.Command{
Use: "pressure",
Short: "read pressure data from netatmo station",
Long: `read pressure data from netatmo station`,
Example: "netatmo pressure",
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 len(args) > 0 {
fmt.Println(cmd.UsageString())
}

printPressureLevel(netatmoClient.GetStationData())

return nil
},
}

func printPressureLevel(stationData netatmo2.StationData) {
fmt.Println("Station name: ", stationData.Body.Devices[0].StationName)
fmt.Println("Pressure:", chalk.Green, math.Round(stationData.Body.Devices[0].DashboardData.AbsolutePressure / 1000 * 760), "mm", chalk.Reset)

}

func init() {
rootCmd.AddCommand(pressureCmd)

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

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// pressureCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// pressureCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
Use: "netatmo",
Short: "read data from your personal netatmo weather station\n",
Long: "Uses the Netatmo Weatherstation API to get your indoor/outdoor\n" +
"temperature, co2 level, nois level, humidity, firmware data, wifi signal strength,\n" +
"temperature, co2 level, pressure level, nois level, humidity, firmware data, wifi signal strength,\n" +
"and more",
Example: "netatmo temp --indoor",
Run: func(cmd *cobra.Command, args []string) {
Expand Down

0 comments on commit 119637d

Please sign in to comment.