add mqtt and device test

This commit is contained in:
HycJack
2026-04-26 20:07:41 +08:00
parent 7c12ca59dd
commit 389f6c4040
22 changed files with 742 additions and 32 deletions

View File

@@ -30,19 +30,19 @@ async def websocket_endpoint(websocket: WebSocket):
await websocket.send_text('{"status": "error", "message": "Not authenticated"}')
return
# 检查设备是否有离线音频URL需要发送
has_pending = await offline_audio_cache.has_pending_audio(device_id)
if has_pending:
audio_urls = await offline_audio_cache.get_audio_urls(device_id)
for audio_url in audio_urls:
try:
await websocket.send_text(f"SOUND_URL:{audio_url}")
session_logger.info(device_id, "offline", f"发送离线音频URL: {audio_url}")
except Exception as e:
session_logger.error(device_id, "offline", f"发送离线音频URL失败: {e}")
# 清空已发送的离线音频URL
await offline_audio_cache.clear_audio_urls(device_id)
session_logger.info(device_id, "offline", f"已清空设备的离线音频URL缓存{len(audio_urls)}")
# # 检查设备是否有离线音频URL需要发送
# has_pending = await offline_audio_cache.has_pending_audio(device_id)
# if has_pending:
# audio_urls = await offline_audio_cache.get_audio_urls(device_id)
# for audio_url in audio_urls:
# try:
# await websocket.send_text(f"SOUND_URL:{audio_url}")
# session_logger.info(device_id, "offline", f"发送离线音频URL: {audio_url}")
# except Exception as e:
# session_logger.error(device_id, "offline", f"发送离线音频URL失败: {e}")
# # 清空已发送的离线音频URL
# await offline_audio_cache.clear_audio_urls(device_id)
# session_logger.info(device_id, "offline", f"已清空设备的离线音频URL缓存共 {len(audio_urls)} 个")
await handle_websocket_messages(websocket, device_id)