fix(cmd/sensor): set tick duration for new sensors

This commit is contained in:
2020-01-11 13:18:38 +01:00
parent 40857249c4
commit 002f3e9e25
3 changed files with 28 additions and 18 deletions

View File

@ -8,12 +8,15 @@ import (
"github.com/spf13/cobra"
)
var enabled bool
var gpioIn string
var i2cAddress uint8
var i2cBus int
var location string
var wireID string
var (
enabled bool
gpioIn string
i2cAddress uint8
i2cBus int
location string
tickDuration string
wireID string
)
var addSensorCmd = &cobra.Command{
Use: "add",
@ -38,10 +41,11 @@ flucky sensor add --i2c-bus 1 --i2c-address 0x76 wetter-station BME280`,
// create new sensor struct
sensor := &types.Sensor{
Name: args[0],
Model: sensorModel,
Location: location,
Enabled: enabled,
Name: args[0],
Model: sensorModel,
Location: location,
Enabled: enabled,
TickDuration: tickDuration,
}
// determine gpio port if set
@ -90,10 +94,11 @@ flucky sensor add --i2c-bus 1 --i2c-address 0x76 wetter-station BME280`,
func init() {
sensorCmd.AddCommand(addSensorCmd)
addSensorCmd.Flags().BoolVar(&enabled, "enabled", true, "Enable Sensor")
addSensorCmd.Flags().StringVar(&gpioIn, "gpio", "", "GPIO")
addSensorCmd.Flags().Uint8Var(&i2cAddress, "i2c-address", 0, "I2C-Address")
addSensorCmd.Flags().IntVar(&i2cBus, "i2c-bus", 0, "I2C-Bus")
addSensorCmd.Flags().StringVar(&location, "location", "", "Sensor location")
addSensorCmd.Flags().StringVar(&wireID, "wire-id", "", "Wire-ID")
addSensorCmd.Flags().BoolVar(&enabled, "enabled", true, "Enable new sensor")
addSensorCmd.Flags().StringVar(&gpioIn, "gpio", "", "Defines the GPIO port")
addSensorCmd.Flags().Uint8Var(&i2cAddress, "i2c-address", 0, "Defines the I2C address on the I2C bus")
addSensorCmd.Flags().IntVar(&i2cBus, "i2c-bus", 0, "Defines the I2C bus")
addSensorCmd.Flags().StringVar(&location, "location", "", "Location of the sensor")
addSensorCmd.Flags().StringVar(&tickDuration, "tick-duration", "1m", "Controls how often values should be read from the sensor when running flucky in daemon mode")
addSensorCmd.Flags().StringVar(&wireID, "wire-id", "", "Defines the Wire-ID")
}