Browse Source

add a router for test /adjust/target

chenhaiyang 4 years ago
parent
commit
d174c72b09
1 changed files with 30 additions and 0 deletions
  1. 30 0
      app/api/routers/targets.py

+ 30 - 0
app/api/routers/targets.py

@@ -34,3 +34,33 @@ async def readjust_target(
         'time': time,
     }
     return response
+
+
+@router.get('/adjust/test', response_model=TargetReadjustResponse, tags=['targets'])
+async def test_readjust_target(
+        project_id: str = Query(..., max_length=50, regex='^Pj'),
+        space_id: str = Query(..., max_length=50, regex='^Sp')
+):
+    feedback = {
+        'a little cold': 1,
+        'so cold': 0,
+        'a little hot': 0,
+        'so hot': 0,
+        'switch on': 0,
+    }
+    try:
+        need_run_room_control = await readjust_all_target(project_id, space_id, feedback=feedback)
+    except Exception as e:
+        logger.error(e)
+        raise HTTPException(
+            status_code=500,
+            detail='Oops, something wrong has happened'
+        )
+
+    response = {
+        'projectId': project_id,
+        'roomId': space_id,
+        'flag': 1 if need_run_room_control else 0,
+        'time': get_time_str()
+    }
+    return response