fix(pkg/sensor): reduce interface functions for better error handling

This commit is contained in:
2020-01-10 19:42:19 +01:00
parent ca4269fff8
commit 95fb1f6745
12 changed files with 159 additions and 93 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"sync"
"time"
"github.com/d2r2/go-bsbmp"
"github.com/d2r2/go-i2c"
@ -19,9 +20,8 @@ type BME280 struct {
*types.Sensor
}
// GetSensorModel returns the sensor model
func (s *BME280) GetSensorModel() types.SensorModel {
return s.Sensor.SensorModel
func (s *BME280) ID() string {
return s.SensorID
}
// Read measured values
@ -124,3 +124,12 @@ func (s *BME280) ReadContinously(ctx context.Context, measuredValueChannel chan<
}
}
}
// Ticker returns a new ticker, which tick every when the sensor should be read
func (s *BME280) Ticker() *time.Ticker {
duration, err := time.ParseDuration(s.TickDuration)
if err != nil {
duration = time.Minute
}
return time.NewTicker(duration)
}