# -*- coding: utf-8 -*- # !/usr/bin/env python import time from apilib.utils_datetime import timestamp_to_dt from apps.web.constant import Const, DeviceCmdCode, MQTT_TIMEOUT from apps.web.core.adapter.base import SmartBox, fill_2_hexByte from apps.web.core.exceptions import ServiceException from apps.web.core.networking import MessageSender from apps.web.device.models import Device class ChargingHaiNiaoBox(SmartBox): def __init__(self, device): super(ChargingHaiNiaoBox, self).__init__(device) # 设备上报事件 def analyze_event_data(self, data): cmdCode = data[6:8] if cmdCode == '86': portData = data[8:12] if portData == '0001': port = '1' reason = data[16:18] elif portData == '0002': port = '2' reason = data[18:20] elif portData == '0004': port = '3' reason = data[20:22] elif portData == '0008': port = '4' reason = data[22:24] elif portData == '0010': port = '5' reason = data[24:26] elif portData == '0020': port = '6' reason = data[26:28] elif portData == '0040': port = '7' reason = data[28:30] elif portData == '0080': port = '8' reason = data[30:32] elif portData == '0100': port = '9' reason = data[32:34] elif portData == '0200': port = '10' reason = data[34:36] else: port = '-1' reason = u'unknown' if reason == '00': desc = u'购买的充电时间用完了。' elif reason in ['04', '06', '07']: desc = u'管理人员可能远程断电了,或是插头被拔掉, 建议您根据已经充电的时间评估是否需要到现场换到其他端口充电。' elif reason in ['02', '03']: desc = u'警告!您的电池超功率,已经停止充电,为了公共安全,不建议您在该充电桩充电!提醒您,为了安全大功率的电池不要放入楼道、室内等位置充电哦。' elif reason == '05': desc = u'空载。' elif reason == '01': desc = u'电池没有充满!原因未知。' else: desc = u'成功!' return {'status': Const.DEV_WORK_STATUS_IDLE, 'cmdCode': cmdCode, 'port': str(int(port) - 1), 'reason': desc} def translate_funcode(self, funCode): funCodeDict = { '01': u'获取端口状态', '02': u'获取设备参数', '03': u'操作端口', '04': u'设置参数', } return funCodeDict.get(funCode, '') def translate_event_cmdcode(self, cmdCode): cmdDict = { '86': u'设备上报信息', } return cmdDict.get(cmdCode, '') def get_port_status_from_dev(self): # 获取端口状态 devInfo = MessageSender.send(self.device, self.make_random_cmdcode(), {'IMEI': self._device['devNo'], "funCode": '01', 'data': '00'}) 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) port2Status = int(devInfo['data'][8:10], 16) # 通道9~10的状态 port8Status = int(devInfo['data'][10:12], 16) # 通道1~8的状态 portStatusInfo = devInfo['data'][72:92] bin2Str = str(bin(port2Status))[2:] while len(bin2Str) < 8: bin2Str = '0' + bin2Str bin8Str = str(bin(port8Status))[2:] while len(bin8Str) < 8: bin8Str = '0' + bin8Str result = {} if bin2Str[6] == '1': result[str(10 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin2Str[6] == '0': result[str(10 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin2Str[7] == '1': result[str(9 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin2Str[7] == '0': result[str(9 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[0] == '1': result[str(8 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[0] == '0': result[str(8 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[1] == '1': result[str(7 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[1] == '0': result[str(7 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[2] == '1': result[str(6 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[2] == '0': result[str(6 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[3] == '1': result[str(5 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[3] == '0': result[str(5 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[4] == '1': result[str(4 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[4] == '0': result[str(4 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[5] == '1': result[str(3 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[5] == '0': result[str(3 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[6] == '1': result[str(2 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[6] == '0': result[str(2 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} if bin8Str[7] == '1': result[str(1 - 1)] = {'status': Const.DEV_WORK_STATUS_WORKING} elif bin8Str[7] == '0': result[str(1 - 1)] = {'status': Const.DEV_WORK_STATUS_IDLE} ii = 0 while ii < 10: statusTemp = portStatusInfo[ii * 2:ii * 2 + 2] if statusTemp != '00': result[str(ii)] = {'status': Const.DEV_WORK_STATUS_FAULT} ii += 1 allPorts, usedPorts, usePorts = self.get_port_static_info(result) Device.update_dev_control_cache(self._device['devNo'], {'allPorts': allPorts, 'usedPorts': usedPorts, 'usePorts': usePorts}) # 这里存在多线程更新缓存的场景,可能性比较低,但是必须先取出来,然后逐个更新状态,然后再记录缓存 ctrInfo = Device.get_dev_control_cache(self._device['devNo']) for strPort, info in result.items(): if ctrInfo.has_key(strPort): ctrInfo[strPort].update({'status': info['status']}) else: ctrInfo[strPort] = info Device.update_dev_control_cache(self._device['devNo'], ctrInfo) return result def get_port_status(self, force = False): # 获取端口状态(缓存) if force: return self.get_port_status_from_dev() ctrInfo = Device.get_dev_control_cache(self._device['devNo']) statusDict = {} allPorts = ctrInfo.get('allPorts', 10) if allPorts == 0: allPorts = 10 for ii in range(allPorts): tempDict = ctrInfo.get(str(ii), {}) if tempDict.has_key('status'): statusDict[str(ii)] = {'status': tempDict.get('status')} elif tempDict.has_key('isStart'): if tempDict['isStart']: statusDict[str(ii)] = {'status': Const.DEV_WORK_STATUS_WORKING} else: statusDict[str(ii)] = {'status': Const.DEV_WORK_STATUS_IDLE} else: statusDict[str(ii)] = {'status': Const.DEV_WORK_STATUS_IDLE} allPorts, usedPorts, usePorts = self.get_port_static_info(statusDict) Device.update_dev_control_cache(self._device['devNo'], {'allPorts': allPorts, 'usedPorts': usedPorts, 'usePorts': usePorts}) return statusDict def get_dev_setting(self): # 获取设备参数 devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '02', 'data': '00'}) 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) confData = devInfo['data'][8::] ewmTime = int(confData[0:4], 16) coinTime = int(confData[4:8], 16) icTime = int(confData[8:12], 16) oneMaxElec = float(int(confData[12:14], 16)) / 10 oneStdElec = float(int(confData[14:16], 16)) / 10 portParam = int(confData[16:18], 16) allMaxElec = float(int(confData[18:20], 16)) / 10 lessElecShutDown = float(int(confData[20:22], 16)) / 10 putCoins = int(confData[22:30], 16) putEwms = int(confData[30:38], 16) putCards = int(confData[38:46], 16) versionNum = int(confData[46:50], 16) binStr = str(bin(portParam))[2:] while len(binStr) < 8: binStr = '0' + binStr standbyDisplay = '0' shutDownMem = False freeMode = False fullClose = False defaultSetting = False allTimeClear = False funcSetting = '0' noElecShutDown = False if int(binStr[0]): standbyDisplay = '1' if int(binStr[1]): shutDownMem = True if int(binStr[2]): freeMode = True if int(binStr[3]): fullClose = True if int(binStr[4]): defaultSetting = True if int(binStr[5]): allTimeClear = True if int(binStr[6]): funcSetting = '1' if int(binStr[7]): noElecShutDown = True return { 'ewmTime': ewmTime, 'coinTime': coinTime, 'icTime': icTime, 'oneMaxElec': oneMaxElec, 'oneStdElec': oneStdElec, 'allMaxElec': allMaxElec, 'lessElecShutDown': lessElecShutDown, 'putCoins': putCoins, 'putEwms': putEwms, 'putCards': putCards, 'versionNum': versionNum, 'standbyDisplay': standbyDisplay, 'shutDownMem': shutDownMem, 'freeMode': freeMode, 'fullClose': fullClose, 'defaultSetting': defaultSetting, 'allTimeClear': allTimeClear, 'funcSetting': funcSetting, 'noElecShutDown': noElecShutDown, } def test(self, coins): port = hex(5) hexPort = fill_2_hexByte(port, 4) if hexPort == '0009': hexPort = '0100' elif hexPort == '000A': hexPort = '0200' elif hexPort == '0003': hexPort = '0004' elif hexPort == '0004': hexPort = '0008' elif hexPort == '0005': hexPort = '0010' elif hexPort == '0006': hexPort = '0020' elif hexPort == '0007': hexPort = '0040' elif hexPort == '0008': hexPort = '0080' hexTime = fill_2_hexByte(hex(1)) data = hexPort + '01' + hexTime devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, { 'IMEI': self._device['devNo'], "funCode": '03', 'data': data }) return devInfo def start_device(self, package, openId, attachParas): if attachParas is None: raise ServiceException({'result': 2, 'description': u'请您选择合适的充电线路、电池类型信息'}) if not attachParas.has_key('chargeIndex'): raise ServiceException({'result': 2, 'description': u'请您选择合适的充电线路'}) port = hex(int(attachParas['chargeIndex']) + 1) hexPort = fill_2_hexByte(port, 4) if hexPort == '0009': hexPort = '0100' elif hexPort == '000A': hexPort = '0200' elif hexPort == '0003': hexPort = '0004' elif hexPort == '0004': hexPort = '0008' elif hexPort == '0005': hexPort = '0010' elif hexPort == '0006': hexPort = '0020' elif hexPort == '0007': hexPort = '0040' elif hexPort == '0008': hexPort = '0080' needTime = int(package['time']) needCoins = int(package['coins']) unit = package.get('unit', u'分钟') if unit == u'小时': needTime = int(package['time']) * 60 elif unit == u'天': needTime = int(package['time']) * 1440 hexTime = fill_2_hexByte(hex(needTime)) data = hexPort + '01' + hexTime devInfo = MessageSender.send(device = self.device, cmd = DeviceCmdCode.OPERATE_DEV_SYNC, payload = { 'IMEI': self._device['devNo'], "funCode": '03', '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'充电桩正在忙,无响应,您的金币还在,请试试其他线路,或者请稍后再试哦'}) data = devInfo['data'][8::] usePort = int(attachParas['chargeIndex']) result = data[4:8] if result == '0000': # 代表失败 newValue = {str(usePort): {'status': Const.DEV_WORK_STATUS_FAULT, 'statusInfo': u'充电站故障'}} Device.update_dev_control_cache(self._device['devNo'], newValue) raise ServiceException({'result': 2, 'description': u'充电站故障'}) start_timestamp = int(time.time()) finishedTime = start_timestamp + needTime * 60 portDict = { 'startTime': timestamp_to_dt(start_timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'status': Const.DEV_WORK_STATUS_WORKING, 'finishedTime': finishedTime, 'coins': float(needCoins), 'isStart': True, 'needTime': needTime, 'openId': openId, 'refunded': False, 'vCardId': self._vcard_id } if 'linkedRechargeRecordId' in attachParas: item = { 'rechargeRcdId': str(attachParas['linkedRechargeRecordId']) } portDict['payInfo'] = [item] Device.update_dev_control_cache(self._device['devNo'], {str(usePort): portDict}) return devInfo # 设置充电时间 def set_charging_time_setting(self, setConf): def send_msg_2_dev(data): 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) if setConf['ewmTime']: data = '01' + fill_2_hexByte(hex(int(setConf['ewmTime'])), 4) send_msg_2_dev(data) if setConf['coinTime']: data = '02' + fill_2_hexByte(hex(int(setConf['coinTime'])), 4) send_msg_2_dev(data) if setConf['icTime']: data = '03' + fill_2_hexByte(hex(int(setConf['icTime'])), 4) send_msg_2_dev(data) # 设置充电电流 def set_charging_elec_setting(self, setConf): def send_msg_2_dev(data): 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) if setConf['oneMaxElec']: data = '04' + fill_2_hexByte(hex(int(setConf['oneMaxElec'])), 4) send_msg_2_dev(data) if setConf['oneStdElec']: data = '05' + fill_2_hexByte(hex(int(setConf['oneStdElec'])), 4) send_msg_2_dev(data) if setConf['allMaxElec']: data = '0E' + fill_2_hexByte(hex(int(setConf['allMaxElec'])), 4) send_msg_2_dev(data) if setConf['lessElecShutDown']: data = '0F' + fill_2_hexByte(hex(int(setConf['lessElecShutDown'])), 4) send_msg_2_dev(data) # 设置功能参数 def set_func_param_setting(self, setConf): def send_msg_2_dev(data): 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) if setConf['funcSetting']: data = '07' + fill_2_hexByte(hex(int(setConf['funcSetting'])), 4) send_msg_2_dev(data) if setConf['standbyDisplay']: data = '0D' + fill_2_hexByte(hex(int(setConf['standbyDisplay'])), 4) send_msg_2_dev(data) # 设置空载自停 def set_no_elec_shut_down(self, noElecShutDown = False): data = '06' + ('0001' if noElecShutDown else '0000') 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) # 设置充满自停 def set_full_close(self, fullClose = False): data = '0A' + ('0001' if fullClose else '0000') 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) # 设置免费使用 def set_free_mode(self, freeMode = False): data = '0B' + ('0001' if freeMode else '0000') 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) # 设置断电记忆 def set_shut_down_mem(self, shutDownMem = False): data = '0C' + ('0001' if shutDownMem else '0000') 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) # 设置清空时间 def set_all_time_clear(self, allTimeClear = False): data = '08' + ('0000' if allTimeClear else '0001') 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) # 设置恢复默认 def set_default_setting(self, defaultSetting = False): data = '09' + ('0000' if defaultSetting else '0001') 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) if devInfo['data'][14:16] == '01': raise ServiceException( {'result': 2, 'description': u'设置失败'}) def stop(self, port = None): self.stop_charging_port(port) infoDict = dict() infoDict['remainder_time'] = 0 return infoDict def stop_charging_port(self, port): self.active_deactive_port(port, False) # 远程停止某个端口的使用 def active_deactive_port(self, port, active): hexPort = fill_2_hexByte(hex(int(port) + 1), 4) if hexPort == '0009': hexPort = '0100' elif hexPort == '000A': hexPort = '0200' elif hexPort == '0003': hexPort = '0004' elif hexPort == '0004': hexPort = '0008' elif hexPort == '0005': hexPort = '0010' elif hexPort == '0006': hexPort = '0020' elif hexPort == '0007': hexPort = '0040' elif hexPort == '0008': hexPort = '0080' if active: return else: data = hexPort + '00' devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '03', 'data': data + '0000'}) 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_port_info(self, line): devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC, {'IMEI': self._device['devNo'], "funCode": '01', 'data': '00'}) 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'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'}) leftTimeData = devInfo['data'][32:72] elecData = devInfo['data'][12:32] ii = int(line) leftTime = int(int(leftTimeData[ii * 4:ii * 4 + 4], 16) / 60) electricity = float(int(elecData[ii * 2:ii * 2 + 2], 16)) / 10 return {'port': str(int(line) - 1), 'leftTime': leftTime, 'electricity': electricity} def set_device_function(self, request, lastSetConf): if request.POST.has_key('noElecShutDown'): # noElecShutDown = True if request.POST.get('noElecShutDown') == 'true' else False noElecShutDown = request.POST.get("noElecShutDown", False) lastSetConf.update({'noElecShutDown': noElecShutDown}) self.set_no_elec_shut_down(lastSetConf['noElecShutDown']) if request.POST.has_key('fullClose'): # fullClose = True if request.POST.get('fullClose') == 'true' else False fullClose = request.POST.get("fullClose", False) lastSetConf.update({'fullClose': fullClose}) self.set_full_close(lastSetConf['fullClose']) if request.POST.has_key('freeMode'): # freeMode = True if request.POST.get('freeMode') == 'true' else False freeMode = request.POST.get("freeMode", False) lastSetConf.update({'freeMode': freeMode}) self.set_free_mode(lastSetConf['freeMode']) if request.POST.has_key('shutDownMem'): # shutDownMem = True if request.POST.get('shutDownMem') == 'true' else False shutDownMem = request.POST.get("shutDownMem", False) lastSetConf.update({'shutDownMem': shutDownMem}) self.set_shut_down_mem(lastSetConf['shutDownMem']) if request.POST.has_key('allTimeClear'): # allTimeClear = True if request.POST.get('allTimeClear') == 'true' else False allTimeClear = request.POST.get("allTimeClear", False) lastSetConf.update({'allTimeClear': allTimeClear}) self.set_all_time_clear(lastSetConf['allTimeClear']) if request.POST.has_key('defaultSetting'): # defaultSetting = True if request.POST.get('defaultSetting') == 'true' else False defaultSetting = request.POST.get("defaultSetting", False) lastSetConf.update({'defaultSetting': defaultSetting}) self.set_default_setting(lastSetConf['defaultSetting']) def set_device_function_param(self, request, lastSetConf): ewmTime = request.POST.get('ewmTime', None) coinTime = request.POST.get('coinTime', None) icTime = request.POST.get('icTime', None) oneMaxElec = request.POST.get('oneMaxElec', None) oneStdElec = request.POST.get('oneStdElec', None) funcSetting = request.POST.get('funcSetting', False) standbyDisplay = request.POST.get('standbyDisplay', None) allMaxElec = request.POST.get('allMaxElec', None) lessElecShutDown = request.POST.get('lessElecShutDown', None) if ewmTime and coinTime and icTime: lastSetConf.update({'ewmTime': int(ewmTime)}) lastSetConf.update({'coinTime': int(coinTime)}) lastSetConf.update({'icTime': int(icTime)}) self.set_charging_time_setting(lastSetConf) if oneMaxElec and oneStdElec and allMaxElec and lessElecShutDown: lastSetConf.update({'oneMaxElec': float(oneMaxElec) * 10}) lastSetConf.update({'oneStdElec': float(oneStdElec) * 10}) lastSetConf.update({'allMaxElec': float(allMaxElec) * 10}) lastSetConf.update({'lessElecShutDown': float(lessElecShutDown) * 10}) self.set_charging_elec_setting(lastSetConf) if funcSetting and standbyDisplay: lastSetConf.update({'funcSetting': True}) lastSetConf.update({'standbyDisplay': True}) self.set_func_param_setting(lastSetConf) @property def isHaveStopEvent(self): return True