improve validate and tests

This commit is contained in:
2025-10-09 17:29:05 +02:00
parent 92640d1ad0
commit 6d3408f34c
2 changed files with 659 additions and 0 deletions
+7
View File
@@ -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