1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import logging
- import simplejson as json
- import time
- from apps.web.constant import DeviceErrorCodeDesc, MQTT_TIMEOUT
- from apps.web.core.adapter.base import OnlineSmartBox
- from apps.web.core.exceptions import ServiceException
- from apps.web.core.networking import MessageSender
- logger = logging.getLogger(__name__)
- class WasherSCHZBox(OnlineSmartBox):
- """
- 四川何总的洗衣机特殊处理,消耗套餐中1个金币发一个脉冲,3个金币2个脉冲,4个金币发3个脉冲,5个金币发4个脉冲
- """
- def __init__(self, device):
- super(WasherSCHZBox, self).__init__(device)
- def start_device(self, package, openId, attachParas):
- pay_count = int(package['coins'])
- pulseCount = pay_count
- if pay_count in [3, 4, 5]:
- pulseCount = pay_count - 1
- result = MessageSender.net_pay(self.device, pulseCount, timeout = MQTT_TIMEOUT.START_DEVICE)
- if result['rst'] != 0:
- logger.debug('WasherSCHZBox() failed to start, result was=%s' % (json.dumps(result),))
- raise ServiceException({'result': 2, 'description': DeviceErrorCodeDesc.get(result['rst'])})
- try:
- if package.has_key('time'):
- unit = package.get('unit', u'分钟')
- duration = int(package['time']) * 60
- if unit == u'小时':
- duration = int(package['time']) * 3600
- elif unit == u'天':
- duration = int(package['time']) * 86400
- result['finishedTime'] = (int(time.time()) + duration)
- except Exception, e:
- logger.exception('error = %s' % e)
- return result
|