improve validate and tests
This commit is contained in:
@@ -2,6 +2,7 @@ package sensors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -13,6 +14,12 @@ func (s *Sensor) Validate() error {
|
||||
return ErrInvalidSensorType
|
||||
}
|
||||
|
||||
validTypes := []SType{Temperature, Humidity, CarbonDioxide, Pressure, Proximity, Light}
|
||||
isValid := slices.Contains(validTypes, s.SensorType)
|
||||
if !isValid {
|
||||
return ErrInvalidSensorType
|
||||
}
|
||||
|
||||
if s.SamplingInterval == nil {
|
||||
defaultInterval := time.Second * 3600
|
||||
s.SamplingInterval = &defaultInterval
|
||||
|
||||
Reference in New Issue
Block a user