예제 #1
0
def open_mouth(mouth_id: object = None) -> object:
    try:
        global last_open_mouth_id, last_mouth_number
        if mouth_id is None:
            logger.info(("open mouth again!", last_open_mouth_id))
            mouth_id = last_open_mouth_id
        else:

            logger.info(("open mouth id :", mouth_id))
            last_open_mouth_id = mouth_id
        mouth_list = BoxDao.get_mouth_by_id({"id": mouth_id})
        if len(mouth_list) != 1:
            logger.warn("mouth list error!")
            return
        _mouth = mouth_list[0]
        cabinet_list = BoxDao.get_cabinet_by_id({"id": _mouth["cabinet_id"]})
        if len(cabinet_list) != 1:
            logger.warn("cabinet list error!")
            return
        cabinet = cabinet_list[0]

        last_mouth_number = _mouth["number"]

        result = LockMachine.open_door(int(cabinet["number"]), int(_mouth["numberInCabinet"]))

        logger.debug(("LockMachine.open_door result is : ", result))
    except Exception as e:
        logger.warn(("open_mouth error :", e))
예제 #2
0
def pull_open_mouth(message_result):
    global last_pull_open_mouth_id, last_pull_mouth_number
    if message_result["mouth"]["id"] is None:
        box_post_message(message_result["id"], "mouth_id is None", "ERROR")
        return
    else:
        logger.info(("Server_pull open mouth id :", message_result["mouth"]["id"]))
        last_pull_open_mouth_id = message_result["mouth"]["id"]
    mouth_list = BoxDao.get_mouth_by_id({"id": message_result["mouth"]["id"]})
    if len(mouth_list) != 1:
        box_post_message(message_result["id"], "mouth list error!", "ERROR")
        return
    _mouth = mouth_list[0]
    cabinet_list = BoxDao.get_cabinet_by_id({"id": _mouth["cabinet_id"]})
    if len(cabinet_list) != 1:
        box_post_message(message_result["id"], "cabinet list error!", "ERROR")
        return
    cabinet = cabinet_list[0]
    last_pull_mouth_number = _mouth["number"]
    result = LockMachine.open_door(int(cabinet["number"]), int(_mouth["numberInCabinet"]))
    if result is True:
        box_post_message(message_result["id"], "the mouth opened!", "SUCCESS")
    else:
        box_post_message(message_result["id"], "the mouth not opened!", "ERROR")