mxzv2.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. # -*- coding: utf-8 -*-
  2. from apps.web.core.adapter.base import *
  3. from apps.web.device.models import Device
  4. class ChargingMXZ2Box(SmartBox):
  5. def __init__(self, device):
  6. super(ChargingMXZ2Box, self).__init__(device)
  7. def translate_funcode(self,funCode):
  8. funCodeDict = {
  9. '31':u'获取端口数量',
  10. '20':u'操作端口',
  11. '02':u'回复刷卡余额',
  12. '03':u'回复刷卡充电',
  13. '04':u'回复结束报文',
  14. '23':u'获取功率',
  15. }
  16. return funCodeDict.get(funCode,'')
  17. def translate_event_cmdcode(self,cmdCode):
  18. cmdDict = {
  19. '02':u'刷卡事件',
  20. '03':u'刷卡启动或者关闭端口',
  21. '04':u'充电结束',
  22. '20':u'端口开始或者结束',
  23. }
  24. return cmdDict.get(cmdCode,'')
  25. def get_port_info(self,line):
  26. portDict = self.get_power()
  27. if portDict.has_key(line):
  28. return {'power':portDict[line]}
  29. def is_port_can_use(self, port, canAdd=False):
  30. return super(ChargingMXZ2Box, self).is_port_can_use(port, True)
  31. def get_port_status(self, force = False):
  32. if force:
  33. return self.get_port_status_from_dev()
  34. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  35. if not ctrInfo.has_key('allPorts'):
  36. self.get_port_status_from_dev()
  37. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  38. allPorts = ctrInfo.get('allPorts',10)
  39. statusDict = {}
  40. for ii in range(allPorts):
  41. tempDict = ctrInfo.get(str(ii+1),{})
  42. if tempDict.has_key('status'):
  43. statusDict[str(ii+1)] = {'status':tempDict.get('status')}
  44. elif tempDict.has_key('isStart'):
  45. if tempDict['isStart']:
  46. statusDict[str(ii+1)] = {'status':Const.DEV_WORK_STATUS_WORKING}
  47. else:
  48. statusDict[str(ii+1)] = {'status':Const.DEV_WORK_STATUS_IDLE}
  49. else:
  50. statusDict[str(ii+1)] = {'status':Const.DEV_WORK_STATUS_IDLE}
  51. allPorts,usedPorts,usePorts = self.get_port_static_info(statusDict)
  52. Device.update_dev_control_cache(self._device['devNo'], {'allPorts':allPorts,'usedPorts':usedPorts,'usePorts':usePorts})
  53. return statusDict
  54. def get_port_status_from_dev(self, attachParas=None):
  55. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, self.make_random_cmdcode(),
  56. {'IMEI': self._device['devNo'],"funCode":'31','data':'00'})
  57. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  58. if devInfo['rst'] == -1:
  59. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  60. elif devInfo['rst'] == 1:
  61. raise ServiceException({'result': 2, 'description': u'充电桩繁忙,无响应,请试试其他线路,或者稍后再试哦'})
  62. data = devInfo['data'][18::]
  63. if data[0:2] == '01':#表示成功
  64. pass
  65. else:
  66. raise ServiceException({'result': 2, 'description': u'获取设备信息失败,,建议您试试旁边其他设备,或者稍后再试哦'})
  67. portNum = int(data[2:4],16)
  68. #充电板那边说,用获取功率的方式更加稳定一些
  69. try:
  70. confDict = Device.objects.get(devNo = self._device['devNo']).otherConf
  71. except Exception,e:
  72. logger.error('update dev=%s coin enable ic enable e=%s' %(self._device['devNo'],e))
  73. raise ServiceException({'result': 2, 'description': u'没有找到该设备的配置信息,请稍候重试,或者换周围其他的设备吧'})
  74. devInfo = Device.get_dev_control_cache(self._device['devNo'])
  75. nowTime = datetime.datetime.now()
  76. resultDict = {}
  77. powerDict = self.get_power()
  78. for port,power in powerDict.items():
  79. portCtrInfo = devInfo.get(str(port))
  80. if int(port) > portNum:
  81. continue
  82. if power <= 25:
  83. resultDict[str(port)] ={'status':Const.DEV_WORK_STATUS_IDLE}
  84. if portCtrInfo is not None:
  85. strStartTime = portCtrInfo.get('startTime',None)
  86. if portCtrInfo.get('isStart',False) and strStartTime:
  87. startTime = to_datetime(strStartTime)
  88. timeDelta = (nowTime - startTime).total_seconds()
  89. if timeDelta <= 60:
  90. resultDict[str(port)] ={'status':Const.DEV_WORK_STATUS_WORKING}
  91. else:#设备功率是按照分钟来取的,端口停掉后,设备一分钟内的状态不会马上变化,所以需要刷新
  92. if portCtrInfo is None:
  93. resultDict[str(port)] ={'status':Const.DEV_WORK_STATUS_WORKING}
  94. else:
  95. strEndTime = portCtrInfo.get('endTime',None)
  96. if not strEndTime:
  97. resultDict[str(port)] ={'status':Const.DEV_WORK_STATUS_WORKING}
  98. else:
  99. endTime = to_datetime(strEndTime)
  100. timeDelta = (nowTime - endTime).total_seconds()
  101. if timeDelta <= 60:
  102. resultDict[str(port)] ={'status':Const.DEV_WORK_STATUS_IDLE}
  103. else:
  104. resultDict[str(port)] ={'status':Const.DEV_WORK_STATUS_WORKING}
  105. portKey = 'port%s' % port
  106. if confDict.has_key(portKey) and confDict[portKey] == Const.DEV_WORK_STATUS_FORBIDDEN:
  107. resultDict[str(port)] = {'status':Const.DEV_WORK_STATUS_FORBIDDEN}
  108. allPorts,usedPorts,usePorts = self.get_port_static_info(resultDict)
  109. Device.update_dev_control_cache(self._device['devNo'], {'allPorts':allPorts,'usedPorts':usedPorts,'usePorts':usePorts})
  110. #这里存在多线程更新缓存的场景,可能性比较低,但是必须先取出来,然后逐个更新状态,然后再记录缓存
  111. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  112. for strPort,info in resultDict.items():
  113. if ctrInfo.has_key(strPort):
  114. ctrInfo[strPort].update({'status':info['status']})
  115. else:
  116. ctrInfo[strPort] = info
  117. Device.update_dev_control_cache(self._device['devNo'],ctrInfo)
  118. return resultDict
  119. def stop_charging_port(self,port):
  120. self.active_deactive_port(port, False)
  121. def lock_unlock_port(self,port,lock):
  122. dev = Device.objects.get(devNo = self._device['devNo'])
  123. portKey = 'port%s' % port
  124. if lock:
  125. dev.otherConf.update({portKey:Const.DEV_WORK_STATUS_FORBIDDEN})
  126. else:
  127. dev.otherConf.update({portKey:Const.DEV_WORK_STATUS_IDLE})
  128. dev.save()
  129. if lock:
  130. self.stop_charging_port(port)
  131. if lock:
  132. Device.update_dev_control_cache(self._device['devNo'], {str(port):{'status':Const.DEV_WORK_STATUS_FORBIDDEN}})
  133. else:
  134. Device.update_dev_control_cache(self._device['devNo'], {str(port):{'status':Const.DEV_WORK_STATUS_IDLE}})
  135. def active_deactive_port(self,port,active,duration=None):
  136. tmpPort = hex(int(port))
  137. hexPort = fill_2_hexByte(tmpPort,2)
  138. if active:
  139. strOp = '01'
  140. else:
  141. strOp = '00'
  142. if duration:
  143. cmdDict = {'IMEI': self._device['devNo'],"funCode":'20','data':'00' + hexPort + strOp,'duration':int(duration) }
  144. else:
  145. cmdDict = {'IMEI': self._device['devNo'],"funCode":'20','data':'00' + hexPort + strOp }
  146. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, self.make_random_cmdcode(),cmdDict)
  147. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  148. if devInfo['rst'] == -1:
  149. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  150. elif devInfo['rst'] == 1:
  151. raise ServiceException({'result': 2, 'description': u'充电桩繁忙,无响应,请试试其他线路,或者稍后再试哦'})
  152. data = devInfo['data'][18::]
  153. if data[0:2] == '01':#表示成功
  154. pass
  155. else:
  156. raise ServiceException({'result': 2, 'description': u'操作和预期不符合,请您选择其他线路,或者稍候再试哦'})
  157. if not active:#关闭充电桩的端口
  158. devInfo = Device.get_dev_control_cache(self._device['devNo'])
  159. portCtrInfo = devInfo.get(str(port),{})
  160. portCtrInfo.update({'isStart':False,'status':Const.DEV_WORK_STATUS_IDLE,'needTime':0,'leftTime':0,'endTime':datetime.datetime.now().strftime(Const.DATETIME_FMT)})
  161. newValue = {str(port):portCtrInfo}
  162. Device.update_dev_control_cache(self._device['devNo'], newValue)
  163. return devInfo
  164. def test(self, coins):
  165. hexPort = fill_2_hexByte(1,2)
  166. cmdDict = {'duration':5}
  167. cmdDict.update({'IMEI': self._device['devNo'],"funCode":'20','data':'00' + hexPort + '01' })
  168. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, self.make_random_cmdcode(), cmdDict)
  169. return devInfo
  170. def start_device(self, package, openId, attachParas):
  171. if attachParas is None:
  172. raise ServiceException({'result': 2, 'description': u'请您选择合适的充电线路、电池类型信息'})
  173. if not attachParas.has_key('chargeIndex'):
  174. raise ServiceException({'result': 2, 'description': u'请您选择合适的充电线路'})
  175. #如果端口正在使用,不允许重复付款
  176. strPort = str(attachParas['chargeIndex'])
  177. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  178. if ctrInfo.__class__.__name__ == 'dict' and ctrInfo.has_key(strPort):
  179. portInfo = ctrInfo[strPort]
  180. if portInfo.has_key('isStart') and portInfo['isStart']:
  181. raise ServiceException({'result': 2, 'description': u'您选择的充电端口正在使用,不允许使用此端口,建议您换其他端口哦!'})
  182. coins = float(package['coins'])
  183. unit = package.get('unit',u'分钟')
  184. if unit in [u'分钟',u'小时',u'天']:
  185. time1 = int(package['time'])
  186. if unit == u'小时':
  187. time1 = time1 * 60
  188. elif unit == u'天':
  189. time1 = time1 * 1440
  190. devObj = Device.objects.get(devNo = self._device['devNo'])
  191. billingType = devObj.otherConf.get('billingType','time')
  192. if billingType == 'time':
  193. minuteFee = devObj.otherConf.get('minuteFee',0.03)
  194. time2 = int(coins/minuteFee)
  195. maxValue = int(min(time1,time2))
  196. cmdDict = {'duration':maxValue}
  197. else:
  198. elecFee = devObj.otherConf.get('elecFee',0.9)
  199. maxValue = int(coins/elecFee*3600)
  200. cmdDict = {'elec':maxValue,'duration':time1}
  201. elif unit == u'次':
  202. devObj = Device.objects.get(devNo = self._device['devNo'])
  203. billingType = devObj.otherConf.get('billingType','time')
  204. if billingType == 'time':
  205. minuteFee = devObj.otherConf.get('minuteFee',0.03)
  206. time2 = int(coins/minuteFee)
  207. cmdDict = {'duration':time2}
  208. else:
  209. elecFee = devObj.otherConf.get('elecFee',0.9)
  210. maxValue = int(coins/elecFee*3600)
  211. cmdDict = {'elec':maxValue}
  212. elif unit == u'度':
  213. devObj = Device.objects.get(devNo = self._device['devNo'])
  214. billingType = devObj.otherConf.get('billingType','time')
  215. if billingType == 'time':
  216. minuteFee = devObj.otherConf.get('minuteFee',0.03)
  217. time2 = int(coins/minuteFee)
  218. cmdDict = {'duration':time2}
  219. else:
  220. elecConf = float(package['time'])
  221. elecFee = devObj.otherConf.get('elecFee',0.9)
  222. maxValue = int(min(coins/elecFee*3600,elecConf*3600))
  223. cmdDict = {'elec':maxValue}
  224. tmpPort = hex(int(attachParas['chargeIndex']))
  225. hexPort = fill_2_hexByte(tmpPort,2)
  226. cmdDict.update({'IMEI': self._device['devNo'],"funCode":'20','data':'00' + hexPort + '01' })
  227. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, self.make_random_cmdcode(),cmdDict,timeout=120)
  228. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  229. if devInfo['rst'] == -1:
  230. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,您的金币还在,重试不需要重新付款,建议您试试旁边其他设备,或者稍后再试哦'})
  231. elif devInfo['rst'] == 1:
  232. raise ServiceException({'result': 2, 'description': u'充电桩繁忙,无响应,您的金币还在,请试试其他线路,或者稍后再试哦'})
  233. data = devInfo['data'][18::]
  234. if data[0:2] == '01':#表示成功
  235. pass
  236. else:
  237. raise ServiceException({'result': 2, 'description': u'操作和预期不符合,请您选择其他线路,或者稍候再试哦'})
  238. #刷新状态
  239. if package.has_key('time'):
  240. needTime = int(float(package.get('time')))
  241. newValue = {
  242. str(attachParas['chargeIndex']):
  243. {
  244. 'status': Const.DEV_WORK_STATUS_WORKING,
  245. 'startTime': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
  246. 'coins': coins,
  247. 'isStart': True,
  248. 'refunded': False,
  249. 'openId': openId,
  250. 'needTime': needTime,
  251. 'vCardId': self._vcard_id
  252. }
  253. }
  254. elif package.has_key('power'):
  255. newValue = {
  256. str(attachParas['chargeIndex']):
  257. {
  258. 'status': Const.DEV_WORK_STATUS_WORKING,
  259. 'startTime': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
  260. 'coins': coins,
  261. 'isStart': True,
  262. 'refunded': False,
  263. 'openId': openId,
  264. 'needPower': package.get('power'),
  265. 'vCardId': self._vcard_id
  266. }
  267. }
  268. Device.update_dev_control_cache(self._device['devNo'], newValue)
  269. return devInfo
  270. def analyze_event_data(self,data):
  271. cmdCode = data[12:14]
  272. if cmdCode == '02':#刷卡
  273. cardNo = str(int(data[20:36][-10::]))
  274. return {'cardNo':cardNo,'cmdCode':cmdCode}
  275. elif cmdCode == '03':#刷卡,启动或者关闭设备
  276. portNo = int(data[20:22],16)
  277. cardNo = str(int(data[24:40][-10::]))
  278. flag = int(data[22:24])
  279. if flag == 0:
  280. isStart = False
  281. return {'cmdCode':cmdCode,'cardNo':cardNo,'port':portNo,'isStart':isStart,'endTime':datetime.datetime.now().strftime(Const.DATETIME_FMT)}
  282. else:
  283. isStart = True
  284. return {'cmdCode':cmdCode,'cardNo':cardNo,'port':portNo,'isStart':isStart,'startTime':datetime.datetime.now().strftime(Const.DATETIME_FMT)}
  285. elif cmdCode == '04':
  286. portNo = int(data[20:22],16)
  287. flag = int(data[22:24])
  288. reason = ''
  289. if flag == 0:
  290. isStart = False
  291. else:
  292. isStart = True
  293. return {'cmdCode':cmdCode,'port':portNo,'isStart':isStart,'reason':reason,'startTime':datetime.datetime.now().strftime(Const.DATETIME_FMT)}
  294. if not isStart:
  295. flag = data[24:26]
  296. if flag == '00':
  297. reason = u'电池没有充满!原因未知。'
  298. elif flag == '01':
  299. reason = u'可能是电池没有接好,或者电池本身就是满电的。建议您到现场检查是否有人误操作,以尽快恢复充电。'
  300. elif flag == '02':
  301. reason = u'恭喜您!电池已经充满电!'
  302. elif flag == '03':
  303. reason = u'警告!您的电池功率超过本机最大限制,已经停止充电,为了公共安全,不建议您在该充电桩充电!提醒您,为了安全大功率的电池不要放入楼道、室内等位置充电哦'
  304. return {'cmdCode':cmdCode,'port':portNo,'isStart':isStart,'reason':reason,'endTime':datetime.datetime.now().strftime(Const.DATETIME_FMT),'flag':flag}
  305. elif cmdCode == '20':
  306. portNo = int(data[20:22],16)
  307. flag = int(data[22:24])
  308. reason = ''
  309. if flag == 0:
  310. isStart = False
  311. else:
  312. isStart = True
  313. return {'cmdCode':cmdCode,'port':portNo,'isStart':isStart,'reason':reason,'startTime':datetime.datetime.now().strftime(Const.DATETIME_FMT)}
  314. if not isStart:
  315. reason = u'管理人员可能远程断电了,建议您根据已经充电的时间评估是否需要到现场换到其他端口充电。'
  316. return {'cmdCode':cmdCode,'port':portNo,'isStart':isStart,'reason':reason,'endTime':datetime.datetime.now().strftime(Const.DATETIME_FMT),'flag':flag}
  317. return None
  318. def response_card_balance(self,cardNo,balance):
  319. devObj = Device.objects.get(devNo = self._device['devNo'])
  320. billingType = devObj.otherConf.get('billingType','time')
  321. if billingType == 'time':
  322. minuteFee = devObj.otherConf.get('minuteFee',0.03)
  323. maxValue = int(float(str(balance))/minuteFee)
  324. maxType = 'duration'
  325. else:
  326. elecFee = devObj.otherConf.get('elecFee',0.9)
  327. maxValue = int(float(str(balance))/elecFee*3600)
  328. maxType = 'elec'
  329. data = ''
  330. try:
  331. if balance == 0:
  332. data = '03'
  333. else:
  334. data = '01' + fill_2_hexByte(hex(int(balance*100)),8)
  335. except Exception,e:
  336. logger.error('can not find the card=%s' % cardNo)
  337. data = '05'
  338. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, DeviceCmdCode.OPERATE_DEV_NO_RESPONSE,
  339. {maxType:maxValue,'IMEI': self._device['devNo'],"funCode":'02','data':data})
  340. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  341. if devInfo['rst'] == -1:
  342. raise ServiceException(
  343. {'result': 2, 'description': u'充电桩正在玩命找网络,请您稍候再试'})
  344. elif devInfo['rst'] == 1:#等于1的时候,说明服务器和远程模块通讯OK,响应已经收到,不需要异常处理
  345. pass
  346. def response_card_charging(self,result):
  347. if result:
  348. data = '01'
  349. else:
  350. data = '00'
  351. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, DeviceCmdCode.OPERATE_DEV_NO_RESPONSE,
  352. {'IMEI': self._device['devNo'],"funCode":'03','data':data})
  353. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  354. if devInfo['rst'] == -1:
  355. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  356. elif devInfo['rst'] == 1:
  357. pass
  358. def response_finished_back(self, result):
  359. if result:
  360. data = '01'
  361. else:
  362. data = '00'
  363. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, DeviceCmdCode.OPERATE_DEV_NO_RESPONSE,
  364. {'IMEI': self._device['devNo'],"funCode":'04','data':data})
  365. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  366. if devInfo['rst'] == -1:
  367. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  368. elif devInfo['rst'] == 1:
  369. pass
  370. def get_power(self):
  371. devInfo = MessageSender.send_for_moxiaozhiv2(self.device, self.make_random_cmdcode(),
  372. {'IMEI': self._device['devNo'],"funCode":'23','data':'00'})
  373. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  374. if devInfo['rst'] == -1:
  375. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'})
  376. elif devInfo['rst'] == 1:
  377. raise ServiceException({'result': 2, 'description': u'充电桩繁忙,无响应,请试试其他线路,或者稍后再试哦'})
  378. data = devInfo['data'][18::]
  379. if data[0:2] == '01':#表示成功
  380. pass
  381. else:
  382. raise ServiceException({'result': 2, 'description': u'获取功率失,请试试其他线路,或者稍后再试哦'})
  383. powerData = data[2:-8]
  384. resultDict = {}
  385. for ii in range(len(powerData)/4):
  386. port = ii + 1
  387. status = powerData[ii*4:ii*4+4]
  388. resultDict[str(port)] = int(status,16)
  389. return resultDict
  390. #目前支持按时间计费,后续支持按照电量计费的方式
  391. def calc_consume_money(self, spendTime, elec):
  392. try:
  393. dev = Device.objects.get(devNo = self._device['devNo'])
  394. except Exception, e:
  395. logger.error('can not find the dev=%s' % self._device['devNo'])
  396. return RMB(0)
  397. billingType = dev.otherConf.get('billingType', 'time')
  398. if billingType == 'time':
  399. minuteFee = dev.otherConf.get('minuteFee', 0.03)
  400. return RMB(1) * spendTime * minuteFee, u'时间计费'
  401. else:
  402. elecFee = dev.otherConf.get('elecFee', 0.9)
  403. return RMB(1) * elecFee * elec, u'电度计费'
  404. def get_dev_setting(self):
  405. try:
  406. dev = Device.objects.get(devNo = self._device['devNo'])
  407. except Exception,e:
  408. logger.error('can not find the dev=%s' % self._device['devNo'])
  409. return {}
  410. minuteFee = dev.otherConf.get('minuteFee',0.03)
  411. elecFee = dev.otherConf.get('elecFee',0.9)
  412. billingType = dev.otherConf.get('billingType','time')
  413. return {'minuteFee':minuteFee,'elecFee':elecFee,'billingType':billingType}
  414. def set_dev_setting(self,conf):
  415. try:
  416. dev = Device.objects.get(devNo = self._device['devNo'])
  417. except Exception,e:
  418. logger.error('can not find the dev=%s' % self._device['devNo'])
  419. return 0
  420. if conf.has_key('minuteFee'):
  421. dev.otherConf.update({'minuteFee':conf['minuteFee']})
  422. if conf.has_key('elecFee'):
  423. dev.otherConf.update({'elecFee':conf['elecFee']})
  424. if conf.has_key('billingType'):
  425. dev.otherConf.update({'billingType':conf['billingType']})
  426. try:
  427. dev.save()
  428. except Exception,e:
  429. logger.exception('save dev=%s conf error=%s' % (self._device['devNo'],e))
  430. def set_device_function_param(self,request,lastSetConf):
  431. minuteFee = float(request.POST.get('minuteFee', None))
  432. if minuteFee:
  433. lastSetConf.update({'minuteFee': float(minuteFee)})
  434. elecFee = float(request.POST.get('elecFee', None))
  435. if elecFee:
  436. lastSetConf.update({'elecFee': float(elecFee)})
  437. billingType = request.POST.get('billingType', 'time')
  438. if billingType:
  439. lastSetConf.update({'billingType': billingType})
  440. minuteFee = request.POST.get('minuteFee', None)
  441. if minuteFee:
  442. lastSetConf.update({'minuteFee': float(minuteFee)})
  443. self.set_dev_setting(lastSetConf)