huiteng.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. # -*- coding: utf-8 -*-
  2. from apps.web.core.adapter.base import *
  3. from apps.web.device.models import Device
  4. class washerHTBox(SmartBox):
  5. def __init__(self, device):
  6. super(washerHTBox, self).__init__(device)
  7. def check_dev_status(self, attachParas=None):
  8. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  9. {'IMEI': self._device['devNo'], "funCode": '01', 'data': '0B'})
  10. if 'rst' in devInfo and devInfo['rst'] != 0:
  11. if devInfo['rst'] == -1:
  12. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  13. elif devInfo['rst'] == 1:
  14. raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,请您稍后再试哦'})
  15. data = devInfo['data']
  16. dataFlag = data[10:14]
  17. if dataFlag != '0000':
  18. raise ServiceException({'result': 2, 'description': u'当前洗衣机正忙,不允许下发启动命令'})
  19. def test(self, coins):
  20. byte1 = '10000000'
  21. byte2 = '0000'
  22. byte2 += '0001'
  23. hexByte1 = decimal_2_hexByte(int(byte1,2))
  24. hexByte2 = decimal_2_hexByte(int(byte2,2))
  25. data = '0A' + hexByte2 + hexByte1
  26. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  27. {'IMEI': self._device['devNo'], "funCode": '04', 'data': data})
  28. return devInfo
  29. def start_device(self, package, openId, attachParas):
  30. washName = package['name']
  31. unit = package.get('unit',u'分钟')
  32. duration = int(package['time'])*60
  33. if unit == u'小时':
  34. duration = int(package['time'])*3600
  35. elif unit == u'天':
  36. duration = int(package['time'])*86400
  37. byte1 = '10000000'
  38. byte2 = '0000'
  39. if washName == u'单脱水':
  40. byte2 += '0001'
  41. elif washName == u'快速洗':
  42. byte2 += '0010'
  43. elif washName == u'标准洗':
  44. byte2 += '0011'
  45. elif washName == u'大物洗':
  46. byte2 += '0100'
  47. else:
  48. raise ServiceException({'result': 2, 'description': u'套餐名称错误,请输入正确的套餐名称'})
  49. hexByte1 = decimal_2_hexByte(int(byte1,2))
  50. hexByte2 = decimal_2_hexByte(int(byte2,2))
  51. data = '0A' + hexByte2 + hexByte1
  52. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  53. {'IMEI': self._device['devNo'], "funCode": '04', 'data': data},
  54. timeout = MQTT_TIMEOUT.START_DEVICE)
  55. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  56. if devInfo['rst'] == -1:
  57. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,您的金币还在,重试不会扣款,建议您试试旁边其他设备,或者稍后再试哦'})
  58. elif devInfo['rst'] == 1:
  59. raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,您的金币还在,重试不会扣款,请您稍后再试哦'})
  60. Device.update_dev_control_cache(self._device['devNo'],
  61. {'openId': openId, 'isStart': True,'vCardId':self._vcard_id})
  62. devInfo['finishedTime'] = (int(time.time()) + int(duration))
  63. return devInfo
  64. def get_dev_setting(self):
  65. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  66. {'IMEI': self._device['devNo'], "funCode": '01', 'data': '05'})
  67. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  68. if devInfo['rst'] == -1:
  69. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  70. elif devInfo['rst'] == 1:
  71. raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,请您稍后再试哦'})
  72. data = devInfo['data']
  73. settingData = data[10:12]
  74. binData = hexbyte_2_bin(settingData)
  75. if binData[0] == '1':
  76. leijibishu = 1
  77. else:
  78. leijibishu = 0
  79. if binData[1] == '1':
  80. qidonganquan = 1
  81. else:
  82. qidonganquan = 0
  83. if binData[2] == '1':
  84. qidongpinghen = 1
  85. else:
  86. qidongpinghen = 0
  87. if binData[3:5] == '00':
  88. duandianjiyi = 0
  89. duandianpaishui = 0
  90. elif binData[3:5] == '01':
  91. duandianjiyi = 1
  92. duandianpaishui = 0
  93. else:
  94. duandianjiyi = 0
  95. duandianpaishui = 1#启动断电排水
  96. if binData[5:7] == '00':
  97. shifouqingling = 0
  98. else:
  99. shifouqingling = 1
  100. return {'leijibishu':leijibishu,'qidonganquan':qidonganquan,'qidongpinghen':qidongpinghen,
  101. 'duandianjiyi':duandianjiyi,'shifouqingling':shifouqingling,'duandianpaishui':duandianpaishui}
  102. def set_dev_setting(self,configDict):
  103. binData = ''
  104. if configDict['shifouqingling'] == 0:
  105. binData += '00'
  106. else:
  107. binData += '11'
  108. binData += '0'
  109. if configDict['duandianpaishui']:
  110. binData += '11'
  111. if configDict['duandianjiyi'] == 0:
  112. binData += '00'
  113. elif configDict['duandianjiyi'] == 1:
  114. binData += '01'
  115. else:
  116. binData += '11'
  117. if configDict['qidongpinghen'] == 0:
  118. binData += '0'
  119. else:
  120. binData += '1'
  121. if configDict['qidonganquan'] == 0:
  122. binData += '0'
  123. else:
  124. binData += '1'
  125. if configDict['leijibishu'] == 0:
  126. binData += '0'
  127. else:
  128. binData += '1'
  129. cmdData = '05' + fill_2_hexByte(hex(int(binData,2)), 2)
  130. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  131. {'IMEI': self._device['devNo'], "funCode": '04', 'data': cmdData})
  132. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  133. if devInfo['rst'] == -1:
  134. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  135. elif devInfo['rst'] == 1:
  136. raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,请您稍后再试哦'})
  137. def get_normal_value(self,flag):
  138. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  139. {'IMEI': self._device['devNo'], "funCode": '01', 'data': flag})
  140. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  141. if devInfo['rst'] == -1:
  142. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  143. elif devInfo['rst'] == 1:
  144. raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,请您稍后再试哦'})
  145. data = devInfo[18::]
  146. value = data[0:2]
  147. return value
  148. def set_normal_value(self, flag, value):
  149. # type: (str, int) -> bool
  150. data = flag + fill_2_hexByte(hex(int(value)), 2)
  151. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  152. {'IMEI': self._device['devNo'], "funCode": '04', 'data': data})
  153. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  154. if devInfo['rst'] == -1:
  155. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  156. elif devInfo['rst'] == 1:
  157. raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,请您稍后再试哦'})
  158. return True
  159. def analyze_event_data(self, data):
  160. flag = data[16:18]
  161. if flag != 'OC':
  162. return {}
  163. binData = hexbyte_2_bin(data[18:20])
  164. if binData[0] == '1':
  165. return {'statusInfo':u'进水故障'}
  166. if binData[1] == '1':
  167. return {'statusInfo':u'安全故障'}
  168. # if binData[0] == '1':
  169. # return {'statusInfo':u'进水故障'}
  170. if binData[3] == '1':
  171. return {'statusInfo':u'平衡开关故障'}
  172. if binData[7] == '1':
  173. return {'statusInfo':u'洗衣未运行'}
  174. def set_device_function(self,request,lastSetConf):
  175. if request.POST.has_key('leijibishu'):
  176. # value = 1 if request.POST.get('leijibishu') == 'true' else 0
  177. value = int(request.POST.get("leijibishu", False))
  178. lastSetConf.update({'leijibishu': value})
  179. if request.POST.has_key('qidonganquan'):
  180. value = 1 if request.POST.get('qidonganquan') else 0
  181. lastSetConf.update({'qidonganquan': value})
  182. if request.POST.has_key('qidongpinghen'):
  183. value = 1 if request.POST.get('qidongpinghen') else 0
  184. lastSetConf.update({'qidongpinghen': value})
  185. if request.POST.has_key('duandianjiyi'):
  186. value = 1 if request.POST.get('duandianjiyi') else 0
  187. lastSetConf.update({'duandianjiyi': value})
  188. if request.POST.has_key('shifouqingling'):
  189. value = 1 if request.POST.get('shifouqingling') else 0
  190. lastSetConf.update({'shifouqingling': value})
  191. if request.POST.has_key('duandianpaishui'):
  192. value = 1 if request.POST.get('duandianpaishui') else 0
  193. lastSetConf.update({'duandianpaishui': value})
  194. self.set_dev_setting(lastSetConf)