fix: temperature, sensor
changes: - sensor temperature add - sensor temperature list - sensor temperature rm - temperature get - temperature log - temperature push
This commit is contained in:
@ -3,6 +3,8 @@ package cmd
|
||||
import (
|
||||
"git.cryptic.systems/fh-trier/go-flucky/cmd/config"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/cmd/remote"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/cmd/sensor"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/cmd/temperature"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -21,7 +23,8 @@ func Execute(version string) {
|
||||
|
||||
config.InitCmd(rootCmd, configDir)
|
||||
remote.InitCmd(rootCmd, configDir)
|
||||
//temperature.InitCmd(rootCmd)
|
||||
sensor.InitCmd(rootCmd, configDir)
|
||||
temperature.InitCmd(rootCmd, configDir)
|
||||
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ var configDir string
|
||||
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "config",
|
||||
Short: "Manage configuration",
|
||||
}
|
||||
|
||||
func InitCmd(cmd *cobra.Command, c string) {
|
||||
|
@ -7,12 +7,14 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var force bool
|
||||
|
||||
var registerRemoteCmd = &cobra.Command{
|
||||
Use: "register",
|
||||
Short: "register on remote servers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := remote.SendDevice(configDir); err != nil {
|
||||
if err := remote.RegisterDevice(configDir, force); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
@ -20,4 +22,5 @@ var registerRemoteCmd = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
remoteCmd.AddCommand(registerRemoteCmd)
|
||||
registerRemoteCmd.Flags().BoolVarP(&force, "force", "f", false, "Force register on a remote server")
|
||||
}
|
||||
|
@ -8,11 +8,11 @@ var configDir string
|
||||
|
||||
var remoteCmd = &cobra.Command{
|
||||
Use: "remote",
|
||||
Short: "remote",
|
||||
Short: "Manage Remote",
|
||||
}
|
||||
|
||||
func InitCmd(cmd *cobra.Command, c string) {
|
||||
configDir = c
|
||||
func InitCmd(cmd *cobra.Command, cnf string) {
|
||||
configDir = cnf
|
||||
|
||||
cmd.AddCommand(remoteCmd)
|
||||
}
|
||||
|
23
cmd/sensor/sensor.go
Normal file
23
cmd/sensor/sensor.go
Normal file
@ -0,0 +1,23 @@
|
||||
package sensor
|
||||
|
||||
import (
|
||||
"git.cryptic.systems/fh-trier/go-flucky/cmd/sensor/temperature"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configDir string
|
||||
|
||||
var sensorCmd = &cobra.Command{
|
||||
Use: "sensor",
|
||||
Short: "Manage Sensors",
|
||||
}
|
||||
|
||||
// Execute a
|
||||
func InitCmd(cmd *cobra.Command, cnf string) {
|
||||
configDir = cnf
|
||||
|
||||
cmd.AddCommand(sensorCmd)
|
||||
|
||||
temperature.InitCmd(sensorCmd, cnf)
|
||||
|
||||
}
|
24
cmd/sensor/temperature/add.go
Normal file
24
cmd/sensor/temperature/add.go
Normal file
@ -0,0 +1,24 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var addTemperatureSensorCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Add Temperature Sensor",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := sensor.AddTemperature(args[0], sensorName, configDir, wirePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureSensorCmd.AddCommand(addTemperatureSensorCmd)
|
||||
}
|
28
cmd/sensor/temperature/list.go
Normal file
28
cmd/sensor/temperature/list.go
Normal file
@ -0,0 +1,28 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var quiet bool
|
||||
|
||||
var listTemperatureSensorCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List Temperature Sensors",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := sensor.PrintTemperature(os.Stdout, configDir, quiet); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureSensorCmd.AddCommand(listTemperatureSensorCmd)
|
||||
|
||||
listTemperatureSensorCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "List only sensor id's")
|
||||
}
|
24
cmd/sensor/temperature/rm.go
Normal file
24
cmd/sensor/temperature/rm.go
Normal file
@ -0,0 +1,24 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rmTemperatureSensorCmd = &cobra.Command{
|
||||
Use: "rm",
|
||||
Short: "Remove Temperature Sensor",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := sensor.RemoveTemperature(args[0], configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureSensorCmd.AddCommand(rmTemperatureSensorCmd)
|
||||
}
|
22
cmd/sensor/temperature/temperature.go
Normal file
22
cmd/sensor/temperature/temperature.go
Normal file
@ -0,0 +1,22 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configDir, sensorName, wirePath string
|
||||
|
||||
var temperatureSensorCmd = &cobra.Command{
|
||||
Use: "temperature",
|
||||
Short: "Manage Temperature Sensors",
|
||||
}
|
||||
|
||||
// Execute a
|
||||
func InitCmd(cmd *cobra.Command, cnf string) {
|
||||
configDir = cnf
|
||||
|
||||
cmd.AddCommand(temperatureSensorCmd)
|
||||
temperatureSensorCmd.PersistentFlags().StringVarP(&sensorName, "name", "n", "", "Define an name for the sensor")
|
||||
temperatureSensorCmd.PersistentFlags().StringVarP(&wirePath, "wire-path", "w", "/sys/bus/w1/devices", "Default path for wire devices")
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package remote
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
@ -8,13 +8,15 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var push bool
|
||||
|
||||
var getTemperatureCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get temperature from sensor",
|
||||
// Args: cobra.ExactArgs(2),
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := temperature.Get(os.Stdout); err != nil {
|
||||
if err := temperature.Get(os.Stdout, args[0], configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
|
27
cmd/temperature/logs.go
Normal file
27
cmd/temperature/logs.go
Normal file
@ -0,0 +1,27 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/temperature"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
//var seconds int32
|
||||
|
||||
var logTemperatureCmd = &cobra.Command{
|
||||
Use: "logs",
|
||||
Short: "logs print all temperatures from all sensors",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := temperature.Logs(os.Stdout, configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureCmd.AddCommand(logTemperatureCmd)
|
||||
//logTemperatureCmd.Flags().Int32VarP(&seconds, "seconds", "s", 1, "Interval to print new temperatures from sensors")
|
||||
}
|
24
cmd/temperature/push.go
Normal file
24
cmd/temperature/push.go
Normal file
@ -0,0 +1,24 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/temperature"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var pushTemperatureCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "push temperature from sensor to remote servers",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := temperature.Push(args[0], configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureCmd.AddCommand(pushTemperatureCmd)
|
||||
}
|
@ -1,16 +1,19 @@
|
||||
package remote
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configDir string
|
||||
|
||||
var temperatureCmd = &cobra.Command{
|
||||
Use: "temperature",
|
||||
Short: "Read temperature from sensor",
|
||||
}
|
||||
|
||||
// Execute a
|
||||
func Init(cmd *cobra.Command) {
|
||||
func InitCmd(cmd *cobra.Command, cnf string) {
|
||||
configDir = cnf
|
||||
|
||||
cmd.AddCommand(temperatureCmd)
|
||||
|
||||
|
Reference in New Issue
Block a user