Refactor temperature struct
This commit is contained in:
parent
fc628e89c0
commit
8325f2f3c6
2 changed files with 16 additions and 10 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
pkg/temperature/temperature.go
Normal file
13
pkg/temperature/temperature.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue