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

@ -68,7 +68,7 @@ func PrintSensors(cnf *config.Configuration, w io.Writer) error {
// declar tabwriter
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
fmt.Fprint(tw, "name\tlocation\ttype\twire-id\ti2c-bus\ti2c-address\tgpio\tenabled\n")
fmt.Fprint(tw, "name\tlocation\ttype\twire-id\ti2c-bus\ti2c-address\tgpio\ttick-duration\tenabled\n")
for _, sensor := range cnf.Sensors {
fmt.Fprintf(tw, "%v\t%v\t%v\t", sensor.Name, sensor.Location, sensor.Model)
@ -97,7 +97,7 @@ func PrintSensors(cnf *config.Configuration, w io.Writer) error {
fmt.Fprintf(tw, "\t")
}
fmt.Fprintf(tw, "%v\n", sensor.Enabled)
fmt.Fprintf(tw, "%v\t%v\n", sensor.TickDuration, sensor.Enabled)
}
tw.Flush()

View File

@ -81,6 +81,11 @@ func (c *Configuration) AddSensor(sensor *types.Sensor) error {
}
}
// check if sensor has a valid tick time
if _, err := time.ParseDuration(sensor.TickDuration); err != nil {
return fmt.Errorf("Can not parse tick duration: %v", sensor.TickDuration)
}
// check if sensor has a valid device id
if sensor.DeviceID != c.Device.ID {
sensor.DeviceID = c.Device.ID