mqtt.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:broadlink-mqtt 作者: eschava 项目源码 文件源码
def record(device, file):
    logging.debug("Recording command to file " + file)
    # receive packet
    device.enter_learning()
    ir_packet = None
    attempt = 0
    while ir_packet is None and attempt < 6:
        time.sleep(5)
        ir_packet = device.check_data()
        attempt = attempt + 1
    if ir_packet is not None:
        # write to file
        directory = os.path.dirname(file)
        if not os.path.exists(directory):
            os.makedirs(directory)
        with open(file, 'wb') as f:
            f.write(str(ir_packet).encode('hex'))
        logging.debug("Done")
    else:
        logging.warn("No command received")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号