Пример #1
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        eRet: eReturnCode = eReturnCode.Error

        if oAction.uCCF_Code != u"":
            # noinspection PyUnresolvedReferences
            oAction.oIRCode = CCfToAndroidIR(oAction.uCCF_Code,
                                             ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd: str = ReplaceVars(oAction.uCmd)

        self.ShowInfo(uMsg=u'Sending Command: ' + uCmd + u' to ' +
                      oSetting.uConfigName)

        oSetting.Connect()
        if oSetting.bIsConnected:
            try:
                Logger.debug("Sending IR Commend to IRBLASTER")
                irblaster.transmit(oAction.oIRCode.iFrequency,
                                   oAction.oIRCode.aPattern)
                eRet = eReturnCode.Success
            except Exception as ex:
                self.ShowWarning(uMsg=u'Can\'t send message: ' + str(ex))
        else:
            Logger.debug("Not Connected")
        return eRet
Пример #2
0
 def ReadAction(self, oAction: cAction) -> None:
     super().ReadAction(oAction)
     oAction.uParams = oAction.dActionPars.get(u'params', u'')
     oAction.uRequestType = oAction.dActionPars.get(
         u'requesttype', u'POST')
     oAction.uHeaders = oAction.dActionPars.get(u'headers', u'{}')
     oAction.uProtocol = oAction.dActionPars.get(
         u'protocol', u'http://')
     oAction.iCodeOK = ToInt(oAction.dActionPars.get(u'codeok', u'200'))
Пример #3
0
    def Split_IFV(self,oAction:cAction,uResponse:str,oSetting:cInterFaceSettings) -> None:
        # handles the return of Video Information Request
        uTmp:str=oAction.uGlobalDestVar
        if not oSetting.uRetVar==u'':
            oAction.uGlobalDestVar=oSetting.uRetVar

        aResponses:List=uResponse.split(',')
        if len(aResponses)>1:
            oSetting.oResultParser.SetVar2(aResponses[0], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Selection', uAddName=u"_video_input_selection")
            oSetting.oResultParser.SetVar2(aResponses[1], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Resolution', uAddName=u"_video_input_resolution")
        if len(aResponses)>2:
            oSetting.oResultParser.SetVar2(aResponses[2], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Color', uAddName=u"_video_input_color")
        if len(aResponses)>3:
            oSetting.oResultParser.SetVar2(aResponses[3], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Bits', uAddName=u"_video_input_bits")
        if len(aResponses)>4:
            oSetting.oResultParser.SetVar2(aResponses[4], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Selection', uAddName=u"_video_output_selection")
        if len(aResponses)>5:
            oSetting.oResultParser.SetVar2(aResponses[5], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Resolution', uAddName=u"_video_output_resolution")
        if len(aResponses)>6:
            oSetting.oResultParser.SetVar2(aResponses[6], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Color', uAddName=u"_video_output_color")
        if len(aResponses)>7:
            oSetting.oResultParser.SetVar2(aResponses[7], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Bits', uAddName=u"_video_output_bits")
        if len(aResponses)>8:
            oSetting.oResultParser.SetVar2(aResponses[8], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Effect', uAddName=u"_video_output_bits")

        if uTmp!=u'':
            oSetting.uRetVar=uTmp
Пример #4
0
    def ExecuteAction(self, *, oAction: cAction) -> Union[int, eReturnCode]:
        """ Executes a single action in a queue (excluding condition verifying)"""

        eRet: Union[int, eReturnCode]

        try:
            oAction.uActionString = ReplaceVars(oAction.uActionString)
            oFunction = Globals.oEvents.dActionFunctions.get(oAction.iActionId)
            if oFunction:
                eRet = oFunction(oAction)
                return eRet
            else:
                ''' this enables to use standardactions / actions without call, but assigning parameters like interface and configname '''

                aActions: List[cAction] = Globals.oActions.GetActionList(
                    uActionName=oAction.uActionString, bNoCopy=True)
                if aActions:
                    if len(aActions) > 1:
                        Logger.error(
                            "you can''t use multiline actions as short cut, use call instead"
                        )

                    oFunction = Globals.oEvents.dActionFunctions.get(
                        aActions[0].iActionId)
                    if oFunction:
                        oAction.uActionString = ReplaceVars(
                            aActions[0].uActionString)
                        Globals.oEvents.CopyActionPars(
                            dTarget=oAction.dActionPars,
                            dSource=aActions[0].dActionPars,
                            uReplaceOption="donotreplacetarget")
                        if not oAction.uRetVar:
                            oAction.uRetVar = aActions[0].uRetVar
                        eRet = oFunction(oAction)
                        return eRet
                Logger.error("ExecuteAction: Action not Found:" +
                             oAction.uActionName + ':' + oAction.uActionString)
                # Globals.oActions.Dump("")
                return eReturnCode.Error
        except Exception as e:
            uMsg = LogError(
                uMsg='Error executing Action:' +
                Globals.oEvents.CreateDebugLine(oAction=oAction, uTxt=''),
                oException=e)
            ShowErrorPopUp(uMessage=uMsg)
            return eReturnCode.Error
Пример #5
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)
        eRet: eReturnCode = eReturnCode.Error

        if oAction.uCCF_Code:
            # noinspection PyUnresolvedReferences
            oAction.uCmd = CCF2ITach(oAction.uCCF_Code,
                                     ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd: str = ReplaceVars(oAction.uCmd,
                                self.uObjectName + u'/' + oSetting.uConfigName)
        uCmd = ReplaceVars(uCmd)
        self.ShowInfo(uMsg=u'Sending Command: ' + uCmd + u' to ' +
                      oSetting.aIniSettings.uHost + ':' +
                      oSetting.aIniSettings.uPort)

        oSetting.Connect()
        if oSetting.bIsConnected:
            uMsg: str = uCmd + u'\r\n'
            try:
                oSetting.oSocket.sendall(ToBytes(uMsg))
                byResponse = oSetting.oSocket.recv(self.iBufferSize)
                self.ShowDebug(uMsg=u'Response' + ToUnicode(byResponse),
                               uParConfigName=oSetting.uConfigName)
                if 'completeir' in ToUnicode(byResponse):
                    eRet = eReturnCode.Success
                else:
                    eRet = eReturnCode.Error
            except Exception as e:
                self.ShowError(uMsg=u'can\'t Send Message',
                               uParConfigName=u'',
                               oException=e)
                eRet = eReturnCode.Error

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #6
0
    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
Пример #7
0
    def SendCommand(self,oAction:cAction,oSetting:cInterFaceSettings,uRetVar:str,bNoLogOut:bool=False) -> eReturnCode:
        super().SendCommand(oAction=oAction,oSetting=oSetting,uRetVar=uRetVar,bNoLogOut=bNoLogOut)

        eRet:eReturnCode = eReturnCode.Error

        if oAction.uCCF_Code != u"":
            # noinspection PyUnresolvedReferences
            oAction.uCmd=CCfToKeene(oAction.uCCF_Code,ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd:str=ReplaceVars(oAction.uCmd)

        self.ShowInfo(uMsg=u'Sending Command: '+uCmd + u' to '+oSetting.aIniSettings.uHost+':'+oSetting.aIniSettings.uPort)

        oSetting.Connect()
        if oSetting.bIsConnected:
            uMsg=uCmd+u'\r\n'
            try:
                uMsg=ReplaceVars(uMsg,self.uObjectName+'/'+oSetting.uConfigName)
                oSetting.oSocket.sendto(ToBytes(uMsg), (oSetting.aIniSettings.uHost, int(oSetting.aIniSettings.uPort)))
                byResponse, addr =  oSetting.oSocket.recvfrom(self.iBufferSize)
                uResponse = ToUnicode(byResponse)
                self.ShowDebug(uMsg=u'Response'+uResponse,uParConfigName=oSetting.uConfigName)
                if 'ACK' in uResponse:
                    eRet = eReturnCode.Success
                else:
                    eRet = eReturnCode.Error
            except Exception as e:
                if str(e)!="timed out":
                    self.ShowError(uMsg=u'Can\'t send message',uParConfigName=oSetting.uConfigName,oException=e)
                else:
                    self.ShowWarning(uMsg=u'Can\'t send message: time out',uParConfigName=oSetting.uConfigName)

                eRet = eReturnCode.Error

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #8
0
    def Split_IFA(self,oAction:cAction,uResponse:str,oSetting:cInterFaceSettings) -> None:
        # handles the return of Audio Information Request
        uTmp:str=oAction.uGlobalDestVar
        if not oSetting.uRetVar==u'':
            oAction.uGlobalDestVar=oSetting.uRetVar

        aResponses:List=uResponse.split(',')

        if len(aResponses)>1:
            oSetting.oResultParser.SetVar2(aResponses[0], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Selection', uAddName=u'_audio_input_selection')
            oSetting.oResultParser.SetVar2(aResponses[1], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Codec', uAddName=u'_audio_input_codec')
        if len(aResponses)>2:
            oSetting.oResultParser.SetVar2(aResponses[2], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Frequency', uAddName=u'_audio_input_frequency')
        if len(aResponses)>3:
            oSetting.oResultParser.SetVar2(aResponses[3], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Channels', uAddName=u'_audio_input_channels')
        if len(aResponses)>4:
            oSetting.oResultParser.SetVar2(aResponses[4], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Output Effect', uAddName=u'_audio_output_effect')
        if len(aResponses)>5:
            oSetting.oResultParser.SetVar2(aResponses[5], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Output Channels', uAddName=u'_audio_output_channels')

        if uTmp!=u'':
            oSetting.uRetVar=uTmp
Пример #9
0
    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
Пример #10
0
    def ExecuteActionCall(self, oAction: cAction) -> eReturnCode:
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-Call
        WikiDoc:TOCTitle:call
        = call =
        Calls a single/multi line action / macro like a function. You have to use the action name of the target as a function name. You can call only  multi line actions / macros, not single actions within a macro.
        This action will modify the error code, if it fails, otherwise it will not change the error code

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |call
        |-
        |actionname
        |multi line action / macro name to call
        The actionname could be the name of an action, or one of the following keywords
        * APPSTARTACTIONS
        * DEFINITIONSTARTACTIONS
        * PAGESTARTACTIONS
        * PAGESTOPACTIONS
        |-
        |pagename
        |Optional: Name of the page, for which Pagestart/stop Actions to call (only if actionname is PAGESTARTACTIONS/PAGESTOPACTIONS)
        |-
        |currentpagename
        |Optional: Name of the the current pagename: (only if actionname is PAGESTARTACTIONS/PAGESTOPACTIONS)
        |-
        |enforce
        |Optional: attribute to enforce page startaction or page stopactions (only if actionname is PAGESTARTACTIONS/PAGESTOPACTIONS). valid options are:
        * ENFORCESTARTACTIONS
        * ENFORCESTOPACTIONS
        |}</div>

        Actionpars:
        If the call is triggered directly by a widget click, each action parameter from the widget will create a variable with name ActionName+"_parameter_"+parameter name. This enables the called function to receive parameters


        A short example:
        <div style="overflow-x: auto;"><syntaxhighlight  lang="xml">
        <action name="Return to last page" string="call gotolastpage" />
        </syntaxhighlight></div>
        WikiDoc:End
        """

        #self.oEventDispatcher.bDoNext = False
        #self.oEventDispatcher.bDoNext = True

        self.oEventDispatcher.LogAction(uTxt=u'Call', oAction=oAction)

        uActionName: str = ReplaceVars(
            oAction.dActionPars.get("actionname", ""))
        uEnforce: str = ReplaceVars(oAction.dActionPars.get("enforce", ""))
        uPageName: str = ReplaceVars(oAction.dActionPars.get("pagename", ""))
        uCurrentPageName: str = ReplaceVars(
            oAction.dActionPars.get("currentpagename", ""))
        bForceState: bool = GetActiveQueue().bForceState
        uLastPageName: str
        oLastPage: cScreenPage

        aActions: List[cAction] = Globals.oActions.GetActionList(
            uActionName=ReplaceVars(uActionName), bNoCopy=False)

        if aActions is None:
            if uActionName == "APPSTARTACTIONS":
                aActions = Globals.oActions.GetPageStartActionList(
                    uActionName=u'appstart', bNoCopy=True)
                if aActions is None:
                    return eReturnCode.Nothing
            elif uActionName == "DEFINITIONSTARTACTIONS":
                aActions = Globals.oActions.GetPageStartActionList(
                    uActionName=u'definitionstart', bNoCopy=True)
                if aActions is None:
                    return eReturnCode.Nothing
            elif uActionName == "PAGESTARTACTIONS":
                # we want to prevent pagestart actions, if the old page was just a popup, or we enforce it
                uLastPageName = ""
                oLastPage = Globals.oTheScreen.oScreenPages.GetLastPageReal()
                if oLastPage:
                    uLastPageName = oLastPage.uPageName
                if (not Globals.oTheScreen.IsPopup(uPageName=uLastPageName)
                    ) or ('ENFORCESTARTACTIONS' in uEnforce):
                    aActions = Globals.oTheScreen.ShowPageGetPageStartActions(
                        uPageName=uPageName)
                    if aActions is not None:
                        uActionName = u"PageStartAction"
                        Logger.debug(
                            "Action: () Calling PageStartAction for page: {0}".
                            format(uPageName))
                        oAction.oParentWidget = Globals.oTheScreen.oCurrentPage.oWidgetBackGround
                    else:
                        return eReturnCode.Nothing
                else:
                    self.oEventDispatcher.LogAction(
                        uTxt=u'Skipping PageStartAction',
                        oAction=oAction,
                        uAddText=u' for: {0}'.format(uPageName))
                    return eReturnCode.Nothing
            elif uActionName == "PAGESTOPACTIONS":
                # we want to prevent pagestop actions, if the new page is just a popup  or we enforce it
                # Or we want to force it
                # noinspection PyRedundantParentheses
                if (not Globals.oTheScreen.IsPopup(uPageName=uCurrentPageName)
                        or ("ENFORCESTOPACTIONS" in uEnforce)):
                    aActions = Globals.oTheScreen.ShowPageGetPageStopActions(
                        uPageName="$var(CURRENTPAGE)")
                    if aActions is not None:
                        uActionName = u"PageStopAction"
                        self.oEventDispatcher.LogAction(
                            uTxt=u'Calling PageStopAction',
                            oAction=oAction,
                            uAddText=u' for: {0}'.format(
                                ReplaceVars("$var(CURRENTPAGE)")))
                        oAction.oParentWidget = Globals.oTheScreen.oCurrentPage.oWidgetBackGround
                    else:
                        return eReturnCode.Nothing
                else:
                    self.oEventDispatcher.LogAction(
                        uTxt=u'Skipping PageStopAction',
                        oAction=oAction,
                        uAddText=u' for: {0}'.format(
                            ReplaceVars("$var(CURRENTPAGE)")))
                    return eReturnCode.Nothing

        if aActions is not None:
            # oTmpFunction=copy(oFunction)
            oTmpFunction: List[cAction] = []
            for oTmp in aActions:
                oTmpFunction.append(copy(oTmp))

            if oAction.oParentWidget is not None:
                self.oEventDispatcher.CopyActionPars(
                    dTarget=oTmpFunction[0].dActionPars,
                    dSource=oAction.oParentWidget.dActionPars,
                    uReplaceOption="donotreplacetarget")
                self.oEventDispatcher.CopyActionPars(
                    dTarget=oAction.dActionPars,
                    dSource=oAction.oParentWidget.dActionPars,
                    uReplaceOption="donotreplacetarget")
            else:
                self.oEventDispatcher.CopyActionPars(
                    dTarget=oTmpFunction[0].dActionPars,
                    dSource=oAction.dActionPars,
                    uReplaceOption="donotreplacetarget")

            #for aActionParKey in oTmpFunction[0].dActionPars:
            #SetVar(uActionName+"_parameter_"+aActionParKey,oTmpFunction[0].dActionPars[aActionParKey])
            for aActionParKey in oAction.dActionPars:
                if aActionParKey != "linefilename" and aActionParKey != "linefilenames":
                    # SetVar(uVarName = uActionName+"_parameter_"+aActionParKey, oVarValue = oAction.dActionPars[aActionParKey])
                    SetVar(uVarName=uActionName + "_parameter_" +
                           aActionParKey,
                           oVarValue=ReplaceVars(
                               oAction.dActionPars[aActionParKey]))

            self.oEventDispatcher.ExecuteActionsNewQueue(
                aActions=oTmpFunction,
                oParentWidget=oAction.oParentWidget,
                bForce=bForceState)
            return eReturnCode.Nothing
        uMsg: str = self.oEventDispatcher.CreateDebugLine(
            oAction=oAction,
            uTxt='Wrong Call') + u"\nFileName:" + oAction.uFileName
        Logger.error(uMsg)
        for uKey in sorted(Globals.oActions.dActionsCommands):
            LogError(uMsg=u'Action: Call: Available Name: [%s]' % uKey)
        DumpQueue()

        ShowErrorPopUp(uTitle='Warning', uMessage=uMsg)
        return eReturnCode.Error
Пример #11
0
    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
Пример #12
0
    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

        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        while iTryCount < self.iMaxTryCount:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    iStatusCode, uRes = self.SendCommand_Helper(
                        oAction, oSetting, self.uObjectName)
                    if iStatusCode == oAction.iCodeOK:
                        eRet = eReturnCode.Success
                        self.ShowDebug(
                            uMsg=u'Sending Command succeeded: : %d' %
                            iStatusCode,
                            uParConfigName=oSetting.uConfigName)
                        break
                    elif iStatusCode == 0:
                        eRet = eReturnCode.Unknown
                        self.ShowWarning(
                            uMsg=
                            u'Sending Command: Response should be %d, maybe error, maybe success: %d [%s]'
                            % (oAction.iCodeOK, iStatusCode, uRes),
                            uParConfigName=oSetting.uConfigName)
                        break
                    else:
                        eRet = eRet.Error
                        oSetting.bIsConnected = False
                        self.ShowError(
                            uMsg=u'Sending Command failed: %d [%s]' %
                            (iStatusCode, ToUnicode(uRes)),
                            uParConfigName=oSetting.uConfigName)
                except Exception as e:
                    self.ShowError(uMsg=u'can\'t Send Message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
            else:
                if iTryCount == self.iMaxTryCount:
                    self.ShowWarning(
                        uMsg=u'Nothing done,not connected! ->[%s]' %
                        oAction.uActionName,
                        uParConfigName=oSetting.uConfigName)
                oSetting.bIsConnected = False

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #13
0
    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
Пример #14
0
 def ReadAction(self, oAction: cAction) -> None:
     super().ReadAction(oAction)
     oAction.uCCF_Code = oAction.dActionPars.get(u'cmd_ccf', u'')
     oAction.uRepeatCount = oAction.dActionPars.get(
         u'repeatcount', u'´1')
Пример #15
0
 def ReadAction(self, oAction: cAction) -> None:
     super().ReadAction(oAction)
     oAction.uParams = oAction.dActionPars.get(u'params', u'')
Пример #16
0
    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
Пример #17
0
    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.Success
        uTmpVar2: str = u""

        if oAction.dActionPars.get('commandname') == "send_string":
            uTmpVar: str = GetVar(uVarName='inputstring')
            uTmpVar2 = uTmpVar
            uTmpVar = uTmpVar.replace(" ", "%s")
            SetVar(uVarName='inputstring', oVarValue=uTmpVar)

        uRetVar = ReplaceVars(uRetVar)
        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        # noinspection PyUnresolvedReferences
        uParams: str = ReplaceVars(oAction.uParams)
        uParams = ReplaceVars(uParams,
                              self.uObjectName + '/' + oSetting.uConfigName)

        while iTryCount < self.iMaxTryCount:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    self.ShowDebug(uMsg="Sending adb command: %s:%s" %
                                   (oAction.uCmd, uParams))
                    oMethod = getattr(oSetting.oDevice, oAction.uCmd)
                    oResult = oMethod(uParams)
                    uCmd, uRetVal = self.ParseResult(oAction, oResult,
                                                     oSetting)
                    self.ShowDebug(uMsg=u'Parsed Resonse:' + uRetVal)
                    if not uRetVar == u'':
                        uRetVal = uRetVal.replace("\n", "")
                        uRetVal = uRetVal.replace("\r", "")
                        SetVar(uVarName=uRetVar, oVarValue=uRetVal)

                    self.ShowDebug(uMsg="Result:" + str(oResult))
                    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

        if oAction.dActionPars.get('commandname') == "send_string":
            SetVar(uVarName='inputstring', oVarValue=uTmpVar2)

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #18
0
    def ExecuteActionSendCommand(self, oAction: cAction) -> eReturnCode:
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-SendCommand
        WikiDoc:TOCTitle:sendcommand
        = sendcommand =
        The core action. This sends a command to an interface. The command parameter are passed to the interface, refer to the interface documentation, which parameters are used.

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |sendcommand
        |-
        |commandname
        |Name of the command to send to the interface
        |-
        |commandparameter
        |additional parameter to pass to interface/codeset
        |-
        |interface
        |Interface to use. If not given, it will be used as given in the following order: widget, anchor, page
        |-
        |configname
        |Configuration to use
        |}</div>
        A short example:
        <div style="overflow-x: auto;"><syntaxhighlight  lang="xml">
        <action name="Send Set Volume Sub" string="sendcommand setvolumesub" commandparameter='{"volumetoset":"$var(volumetoset)"}'/>
        </syntaxhighlight></div>
        WikiDoc:End
        """
        uInterFace: str = u''
        uConfigName: str = u''
        uCommandName: str

        vCommandParameter: Union[str, Dict] = oAction.dActionPars.get(
            "commandparameter", "{}")
        if isinstance(vCommandParameter, str):
            oAction.dCommandParameter = ToDic(ReplaceVars(vCommandParameter))
        if isinstance(vCommandParameter, dict):
            oAction.dCommandParameter = ToDic(
                ReplaceVars(DictToUnicode(vCommandParameter)))

        uCommandName = ReplaceVars(oAction.dActionPars.get("commandname", ""))

        try:
            uInterFace, uConfigName = self.oEventDispatcher.GetTargetInterfaceAndConfig(
                oAction=oAction)

            oInterface: cBaseInterFace = Globals.oInterFaces.GetInterface(
                uInterFace)
            if oInterface:
                if not oInterface.bIsInit:
                    oInterface.Init(uInterFace)
                oTmpAction: cAction = copy(oAction)
                oTmpAction.uActionString = ReplaceVars(
                    oTmpAction.uActionString)
                oTmpAction.dActionPars[u'configname'] = uConfigName
                Logger.debug(
                    u'Action: Send Command: [%s] Interface: %s Config: %s' %
                    (uCommandName, uInterFace, uConfigName))
                eRet: eReturnCode = oInterface.DoAction(oTmpAction)
                SetVar(uVarName=u'INTERFACEERRORCODE_' + uInterFace + u'_' +
                       uConfigName,
                       oVarValue=ToUnicode(eRet))
                return eRet
            else:
                if uInterFace != "":
                    SetVar(uVarName=u'INTERFACEERRORCODE_' + uInterFace +
                           u'_' + uConfigName,
                           oVarValue=u'1')
                    LogError(
                        uMsg=
                        u'Action: Send Command failed #1: [%s] Interface: %s Config: %s : Interface not found!'
                        % (uCommandName, uInterFace, uConfigName))
                else:
                    LogError(
                        uMsg=
                        u'Action: Send Command failed #2: [%s]:  No Interface given!'
                        % uCommandName)
                return eReturnCode.Error
        except Exception as e:
            SetVar(uVarName=u'INTERFACEERRORCODE_' + uInterFace + u'_' +
                   uConfigName,
                   oVarValue=u"1")
            LogError(
                uMsg=
                u'Action: Send Command failed #2: [%s] Interface: %s Config: %s'
                % (uCommandName, uInterFace, uConfigName),
                oException=e)
            return eReturnCode.Error
Пример #19
0
    def ExecuteActionShowQuestion(self, oAction: cAction) -> eReturnCode:
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-ShowQuestion
        WikiDoc:TOCTitle:showquestion
        = showquestion =
        This action 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 Question" string="showquestion" title="Mytitle" message="MyMessage" actionyes="myYesAction" actionno="myNoAction"/>
        </syntaxhighlight></div>
        WikiDoc:End
        """

        self.oEventDispatcher.LogAction(uTxt=u'ShowQuestion', oAction=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: str = ReplaceVars(oAction.dActionPars.get("close", ""))
        uDontStopQueue: str = ReplaceVars(
            oAction.dActionPars.get("dontstopqueue", ""))
        self.oEventDispatcher.bDoNext = False

        if uClose:
            if self.oQuestionAction:
                StopWait()
                self.oQuestionAction.oQuestionPopup.ClosePopup()
                return eReturnCode.Nothing
        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 eReturnCode.Nothing