# -*- coding: utf-8 -*- from apps.web.core.adapter.base import * from apps.web.device.models import Device class washerHTBox(SmartBox): def __init__(self, device): super(washerHTBox, self).__init__(device) def check_dev_status(self, attachParas=None): devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '01', 'data': '0B'}) if 'rst' in devInfo and devInfo['rst'] != 0: if devInfo['rst'] == -1: raise ServiceException({'result': 2, 'description': u'洗衣机正在玩命找网络,建议您试试旁边其他设备,或者稍后再试哦'}) elif devInfo['rst'] == 1: raise ServiceException({'result': 2, 'description': u'洗衣机繁忙,无响应,请您稍后再试哦'}) data = devInfo['data'] dataFlag = data[10:14] if dataFlag != '0000': raise ServiceException({'result': 2, 'description': u'当前洗衣机正忙,不允许下发启动命令'}) def test(self, coins): byte1 = '10000000' byte2 = '0000' byte2 += '0001' hexByte1 = decimal_2_hexByte(int(byte1,2)) hexByte2 = decimal_2_hexByte(int(byte2,2)) data = '0A' + hexByte2 + hexByte1 devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '04', 'data': data}) return devInfo def start_device(self, package, openId, attachParas): washName = package['name'] 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 byte1 = '10000000' byte2 = '0000' if washName == u'单脱水': byte2 += '0001' elif washName == u'快速洗': byte2 += '0010' elif washName == u'标准洗': byte2 += '0011' elif washName == u'大物洗': byte2 += '0100' else: raise ServiceException({'result': 2, 'description': u'套餐名称错误,请输入正确的套餐名称'}) hexByte1 = decimal_2_hexByte(int(byte1,2)) hexByte2 = decimal_2_hexByte(int(byte2,2)) data = '0A' + hexByte2 + hexByte1 devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '04', 'data': data}, 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, 'isStart': True,'vCardId':self._vcard_id}) devInfo['finishedTime'] = (int(time.time()) + int(duration)) return devInfo def get_dev_setting(self): devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '01', 'data': '05'}) 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'洗衣机繁忙,无响应,请您稍后再试哦'}) data = devInfo['data'] settingData = data[10:12] binData = hexbyte_2_bin(settingData) if binData[0] == '1': leijibishu = 1 else: leijibishu = 0 if binData[1] == '1': qidonganquan = 1 else: qidonganquan = 0 if binData[2] == '1': qidongpinghen = 1 else: qidongpinghen = 0 if binData[3:5] == '00': duandianjiyi = 0 duandianpaishui = 0 elif binData[3:5] == '01': duandianjiyi = 1 duandianpaishui = 0 else: duandianjiyi = 0 duandianpaishui = 1#启动断电排水 if binData[5:7] == '00': shifouqingling = 0 else: shifouqingling = 1 return {'leijibishu':leijibishu,'qidonganquan':qidonganquan,'qidongpinghen':qidongpinghen, 'duandianjiyi':duandianjiyi,'shifouqingling':shifouqingling,'duandianpaishui':duandianpaishui} def set_dev_setting(self,configDict): binData = '' if configDict['shifouqingling'] == 0: binData += '00' else: binData += '11' binData += '0' if configDict['duandianpaishui']: binData += '11' if configDict['duandianjiyi'] == 0: binData += '00' elif configDict['duandianjiyi'] == 1: binData += '01' else: binData += '11' if configDict['qidongpinghen'] == 0: binData += '0' else: binData += '1' if configDict['qidonganquan'] == 0: binData += '0' else: binData += '1' if configDict['leijibishu'] == 0: binData += '0' else: binData += '1' cmdData = '05' + fill_2_hexByte(hex(int(binData,2)), 2) devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '04', 'data': cmdData}) 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'洗衣机繁忙,无响应,请您稍后再试哦'}) def get_normal_value(self,flag): devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '01', 'data': flag}) 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'洗衣机繁忙,无响应,请您稍后再试哦'}) data = devInfo[18::] value = data[0:2] return value def set_normal_value(self, flag, value): # type: (str, int) -> bool data = flag + fill_2_hexByte(hex(int(value)), 2) devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '04', 'data': data}) 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'洗衣机繁忙,无响应,请您稍后再试哦'}) return True def analyze_event_data(self, data): flag = data[16:18] if flag != 'OC': return {} binData = hexbyte_2_bin(data[18:20]) if binData[0] == '1': return {'statusInfo':u'进水故障'} if binData[1] == '1': return {'statusInfo':u'安全故障'} # if binData[0] == '1': # return {'statusInfo':u'进水故障'} if binData[3] == '1': return {'statusInfo':u'平衡开关故障'} if binData[7] == '1': return {'statusInfo':u'洗衣未运行'} def set_device_function(self,request,lastSetConf): if request.POST.has_key('leijibishu'): # value = 1 if request.POST.get('leijibishu') == 'true' else 0 value = int(request.POST.get("leijibishu", False)) lastSetConf.update({'leijibishu': value}) if request.POST.has_key('qidonganquan'): value = 1 if request.POST.get('qidonganquan') else 0 lastSetConf.update({'qidonganquan': value}) if request.POST.has_key('qidongpinghen'): value = 1 if request.POST.get('qidongpinghen') else 0 lastSetConf.update({'qidongpinghen': value}) if request.POST.has_key('duandianjiyi'): value = 1 if request.POST.get('duandianjiyi') else 0 lastSetConf.update({'duandianjiyi': value}) if request.POST.has_key('shifouqingling'): value = 1 if request.POST.get('shifouqingling') else 0 lastSetConf.update({'shifouqingling': value}) if request.POST.has_key('duandianpaishui'): value = 1 if request.POST.get('duandianpaishui') else 0 lastSetConf.update({'duandianpaishui': value}) self.set_dev_setting(lastSetConf)