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