# coding=utf-8 import time from apps.web.core.adapter.base import SmartBox from apps.web.core.exceptions import ServiceException from apps.web.core.networking import MessageSender class HaierBox(SmartBox): def start_device(self, package, openId, attachParas): washName = package["name"] if washName == u"大物洗": 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() needTime = 45 * 60 elif washName == u"标准洗": 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() needTime = 35 * 60 elif washName == u"快速洗": 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() needTime = 25 * 60 elif washName == u"单脱水": 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() needTime = 9 * 60 elif washName == u"桶自洁": 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() needTime = 2 * 60 else: raise ServiceException({"result": 2, "description": u"不支持的模式,套餐设置错误"}) result = MessageSender.send( device=self.device, cmd=210, payload={ "IMEI": self.device.devNo, "funCode": "start", "data": "".join(wash_uart) }, timeout=10 ) if result["rst"] == 1: raise ServiceException({"result": 2, "description": u"设备繁忙,请稍后再试"}) if result["rst"] == -1: raise ServiceException({"result": 2, "description": u"设备网络故障(1), 请稍后重试"}) # 没有协议 经过测试猜测应该是 启动失败的返回报文 if result["data"] == "FFFF0C000000000000030000000413": raise ServiceException({"result": 2, "description": u"设备启动故障(2), 请稍后重试"}) result["finishedTime"] = int(time.time()) + needTime return result