def Wait(self): """ Main entry point to wait """ Logger.debug("Checking for permissions") self.bIsWaiting = True self.bCancel = False self.bHasPermissions = OS_CheckPermissions() if self.bHasPermissions: Globals.bHasPermissions = True return True StartWait() bLangLoaded: bool = ExistLVar('5042') if bLangLoaded: uMessage: str = u'$lvar(5042)' uGrant: str = u'$lvar(5043)' else: uMessage: str = "ORCA requires write access, please grant" uGrant: str = "Grant Access" self.oPopup = ShowQuestionPopUp(uTitle=u'$lvar(5010)', uMessage=uMessage, fktYes=self.GrantAccess, fktNo=self.StopApp, uStringYes=uGrant, uStringNo=u'$lvar(5005)', uSound=u'message') Clock.schedule_once(self.StartNextThread, 0) return False
def ShowError(self, *, uTitle: str = u'', uMessage: str = u'', bAbort: bool = False, uTextContinue: str = u'', uTextQuit: str = u'', uStringDetails: str = u'') -> None: """Show an Error Message as Popup :param str uTitle: Title for Popup :param str uMessage: Message to Show :param bool bAbort: Terminates application after showing the popup (User decision) :param str uTextContinue: Caption for the continue button :param str uTextQuit: Caption for te Quit Button :param str uStringDetails: The details text Returns: Nothing """ StartWait() if bAbort: self.RaiseQuestion(uTitle=uTitle, uMessage=uMessage, fktYes=self.fktContinue, fktNo=self.fktErrorPopUpClose, uStringYes=uTextContinue, uStringNo=uTextQuit, uStringDetails=uStringDetails) else: self.RaiseQuestion(uTitle=uTitle, uMessage=uMessage, fktYes=self.fktContinue, uStringYes=uTextContinue, uStringDetails=uStringDetails) return
def ShowError(self, uTitle='', uMessage='', bAbort=False, uTextContinue='', uTextQuit='', uStringDetails=u''): """Show an Error Message as Popup sTitle: Title for Popup sMessage: Message to Show bAbort: Terminates application after showing the popup (User decision) Returns: Nothing """ StartWait() if bAbort: self.RaiseQuestion(uTitle=uTitle, uMessage=uMessage, fktYes=self.fktContinue, fktNo=self.fktErrorPopUpClose, uStringYes=uTextContinue, uStringNo=uTextQuit, uStringDetails=uStringDetails) else: self.RaiseQuestion(uTitle=uTitle, uMessage=uMessage, fktYes=self.fktContinue, uStringYes=uTextContinue, uStringDetails=uStringDetails) return
def Receive(self, uResponse: str): aActionTrigger: Optional[List[cBaseTrigger]] uResponse = ToUnicode(uResponse) if self.oAction is not None: uCmd, uRetVal = self.oInterFace.ParseResult( self.oAction, uResponse, self) self.ShowDebug(uMsg=u'Parsed Responses:' + uRetVal) if not self.uRetVar == u'' and not uRetVal == u'': SetVar(uVarName=self.uRetVar, oVarValue=uRetVal) # We do not need to wait for an response anymore StartWait(0) self.oAction = None else: oAction: cAction = self.dStandardActions["defaultresponse"] if oAction: uCommand = self.oInterFace.ParseResult( oAction, uResponse, self) if not isinstance(uCommand, str): if len(uCommand) > 0: uCommand = uCommand[1] # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it aActionTrigger = self.GetTrigger(uCommand) if aActionTrigger is not None: for oActionTrigger in oActionTrigger: self.CallTrigger(oActionTrigger, uResponse) else: self.ShowDebug(uMsg=u'Discard message:' + uCommand + ':' + uResponse)
def Receive(self) -> None: #Main Listening Thread to receice eiscp messages uResponses: str uResponse: str aResponses: List aActionTrigger: List[cBaseTrigger] #Loop until closed by external flag try: while not self.bStopThreadEvent: if self.oSocket is not None: ready: Tuple = select.select([self.oSocket], [], [], 1.0) # the first element of the returned list is a list of readable sockets if ready[0]: byResponses = self.oSocket.recv(self.iBufferSize) # there could be more than one response, so we need to split them uResponses = ToUnicode(byResponses) aResponses = uResponses.split("[EOL]") for uResponse in aResponses: # Todo: find proper encoding if not uResponse == u'' and not uResponse == u'ORCA.ORCA Connecting...': if True: # If the returned Command is a response to the send message if uResponse.startswith( u'RemoteGhost.'): self.ShowDebug( uMsg=u'Returned Message:' + uResponse) #todo: parse the command from return # We do not need to wait for an response anymore StartWait(0) # we got our response, all other responses are for somebody else self.uMsg = u'' else: # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it aActionTrigger = self.GetTrigger( uResponse) if len(aActionTrigger) > 0: for oActionTrigger in aActionTrigger: self.CallTrigger( oActionTrigger, uResponse) else: self.ShowDebug( uMsg=u'Discard message:' + uResponse) except Exception as e: self.ShowError(uMsg=u'Error Receiving Response:', oException=e) self.bIsConnected = False try: if not self.oSocket is None: self.ShowDebug(uMsg=u'Closing socket in Thread') self.oSocket.close() except Exception as e: self.ShowError(uMsg=u'Error closing socket in Thread', oException=e)
def DownloadDefinition(self, uDefinitionName): """ Downloads a specific definition and restarts after """ StartWait() Globals.oDownLoadSettings.LoadDirect( ' :definitions:' + uDefinitionName, True) return False # we do not proceed here as Downloader will restart
def LoadSingleFile(self, *, uRef: str, oProgressBar: cProgressBar) -> bool: """ Loads a single resource by web dispatches on_download_finished when finished """ self.oRef = cDownLoadObject() self.oRef.FromString(uPars=uRef) uUrl = self.oRef.dPars["Url"] self.uTarget = self.oRef.dPars["Target"] self.uType = self.oRef.dPars["Type"] self.uName = self.oRef.dPars["Name"] self.uVersion = self.oRef.dPars["Version"] self.oFnDest = cFileName('').ImportFullPath( uFnFullName=self.oRef.dPars["Dest"]) self.oWeb = None self.oProgressBar = oProgressBar self.bFinished = False self.bOnError = False self.bIsLoading = True self.bFirstMessage = True StartWait() try: Logger.debug("LoadOnlineResource: Downloading [%s] to [%s]" % (uUrl, self.oFnDest.string)) # noinspection PyUnresolvedReferences self.uUrl = urllib.parse.quote(uUrl, safe="%/:=&?~#+!$,;'@()*[]") #self.uUrl = urllib.quote(uUrl,safe="%:=&?~#+!$,;'@()*[]") #todo: fix ocaremote ssl problem and remove verify=false self.oWeb = UrlRequest(self.uUrl, verify=False, on_success=self.OnSuccess, on_failure=self.OnFailure, on_error=self.OnError, on_progress=self.OnProgress, decode=False, file_path=self.oFnDest.string, debug=False) return True except Exception as e: LogError(uMsg=u'can\'t load online resource LSF: %s to %s' % (self.uUrl, self.oFnDest.string), oException=e) self.bFinished = True self.bOnError = True self.bIsLoading = False StopWait() SetVar(uVarName="DOWNLOADERROR", oVarValue="1") # noinspection PyUnresolvedReferences self.dispatch('on_download_finished') return False
def LoadXMLFile(self) -> bool: """ The main function to load the xml """ SetDefinitionContext(uDefinitionName=self.uName) Globals.oTheScreen.LogToSplashScreen2(uText=self.uDefDescription) Logger.info(u'Loading definition XmlFile:' + Globals.oDefinitionPathes.oFnDefinition) oET_Root: Element = self.oET_Root try: Logger.debug(u'Definition %s (%s): Loading xml includes' % (self.uName, self.uAlias)) Orca_include( oElem=oET_Root, pLoader=orca_et_loader, uFileName=Globals.oDefinitionPathes.oFnDefinition.string) SetDefinitionContext(uDefinitionName=self.uName) except Exception as e: StartWait() ShowErrorPopUp( uTitle="LoadXMLFile:Fatal Error", uMessage=LogError( uMsg=u'Fatal Error: definition xml file faulty:' + self.uName, oException=e), bAbort=True) SetVar(uVarName='ORCASTANDARDPAGESINCLUDED', oVarValue="1") Globals.oTheScreen.uDefName = self.oRepManEntry.oRepEntry.uName self.oDefinitions.uDefinitionAuthor = self.oRepManEntry.oRepEntry.uAuthor self.oDefinitions.uDefinitionVersion = self.oRepManEntry.oRepEntry.uVersion SetVar(uVarName=u'DEFINITIONAUTHOR', oVarValue=self.oDefinitions.uDefinitionAuthor) SetVar(uVarName=u'DEFINITIONVERSION', oVarValue=self.oDefinitions.uDefinitionVersion) SetVar(uVarName=u'DEFINITIONSUPPORT', oVarValue=self.oDefinitions.uDefinitionSupport) Logger.debug(u'Definition [%s] : Ratios %fx%f:' % (self.uName, self.fRationX, self.fRationY)) if self.bImportPages: # get a list of all pages and add Them oXMLPages: Element = oET_Root.find('pages') for oXMLPage in oXMLPages.findall('page'): Globals.oTheScreen.oScreenPages.AddPageFromXmlNode( oXMLPage=oXMLPage) oXMLPageImport: Element = oXMLPages.find('pageimport') if oXMLPageImport is not None: for oXMLPage in oXMLPageImport.findall('page'): Globals.oTheScreen.oScreenPages.AddPageFromXmlNode( oXMLPage=oXMLPage) Globals.oNotifications.SendNotification( uNotification="DEFINITIONPAGESLOADED", **{"definition": self}) RestoreDefinitionContext() return True
def LoadSingleFile(self, sRef, oProgressBar): """ Loads a single resource by web dispatches on_download_finished when finished """ self.oRef = cDownLoadObject() self.oRef.FromString(sRef) uUrl = self.oRef.aPars["Url"] self.uDest = self.oRef.aPars["Dest"] self.uTarget = self.oRef.aPars["Target"] self.uType = self.oRef.aPars["Type"] self.uName = self.oRef.aPars["Name"] self.uVersion = self.oRef.aPars["Version"] self.oWeb = None self.oProgressBar = oProgressBar self.bFinished = False self.bOnError = False self.bIsLoading = True self.bFirstMessage = True StartWait() try: Logger.debug("LoadOnlineResource: Downloading [%s] to [%s]" % (uUrl, self.uDest)) if PY2: self.uUrl = urllib.quote(uUrl, safe="%/:=&?~#+!$,;'@()*[]") else: self.uUrl = urllib.parse.quote(uUrl, safe="%/:=&?~#+!$,;'@()*[]") #self.uUrl = urllib.quote(uUrl,safe="%:=&?~#+!$,;'@()*[]") self.oWeb = UrlRequest(self.uUrl, on_success=self.OnSuccess, on_failure=self.OnFailure, on_error=self.OnError, on_progress=self.OnProgress, decode=False, file_path=self.uDest, debug=False) return True except Exception as e: LogError( u'can\'t load online resource: %s to %s' % (self.uUrl, self.uDest), e) self.bFinished = True self.bOnError = True self.bIsLoading = False StopWait() SetVar(uVarName="DOWNLOADERROR", oVarValue="1") self.dispatch('on_download_finished') return False
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 uMsg: str byMsg: bytes if uRetVar != "": oAction.uGlobalDestVar = uRetVar oSetting.uRetVar = uRetVar uMsg = oAction.uCmd uMsg = ReplaceVars(uMsg, self.uObjectName + '/' + oSetting.uConfigName) uMsg = ReplaceVars(uMsg) #Logger.info ('Interface '+self.uObjectName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort) while iTryCount < self.iMaxTryCount: iTryCount += 1 oSetting.Connect() if oSetting.bIsConnected: #time.sleep(2) try: self.ShowInfo(uMsg=u'Sending Command: "' + uMsg + u'" to ' + oSetting.aIniSettings.uHost + ':' + oSetting.aIniSettings.uPort, uParConfigName=oSetting.uConfigName) uMsg = uMsg.replace('\\n', '\n') uMsg = uMsg.replace('\\r', '\r') byMsg = ToBytes(uMsg) if oAction.bWaitForResponse: #All response comes to receiver thread, so we should hold the queue until vars are set StartWait(self.iWaitMs) oSetting.oTelnet.write(byMsg) eRet = eReturnCode.Success break except Exception as e: self.ShowError(uMsg=u'can\'t Send Message', uParConfigName=oSetting.uConfigName, oException=e) eRet = eReturnCode.Error oSetting.Disconnect() self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut) return eRet
def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False): cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut) iTryCount = 0 iRet = 1 if uRetVar != "": oAction.uGlobalDestVar = uRetVar oSetting.uRetVar = uRetVar uMsg = oAction.uCmd uMsg = ReplaceVars(uMsg, self.uInterFaceName + '/' + oSetting.uConfigName) uMsg = ReplaceVars(uMsg) #Logger.info ('Interface '+self.uInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort) while iTryCount < 2: iTryCount += 1 oSetting.Connect() if oSetting.bIsConnected: #time.sleep(2) try: self.ShowInfo( u'Sending Command: "' + uMsg + u'" to ' + oSetting.aInterFaceIniSettings.uHost + ':' + oSetting.aInterFaceIniSettings.uPort, oSetting.uConfigName) uMsg = uMsg.replace('\\n', '\n') uMsg = uMsg.replace('\\r', '\r') #Bypass unicode bug in python 2.7 uMsg = str(uMsg) if oAction.bWaitForResponse == True: #All response comes to receiver thread, so we should hold the queue until vars are set StartWait(self.iWaitMs) oSetting.oTelnet.write(uMsg) iRet = 0 break except Exception as e: self.ShowError(u'can\'t Send Message', oSetting.uConfigName, e) iRet = 1 oSetting.Disconnect() if oSetting.bIsConnected: if oSetting.aInterFaceIniSettings.iTimeToClose == 0: oSetting.Disconnect() elif oSetting.aInterFaceIniSettings.iTimeToClose != -1: Clock.unschedule(oSetting.FktDisconnect) Clock.schedule_once( oSetting.FktDisconnect, oSetting.aInterFaceIniSettings.iTimeToClose) return iRet
def RepositoryUpdate(self): """ Updates all loaded repository files when a new ORCA version has been detected """ if not Globals.bProtected: Logger.info("New ORCA version detected, updating all repositories") self.InitPathes() Globals.oTheScreen.LoadLanguage() StartWait() Globals.oDownLoadSettings.UpdateAllInstalledRepositories( bForce=False) self.bClearCaches = True # self.RestartAfterRepositoryUpdate() return True return False
def Receive(self) -> None: #Main Listening Thread to receive Telnet messages aActionTrigger: List[cBaseTrigger] #Loop until closed by external flag try: while not self.bStopThreadEvent: if self.oTelnet is not None: self.uResponse = u'' bResponse: bytes if not self.aIniSettings.uResultEndString == u'': bResponse = self.oTelnet.read_until( ToBytes(self.aIniSettings.uResultEndString), 10) else: bResponse = self.oTelnet.read_eager() self.uResponse = ToUnicode(bResponse) if not self.uResponse == u'': uCmd, uRetVal = self.oInterFace.ParseResult( oAction=self.oAction, uResponse=self.uResponse, oSetting=self) self.ShowDebug(uMsg=u'Parsed Resonse:' + uRetVal) if not self.uRetVar == u'': SetVar(uVarName=self.uRetVar, oVarValue=uRetVal) # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it aActionTrigger = self.GetTrigger(uRetVal) if len(aActionTrigger) > 0: for oActionTrigger in aActionTrigger: self.CallTrigger(oActionTrigger, uRetVal) else: self.ShowDebug(uMsg=u'Discard message:' + uRetVal + ":" + self.uResponse) StartWait(0) except Exception as e: self.ShowError(uMsg=u'Error Receiving Response:', oException=e) self.bIsConnected = False try: self.oTelnet.write(ToBytes("exit\n")) self.oTelnet.close() except Exception as e: self.ShowError(uMsg=u'Error closing socket in Thread', oException=e)
def Wait(self): """ Main entry point to wait """ Logger.debug("Checking for network connectivity") self.bIsWaiting = True self.bCancel = False StartWait() self.bIsOnline = False bLangLoaded = ExistLVar('5012') if bLangLoaded: uMessage = u'$lvar(5012)' else: uMessage = "Waiting for network connectivity" self.oPopup = ShowQuestionPopUp(uTitle=u'$lvar(5010)', uMessage=uMessage, fktYes=self.CancelWaitForConnectivity, uStringYes=u'$lvar(5009)', uSound=u'message') Clock.schedule_once(self.StartNextThread, 0) return False
def Receive(self): #Main Listening Thread to receive json messages #Loop until closed by external flag try: while not self.bStopThreadEvent: if self.oSocket is not None: ready = select.select([self.oSocket], [], [], 1.0) # the first element of the returned list is a list of readable sockets if ready[0]: self.bHandled = False sResponses = self.oSocket.recv(self.iBufferSize) uResponses = ToUnicode(sResponses) # there could be more than one response, so we need to split them # unfortunately, there is no end char in a json respone aResponses = uResponses.split('}{') if not len(aResponses) == 1: i = 0 while i < len(aResponses): if i == 0: aResponses[i] += '}' else: aResponses[i] = u'{' + aResponses[i] i += 1 uID = 0 for uResponse in aResponses: if not uResponse == u'': if '"result":"pong"' in uResponse: pass else: # Get the Command and the payload # If the returned Command is a response to the send message uCommand, uID = self.oInterFace.ParseResult_JsonHeader( uResponse) if uID == self.uID: uCmd, uRetVal = self.oInterFace.ParseResult( self.oAction, uResponse, self) self.ShowDebug( u'Parsed Respones:' + uRetVal) if not self.uRetVar == u'' and not uRetVal == u'': SetVar(uVarName=self.uRetVar, oVarValue=uRetVal) # We do not need to wait for an response anymore StartWait(0) self.bHandled = True if not self.bHandled: # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it oActionTrigger = self.GetTrigger( uCommand) if oActionTrigger is not None: self.CallTrigger( oActionTrigger, uResponse) else: self.ShowDebug( u'Discard message:' + uCommand + ':' + uResponse) #print "LEAVE PARSE" fSleep(0.01) except Exception as e: if self.bIsConnected: self.ShowError(u'Error Receiving Response:', e) self.bIsConnected = False try: if self.oSocket is not None: self.ShowDebug(u'Closing socket in Thread') self.oSocket.close() except Exception as e: self.ShowError(u'Error closing socket in Thread', e)
def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False): cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut) uCmd = oAction.uCmd uPrefix = u'' if uCmd == u'*': uCmd = oAction.dActionPars['commandname'] # call the function to pass string to eventghost if oAction.uType == u'command': uPrefix = u'c' elif oAction.uType == u'event': uPrefix = u'e' + oSetting.aInterFaceIniSettings.uPreFix elif oAction.uType == u'key': uPrefix = u'k' elif oAction.uType == u'macro': uPrefix = u'a' elif oAction.uType == u'mouse': uPrefix = u'm' else: Logger.warning(u'Invalid type: ' + oAction.uType) iTryCount = 0 iRet = 1 uCmd = ReplaceVars(oAction.uCmd) uCmd = ReplaceVars(uCmd, self.uInterFaceName + '/' + oSetting.uConfigName) self.ShowInfo( u'Sending Command: ' + uPrefix + uCmd + u' to ' + oSetting.aInterFaceIniSettings.uHost + ':' + oSetting.aInterFaceIniSettings.uPort, oSetting.uConfigName) while iTryCount < 2: iTryCount += 1 oSetting.Connect() # we need to verify if we are really connected, as the connection might have died # and .sendall will not return on error in this case #bIsConnected=oSetting.IsConnected() if oSetting.bIsConnected: uMsg = uPrefix + uCmd + u'\n' try: StartWait(self.iWaitMs) if PY2: oSetting.oSocket.sendall(uMsg) else: oSetting.oSocket.sendall(ToBytes(uMsg)) iRet = 0 break except Exception as e: self.ShowError(u'can\'t Send Message', oSetting.uConfigName, e) oSetting.Disconnect() iRet = 1 if oSetting.bIsConnected: if oSetting.aInterFaceIniSettings.iTimeToClose == 0: oSetting.Disconnect() elif oSetting.aInterFaceIniSettings.iTimeToClose != -1: Clock.unschedule(oSetting.FktDisconnect) Clock.schedule_once( oSetting.FktDisconnect, oSetting.aInterFaceIniSettings.iTimeToClose) return iRet
def Receive(self): # Main Listening Thread to receive eiscp messages # self (the settings object) is not reliable passed , to we use it passed from the Thread object oThread = currentThread() # noinspection PyUnresolvedReferences oParent:cInterFaceSettings = oThread.oParent aReadSocket:List aWriteSocket:List aExceptional:List uCommand:str uResponse:str oTmpAction:Union[cBaseTrigger,cAction] aTmpAction:List[Union[cBaseTrigger,cAction]] = [] aActionTrigger:Optional[List[cBaseTrigger]] #Loop until closed by external flag try: while not oParent.bStopThreadEvent: if oParent.oSocket is not None: # on Windows, the timeout does not work, (known error) # which means the the receiveall will run on error, so we need to skip the error message aReadSocket, aWriteSocket, aExceptional = select.select([oParent.oSocket],[],[],0.1) if len(aReadSocket) >0 and aReadSocket[0]: i:int = 0 while self.bBusy: sleep(0.01) i += 1 if i > 200: oParent.ShowError(uMsg="Busy Time Out") self.bBusy = False self.bBusy = True byResponseHeader:bytes = oParent.Helper_ReceiveAll(aReadSocket[0], 16) # noinspection PyInterpreter if len(byResponseHeader)>0: # Get the Command and the payload uCommand,uResponse=oParent.UnpackEISPResponse(byResponseHeader) # print ("Receive:",uCommand,":",uResponse) # This returns ASCII of sResponse, we will convert it one line later # we might get a response without dedicated requesting it, so lets use an action # from previous request to get the return vars bHandleSpecialResponse:bool = False # Default is the last action (That is the command, where we MIGHT get the response from del aTmpAction[:] aTmpAction.append(self.oAction) if uCommand == self.uMsg[:3]: # if we have a response to the last action, lets store the action for future use # in case we got a response without requesting it # Not 100% logic, but should fit in 99.9 % of the cases if len(oParent.GetTrigger(uCommand))==0: oParent.dResponseActions[uCommand] = copy(aTmpAction[0]) bHandleSpecialResponse = True # Lets check , if we have a trigger set for unrequested responses aActionTrigger = oParent.GetTrigger(uCommand) if len(aActionTrigger)>0: aTmpAction=aActionTrigger bHandleSpecialResponse = True elif not bHandleSpecialResponse: # If we don't have an trigger and its not a response to the action # lets use the stored action, if we have it if uCommand in oParent.dResponseActions: aTmpAction[0] = oParent.dResponseActions[uCommand] bHandleSpecialResponse = True if bHandleSpecialResponse: if uCommand==u'NLS': # This might return an adjusted Response # We don't support multiple triggers on NLS so we just take the first action uCommand,uResponse=oParent.oInterFace.Handle_NLS(aTmpAction[0],uResponse,self) # uResponse=ToUnicode(uResponse) if bHandleSpecialResponse: if uCommand == u'NRI': for oTmpAction in aTmpAction: oParent.oInterFace.Handle_NRI(oTmpAction, uResponse, oParent) elif uCommand==u'NJA': # multiple trigger on jacket infos (the picture split into multiple parts) not supported uCommand,uResponse=oParent.oInterFace.Handle_NJA(aTmpAction[0],uResponse,oParent) elif uCommand==u'LMD': uResponse=oParent.oInterFace.ISCP_LMD_To_Text(uResponse) elif uCommand==u'IFA': for oTmpAction in aTmpAction: oParent.oInterFace.Split_IFA(oTmpAction,uResponse,oParent) elif uCommand==u'IFV': for oTmpAction in aTmpAction: oParent.oInterFace.Split_IFV(oTmpAction,uResponse,oParent) elif uCommand==u'MVL' or uCommand==u'CTL' or uCommand==u'SWL': if uResponse!=u'N/A': uResponse=str(int(uResponse, 16)) # If the returned Command is a response to the send message if uCommand==oParent.uMsg[:3]: #uCmd,uRetVal=self.oInterFace.ParseResult(self.oAction,uResponse,self) uRetVal:str = u'' if not oParent.uRetVar==u'': uTmp=oParent.oAction.uGlobalDestVar oParent.oAction.uGlobalDestVar=oParent.uRetVar uCmd,uRetVal=oParent.oInterFace.ParseResult(oParent.oAction,uResponse,oParent) oParent.oAction.uGlobalDestVar=uTmp if not oParent.uRetVar==u'' and not uRetVal==u'': SetVar(uVarName = self.uRetVar, oVarValue = uRetVal) # we got our response, all other responses are for somebody else #self.uMsg='' # we have a notification issued by the device, so lets have a look, if we have a trigger code to it aActionTrigger=oParent.GetTrigger(uCommand) if len(aActionTrigger)>0: oParent.ShowInfo(uMsg=u'Calling Trigger for:' + uCommand) for oActionTrigger in aActionTrigger: oParent.CallTrigger(oActionTrigger,uResponse) else: if not uCommand==oParent.uMsg[:3]: if not uCommand==u'LTN': if not uCommand==u'': if not uCommand+ ':'+uResponse=="NST:p--": oParent.ShowDebug(uMsg=u'Discard message: [%s]:[%s]: Looking for [%s]' %(uCommand,uResponse,oParent.uMsg[:3])) # self.uMsg='' # We do not need to wait for an response anymore StartWait(0) else: Logger.warning("Onkyo close request") oParent.Disconnect() oParent.Connect() self.bBusy = False except Exception as e: self.ShowError(uMsg=u'Receive:Error Receiving Response:',oException=e) self.bIsConnected = False self.bBusy = False try: if self.oSocket is not None: self.ShowDebug(uMsg=u'Closing socket in Thread') self.oSocket.close() self.oSocket = None except Exception as e: self.ShowError(uMsg=u'Error closing socket in Thread',oException=e)
def SendCommand(self,oAction:cAction,oSetting:cInterFaceSettings,uRetVar:str,bNoLogOut:bool=False) -> eReturnCode: super().SendCommand(oAction=oAction,oSetting=oSetting,uRetVar=uRetVar,bNoLogOut=bNoLogOut) uTst:str uFormat:str uKey:str iTryCount:int = 0 eRet:eReturnCode = eReturnCode.Error uMsg:str = oAction.uCmd if uRetVar!="": oAction.uGlobalDestVar=uRetVar uTst=uMsg[:3] if uTst==u'MVL' and uMsg!=u'MVLUP' and uMsg!=u'MVLDOWN' and not uMsg.endswith("QSTN"): Var_Int2Hex(uVarName = self.uObjectName+'/'+oSetting.uConfigName+'volumetoset') if (uTst==u'CTL' or uTst==u'SWL') and not uMsg.endswith("QSTN"): uFormat='{:+03X}' uKey = oSetting.aIniSettings.uHost + oSetting.aIniSettings.uPort if uKey in self.dDeviceSettings: if uTst == u'CTL': uFormat=self.dDeviceSettings[uKey].uVar_CTLFormat else: uFormat = self.dDeviceSettings[uKey].uVar_SWLFormat Var_Int2Hex(uVarName = self.uObjectName + '/' + oSetting.uConfigName + 'volumetoset', uFormat = uFormat) uMsg = ReplaceVars(uMsg,self.uObjectName+'/'+oSetting.uConfigName) uMsg = ReplaceVars(uMsg) oSetting.uMsg = uMsg oSetting.uRetVar = uRetVar if uTst == u"NRI": uKey = oSetting.aIniSettings.uHost + oSetting.aIniSettings.uPort if uKey in self.dDeviceSettings and False: self.dDeviceSettings[uKey].WriteVars(uVarPrefix=uRetVar, oAction=oAction) return eReturnCode.Success else: self.dDeviceSettings[uKey] = self.cDeviceSettings(self, oSetting) # we write the defaults to var, in case we can't connect to the receiver self.dDeviceSettings[uKey].WriteVars(uVarPrefix=uRetVar, oAction=oAction) #Logger.info (u'Interface '+self.uObjectName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort) while iTryCount<self.iMaxTryCount: iTryCount+=1 oSetting.Connect() if oSetting.bIsConnected: try: oAction.uGetVar = ReplaceVars(oAction.uGetVar,self.uObjectName+'/'+oSetting.uConfigName) oAction.uGetVar = ReplaceVars(oAction.uGetVar) self.ShowInfo (uMsg=u'Sending Command: '+uMsg + ' to '+oSetting.aIniSettings.uHost+':'+oSetting.aIniSettings.uPort,uParConfigName=oSetting.uConfigName) byMsg:bytes = oSetting.CreateEISPHeader(uMsg) if oAction.bWaitForResponse: #All response comes to receiver thread, so we should hold the queue until vars are set if uTst!='NRI': StartWait(self.iWaitMs) else: StartWait(2000) oSetting.oSocket.sendall(byMsg) eRet = eReturnCode.Success break except Exception as e: self.ShowError(uMsg = u'Can\'t Send Message',uParConfigName=oSetting.uConfigName,oException=e) eRet = eReturnCode.Error oSetting.Disconnect() if not uRetVar==u'': SetVar(uVarName = uRetVar, oVarValue = u"Error") else: if iTryCount==self.iMaxTryCount: self.ShowWarning(uMsg=u'Nothing done,not connected! ->[%s]' % oAction.uActionName, uParConfigName=oSetting.uConfigName) if uRetVar: SetVar(uVarName = uRetVar, oVarValue = u"?") self.CloseSettingConnection(oSetting=oSetting,bNoLogOut=bNoLogOut) return eRet
def ExecuteActionShowQuestion(self, oAction): """ WikiDoc:Doc WikiDoc:Context:ActionsDetails WikiDoc:Page:Actions-ShowQuestion WikiDoc:TOCTitle:showquestion = showquestion = This actions open a separate page where the user can answer a question. Can be used to show a popup message as well <div style="overflow:auto; "> {| class="wikitable" ! align="left" | Attribute ! align="left" | Description |- |string |showquestion |- |title |Title of the question-popup |- |message |Message for the question bar popup (normally the question) |- |actionyes |Name of the action to called, if the user presses the Yes button |- |actionno |Name of the action to called, if the user presses the No button |- |dontstopqueue |Doesn't stop the queue (if set to any value). As standard, the queue will be stopped until the answer to the question has been given. |- |close |Closes the question popup. Use it only, when you used the dontstopqueue flag |}</div> A short example: <div style="overflow-x: auto;"><syntaxhighlight lang="xml"> <action name="My Qustion" string="showquestion" title="Mytitle" message="MyMessage" actionyes="myYesAction" actionno="myNoAction"/> </syntaxhighlight></div> WikiDoc:End """ self.oEvenDispatcher.LogAction(u'ShowQuestion', oAction) oAction.uTitle = ReplaceVars(oAction.dActionPars.get("title", "")) oAction.uMessage = ReplaceVars(oAction.dActionPars.get("message", "")) oAction.uActionYes = ReplaceVars( oAction.dActionPars.get("actionyes", "")) oAction.uActionNo = ReplaceVars(oAction.dActionPars.get( "actionno", "")) uClose = ReplaceVars(oAction.dActionPars.get("close", "")) uDontStopQueue = ReplaceVars( oAction.dActionPars.get("dontstopqueue", "")) if uClose: if self.oQuestionAction: StopWait() self.oQuestionAction.oQuestionPopup.ClosePopup() return -2 if uDontStopQueue == "": StartWait() self.oQuestionAction = oAction if oAction.uActionYes == '' and oAction.uActionNo == '': self.oQuestionAction.oQuestionPopup = ShowQuestionPopUp( uTitle=oAction.uTitle, uMessage=oAction.uMessage, uSound=u'message') elif oAction.uActionNo == '': self.oQuestionAction.oQuestionPopup = ShowQuestionPopUp( uTitle=oAction.uTitle, uMessage=oAction.uMessage, fktYes=self.__fktExecuteActionShowQuestionOption1, uStringYes='$lvar(5000)', uSound=u'message') else: self.oQuestionAction.oQuestionPopup = ShowQuestionPopUp( uTitle=oAction.uTitle, uMessage=oAction.uMessage, fktYes=self.__fktExecuteActionShowQuestionOption1, fktNo=self.__fktExecuteActionShowQuestionOption2, uStringYes='$lvar(5001)', uStringNo='$lvar(5002)', uSound=u'message') self.oQuestionAction.oQuestionPopup.bPreventCloseOnEscKey = True return -2
def SendCommand(self, oAction: cAction, oSetting: cInterFaceSettings, uRetVar: str, bNoLogOut: bool = False) -> eReturnCode: super().SendCommand(oAction=oAction, oSetting=oSetting, uRetVar=uRetVar, bNoLogOut=bNoLogOut) if uRetVar != "": oAction.uGlobalDestVar = uRetVar iTryCount = 0 eRet: eReturnCode = eReturnCode.Error #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort) while iTryCount < self.iMaxTryCount: iTryCount += 1 oSetting.Connect() # we need to verify if we are really connected, as the connection might have died # and .sendall will not return on error in this case #bIsConnected=oSetting.IsConnected() if oSetting.bIsConnected: uMsg = oAction.uCmd try: uMsg = ReplaceVars( uMsg, self.uObjectName + '/' + oSetting.uConfigName) uMsg = ReplaceVars(uMsg) oAction.uGetVar = ReplaceVars( oAction.uGetVar, self.uObjectName + '/' + oSetting.uConfigName) oAction.uGetVar = ReplaceVars(oAction.uGetVar) oSetting.uMsg = uMsg oSetting.uRetVar = uRetVar oSetting.uRetVar = uRetVar self.ShowInfo(uMsg=u'Sending Command: ' + uMsg + ' to ' + oSetting.aIniSettings.uHost + ':' + oSetting.aIniSettings.uPort, uParConfigName=oSetting.uConfigName) #All response comes to receiver thread, so we should hold the queue until vars are set if oSetting.oAction.bWaitForResponse: StartWait(self.iWaitMs) oSetting.oWebSocket.send(uMsg) fSleep(fSeconds=0.01) eRet = eReturnCode.Success break except Exception as e: self.ShowError(uMsg=u'Can\'t send message', uParConfigName=oSetting.uConfigName, oException=e) eRet = eReturnCode.Error oSetting.Disconnect() oSetting.bOnError = True if not uRetVar == u'': SetVar(uVarName=uRetVar, oVarValue=u"Error") else: if not uRetVar == u'': SetVar(uVarName=uRetVar, oVarValue=u"Error") self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut) return eRet
def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False): cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut) if uRetVar != "": oAction.uGlobalDestVar = uRetVar iTryCount = 0 iRet = 1 #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort) while iTryCount < 2: iTryCount += 1 oSetting.Connect() # we need to verify if we are really connected, as the connection might have died # and .sendall will not return on error in this case #bIsConnected=oSetting.IsConnected() if oSetting.bIsConnected: uMsg = oAction.uCmd try: uMsg = ReplaceVars( uMsg, self.uInterFaceName + '/' + oSetting.uConfigName) uMsg = ReplaceVars(uMsg) oAction.uGetVar = ReplaceVars( oAction.uGetVar, self.uInterFaceName + '/' + oSetting.uConfigName) oAction.uGetVar = ReplaceVars(oAction.uGetVar) oSetting.uMsg = uMsg oSetting.uRetVar = uRetVar oSetting.uRetVar = uRetVar self.ShowInfo( u'Sending Command: ' + uMsg + ' to ' + oSetting.aInterFaceIniSettings.uHost + ':' + oSetting.aInterFaceIniSettings.uPort, oSetting.uConfigName) #All response comes to receiver thread, so we should hold the queue until vars are set if oSetting.oAction.bWaitForResponse: StartWait(self.iWaitMs) oSetting.oWebSocket.send(uMsg) fSleep(0.01) iRet = 0 break except Exception as e: self.ShowError(u'Can\'t send message', oSetting.uConfigName, e) iRet = 1 oSetting.Disconnect() oSetting.bOnError = True if not uRetVar == u'': SetVar(uVarName=uRetVar, oVarValue=u"Error") else: if not uRetVar == u'': SetVar(uVarName=uRetVar, oVarValue=u"Error") if oSetting.bIsConnected: if oSetting.aInterFaceIniSettings.iTimeToClose == 0: oSetting.Disconnect() elif oSetting.aInterFaceIniSettings.iTimeToClose != -1: Clock.unschedule(oSetting.FktDisconnect) Clock.schedule_once( oSetting.FktDisconnect, oSetting.aInterFaceIniSettings.iTimeToClose) return iRet
def SendCommand(self, oAction: cAction, oSetting: cInterFaceSettings, uRetVar: str, bNoLogOut: bool = False) -> eReturnCode: super().SendCommand(oAction=oAction, oSetting=oSetting, uRetVar=uRetVar, bNoLogOut=bNoLogOut) uCmd: str uPrefix: str = u'' iTryCount: int = 0 eRet: eReturnCode = eReturnCode.Error # call the function to pass string to eventghost if oAction.uType == u'command': uPrefix = u'c' elif oAction.uType == u'event': uPrefix = u'e' + oSetting.aIniSettings.uPreFix elif oAction.uType == u'key': uPrefix = u'k' elif oAction.uType == u'macro': uPrefix = u'a' elif oAction.uType == u'mouse': uPrefix = u'm' else: Logger.warning(u'Invalid type: ' + oAction.uType) uCmd = ReplaceVars(oAction.uCmd) uCmd = ReplaceVars(uCmd, self.uObjectName + '/' + oSetting.uConfigName) if uCmd == u'*': uCmd = oAction.dActionPars['commandname'] self.ShowInfo(uMsg=u'Sending Command: ' + uPrefix + uCmd + u' to ' + oSetting.aIniSettings.uHost + ':' + oSetting.aIniSettings.uPort, uParConfigName=oSetting.uConfigName) while iTryCount < self.iMaxTryCount: iTryCount += 1 oSetting.Connect() # we need to verify if we are really connected, as the connection might have died # and .sendall will not return on error in this case #bIsConnected=oSetting.IsConnected() if oSetting.bIsConnected: uMsg = uPrefix + uCmd + u'\n' try: StartWait(self.iWaitMs) oSetting.oSocket.sendall(ToBytes(uMsg)) eRet = eReturnCode.Success break except Exception as e: self.ShowError(uMsg=u'can\'t Send Message', uParConfigName=oSetting.uConfigName, oException=e) oSetting.Disconnect() eRet = eReturnCode.Error self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut) return eRet