Skip to content
Snippets Groups Projects
Commit 9d9fd9bd authored by Robert Goldmann's avatar Robert Goldmann
Browse files

refactoring

parent fbb73b73
No related branches found
No related tags found
No related merge requests found
......@@ -46,19 +46,20 @@ def construct_blueprint(settings):
sensorParams = RequestValidator.validate_parameters(sensor,
SensorParameters.get_values(),
f'sensor "{sensor}"')
__add_or_update_sensor(database, device, sensorParams)
except ValidationError as e:
return e.response, 400
return ""
def __add_or_update_sensor(database, device, sensorParams):
sensorName = sensorParams[SensorParameters.NAME.value]
sensorType = sensorParams[SensorParameters.TYPE.value]
sensorValue = sensorParams[SensorParameters.VALUE.value]
sensor = database.get_sensor(device[0], sensorName)
if sensor:
database.update_sensor(device, sensorName, sensorType, sensorValue)
else:
database.add_sensor(device, sensorName, sensorType, sensorValue)
except ValidationError as e:
return e.response, 400
return ""
return routes
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment