zuliao2.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. from apps.web.constant import DeviceCmdCode, MQTT_TIMEOUT
  4. from apps.web.core.adapter.base import SmartBox
  5. from apps.web.core.exceptions import ServiceException
  6. from apps.web.core.networking import MessageSender
  7. from apps.web.device.models import Device
  8. class PedicureBox2(SmartBox):
  9. def __init__(self, device):
  10. super(PedicureBox2, self).__init__(device)
  11. def start_device(self, package, openId, attachParas):
  12. #: 首先检查设备是否在线
  13. unit = package.get('unit', u'分钟')
  14. if unit == u'分钟':
  15. duration = int(package['time']) * 60
  16. elif unit == u'小时':
  17. duration = int(package['time']) * 3600
  18. elif unit == u'天':
  19. duration = int(package['time']) * 86400
  20. else:
  21. duration = int(package['time']) * 60
  22. devInfo = MessageSender.send(self.device, DeviceCmdCode.PAY_MONEY,
  23. {'IMEI': self._device['devNo'], 'duration': duration},
  24. timeout = MQTT_TIMEOUT.START_DEVICE)
  25. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  26. if devInfo['rst'] == -1:
  27. raise ServiceException({'result': 2, 'description': u'足疗机正在玩命找网络,您的金币还在,重试不需要重新付款,建议您试试旁边其他设备,或者稍后再试哦'})
  28. elif devInfo['rst'] == 1:
  29. raise ServiceException({'result': 2, 'description': u'足疗机正在忙,无响应,您的金币还在,重试不需要重新付款,请试试其他线路,或者请稍后再试哦'})
  30. Device.update_dev_control_cache(self._device['devNo'], {'openId': openId, 'vCardId': self._vcard_id})
  31. return devInfo