jh_access.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. from typing import Dict
  4. from apps.web.constant import DeviceCmdCode, MQTT_TIMEOUT
  5. from apps.web.core.adapter.base import SmartBox
  6. from apps.web.core.exceptions import ServiceException
  7. from apps.web.core.networking import MessageSender
  8. class JHAccessBox(SmartBox):
  9. def __init__(self, device):
  10. super(JHAccessBox, self).__init__(device)
  11. def test(self, coins):
  12. devInfo = MessageSender.send(device = self.device, cmd = DeviceCmdCode.OPERATE_DEV_SYNC, payload = {
  13. 'IMEI': self._device['devNo'],
  14. 'funCode': '01',
  15. 'data': '01'
  16. })
  17. return devInfo
  18. def start_device(self, package, openId, attachParas):
  19. # type: (Dict, str, Dict)->Dict
  20. devInfo = MessageSender.send(device = self.device, cmd = DeviceCmdCode.OPERATE_DEV_SYNC, payload = {
  21. 'IMEI': self._device['devNo'],
  22. 'funCode': '01',
  23. 'data': '01'
  24. }, timeout = MQTT_TIMEOUT.START_DEVICE)
  25. # TODO zjl 此设备类型不会有
  26. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  27. if devInfo['rst'] == -1:
  28. raise ServiceException(
  29. {
  30. 'result': 2,
  31. 'description': u'正在玩命找网络,请稍后重试'
  32. }
  33. )
  34. elif devInfo['rst'] == 1:
  35. raise ServiceException(
  36. {
  37. 'result': 2,
  38. 'description': u'设备正在忙,请稍后再试'
  39. }
  40. )
  41. return devInfo