Browse Source

分开网关和摄像头列表

peng 3 years ago
parent
commit
ea32f63330
1 changed files with 22 additions and 7 deletions
  1. 22 7
      Controller/SensorGateway/GatewayFamilyRoomController.py

+ 22 - 7
Controller/SensorGateway/GatewayFamilyRoomController.py

@@ -217,17 +217,32 @@ class GatewayFamilyRoomView(View):
                 values('device_id', 'type', 'nickname', 'room_id').order_by('sort')
             if not family_room_device_qs.exists():
                 return response.json(0, [])
-            device_room = []
+
+            gateways = []
+            cameras = []
             # 查询房间名称
             for device in family_room_device_qs:
                 room_id = device['room_id']
+                device_type = device['type']
                 room_name = FamilyRoom.objects.filter(id=room_id)
-                device_room.append({
-                    'deviceId': device['device_id'],
-                    'deviceType': device['type'],
-                    'nickName': device['nickname'],
-                    'roomName': room_name.first().name if room_name.exists() else '',
-                })
+                if device_type == 200:   # 网关设备
+                    gateways.append({
+                        'deviceId': device['device_id'],
+                        'deviceType': device_type,
+                        'nickName': device['nickname'],
+                        'roomName': room_name.first().name if room_name.exists() else '',
+                    })
+                else:   # 摄像头设备
+                    cameras.append({
+                        'deviceId': device['device_id'],
+                        'deviceType': device_type,
+                        'nickName': device['nickname'],
+                        'roomName': room_name.first().name if room_name.exists() else '',
+                    })
+            device_room = {
+                'gateways': gateways,
+                'cameras': cameras
+            }
             return response.json(0, device_room)
         except Exception as e:
             return response.json(500, repr(e))