Skip to content

Commit f50165b

Browse files
committed
wip
1 parent 24dde58 commit f50165b

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

coderbot/activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def delete(self, name, logical = True):
6464
if len(activities) > 0:
6565
activity = activities[0]
6666
if activity.get("default", False) is True:
67-
self.activities.update({'default': True}, self.query.stock == True)
67+
self.activities.update({'default': True}, self.query.kind == ACTIVITY_KIND_STOCK)
6868
if logical:
6969
activity["status"] = ACTIVITY_STATUS_DELETED
7070
activity["modified"] = datetime.now().isoformat()

coderbot/api.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,47 +123,47 @@ def get_info():
123123

124124
def stop():
125125
bot.stop()
126-
return 200
126+
return {}
127127

128128
def move(body):
129129
speed=body.get("speed")
130130
elapse=body.get("elapse")
131131
distance=body.get("distance")
132132
if (speed is None or speed == 0) or (elapse is not None and distance is not None):
133-
return 400
133+
return None, 400
134134
bot.move(speed=speed, elapse=elapse, distance=distance)
135-
return 200
135+
return {}
136136

137137
def turn(body):
138138
speed=body.get("speed")
139139
elapse=body.get("elapse")
140140
distance=body.get("distance")
141141
if (speed is None or speed == 0) or (elapse is not None and distance is not None):
142-
return 400
142+
return None, 400
143143
bot.turn(speed=speed, elapse=elapse, distance=distance)
144-
return 200
144+
return {}
145145

146146
def takePhoto():
147147
try:
148148
cam.photo_take()
149149
audio_device.say(settings.get("sound_shutter"))
150-
return 200
150+
return {}
151151
except Exception as e:
152152
logging.warning("Error: %s", e)
153153

154154
def recVideo():
155155
try:
156156
cam.video_rec()
157157
audio_device.say(settings.get("sound_shutter"))
158-
return 200
158+
return {}
159159
except Exception as e:
160160
logging.warning("Error: %s", e)
161161

162162
def stopVideo():
163163
try:
164164
cam.video_stop()
165165
audio_device.say(settings.get("sound_shutter"))
166-
return 200
166+
return {}
167167
except Exception as e:
168168
logging.warning("Error: %s", e)
169169

@@ -172,24 +172,24 @@ def speak(body):
172172
locale = body.get("locale", "")
173173
logging.debug("say: " + text + " in: " + locale)
174174
audio_device.say(text, locale)
175-
return 200
175+
return {}
176176

177177
def reset():
178178
Balena.get_instance().purge()
179-
return 200
179+
return {}
180180

181181
def halt():
182182
audio_device.say(what=settings.get("sound_stop"))
183183
Balena.get_instance().shutdown()
184-
return 200
184+
return {}
185185

186186
def restart():
187187
Balena.get_instance().restart()
188188

189189
def reboot():
190190
audio_device.say(what=settings.get("sound_stop"))
191191
Balena.get_instance().reboot()
192-
return 200
192+
return {}
193193

194194
def video_stream(a_cam):
195195
while True:
@@ -223,22 +223,22 @@ def getPhoto(name):
223223
return send_file(media_file, mimetype=mimetype.get(name[:-3], 'image/jpeg'), max_age=0)
224224
except picamera.exc.PiCameraError as e:
225225
logging.error("Error: %s", str(e))
226-
return 503
226+
return {"exception": str(e)}, 503
227227
except FileNotFoundError:
228-
return 404
228+
return None, 404
229229

230230
def savePhoto(name, body):
231231
try:
232232
cam.update_photo({"name": name, "tag": body.get("tag")})
233233
except FileNotFoundError:
234-
return 404
234+
return None, 404
235235

236236
def deletePhoto(name):
237237
logging.debug("photo delete")
238238
try:
239239
cam.delete_photo(name)
240240
except FileNotFoundError:
241-
return 404
241+
return None, 404
242242

243243
def restoreSettings():
244244
Config.restore()
@@ -249,14 +249,14 @@ def loadSettings():
249249

250250
def saveSettings(body):
251251
Config.write(body)
252-
return 200
252+
return Config.write(body)
253253

254254
def updateFromPackage():
255255
os.system('sudo bash /home/pi/clean-update.sh')
256256
file_to_upload = connexion.request.files['file_to_upload']
257257
file_to_upload.save(os.path.join('/home/pi/', 'update.tar'))
258258
os.system('sudo reboot')
259-
return 200
259+
return {}
260260

261261
def listMusicPackages():
262262
"""
@@ -291,7 +291,7 @@ def deleteMusicPackage(name):
291291
"""
292292
musicPkg = MusicPackageManager.get_instance()
293293
musicPkg.deletePackage(name)
294-
return 200
294+
return {}
295295

296296
## Programs
297297

@@ -305,14 +305,14 @@ def saveProgram(name, body):
305305
return "defaultCannotOverwrite", 400
306306
program = Program(name=body.get("name"), code=body.get("code"), dom_code=body.get("dom_code"), modified=datetime.now(), status="active")
307307
prog_engine.save(program)
308-
return 200
308+
return {}
309309

310310
def loadProgram(name):
311311
existing_program = prog_engine.load(name)
312312
if existing_program:
313313
return existing_program.as_dict(), 200
314314
else:
315-
return 404
315+
return None, 404
316316

317317
def deleteProgram(name):
318318
prog_engine.delete(name, logical=True)
@@ -415,18 +415,18 @@ def deleteCNNModel(name):
415415

416416
def cloudSyncRequest():
417417
CloudManager.get_instance().sync()
418-
return 200
418+
return {}
419419

420420
def cloudSyncStatus():
421421
return CloudManager.get_instance().sync_status()
422422

423423
def cloudRegistrationRequest(body):
424424
CloudManager.get_instance().register(body)
425-
return 200
425+
return {}
426426

427427
def cloudRegistrationDelete():
428428
CloudManager.get_instance().unregister()
429-
return 200
429+
return {}
430430

431431
def cloudRegistrationStatus():
432432
registration = cloud_settings.get('registration', {})

coderbot/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Serve a custom version of the swagger ui (Jinja2 templates) based on the default one
3434
# from the folder 'swagger-ui'. Clone the 'swagger-ui' repository inside the backend folder
35-
options = {"swagger_ui": False}
35+
options = {"swagger_ui": True}
3636
connexionApp = connexion.App(__name__, options=options)
3737

3838
# Connexion wraps FlaskApp, so app becomes connexionApp.app

coderbot/v1.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ paths:
3030
responses:
3131
200:
3232
description: "ok"
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/Settings'
3337
tags:
3438
- CoderBot configuration
3539
/settings/restore:

0 commit comments

Comments
 (0)