|
@@ -38,8 +38,8 @@ class GatewaySubDeviceView(View):
|
|
|
user_id = token_obj.userID
|
|
|
if operation == 'add': # 添加子设备
|
|
|
return self.add_sub_device(request_dict, user_id, response)
|
|
|
- elif operation == 'query': # 查询子设备
|
|
|
- return self.query(request_dict, user_id, response)
|
|
|
+ elif operation == 'detail': # 查询子设备信息
|
|
|
+ return self.query_sub_device(request_dict, response)
|
|
|
elif operation == 'update': # 更新子设备信息
|
|
|
return self.sensor_update(request_dict, response)
|
|
|
elif operation == 'delete': # 删除子设备
|
|
@@ -65,7 +65,8 @@ class GatewaySubDeviceView(View):
|
|
|
@request_dict srcAddr: 短地址
|
|
|
@request_dict mac: mac地址
|
|
|
@request_dict deviceModel: 设备型号
|
|
|
- @request_dict manufacturer: 厂家名称
|
|
|
+ @request_dict manufacturer: 制造商
|
|
|
+ @request_dict sensorSerial: 传感器序列号
|
|
|
@request_dict firmwareVersion: 固件版本
|
|
|
@request_dict hardwareVersion: 硬件版本
|
|
|
@request_dict familyId: 家庭id
|
|
@@ -118,34 +119,25 @@ class GatewaySubDeviceView(View):
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
@staticmethod
|
|
|
- def query(request_dict, user_id, response):
|
|
|
+ def query_sub_device(request_dict, response):
|
|
|
"""
|
|
|
查询子设备
|
|
|
@param request_dict: 请求参数
|
|
|
- @request_dict serial_number: 序列号
|
|
|
- @param user_id: 用户id
|
|
|
+ @request_dict gatewaySubId: 子设备id
|
|
|
@param response: 响应对象
|
|
|
@return: response
|
|
|
"""
|
|
|
- serial_number = request_dict.get('serialNumber', None)
|
|
|
+ sub_device_id = request_dict.get('gatewaySubId', None)
|
|
|
|
|
|
- if not all([serial_number]):
|
|
|
+ if not all([sub_device_id]):
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
- device_info_qs = Device_Info.objects.filter(userID_id=user_id, serial_number=serial_number).values('id')
|
|
|
- if not device_info_qs.exists():
|
|
|
- return response.json(14)
|
|
|
- device_id = device_info_qs[0]['id']
|
|
|
- count = GatewaySubDevice.objects.filter(device_id=device_id).count()
|
|
|
- gateway_sub_device_qs = GatewaySubDevice.objects.filter(device_id=device_id).values('device_type',
|
|
|
- 'nickname', 'ieee_addr',
|
|
|
- 'src_addr', 'status')
|
|
|
- gateway_sub_device_list = [gateway_sub_device for gateway_sub_device in gateway_sub_device_qs]
|
|
|
- res = {
|
|
|
- 'count': count,
|
|
|
- 'gateway_sub_device_list': gateway_sub_device_list
|
|
|
- }
|
|
|
- return response.json(0, res)
|
|
|
+ gateway_sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('manufacturer',
|
|
|
+ 'device_model',
|
|
|
+ 'mac', 'sensor_serial')
|
|
|
+ if not gateway_sub_device_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ return response.json(0, list(gateway_sub_device_qs))
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
|
|