xiyiji.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. # -*- coding: utf-8 -*-
  2. from apps.web.core.adapter.base import *
  3. from apps.web.device.models import Device
  4. class WasherBox(SmartBox):
  5. def __init__(self, device):
  6. super(WasherBox, self).__init__(device)
  7. def analyze_event_data(self,data):
  8. return self.analyze_get_data(data)
  9. def analyze_get_data(self,data):
  10. temp = data[6:8]
  11. status = Const.DEV_WORK_STATUS_IDLE
  12. tempStatus = ''
  13. if temp == '01':
  14. tempStatus = u'待机'
  15. elif temp == '02':
  16. status =Const.DEV_WORK_STATUS_WORKING
  17. tempStatus = u'运转'
  18. elif temp == '03':
  19. status =Const.DEV_WORK_STATUS_PAUSE
  20. tempStatus = u'暂停'
  21. elif temp == '04':
  22. status = Const.DEV_WORK_STATUS_FAULT
  23. tempStatus = u'故障'
  24. elif temp == '05':
  25. status =Const.DEV_WORK_STATUS_WORKING
  26. tempStatus = u'参数设置'
  27. elif temp == '06':
  28. status =Const.DEV_WORK_STATUS_WORKING
  29. tempStatus = u'自检'
  30. else:
  31. status =Const.DEV_WORK_STATUS_IDLE
  32. tempStatus = u'待机'
  33. temp = data[8:10]
  34. program = ''
  35. if temp == '01':
  36. program = u'单脱水'
  37. elif temp == '02':
  38. program = u'快速'
  39. elif temp == '03':
  40. program = u'标准'
  41. elif temp == '04':
  42. program = u'大物'
  43. elif temp == '05':
  44. program = u'加热快速'
  45. elif temp == '06':
  46. program = u'加热标准'
  47. elif temp == '07':
  48. program = u'加热大物'
  49. temp = data[10:12]
  50. process = ''
  51. if temp == '01':
  52. process = u'预约'
  53. elif temp == '02':
  54. process = u'浸泡'
  55. elif temp == '03':
  56. process = u'洗涤'
  57. elif temp == '04':
  58. process = u'漂洗'
  59. elif temp == '05':
  60. process = u'脱水'
  61. elif temp == '06':
  62. process = u'主进水'
  63. temp = data[14:16] + data[12:14]
  64. leftTime= int(temp,16)
  65. temp = data[16:18]
  66. binFault = hexbyte_2_bin(temp)
  67. faultStr = ''
  68. if binFault[0] == '1':
  69. status = Const.DEV_WORK_STATUS_FAULT
  70. faultStr = u'进水超时'
  71. if binFault[1] == '1':
  72. status = Const.DEV_WORK_STATUS_FAULT
  73. faultStr = u'排水超时'
  74. if binFault[2] == '1':
  75. status = Const.DEV_WORK_STATUS_FAULT
  76. faultStr = u'脱水开盖'
  77. if binFault[3] == '1':
  78. status = Const.DEV_WORK_STATUS_FAULT
  79. faultStr = u'脱水不平衡'
  80. if binFault[4] == '1':
  81. status = Const.DEV_WORK_STATUS_FAULT
  82. faultStr = u'通讯故障'
  83. if binFault[5] == '1':
  84. status = Const.DEV_WORK_STATUS_FAULT
  85. faultStr = u'童锁开盖'
  86. if binFault[6] == '1':
  87. status = Const.DEV_WORK_STATUS_FAULT
  88. faultStr = u'溢水'
  89. if binFault[7] == '1':
  90. status = Const.DEV_WORK_STATUS_FAULT
  91. faultStr = u'水位传感器故障'
  92. temp = data[18:20]
  93. binFault = hexbyte_2_bin(temp)
  94. if binFault[0] == '1':
  95. status = Const.DEV_WORK_STATUS_FAULT
  96. faultStr = u'数据存储故障'
  97. if binFault[1] == '1':
  98. status = Const.DEV_WORK_STATUS_FAULT
  99. faultStr = u'温度传感器故障'
  100. if binFault[2] == '1':
  101. status = Const.DEV_WORK_STATUS_FAULT
  102. faultStr = u'无水加热故障'
  103. if binFault[3] == '1':
  104. status = Const.DEV_WORK_STATUS_FAULT
  105. faultStr = u'电机堵转故障'
  106. if binFault[4] == '1':
  107. status = Const.DEV_WORK_STATUS_FAULT
  108. faultStr = u'IPM温度过高故障'
  109. if binFault[5] == '1':
  110. status = Const.DEV_WORK_STATUS_FAULT
  111. faultStr = u'电机过流故障'
  112. if binFault[6] == '1':
  113. status = Const.DEV_WORK_STATUS_FAULT
  114. faultStr = u'电机缺相故障'
  115. if binFault[7] == '1':
  116. status = Const.DEV_WORK_STATUS_FAULT
  117. faultStr = u'驱动器故障'
  118. if status == Const.DEV_WORK_STATUS_FAULT:
  119. statusInfo = faultStr
  120. elif status == Const.DEV_WORK_STATUS_FORBIDDEN:
  121. statusInfo = u'禁用'
  122. elif status == Const.DEV_WORK_STATUS_IDLE:
  123. statusInfo = u'待机'
  124. elif status == Const.DEV_WORK_STATUS_PAUSE:
  125. statusInfo = u'暂停'
  126. else:
  127. statusInfo = u'%s 当前套餐:%s 当前环节:%s' % (tempStatus,program,process)
  128. return {'status':status,'statusInfo':statusInfo,'leftTime':leftTime}
  129. def get_dev_info(self):
  130. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  131. {'IMEI': self._device['devNo'], "funCode": "A1", "data": ""})
  132. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  133. if devInfo['rst'] == -1:
  134. raise ServiceException(
  135. {'result': 2, 'description': u'当前洗衣机正在玩命找网络,请您稍候再试'})
  136. elif devInfo['rst'] == 1:
  137. raise ServiceException(
  138. {'result': 2, 'description': u'当前洗衣机忙,无响应,请您稍候再试'})
  139. info = self.analyze_get_data(devInfo['data'])
  140. return info
  141. def start_device(self, package, openId, attachParas):
  142. info = self.get_dev_info()
  143. if info['status'] == Const.DEV_WORK_STATUS_FAULT:
  144. raise ServiceException(
  145. {'result': 2, 'description': u'当前洗衣机故障:%s' % info['statusInfo']})
  146. if u'待机' not in info['statusInfo']:
  147. raise ServiceException(
  148. {'result': 2, 'description': u'当前洗衣机%s,请稍候使用' % info['statusInfo']})
  149. data = ''
  150. washName = package['name']
  151. temp = ''
  152. if washName == Const.WASHER_BOX_SET_TQJ:
  153. temp = '10'
  154. elif washName == Const.WASHER_BOX_SET_DTS:
  155. temp = '08'
  156. elif washName == Const.WASHER_BOX_SET_KSX:
  157. temp = '04'
  158. elif washName == Const.WASHER_BOX_SET_BZX:
  159. temp = '02'
  160. elif washName == Const.WASHER_BOX_SET_DWX:
  161. temp = '01'
  162. data = data + temp
  163. data = data + '00'
  164. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  165. {'IMEI': self._device['devNo'], "funCode": "81", "data": data},
  166. timeout = MQTT_TIMEOUT.START_DEVICE)
  167. if result['rst'] != 0:
  168. if result['rst'] == -1:
  169. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,您的金币还在,重试不需要重新付款,建议您试试旁边其他设备,或者试试投硬币,或者稍后再试哦'})
  170. elif result['rst'] == 1:
  171. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,您的金币还在,设备暂时不能网络支付,请尝试投币哦'})
  172. else:
  173. raise ServiceException({'result': 2, 'description': u'系统错误,您的金币还在,款请尝试投币哦'})
  174. resCode = result['data'][6:8]
  175. if resCode == '0F':
  176. raise ServiceException({'result': 2, 'description': u'主板见通讯失败,请试试投币,并报障给老板哦'})
  177. Device.update_dev_control_cache(self._device['devNo'], {'openId':openId})
  178. return result
  179. def get_device_function_by_key(self,keyName):
  180. if keyName == 'workingStatus':
  181. infoDict = self.get_dev_info()
  182. return {"workingStatus": infoDict['statusInfo']}
  183. return None
  184. def stop_pause_continue(self,state):
  185. cmd = ''
  186. if state == 'stop':
  187. cmd = '20'
  188. elif state == 'pause':
  189. cmd = '40'
  190. elif state == 'continue':
  191. cmd = '80'
  192. cmd += '00'
  193. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  194. {'IMEI': self._device['devNo'], "funCode": "81", "data": cmd})
  195. if result['rst'] != 0:
  196. if result['rst'] == -1:
  197. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者试试投硬币,或者稍后再试哦'})
  198. elif result['rst'] == 1:
  199. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,设备暂时不能网络支付,请尝试投币哦'})
  200. else:
  201. raise ServiceException({'result': 2, 'description': u'系统错误,请尝试投币哦'})
  202. resCode = result['data'][6:8]
  203. if resCode == '0F':
  204. raise ServiceException({'result': 2, 'description': u'主板见通讯失败,请试试投币,并报障给老板哦'})
  205. if state == 'stop':
  206. Device.update_dev_control_cache(self._device['devNo'], {'status':Const.DEV_WORK_STATUS_IDLE})
  207. else:
  208. Device.update_dev_control_cache(self._device['devNo'], {'status':Const.DEV_WORK_STATUS_WORKING})
  209. return result
  210. def get_wash_config(self):
  211. result = {
  212. Const.WASHER_BOX_DTS :{'price':0,'time':0},
  213. Const.WASHER_BOX_KS :{'price':0,'time':0},
  214. Const.WASHER_BOX_BZ :{'price':0,'time':0},
  215. Const.WASHER_BOX_DW:{'price':0,'time':0},
  216. Const.WASHER_BOX_YEBENG:{'price':0,'time':0},
  217. Const.WASHER_BOX_JRKS :{'price':0,'time':0},
  218. Const.WASHER_BOX_JRBZ :{'price':0,'time':0},
  219. Const.WASHER_BOX_JRDW :{'price':0,'time':0},
  220. }
  221. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  222. {'IMEI': self._device['devNo'], "funCode": "A2", "data": ""})
  223. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  224. if devInfo['rst'] == -1:
  225. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者试试投硬币,或者稍后再试哦'})
  226. elif devInfo['rst'] == 1:
  227. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,设备暂时不能网络支付,请尝试投币哦'})
  228. else:
  229. raise ServiceException({'result': 2, 'description': u'系统错误'})
  230. priceData = devInfo['data'][6:20]
  231. result[Const.WASHER_BOX_DTS]['price'] = int(priceData[0:2],16)
  232. result[Const.WASHER_BOX_KS]['price'] = int(priceData[2:4],16)
  233. result[Const.WASHER_BOX_BZ]['price'] = int(priceData[4:6],16)
  234. result[Const.WASHER_BOX_DW]['price'] = int(priceData[6:8],16)
  235. result[Const.WASHER_BOX_JRKS]['price'] = int(priceData[8:10],16)
  236. result[Const.WASHER_BOX_JRBZ]['price'] = int(priceData[10:12],16)
  237. result[Const.WASHER_BOX_JRDW]['price'] = int(priceData[12:14],16)
  238. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  239. {'IMEI': self._device['devNo'], "funCode": "A3", "data": ""})
  240. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  241. if devInfo['rst'] == -1:
  242. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者试试投硬币,或者稍后再试哦'})
  243. elif devInfo['rst'] == 1:
  244. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,设备暂时不能网络支付,请尝试投币哦'})
  245. else:
  246. raise ServiceException({'result': 2, 'description': u'系统错误'})
  247. timeData = devInfo['data'][6:22]
  248. result[Const.WASHER_BOX_DTS]['time'] = int(timeData[0:2],16)
  249. result[Const.WASHER_BOX_KS]['time'] = int(timeData[2:4],16)
  250. result[Const.WASHER_BOX_BZ]['time'] = int(timeData[4:6],16)
  251. result[Const.WASHER_BOX_DW]['time'] = int(timeData[6:8],16)
  252. result[Const.WASHER_BOX_YEBENG]['time'] = int(timeData[8:10],16)
  253. result[Const.WASHER_BOX_JRKS]['time'] = int(timeData[10:12],16)
  254. result[Const.WASHER_BOX_JRBZ]['time'] = int(timeData[12:14],16)
  255. result[Const.WASHER_BOX_JRDW]['time'] = int(timeData[14:16],16)
  256. return result
  257. def set_wash_config(self,washConfig):
  258. priceTemp,timeTemp = '',''
  259. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_DTS]['price'])
  260. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_KS]['price'])
  261. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_BZ]['price'])
  262. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_DW]['price'])
  263. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_JRKS]['price'])
  264. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_JRBZ]['price'])
  265. priceTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_JRDW]['price'])
  266. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_DTS]['time'])
  267. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_KS]['time'])
  268. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_BZ]['time'])
  269. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_DW]['time'])
  270. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_YEBENG]['time'])
  271. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_JRKS]['time'])
  272. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_JRBZ]['time'])
  273. timeTemp += decimal_2_hexByte(washConfig[Const.WASHER_BOX_JRDW]['time'])
  274. priceTemp += '00'
  275. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  276. {'IMEI': self._device['devNo'], "funCode": "82", "data": priceTemp})
  277. if result['rst'] != 0:
  278. if result['rst'] == -1:
  279. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  280. elif result['rst'] == 1:
  281. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  282. else:
  283. raise ServiceException({'result': 2, 'description': u'系统错误'})
  284. resCode = result['data'][6:8]
  285. if resCode == '0F':
  286. raise ServiceException({'result': 2, 'description': u'设置价格失败,主板间通讯失败,检查下是否GSM通讯模块和主板之间的连接'})
  287. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  288. {'IMEI': self._device['devNo'], "funCode": "83", "data": timeTemp})
  289. if result['rst'] != 0:
  290. if result['rst'] == -1:
  291. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  292. elif result['rst'] == 1:
  293. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  294. else:
  295. raise ServiceException({'result': 2, 'description': u'系统错误'})
  296. resCode = result['data'][6:8]
  297. if resCode == '0F':
  298. raise ServiceException({'result': 2, 'description': u'设置时间失败,主板间通讯失败,检查下是否GSM通讯模块和主板之间的连接'})
  299. return result
  300. #快速水位设定 标准水位设定 大物水位设定 脱水转速设定 温度设定
  301. def set_process_config(self,config):
  302. cmd = decimal_2_hexByte(config['kssw']) + decimal_2_hexByte(config['bzsw'])\
  303. + decimal_2_hexByte(config['dwsw']) + decimal_2_hexByte(config['tszs']) + decimal_2_hexByte(config['wdsz']) + '000000'
  304. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  305. {'IMEI': self._device['devNo'], "funCode": "84", "data": cmd})
  306. if result['rst'] != 0:
  307. if result['rst'] == -1:
  308. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  309. elif result['rst'] == 1:
  310. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  311. else:
  312. raise ServiceException({'result': 2, 'description': u'系统错误'})
  313. resCode = result['data'][6:8]
  314. if resCode == '0F':
  315. raise ServiceException({'result': 2, 'description': u'设置过程参数失败,主板间通讯失败,检查下是否GSM通讯模块和主板之间的连接'})
  316. return result
  317. def get_process_config(self):
  318. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  319. {'IMEI': self._device['devNo'], "funCode": 'A4', "data": ""})
  320. if result['rst'] != 0:
  321. if result['rst'] == -1:
  322. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  323. elif result['rst'] == 1:
  324. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  325. else:
  326. raise ServiceException({'result': 2, 'description': u'系统错误'})
  327. temp = result['data'][6:16]
  328. result['kssw'] = int(temp[0:2],16)
  329. result['bzsw'] = int(temp[2:4],16)
  330. result['dwsw'] = int(temp[4:6],16)
  331. result['tszs'] = int(temp[6:8],16)
  332. result['wdsz'] = int(temp[8:10],16)
  333. return result
  334. def set_special_config(self,specialConfig):
  335. cmd = ''
  336. bConfig = '000000'+ str(specialConfig['qcbcbh']) + str(specialConfig['ddjy'])
  337. hexConfig = decimal_2_hexByte(int(bConfig,2))
  338. cmd =cmd + hexConfig +'00'
  339. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  340. {'IMEI': self._device['devNo'], "funCode": "85", "data": cmd})
  341. if result['rst'] != 0:
  342. if result['rst'] == -1:
  343. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  344. elif result['rst'] == 1:
  345. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  346. else:
  347. raise ServiceException({'result': 2, 'description': u'系统错误'})
  348. resCode = result['data'][6:8]
  349. if resCode == '0F':
  350. raise ServiceException({'result': 2, 'description': u'设置过程参数失败,主板间通讯失败,检查下是否GSM通讯模块和主板之间的连接'})
  351. return result
  352. def press_down_key(self,keyName):
  353. if keyName in ['stop','pause','continue']:
  354. return self.stop_pause_continue(keyName)
  355. self.set_control_config(keyName)
  356. def set_control_config(self,buttonName):
  357. cmd = ''
  358. if buttonName == 'ccms1' :
  359. cmd = '01'
  360. elif buttonName == 'ccms2':
  361. cmd = '02'
  362. elif buttonName == 'tz':
  363. cmd = '03'
  364. elif buttonName == 'js':
  365. cmd = '04'
  366. elif buttonName == 'ajkq':
  367. cmd = '05'
  368. elif buttonName == 'ajgb':
  369. cmd = '06'
  370. elif buttonName == 'tbkq':
  371. cmd = '07'
  372. elif buttonName == 'tbgb':
  373. cmd = '08'
  374. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  375. {'IMEI': self._device['devNo'], "funCode": "86", "data": cmd})
  376. if result['rst'] != 0:
  377. if result['rst'] == -1:
  378. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  379. elif result['rst'] == 1:
  380. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  381. else:
  382. raise ServiceException({'result': 2, 'description': u'系统错误'})
  383. resCode = result['data'][6:8]
  384. if resCode == '0F':
  385. raise ServiceException({'result': 2, 'description': u'设置过程参数失败,主板间通讯失败,检查下是否GSM通讯模块和主板之间的连接'})
  386. return result
  387. def get_special_config(self):
  388. result = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  389. {'IMEI': self._device['devNo'], "funCode": "A5", "data": ''})
  390. if result['rst'] != 0:
  391. if result['rst'] == -1:
  392. raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,请稍候再试'})
  393. elif result['rst'] == 1:
  394. raise ServiceException({'result': 2, 'description': u'洗衣机主板连接故障,请检查下GSM模块和主板之间的连接'})
  395. else:
  396. raise ServiceException({'result': 2, 'description': u'系统错误'})
  397. temp = result['data'][6:8]
  398. binTemp = hexbyte_2_bin(temp)[::-1]
  399. result['ddjy'] = int(binTemp[0])
  400. result['qcbcbh'] = int(binTemp[1])
  401. return result
  402. def get_dev_setting(self):
  403. sConfig = self.get_special_config()
  404. wConfig = self.get_wash_config()
  405. pConfig = self.get_process_config()
  406. para = {}
  407. para.update(sConfig)
  408. para.update(wConfig)
  409. para.update(pConfig)
  410. #为了配合前台,还需要给他转义下
  411. para['kssw'] = pConfig['kssw']
  412. para['bzsw'] = pConfig['bzsw']
  413. para['dwsw'] = pConfig['dwsw']
  414. para['liquidPump'] = wConfig[Const.WASHER_BOX_YEBENG]['time']
  415. para['tszs'] = pConfig['tszs']
  416. para['wdsz'] = pConfig['wdsz']
  417. para['powerDownMemory'] = True if sConfig['ddjy'] == 1 else False
  418. para['protect'] = True if sConfig['qcbcbh'] == 1 else False
  419. return para
  420. def set_device_function(self,request,lastSetConf):
  421. oldSConfig = {'ddjy': lastSetConf['ddjy'], 'qcbcbh': lastSetConf['qcbcbh']}
  422. if request.POST.has_key('powerDownMemory'):
  423. powerDownMemory = bool(request.POST.get('powerDownMemory'))
  424. ddjy = 1 if powerDownMemory else 0
  425. oldSConfig.update({'ddjy': ddjy})
  426. lastSetConf.update({'ddjy': ddjy})
  427. self.set_special_config(oldSConfig)
  428. if request.POST.has_key('protect'):
  429. protect = bool(request.POST.get('protect'))
  430. qcbcbh = 1 if protect else 0
  431. oldSConfig.update({'qcbcbh': qcbcbh})
  432. lastSetConf.update({'qcbcbh': qcbcbh})
  433. self.set_special_config(oldSConfig)
  434. def set_device_function_param(self,request,lastSetConf):
  435. oldPConfig = {'kssw': lastSetConf['kssw'], 'bzsw': lastSetConf['bzsw'], 'dwsw': lastSetConf['dwsw'],
  436. 'tszs': lastSetConf['tszs'], 'wdsz': lastSetConf['wdsz']}
  437. kssw = request.POST.get('kssw', None)
  438. if kssw:
  439. oldPConfig['kssw'] = int(kssw)
  440. bzsw = request.POST.get('bzsw', None)
  441. if bzsw:
  442. oldPConfig['bzsw'] = int(bzsw)
  443. dwsw = request.POST.get('dwsw', None)
  444. if dwsw:
  445. oldPConfig['dwsw'] = int(dwsw)
  446. tszs = request.POST.get('tszs', None)
  447. if tszs:
  448. oldPConfig['tszs'] = int(tszs)
  449. wdsz = request.POST.get('wdsz', None)
  450. if wdsz:
  451. oldPConfig['wdsz'] = int(wdsz)
  452. if kssw or bzsw or dwsw or tszs or wdsz:
  453. self.set_process_config(oldPConfig)
  454. if request.POST.has_key('nightPump'):
  455. oldWConfig = {
  456. Const.WASHER_BOX_DTS: lastSetConf[Const.WASHER_BOX_DTS],
  457. Const.WASHER_BOX_KS: lastSetConf[Const.WASHER_BOX_KS],
  458. Const.WASHER_BOX_BZ: lastSetConf[Const.WASHER_BOX_BZ],
  459. Const.WASHER_BOX_DW: lastSetConf[Const.WASHER_BOX_DW],
  460. Const.WASHER_BOX_YEBENG: lastSetConf[Const.WASHER_BOX_YEBENG],
  461. Const.WASHER_BOX_JRKS: lastSetConf[Const.WASHER_BOX_JRKS],
  462. Const.WASHER_BOX_JRBZ: lastSetConf[Const.WASHER_BOX_JRBZ],
  463. Const.WASHER_BOX_JRDW: lastSetConf[Const.WASHER_BOX_JRDW],
  464. }
  465. yebeng = request.POST.get('nightPump', None)
  466. if yebeng:
  467. oldWConfig[Const.WASHER_BOX_YEBENG]['time'] = yebeng
  468. self.set_wash_config(oldWConfig)
  469. def count_down(self,request,dev,agent,group,devType,lastOpenId,port=None):
  470. devInfo = self.get_dev_info()
  471. if devInfo['rst'] == -1:
  472. return JsonResponse({'result': 0, 'description': u'洗衣机网络不太好,您试下投币,或者周边其他设备,或者稍后再试试哦'})
  473. if devInfo['rst'] == 1:
  474. return JsonResponse({'result': 0, 'description': u'洗衣机设备主板连接故障,请投币试试'})
  475. if devInfo['status'] == Const.WASHER_BOX_GZ:
  476. statusDesc = Const.WASHER_STATUS_CODE_DESC[Const.WASHER_BOX_GZ]
  477. if len(devInfo['faultList']) > 0:
  478. faultDesc = Const.EVENT_CODE_DESC[devInfo['faultList'][0]]
  479. desc = '出现了%s,%s' % (statusDesc, faultDesc)
  480. else:
  481. desc = '出现了%s' % statusDesc
  482. return JsonResponse({'result': 0, 'description': u'洗衣机' + desc + u'。您联系下老板哦'})
  483. return JsonResponse(
  484. {
  485. 'result': 1,
  486. 'description': '',
  487. 'payload': {
  488. 'surplus': devInfo['surplus'],
  489. 'sum': devInfo['surplus'],
  490. 'name': group['groupName'],
  491. 'address': group['address'],
  492. 'code': devType.get('code'),
  493. 'orderProcessing': False,
  494. 'logicalCode': dev['logicalCode'],
  495. 'user': 'me' if lastOpenId == request.user.openId else 'notme',
  496. 'agentFeatures': agent.features,
  497. }
  498. })