Refactor temperature struct

This commit is contained in:
Søren Rasmussen 2021-09-30 20:36:41 +02:00
parent fc628e89c0
commit 8325f2f3c6
2 changed files with 16 additions and 10 deletions

View file

@ -13,12 +13,6 @@ import (
"github.com/rs/zerolog/log"
)
type TemperatureReading struct {
Sensor string
Time time.Time
Value int64
}
var (
ErrReadSensor = errors.New("Failed to read sensor temperature")
@ -43,7 +37,6 @@ func SetSensors(newSensors []string) {
}
func Serve(ctx context.Context, wg *sync.WaitGroup) {
wg.Add(1)
defer wg.Done()
for {
@ -85,7 +78,7 @@ func readSensors() {
C <- &TemperatureReading{
Time: time.Now(),
Sensor: sensor,
Value: t,
MilliDegrees: t,
}
}
}

View file

@ -0,0 +1,13 @@
package temperature
import "time"
type TemperatureReading struct {
Sensor string
Time time.Time
MilliDegrees int64
}
func (t *TemperatureReading) Degrees() float64 {
return float64(t.MilliDegrees) / 1000.0
}