fix: cli temperature read

changes:
- fix: read temperature values without daemon
  Add subcommand to read temperature values without starting the daemon

- fix: implement measured value types
  Replace measured value types with constants

- fix: add sensor pipelines
  Add functions which returns a channel with measured values

- fix: filter measured values from a channel
  Add functions to filter measured values by sensor id or measured
  value types.
This commit is contained in:
2020-09-21 19:36:42 +02:00
parent 7cbd80c726
commit 3a090d190e
17 changed files with 481 additions and 77 deletions

View File

@ -8,6 +8,25 @@ import (
"git.cryptic.systems/volker.raschek/flucky/pkg/types"
)
func PrintMeasuredValues(measuredValues []*types.MeasuredValue, w io.Writer) error {
// declar tabwriter
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
fmt.Fprint(tw, "timestamp\ttype\tvalue\n")
for i := range measuredValues {
fmt.Fprintf(tw, "%v\t%v\t%v\n", measuredValues[i].Date.String(), measuredValues[i].ValueType, measuredValues[i].Value)
}
err := tw.Flush()
if err != nil {
return err
}
return nil
}
// PrintSensors displays a list with all configured sensors
func PrintSensors(sensors []*types.Sensor, w io.Writer) error {
@ -42,7 +61,10 @@ func PrintSensors(sensors []*types.Sensor, w io.Writer) error {
fmt.Fprintf(tw, "%v\t%v\n", sensor.TickDuration, sensor.Enabled)
}
tw.Flush()
err := tw.Flush()
if err != nil {
return err
}
return nil
}