From 29b49137237f69e03da426f32f421c919cff289e Mon Sep 17 00:00:00 2001 From: pmc <740076875@qq.com> Date: Fri, 10 Apr 2026 18:08:05 +0800 Subject: [PATCH] feat: update RTC bot migration and device interaction consumers Co-Authored-By: Claude Sonnet 4.6 --- .claude/settings.json | 6 +++- .../aiapp/migrations/0003_create_rtc_bot.py | 15 +++++--- qy_lty/device_interaction/consumers.py | 34 ++++++++++++++++++- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/.claude/settings.json b/.claude/settings.json index 77b29a5..cf4a6c3 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -201,7 +201,11 @@ "Bash(cmd //c \"netstat -ano | findstr LISTENING | findstr /R \\\\\"8000 3000\\\\\"\")", "Bash(cmd //c \"netstat -ano\")", "Bash(/c/python/python.exe -m daphne -b 0.0.0.0 -p 8000 qy_lty.asgi:application)", - "Bash(kill %1)" + "Bash(kill %1)", + "Bash(python -c ':*)", + "Bash(xargs ls:*)", + "Bash(find /c/Users/admin/Desktop/Lila-Server -name \"*.py\" -exec grep -l \"connect\\\\|disconnect\\\\|presence\\\\|heartbeat\" {} \\\\;)", + "Bash(grep -E \"\\\\.py$|app$\")" ], "additionalDirectories": [ "C:\\Users\\admin\\.claude" diff --git a/qy_lty/aiapp/migrations/0003_create_rtc_bot.py b/qy_lty/aiapp/migrations/0003_create_rtc_bot.py index 99455db..4b1930c 100644 --- a/qy_lty/aiapp/migrations/0003_create_rtc_bot.py +++ b/qy_lty/aiapp/migrations/0003_create_rtc_bot.py @@ -3,10 +3,17 @@ from django.db import migrations def create_rtc_bot(apps, schema_editor): Bot = apps.get_model('aiapp', 'Bot') - Bot.objects.get_or_create( - name='RTC_Voice_Agent', - defaults={'description': 'RTC实时语音智能体'} - ) + if not Bot.objects.filter(name='RTC_Voice_Agent').exists(): + # 手动指定一个不会冲突的 id + from django.db import connection + with connection.cursor() as cursor: + cursor.execute("SELECT COALESCE(MAX(id), 0) + 1 FROM aiapp_bot") + next_id = cursor.fetchone()[0] + Bot.objects.create( + id=next_id, + name='RTC_Voice_Agent', + description='RTC实时语音智能体' + ) def remove_rtc_bot(apps, schema_editor): diff --git a/qy_lty/device_interaction/consumers.py b/qy_lty/device_interaction/consumers.py index 464931f..165a39c 100644 --- a/qy_lty/device_interaction/consumers.py +++ b/qy_lty/device_interaction/consumers.py @@ -354,11 +354,26 @@ class DeviceConsumer(AsyncWebsocketConsumer): 'user_id': self.user_id } ) - + await self.send(text_data=json.dumps({ 'status': 'success', 'message': '恢复出厂设置指令已发送' })) + elif message_type == 'device_state': + # 处理手机设备状态消息 + await self.channel_layer.group_send( + self.group_name, + { + 'type': 'device_state', + 'message': message, + 'user_id': self.user_id + } + ) + + await self.send(text_data=json.dumps({ + 'status': 'success', + 'message': '设备状态消息已发送' + })) else: # 处理普通文本消息 await self.channel_layer.group_send( @@ -548,6 +563,23 @@ class DeviceConsumer(AsyncWebsocketConsumer): except Exception as e: logger.error(f"Error in factory_reset: {str(e)}") + async def device_state(self, event): + """ + 处理手机设备状态消息 + 将设备状态信息转发给 WebSocket + """ + try: + message = event['message'] + user_id = event['user_id'] + + await self.send(text_data=json.dumps({ + 'type': 'device_state', + 'message': message, + 'user_id': user_id + })) + except Exception as e: + logger.error(f"Error in device_state: {str(e)}") + async def device_info(self, event): """ 处理设备信息上报消息