resolve sensor
This commit is contained in:
parent
4b6d8e6c6b
commit
395e4530af
3 changed files with 6 additions and 5 deletions
3
main.go
3
main.go
|
@ -55,7 +55,8 @@ func main() {
|
|||
}
|
||||
|
||||
func handleNewWeatherData(wd storage.WeatherData) error {
|
||||
if !config.AllowUnregisteredSensors() && !sensorRegistry.ExistSensorId(wd.SensorId) {
|
||||
_, couldResolve := sensorRegistry.ResolveSensorById(wd.SensorId)
|
||||
if !config.AllowUnregisteredSensors() && !couldResolve {
|
||||
return errors.New("sensor have to be registered")
|
||||
}
|
||||
weatherStorage.Save(wd)
|
||||
|
|
|
@ -35,13 +35,13 @@ func (registry *inmemorySensorRegistry) ExistSensorName(name string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (registry *inmemorySensorRegistry) ExistSensorId(sensorId uuid.UUID) bool {
|
||||
func (registry *inmemorySensorRegistry) ResolveSensorById(sensorId uuid.UUID) (*WeatherSensor, bool) {
|
||||
for _, s := range registry.weatherSensors {
|
||||
if s.Id == sensorId {
|
||||
return true
|
||||
return s, true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (registry *inmemorySensorRegistry) ExistSensor(sensor *WeatherSensor) bool {
|
||||
|
|
|
@ -17,7 +17,7 @@ type WeatherStorage interface {
|
|||
type SensorRegistry interface {
|
||||
RegisterSensorByName(string) (*WeatherSensor, error)
|
||||
ExistSensor(*WeatherSensor) bool
|
||||
ExistSensorId(uuid.UUID) bool
|
||||
ResolveSensorById(uuid.UUID) (*WeatherSensor, bool)
|
||||
GetSensors() []*WeatherSensor
|
||||
Close() error
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue