haier.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # coding=utf-8
  2. import time
  3. from apps.web.core.adapter.base import SmartBox
  4. from apps.web.core.exceptions import ServiceException
  5. from apps.web.core.networking import MessageSender
  6. class HaierBox(SmartBox):
  7. def start_device(self, package, openId, attachParas):
  8. washName = package["name"]
  9. if washName == u"大物洗":
  10. wash_uart = "FF FF 28 00 00 00 00 00 00 60 00 01 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9A".split()
  11. needTime = 45 * 60
  12. elif washName == u"标准洗":
  13. wash_uart = "FF FF 28 00 00 00 00 00 00 60 00 01 00 23 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 AC".split()
  14. needTime = 35 * 60
  15. elif washName == u"快速洗":
  16. wash_uart = "FF FF 28 00 00 00 00 00 00 60 00 01 00 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 98".split()
  17. needTime = 25 * 60
  18. elif washName == u"单脱水":
  19. wash_uart = "FF FF 28 00 00 00 00 00 00 60 00 01 00 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 A5".split()
  20. needTime = 9 * 60
  21. elif washName == u"桶自洁":
  22. wash_uart = "FF FF 28 00 00 00 00 00 00 60 00 01 00 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 96".split()
  23. needTime = 2 * 60
  24. else:
  25. raise ServiceException({"result": 2, "description": u"不支持的模式,套餐设置错误"})
  26. result = MessageSender.send(
  27. device=self.device,
  28. cmd=210,
  29. payload={
  30. "IMEI": self.device.devNo,
  31. "funCode": "start",
  32. "data": "".join(wash_uart)
  33. },
  34. timeout=10
  35. )
  36. if result["rst"] == 1:
  37. raise ServiceException({"result": 2, "description": u"设备繁忙,请稍后再试"})
  38. if result["rst"] == -1:
  39. raise ServiceException({"result": 2, "description": u"设备网络故障(1), 请稍后重试"})
  40. # 没有协议 经过测试猜测应该是 启动失败的返回报文
  41. if result["data"] == "FFFF0C000000000000030000000413":
  42. raise ServiceException({"result": 2, "description": u"设备启动故障(2), 请稍后重试"})
  43. result["finishedTime"] = int(time.time()) + needTime
  44. return result