def _run(self, log): value = self.getGlobalOperationMode() if self.getUnitId() is None else self.getLocalOperationMode() code = constant.apis_operation_mode_2_code[_s(value)] url = 'http://' + config.apis_web_host + ':' + _s(config.apis_web_budo_emulator_port) + '/setOperationMode' data = urllib.parse.urlencode({ 'unitId' : _s(self.getUnitId()), 'value' : code, }) url += '?' + data log.add(' url : ' + url) res = urllib.request.urlopen(url, timeout = 1).read() log.add(' response : ' + res.decode('utf-8').strip()) log.add(' done') return True
def _run(self, log): deal = {} deal['createDateTime'] = datetime.datetime.now(pytz.timezone('Asia/Tokyo')).strftime('%Y/%m/%d-%H:%M:%S') deal['type'] = 'discharge' deal['unitId'] = self.getDischargeUnitId() deal['requestUnitId'] = self.getDischargeUnitId() deal['acceptUnitId'] = self.getChargeUnitId() deal['dischargeUnitId'] = self.getDischargeUnitId() deal['chargeUnitId'] = self.getChargeUnitId() deal['dealGridCurrentA'] = self.getDealGridCurrentA() deal['dealAmountWh'] = self.getDealAmountWh() deal['pointPerWh'] = self.getPointPerWh() if self.getDischargeUnitEfficientGridVoltageV() is not None: deal['dischargeUnitEfficientGridVoltageV'] = self.getDischargeUnitEfficientGridVoltageV() if self.getChargeUnitEfficientGridVoltageV() is not None: deal['chargeUnitEfficientGridVoltageV'] = self.getChargeUnitEfficientGridVoltageV() deal['testFeature'] = {} if 0 < len(self.__testFeature['dcdc']): deal['testFeature']['dcdc'] = self.__testFeature['dcdc'] val = json.dumps(deal) url = 'http://' + config.apis_web_host + ':' + _s(config.apis_web_api_server_port) + '/deal' log.add(' url : ' + url) log.add(' data : ' + val) data = urllib.parse.urlencode({'json' : val}) res = urllib.request.urlopen(url, data.encode('utf-8'), timeout = 1).read() log.add(' response : ' + res.decode('utf-8').strip()) log.add(' done') return True
def _run(self, log): family, socktype, proto, canonname, sockaddr = socket.getaddrinfo(config.apis_log_group_address, config.apis_log_port, socket.AF_UNSPEC, socket.SOCK_DGRAM, 0, socket.AI_PASSIVE)[0] log.add(' family : ' + repr(family)) log.add(' socktype : ' + repr(socktype)) log.add(' proto : ' + repr(proto)) log.add(' canonname : ' + repr(canonname)) log.add(' sockaddr : ' + repr(sockaddr)) self.__sock = socket.socket(family, socktype, proto) self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__sock.settimeout(5) if family == socket.AF_INET6: self.__sock.bind(sockaddr) elif family == socket.AF_INET: self.__sock.bind(('0.0.0.0', sockaddr[1])) group = socket.inet_pton(family, config.apis_log_group_address) mreq = struct.pack('4sL', group, socket.INADDR_ANY) self.__sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) else: raise RuntimeError('unknown address family : ' + family) log.add(' waiting for log : \'' + _s(self.getMessage()) + '\', from unit : ' + _s(self.getUnitId())) results = [] self.__doWaitLogRunning = True t = Thread(target = self.__doWaitLog, args = (results,)) t.daemon = True t.start() t.join(self.getTimeoutS()) self.__doWaitLogRunning = False self.__sock.close() self.__sock = None if 0 < len(results): log.add(' log received : ' + results[0]) log.add(' done') return True else: log.add(' timed out') return False
def _run(self, log): url = 'http://' + config.apis_web_host + ':' + _s(config.apis_web_api_server_port) + '/error' data = urllib.parse.urlencode({ 'unitId' : self.getUnitId(), 'category' : self.getCategory(), 'extent' : self.getExtent(), 'level' : self.getLevel(), 'message' : self.getMessage(), }) log.add(' url : ' + url) log.add(' data : ' + data) res = urllib.request.urlopen(url, data.encode('utf-8'), timeout = 1).read() log.add(' response : ' + res.decode('utf-8').strip()) log.add(' done') return True
def _run(self, log): log.add(' waiting ' + _s(self.getDurationS()) + ' (s)') time.sleep(self.getDurationS()) log.add(' done') return True
def _run(self, log): unitId = _s(self.getUnitId()) com = _s(self.getCommand()) url = None if config.is_emulation: log.add(' emulator') url = 'http://' + config.emulator_host + ':' + _s(config.emulator_port) if com == 'MODE': code = constant.dcdc_mode_2_code[self.getMode()] url += '/set/dcdc/' + unitId + '?mode=' + code + '&dvg=' + _s(self.getGridVoltageV()) + '&dig=' + _s(self.getGridCurrentA()) + '&drg=' + _s(self.getDroopRatio()) elif com == 'VOLTAGE': url += '/set/dcdc/voltage/' + unitId + '?dvg=' + _s(self.getGridVoltageV()) + '&drg=' + _s(self.getDroopRatio()) elif com == 'CURRENT': url += '/set/dcdc/current/' + unitId + '?dig=' + _s(self.getGridCurrentA()) else: raise RuntimeError('bad command : ' + _s(com)) else: log.add(' actual device') unit = self._findUnitById(unitId) url = 'http://' + unit['host'] + ':' + _s(unit['dcdc_port']) if com == 'MODE': code = constant.dcdc_mode_2_code[self.getMode()] url += '/remote/set?mode=' + code + '&dvg=' + _s(self.getGridVoltageV()) + '&dig=' + _s(self.getGridCurrentA()) + '&drg=' + _s(self.getDroopRatio()) elif com == 'VOLTAGE': url += '/remote/set/voltage?dvg=' + _s(self.getGridVoltageV()) + '&drg=' + _s(self.getDroopRatio()) elif com == 'CURRENT': url += '/remote/set/current?dig=' + _s(self.getGridCurrentA()) else: raise RuntimeError('bad command : ' + _s(com)) log.add(' url : ' + url) res = urllib.request.urlopen(url, timeout = 5).read() log.add(' response : ' + res.decode('utf-8').strip()) log.add(' done') return True