def ReadAction(self, oAction: cAction) -> None: """ Adds and defaults some common attributes to the action :param cAction oAction: Reads an action from the action pars """ oAction.uType = oAction.dActionPars.get(u'type', u'send') oAction.uCmd = oAction.dActionPars.get(u'cmd', u'No cmd action defined') oAction.uLocalDestVar = oAction.dActionPars.get( u'ldestvar', u'RESULT_' + oAction.uActionName) oAction.uGlobalDestVar = oAction.dActionPars.get( u'gdestvar', u'RESULT_' + oAction.uActionName) oAction.uGetVar = oAction.dActionPars.get(u'getvar', u'') oAction.bWaitForResponse = ToBool( oAction.dActionPars.get(u'waitforresponse', u'0')) oAction.uParseResultOption = oAction.dActionPars.get( u'parseoption', self.aIniSettings.uParseResultOption) oAction.uParseResultTokenizeString = oAction.dActionPars.get( u'parsetoken', self.aIniSettings.uParseResultTokenizeString) oAction.uParseResultFlags = oAction.dActionPars.get( u'parseflags', self.aIniSettings.uParseResultFlags) oAction.uResultEndString = oAction.dActionPars.get( u'parseendstring', self.aIniSettings.uResultEndString) oAction.dActionPars['interface'] = self.oInterFace.uObjectName oAction.dActionPars['configname'] = self.uConfigName if oAction.dActionPars.get('varcontext', '') == "codeset": oAction.dActionPars["varcontext"] = self.uContext
def SendCommand(self, oAction: cAction, oSetting: cInterFaceSettings, uRetVar: str, bNoLogOut: bool = False) -> eReturnCode: super().SendCommand(oAction=oAction, oSetting=oSetting, uRetVar=uRetVar, bNoLogOut=bNoLogOut) iTryCount: int = 0 eRet: eReturnCode = eReturnCode.Error uRetVar = ReplaceVars(uRetVar) oSetting.uRetVar = uRetVar if uRetVar != "": oAction.uGlobalDestVar = uRetVar dCmd: Dict = ToDic(oAction.uCmd) uCmd: str = dCmd["method"] dParams: Dict = dCmd["params"] while iTryCount < self.iMaxTryCount: iTryCount += 1 oSetting.Connect() if oSetting.bIsConnected: try: self.ShowDebug(uMsg="Sending elv max command: %s" % uCmd) oFunc: Callable = self.dInterfaceFunctions.get(uCmd) aResult: List = [] if oFunc is not None: aResult = oFunc(oSetting=oSetting, oAction=oAction, dParams=dParams) else: self.ShowError(uMsg="Function not implemented: %s" % uCmd) for dLine in aResult: uGlobalDestVarSave: str = oAction.uGlobalDestVar uLocalDestVarSave: str = oAction.uLocalDestVar if u'L' in oAction.uParseResultFlags: aTmpGlobalDestVar: List = ToList( oAction.uGlobalDestVar) aTmpLocalDestVar: List = ToList( oAction.uLocalDestVar) oAction.uGlobalDestVar = "".join( '"' + e + dLine.uVarSuffix + '",' for e in aTmpGlobalDestVar)[:-1] oAction.uLocalDestVar = "".join( '"' + e + dLine.uVarSuffix + '",' for e in aTmpLocalDestVar)[:-1] else: oAction.uGlobalDestVar = oAction.uGlobalDestVar + dLine.uVarSuffix oAction.uLocalDestVar = oAction.uLocalDestVar + dLine.uVarSuffix uCmd, uRetVal = self.ParseResult( oAction, dLine.dValue, oSetting) oAction.uGlobalDestVar = uGlobalDestVarSave oAction.uLocalDestVar = uLocalDestVarSave eRet = eReturnCode.Success break except Exception as e: self.ShowError(uMsg=u'can\'t Send Message', uParConfigName=oSetting.uConfigName, oException=e) eRet = eReturnCode.Error else: oSetting.bIsConnected = False self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut) return eRet