def enrollDevice(deviceOwner = "", deviceType = "", deviceName = ""): deviceId = generateId() device = Device() device.deviceID = deviceId device.deviceType = deviceType device.deviceName = deviceName device.deviceOwner = deviceOwner deviceDao = DeviceDAO() return deviceDao.createDevice(device)
def get(self): devDAO = DeviceDAO(self.db) listaDevices = devDAO.getAll() jsonData = json.dumps(listaDevices, default=Device.encodeDevice) respuesta = self.app.response_class(response=jsonData, status=200, mimetype='application/json') return respuesta
def get(self): #c = self.db.cursor() #c.execute("SELECT * FROM Devices") #return "data:"+str(c.fetchall()) dev_dao = DeviceDAO(self.db) list_devices = dev_dao.get_all() data_json = json.dumps(list_devices, default=Device.dev_to_dict) response = self.app.response_class(response=data_json, status=200, mimetype='application/json') return response
def put(self, id_dev): #modifico estado de device dev_dao = DeviceDAO(self.db) state = self.request.form['state'] #leo body de PUT ret = "ERROR" if dev_dao.set_state(id_dev, state): ret = "OK" response = self.app.response_class(response=json.dumps({"state": ret}), status=200, mimetype='application/json') return response
def get(self): #Creo DAO dev_dao = DeviceDAO(self.db) #Obtengo lista de obj Device list_devices = dev_dao.get_all() #transformo lista en JSON json_data = json.dumps(list_devices, default=Device.encode_device) #Construyo respuesta y la devuelvo response = self.app.response_class(response=json_data, status=200, mimetype='application/json') return response
def putID(self, idDevice): devDAO = DeviceDAO(self.db) stateRecibido = self.request.form.get("state") if devDAO.setState(idDevice, stateRecibido) == True: ret = "OK" else: ret = "ERROR" respuesta = self.app.response_class(response=json.dumps({"state": ret}), status=200, content_type='application/json') return respuesta
def get(self): devDao = DeviceDAO(self.conn) list_devices = devDao.get_all() #Me devuelve una lista de objetos Device return json.dumps(list_devices, default=Device.object_to_dict)
def put(self, id_device): devDao = DeviceDAO(self.conn) #status me vino en el body status = self.request.form['state'] devDao.set_state(id_device, status) return "OK!"