sichuanhezong.py 1.7 KB

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