def sensors_sensor_id_get(sensorId): """ method to get a sensor using sensor id """ try: sensor = Sensor.get(sensorId) except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) return sensor.attribute_values
def sensors_sensor_id_delete(sensorId) -> str: try: sensor = Sensor.get(sensorId) sensor.delete() except Exception as e: return 'Sensor with id=%s does not exist.' % (sensorId) return 'Successfully deleted sensor with id=%s.' % (sensorId)
def db_put(id,type,newSensor): if type not in types: return 1 if type == 'sensor': try: sensor = Sensor.get(id) except Exception: return 2 # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newSensor: try: building = Building.get(newSensor['buildingId']) except Exception as e: return 2 attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key != 'id': if newSensor[key] == '': sensor.update_item(key, value=' ', action='PUT') else: sensor.update_item(key, value=newSensor[key], action='PUT') return 0
def sensors_sensor_id_delete(sensorId) -> str: try: sensor = Sensor.get(sensorId) sensor.delete() except Exception as e: return 'Sensor with id=%s does not exist.' % (sensorId) return 'Successfully deleted sensor with id=%s.' % (sensorId)
def sensors_sensor_id_get(sensorId): """ method to get a sensor using sensor id """ try: sensor = Sensor.get(sensorId) except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) return sensor.attribute_values
def robots_robot_id_put(robotId, newRobot): """ method to update a robot using robot id """ try: robot = Robot.get(robotId) except Exception: return 'Robot with id=%s does not exist.' % (robotId),404 # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newRobot: try: building = Building.get(newRobot['buildingId']) except Exception as e: return 'Building with specified ID does not exist',412 # Do the same for sensor ID if 'sensorId' in newRobot: for val in newRobot['sensorId']: try: #print(val) sensor = Sensor.get(val) except Exception as e: return 'Sensor with specified ID does not exist',412 attributes = robot.attribute_values.keys() for key in newRobot.keys(): if key in attributes and key!= "id": # print(key) robot.update_item(key, value=newRobot[key], action='PUT') return 'Robot with id=%s updated successfully.' % (robotId),200
def robots_robot_id_put(robotId, newRobot): """ method to update a robot using robot id """ try: robot = Robot.get(robotId) except Exception: return 'Robot with id=%s does not exist.' % (robotId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newRobot: try: building = Building.get(newRobot['buildingId']) except Exception as e: return 'Building with specified ID does not exist' # Do the same for sensor ID if 'sensorId' in newRobot: try: sensor = Sensor.get(newRobot['sensorId']) except Exception as e: return 'Sensor with specified ID does not exist' attributes = robot.attribute_values.keys() for key in newRobot.keys(): if key in attributes and key is not 'id': robot.update_item(key, value=newRobot[key], action='PUT') return 'Robot with id=%s updated successfully.' % (robotId)
def sensors_sensor_id_delete(sensorId): """ method to delete a sensor using sensor id """ try: sensor = Sensor.get(sensorId) sensor.delete() except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) return 'Successfully deleted sensor with id=%s.' % (sensorId)
def sensors_sensor_id_delete(sensorId): """ method to delete a sensor using sensor id """ try: sensor = Sensor.get(sensorId) sensor.delete() except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) return 'Successfully deleted sensor with id=%s.' % (sensorId)
def sensors_sensor_id_put(sensorId, newSensor) -> str: try: sensor = Sensor.get(sensorId) except Exception as e: return 'Sensor with id=%s does not exist.' % (sensorId) attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key is not 'id': sensor.update_item(key, value=newSensor[key], action='PUT') return 'Sensor with id=%s updated successfully.' % (sensorId)
def sensors_sensor_id_put(sensorId, newSensor) -> str: try: sensor = Sensor.get(sensorId) except Exception as e: return 'Sensor with id=%s does not exist.' % (sensorId) attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key is not 'id': sensor.update_item(key, value=newSensor[key], action='PUT') return 'Sensor with id=%s updated successfully.' % (sensorId)
def db_delete(id, type): if type not in types: return 1 if type == 'sensor': try: sensor = Sensor.get(id) sensor.delete() except Exception: return 2 return 0
def db_get(id,type): if type not in types: return [1,''] if type == 'sensor': try: sensor = Sensor.get(id) returnList = [0,sensor.attribute_values] except Exception: return [2,''] return returnList
def sensors_sensor_id_put(sensorId, newSensor): """ method to update sensor using sensor id """ try: sensor = Sensor.get(sensorId) except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newSensor: try: building = Building.get(newSensor['buildingId']) except Exception as e: return 'Building with specified ID does not exist' attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key is not 'id': sensor.update_item(key, value=newSensor[key], action='PUT') return 'Sensor with id=%s updated successfully.' % (sensorId)
def sensors_sensor_id_put(sensorId, newSensor): """ method to update sensor using sensor id """ try: sensor = Sensor.get(sensorId) except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newSensor: try: building = Building.get(newSensor['buildingId']) except Exception as e: return 'Building with specified ID does not exist' attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key is not 'id': sensor.update_item(key, value=newSensor[key], action='PUT') return 'Sensor with id=%s updated successfully.' % (sensorId)
def sensors_sensor_id_get(sensorId) -> str: try: sensor = Sensor.get(sensorId) except Exception as e: return 'Sensor with id=%s does not exist.' % (sensorId) return sensor.attribute_values
def sensors_sensor_id_get(sensorId) -> str: try: sensor = Sensor.get(sensorId) except Exception as e: return 'Sensor with id=%s does not exist.' % (sensorId) return sensor.attribute_values