fix: temperature, sensor
changes: - sensor temperature add - sensor temperature list - sensor temperature rm - temperature get - temperature log - temperature push
This commit is contained in:
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")
|
||||
|
||||
}
|
Reference in New Issue
Block a user