def Discover(self, **kwargs): self.dReq.uSerial = kwargs.get('serialnumber', "") uConfigName: str = kwargs.get('configname', self.uConfigName) oSetting: cBaseScriptSettings = self.GetSettingObjectForConfigName( uConfigName=uConfigName) fTimeOut: float = ToFloat( kwargs.get('timeout', oSetting.aIniSettings.fTimeOut)) bOnlyOnce: bool = ToBool(kwargs.get('onlyonce', "1")) self.bDoNotWait = ToBool(kwargs.get('donotwait', "0")) del self.aResults[:] del self.aThreads[:] self.ShowDebug(uMsg=u'Try to discover ELV MAX device: %s ' % self.dReq.uSerial) try: oThread = cThread_Discover_ELVMAX(bOnlyOnce=bOnlyOnce, dReq=self.dReq, uIPVersion="IPv4Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if not self.bDoNotWait: for oT in self.aThreads: oT.join() self.SendEndNotification() if len(self.aResults) > 0: return TypedQueryDict([ ("Host", self.aResults[0].uFoundIP), ("Hostname", self.aResults[0].uFoundHostName), ("Serial", self.aResults[0].uFoundSerial), ("Name", self.aResults[0].uFoundName) ]) else: self.ShowWarning(uMsg=u'No ELV MAX Cube found %s' % self.dReq.uSerial) TypedQueryDict([("Host", ""), ("Hostname", ""), ("Serial", ""), ("Name", "")]) else: self.ClockCheck = Clock.schedule_interval( self.CheckFinished, 0.1) except Exception as e: self.ShowError(uMsg="Error on Discover", oException=e) return TypedQueryDict([("Host", ""), ("Hostname", ""), ("Serial", ""), ("Name", "")])
def Discover(self,**kwargs): self.dReq.clear() uConfigName:str = kwargs.get('configname',self.uConfigName) oSetting:cBaseScriptSettings = self.GetSettingObjectForConfigName(uConfigName=uConfigName) self.dReq.bReturnPort = ToBool(kwargs.get('returnport',"0")) fTimeOut:float = ToFloat(kwargs.get('timeout',oSetting.aIniSettings.fTimeOut)) uIPVersion:str = kwargs.get('ipversion',"IPv4Only") bOnlyOnce:bool = ToBool(kwargs.get('onlyonce',"1")) self.bDoNotWait = ToBool(kwargs.get('donotwait',"0")) Logger.debug (u'Try to discover device by Kira Discovery (%s)' % uIPVersion) del self.aResults[:] del self.aThreads[:] try: if uIPVersion == "IPv4Only" or uIPVersion == "All" or (uIPVersion == "Auto" and Globals.uIPAddressV6 == ""): oThread = cThread_Discover_Kira(bOnlyOnce=bOnlyOnce,dReq=self.dReq,uIPVersion="IPv4Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if uIPVersion == "IPv6Only" or uIPVersion == "All" or (uIPVersion == "Auto" and Globals.uIPAddressV6 != ""): oThread = cThread_Discover_Kira(bOnlyOnce=bOnlyOnce, dReq=self.dReq, uIPVersion="IPv6Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if not self.bDoNotWait: for oT in self.aThreads: oT.join() self.SendEndNotification() if len(self.aResults)>0: return {"Host":self.aResults[0].uFoundIP, "Hostname": self.aResults[0].uFoundHostName, 'Exception': None} else: Logger.warning(u'Kira Discover: No device found' ) else: self.ClockCheck=Clock.schedule_interval(self.CheckFinished,0.1) return {"Host": "", "Hostname": "", 'Exception': None} except Exception as e: LogError(uMsg=u'Error on discover uPnP',oException=e) return {"Host": "", "Hostname": "", 'Exception': e}
def ExecuteActionBlockGui(self, oAction: cAction) -> eReturnCode: """ WikiDoc:Doc WikiDoc:Context:ActionsDetails WikiDoc:Page:Actions-BlockGui WikiDoc:TOCTitle:blockgui = blockgui = Blocks screen elements to react on touches. Helpful to ensure, that actions are finished and not interrupted by users touching screen elements This action will not modify the error code <div style="overflow:auto; "> {| border=1 class="wikitable" ! align="left" | string |- |blockgui |- |status |0 or 1: 1=block the gui, 0 = unblock the gui |}</div> WikiDoc:End """ self.oEventDispatcher.LogAction(uTxt=u'BlockGui', oAction=oAction) Globals.oTheScreen.BlockGui(bStatus=ToBool( ReplaceVars(oAction.dActionPars.get("status", "0")))) return eReturnCode.Nothing
def On_ConfigChange(self, oSettings: KivySettings, oConfig: KivyConfigParser, uSection: str, uKey: str, uValue: str): """ reacts, if user changes a setting """ if uKey == u'configchangebuttons': self.uCurrentSection = uSection if uValue == u'button_add': SetVar(uVarName=u'SCRIPTINPUT', oVarValue=u'DEVICE_dummy') self.oInputKeyboard = ShowKeyBoard(uDestVar=u'SCRIPTINPUT', oFktNotify=self.On_InputAdd) if uValue == u'button_delete': ShowQuestionPopUp(uTitle=u'$lvar(5003)', uMessage=u'$lvar(5044)', fktYes=self.On_InputDel, uStringYes=u'$lvar(5001)', uStringNo=u'$lvar(5002)') if uValue == u'button_rename': SetVar(uVarName=u'SCRIPTINPUT', oVarValue=uSection) self.oInputKeyboard = ShowKeyBoard(uDestVar=u'SCRIPTINPUT', oFktNotify=self.On_InputRen) else: oSetting = self.oObject.GetSettingObjectForConfigName( uConfigName=uSection) if uKey in self.dSettingsCombined: uType = self.dSettingsCombined[uKey].get("type") if uType == "numeric" or uType == "numericslider": oSetting.aIniSettings[uKey] = ToInt(uValue) elif uType == "numericfloat": oSetting.aIniSettings[uKey] = ToFloat(uValue) elif uType == "bool": oSetting.aIniSettings[uKey] = ToBool(uValue) else: oSetting.aIniSettings[uKey] = uValue
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 __init__(self, oScript: cScript): super().__init__(oScript) self.aIniSettings.uHost = oScript.oEnvParameter.uFTPServer self.aIniSettings.uUser = oScript.oEnvParameter.uFTPUser self.aIniSettings.uPassword = oScript.oEnvParameter.uFTPPassword self.aIniSettings.uFTPPath = oScript.oEnvParameter.uFTPServerPath self.aIniSettings.oPathRepSource = oScript.oEnvParameter.oPathRepSource self.aIniSettings.uWWWServerPath = oScript.oEnvParameter.uWWWServerPath self.aIniSettings.bFTPSSL = ToBool(oScript.oEnvParameter.uFTPSSL) if Globals.uPlatform == "linux": self.aIniSettings.oPathRepSource_linux = oScript.oEnvParameter.oPathRepSource elif Globals.uPlatform == "win": self.aIniSettings.oPathRepSource_win = oScript.oEnvParameter.oPathRepSource elif Globals.uPlatform == "android": self.aIniSettings.oPathRepSource_android = oScript.oEnvParameter.oPathRepSource elif Globals.uPlatform == "ios": self.aIniSettings.oPathRepSource_ios = oScript.oEnvParameter.oPathRepSource elif Globals.uPlatform == "macosx": self.aIniSettings.oPathRepSource_macosx = oScript.oEnvParameter.oPathRepSource else: pass uVersion: str = str(Globals.iVersion) self.aIniSettings.uWWWServerPath = self.aIniSettings.uWWWServerPath.replace( uVersion, "$var(REPVERSION)") self.aIniSettings.uFTPPath = self.aIniSettings.uFTPPath.replace( uVersion, "$var(REPVERSION)")
def GetXMLBoolValue(*, oXMLNode: Element, uTag: str, bMandatory: bool, bDefault: bool) -> bool: """ Returns a bool from a xml value """ return ToBool( GetXMLTextValue(oXMLNode=oXMLNode, uTag=uTag, bMandatory=bMandatory, vDefault=bDefault))
def GetXMLBoolAttribute(*, oXMLNode: Element, uTag: str, bMandatory: bool, bDefault: bool) -> bool: """ Returns an bool from a xml attribute """ return ToBool( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=uTag, bMandatory=bMandatory, vDefault=bDefault))
def ReadConfigFromIniFile(self, uConfigName): """ Reads the script config file """ if self.aScriptIniSettings.bInitCompleted: return self.aScriptIniSettings.bInitCompleted = True if uConfigName != u'': self.uConfigName = uConfigName self.uContext = self.oScript.uScriptName + u'/' + self.uConfigName self.uSection = self.uConfigName try: self.oScript.oScriptConfig.LoadConfig() SetVar(uVarName=u'ScriptConfigSection', oVarValue=uConfigName) dIniDef = self.oScript.oScriptConfig.CreateSettingJsonCombined( self) for uKey2 in dIniDef: oLine = dIniDef[uKey2] uType = oLine.get("type") uKey = oLine.get("key") uDefault = oLine.get("default") if uKey is None or uDefault is None: continue # we replace JSON defaults by script-settings defaults, if exists if self.aScriptIniSettings.queryget(uKey) is not None: uDefault = self.aScriptIniSettings.queryget(uKey) uResult = Config_GetDefault_Str( self.oScript.oScriptConfig.oConfigParser, self.uSection, uKey, uDefault) if uType == "scrolloptions" or uType == "string": self.aScriptIniSettings[uKey] = ReplaceVars(uResult) elif uType == "numeric" or uType == "numericslider": self.aScriptIniSettings[uKey] = ToInt(uResult) elif uType == "numericfloat": self.aScriptIniSettings[uKey] = ToFloat(uResult) elif uType == "bool": self.aScriptIniSettings[uKey] = ToBool(uResult) elif uType == "title" or uType == "buttons" or uType == "path" or uType == "varstring": pass else: self.ShowError( u'Cannot read config name (base), wrong attribute:' + self.oScript.oScriptConfig.oFnConfig.string + u' Section:' + self.uSection + " " + oLine["type"]) self.oScript.oScriptConfig.oConfigParser.write() except Exception as e: self.ShowError(uMsg=u'Cannot read config name (base):' + self.oScript.oScriptConfig.oFnConfig.string + u' Section:' + self.uSection, oException=e) return
def GetXMLBoolAttributeVar(*, oXMLNode: Element, uTag: str, bMandatory: bool, bDefault: bool) -> bool: """ Returns an bool from a xml attribute (given as var) """ return ToBool( ReplaceVars( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=uTag, bMandatory=bMandatory, vDefault=ToUnicode(bDefault))))
def Discover(self,**kwargs): self.oReq.clear() uConfigName = kwargs.get('configname',self.uConfigName) oSetting = self.GetSettingObjectForConfigName(uConfigName=uConfigName) self.oReq.bReturnPort = ToBool(kwargs.get('returnport',"0")) fTimeOut = ToFloat(kwargs.get('timeout',oSetting.aScriptIniSettings.fTimeOut)) uIPVersion = kwargs.get('ipversion',"IPv4Only") bOnlyOnce = ToBool(kwargs.get('onlyonce',"1")) Logger.debug (u'Try to discover device by Kira Discovery (%s)' % uIPVersion) del self.aResults[:] del self.aThreads[:] try: oThread = None if uIPVersion == "IPv4Only" or uIPVersion == "All" or (uIPVersion == "Auto" and Globals.uIPAddressV6 == ""): oThread = cThread_Discover_Kira(bOnlyOnce=bOnlyOnce,oReq=self.oReq,uIPVersion="IPv4Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if uIPVersion == "IPv6Only" or uIPVersion == "All" or (uIPVersion == "Auto" and Globals.uIPAddressV6 != ""): oThread = cThread_Discover_Kira(bOnlyOnce=bOnlyOnce, oReq=self.oReq, uIPVersion="IPv6Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() for oT in self.aThreads: oT.join() if len(self.aResults)>0: return {"Host":self.aResults[0].sFoundIP, "Hostname": self.aResults[0].uFoundHostName, 'Exception': None} else: Logger.warning(u'Kira Discover: No device found' ) return {"Host": "", "Hostname": "", 'Exception': None} except Exception as e: LogError(u'Error on discover uPnP',e) return {"Host": "", "Hostname": "", 'Exception': e}
def NormalizeChannelName(self, **kwargs) -> Dict: """ Sets the TV Logos for the parsed channels :param kwargs: argument dic, need to have definitionalias, interface, configname, force """ try: uChannelName:str = ReplaceVars(kwargs['channelname']) bRemoveHD:bool = ToBool(ReplaceVars(kwargs['removehd'])) return {"ret":1,"channelname":NormalizeName(uName=uChannelName,bRemoveHD=bRemoveHD)} except Exception as e: self.ShowError(uMsg="Can''t run NormalizeChannelName, invalid parameter",uParConfigName=self.uConfigName,oException=e) return {"ret":1}
def __init__(self,oScript): cBaseScriptSettings.__init__(self,oScript) self.aScriptIniSettings.uHost = Globals.oParameter.uFTPServer self.aScriptIniSettings.uUser = Globals.oParameter.uFTPUser self.aScriptIniSettings.uPassword = Globals.oParameter.uFTPPassword self.aScriptIniSettings.uFTPPath = Globals.oParameter.uFTPServerPath self.aScriptIniSettings.uPathRepSource = Globals.oParameter.oPathRepSource self.aScriptIniSettings.uWWWServerPath = Globals.oParameter.uWWWServerPath self.aScriptIniSettings.bFTPSSL = ToBool(Globals.oParameter.uFTPSSL) uVersion = str(Globals.iVersion) self.aScriptIniSettings.uWWWServerPath = self.aScriptIniSettings.uWWWServerPath.replace(uVersion,"$var(REPVERSION)") self.aScriptIniSettings.uFTPPath = self.aScriptIniSettings.uFTPPath.replace(uVersion,"$var(REPVERSION)")
def Discover(self, **kwargs): uConfigName = kwargs.get('configname', self.uConfigName) oSetting = self.GetSettingObjectForConfigName(uConfigName=uConfigName) fTimeOut = ToFloat( kwargs.get('timeout', oSetting.aScriptIniSettings.fTimeOut)) bOnlyOnce = ToBool(kwargs.get('onlyonce', "1")) del self.aResults[:] del self.aThreads[:] uIPSubNet = Globals.uIPGateWayAssumedV4 uIPSubNet = uIPSubNet[:uIPSubNet.rfind(".")] + "." for i in range(154, 155): uIP = uIPSubNet + str(i) oThread = cThread_CheckIP(uIP=uIP, bOnlyOnce=bOnlyOnce, fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) oThread.start() for oT in self.aThreads: oT.join() if len(self.aResults): uHost = self.aResults[0]["ip"] uPort = self.aResults[0]["port"] uModel = self.aResults[0]["model"] uHostName = self.aResults[0]["hostname"] uIPVersion = self.aResults[0]["ipversion"] return { 'Host': uHost, 'Port': uPort, 'Model': uModel, 'Hostname': uHostName, "IPVersion": uIPVersion, 'Exception': None } LogErrorSmall( "Enigma-Discover: Could not find a Enigma Receiver on the network") return { 'Host': '', 'Port': '', 'Model': '', 'Hostname': '', "IPVersion": '', 'Exception': None }
def Discover(self, **kwargs) -> Dict: uIP: str uConfigName: str = kwargs.get('configname', self.uConfigName) oSetting: cBaseScriptSettings = self.GetSettingObjectForConfigName( uConfigName=uConfigName) fTimeOut: float = ToFloat( kwargs.get('timeout', oSetting.aIniSettings.fTimeOut)) bOnlyOnce: bool = ToBool(kwargs.get('onlyonce', "1")) uIPSubNet: str = Globals.uIPGateWayV4 uIPSubNet: str = uIPSubNet[:uIPSubNet.rfind(".")] + "." self.bDoNotWait = ToBool(kwargs.get('donotwait', 0)) del self.aResults[:] del self.aThreads[:] for i in range(1, 255): uIP = uIPSubNet + str(i) oThread: cThread_CheckIP = self.GetThreadClass()( uIP=uIP, bOnlyOnce=bOnlyOnce, fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) oThread.start() if not self.bDoNotWait: for oThread in self.aThreads: oThread.join() self.SendEndNotification() if len(self.aResults) > 0: return self.CreateReturnDict(self.aResults[0]) else: Logger.debug(self.uNothingFoundMessage) return self.CreateReturnDict(None) else: self.ClockCheck = Clock.schedule_interval(self.CheckFinished, 0.1) return self.CreateReturnDict(None)
def ReadSoundVolumesFromConfig(self, *, oConfig: ConfigParser) -> None: """ Reads the sound volumes from the given configparser """ for uSoundName in self.aSounds: self.SetSoundVolume(uSoundName=uSoundName, iValue=Config_GetDefault_Int( oConfig=oConfig, uSection=u'ORCA', uOption=u'soundvolume_' + uSoundName, uDefaultValue=u'100')) self.bMute = ToBool( Config_GetDefault_Int(oConfig=oConfig, uSection=u'ORCA', uOption=u'sound_muteall', uDefaultValue=u'0'))
def ExecuteActionDiscover(self, oAction: cAction) -> eReturnCode: """ WikiDoc:Doc WikiDoc:Context:ActionsDetails WikiDoc:Page:Actions-Discover WikiDoc:TOCTitle:discover = discover = Discovers either a device for a configuration / Interface or discovers all. The host name must be "discover" and the device must not have been discovered previously. <div style="overflow:auto; "> {| class="wikitable" ! align="left" | Attribute ! align="left" | Description |- |string |discover |- |interface |The name of the interface to discover. Leave empty to discover all |- |config |The name of the config to discover. Only valid if you apply the interface name |- |gui |If set to '1', a message is shown and the DISCOVERFAILED variable will be set to TRUE or FALSE. In this case the LASTERRORCODE is invalid. If gui set to 0, a silent discover is performed and the LASTERRORCoDE is set to '0' if successful or '1' if failed. |}</div> A short example: <div style="overflow-x: auto;"><syntaxhighlight lang="xml"> <action string="discover" /> </syntaxhighlight></div> WikiDoc:End """ uInterFace: str = ReplaceVars(oAction.dActionPars.get( u'interface', '')) uConfigName: str = ReplaceVars( oAction.dActionPars.get(u'configname', '')) bGui: bool = ToBool(ReplaceVars(oAction.dActionPars.get(u'gui', '0'))) Logger.debug(u'Action: discover: Interface: %s Config: %s' % (uInterFace, uConfigName)) return Globals.oInterFaces.DiscoverAll(uInterFaceName=uInterFace, uConfigName=uConfigName, bGui=bGui)
def ExecuteActionExecuteFTPCommand(self,oAction:cAction) -> eReturnCode: """ executeftpcommand: Executes various FTP commands (connect, disconnect, uploadfile) Parameter: None """ self.oEventDispatcher.LogAction(uTxt=u'ExecuteFTPCommand',oAction=oAction) bRet:bool = False uCommand:str = ReplaceVars(oAction.dActionPars.get("command", "")) uHost:str = ReplaceVars(oAction.dActionPars.get("host", "")) uUsername:str = ReplaceVars(oAction.dActionPars.get("user", "")) uPassword:str = ReplaceVars(oAction.dActionPars.get("password", "")) uSSL:str = ReplaceVars(oAction.dActionPars.get("ssl", "")) oLocalFile:cFileName = cFileName('').ImportFullPath(uFnFullName=ReplaceVars(oAction.dActionPars.get("localfile", ""))) oLocalBaseFolder:cPath = cPath(ReplaceVars(oAction.dActionPars.get("localbasefolder", ""))) oRemoteBaseFolder:cPath = cPath(ReplaceVars(oAction.dActionPars.get("remotebasefolder",""))) if Globals.oFTP is None: Globals.oFTP = cFTP(ToBool(uSSL)) if uCommand==u'connect': bRet = Globals.oFTP.Connect(uServer=uHost) if bRet: bRet=Globals.oFTP.Login(uUsername=uUsername, uPassword=uPassword ) elif uCommand==u'disconnect': bRet=Globals.oFTP.DisConnect() elif uCommand==u'uploadfile': bRet = Globals.oFTP.UploadLocalFile(oFile=oLocalFile, oBaseLocalDir=oLocalBaseFolder, oBaseRemoteDir=oRemoteBaseFolder) elif uCommand==u'downloadfile': bRet = Globals.oFTP.DownloadRemoteFile(oFnFile=oLocalFile, oPathLocal=oLocalBaseFolder, oPathRemote=oRemoteBaseFolder) if bRet: return eReturnCode.Success else: return eReturnCode.Error
def Discover(self, **kwargs) -> Dict: self.dReq.clear() uConfigName: str = kwargs.get('configname', self.uConfigName) oSetting: cBaseScriptSettings = self.GetSettingObjectForConfigName( uConfigName=uConfigName) self.dReq.uManufacturer = kwargs.get('manufacturer', "") self.dReq.uModels = kwargs.get('models', "") self.dReq.uFriendlyName = kwargs.get('prettyname', "") self.dReq.bReturnPort = ToBool(kwargs.get('returnport', "0")) fTimeOut: float = ToFloat( kwargs.get('timeout', oSetting.aIniSettings.fTimeOut)) uParST: str = kwargs.get('servicetypes', "ssdp:all") uIPVersion: str = kwargs.get('ipversion', "IPv4Only") aST: List = uParST.split(',') bOnlyOnce: bool = ToBool(kwargs.get('onlyonce', "1")) self.bDoNotWait = ToBool(kwargs.get('donotwait', "0")) self.ShowDebug( uMsg= u'Try to discover %s device by UPNP: Models: %s , PrettyName: %s ' % (self.dReq.uManufacturer, self.dReq.uModels, self.dReq.uFriendlyName)) del self.aResults[:] del self.aThreads[:] try: for uST in aST: if uIPVersion == "IPv4Only" or uIPVersion == "All" or ( uIPVersion == "Auto" and Globals.uIPAddressV6 == ""): oThread = cThread_Discover_UPNP(bOnlyOnce=bOnlyOnce, dReq=self.dReq, uIPVersion="IPv4Only", fTimeOut=fTimeOut, uST=uST, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if uIPVersion == "IPv6Only" or uIPVersion == "All" or ( uIPVersion == "Auto" and Globals.uIPAddressV6 != ""): oThread = cThread_Discover_UPNP(bOnlyOnce=bOnlyOnce, dReq=self.dReq, uIPVersion="IPv6Only", fTimeOut=fTimeOut, uST=uST, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if not self.bDoNotWait: for oT in self.aThreads: oT.join() self.SendEndNotification() if len(self.aResults) > 0: return { "Host": self.aResults[0].uFoundIP, "Hostname": self.aResults[0].uFoundHostName, "Model": self.aResults[0].uFoundModel, "FriendlyName": self.aResults[0].uFoundFriendlyName, "Manufacturer": self.aResults[0].uFoundManufacturer, "ServiceType": self.aResults[0].uFoundServiceType, "IPVersion": self.aResults[0].uIPVersion, 'Exception': None } else: self.ShowWarning( uMsg=u'No device found device %s:%s:%s' % (self.dReq.uManufacturer, self.dReq.uModels, self.dReq.uFriendlyName)) else: self.ClockCheck = Clock.schedule_interval( self.CheckFinished, 0.1) return { "Host": "", "Hostname": "", "Model": "", "FriendlyName": "", "Manufacturer": "", "ServiceType": "", "IPVersion": "", 'Exception': None } except Exception as e: LogError(uMsg=u'Error on discover uPnP', oException=e) return { "Host": "", "Hostname": "", "Model": "", "FriendlyName": "", "Manufacturer": "", "ServiceType": "", "IPVersion": "", 'Exception': e }
def GetXMLBoolValueVar(oXMLNode, uTag, bMandantory, bDefault): """ Returns a bool from a xml value (given as var)""" return ToBool( ReplaceVars( GetXMLTextValue(oXMLNode, uTag, bMandantory, ToUnicode(bDefault))))
def GetXMLBoolAttribute(oXMLNode, uTag, bMandantory, bDefault): """ Returns an bool from a xml attribute """ return ToBool(GetXMLTextAttribute(oXMLNode, uTag, bMandantory, bDefault))
def OrcaConfigParser_On_Setting_Change(config: kivyConfig, section: str, key: str, value: str) -> None: uSection: str = section uKey: str = key uValue: str = value # uValue = ToUnicode(value) if uSection == "ORCA": if uKey == u'button_clear_atlas': ClearAtlas() elif uKey == u"button_notification": uNotification = uValue.split("_")[-1] Globals.oNotifications.SendNotification( uNotification=uNotification, **{ "key": uKey, "value": uValue }) elif uKey == u'button_discover_rediscover': if uValue == u'button_discover_rediscover': Globals.oInterFaces.DiscoverAll() else: Globals.oInterFaces.DiscoverAll(bForce=True) elif uKey == u'button_discover_results': from ORCA.utils.Discover import cDiscover_List Globals.oApp.oDiscoverList = cDiscover_List() Globals.oApp.oDiscoverList.ShowList() elif uKey == u'button_installed_reps': Globals.oDownLoadSettings.LoadDirect(uDirect=uValue, bForce=True) elif uKey == u'button_show_installationhint': Var_DeleteCookie(uVarName='SHOWINSTALLATIONHINT', uPrefix=Globals.uDefinitionName) Globals.oTheScreen.AddActionToQueue( aActions=[{ 'string': 'call', 'actionname': 'Fkt ShowInstallationHint' }]) elif uKey == u'button_show_powerstati': Globals.oTheScreen.AddActionShowPageToQueue( uPageName=u'Page_PowerStati') elif uKey == u'button_updateallreps': Globals.oDownLoadSettings.UpdateAllInstalledRepositories( bForce=True) elif uKey == u'showborders': Globals.bShowBorders = not Globals.bShowBorders Globals.oTheScreen.AddActionToQueue( aActions=[{ 'string': 'updatewidget *@*' }]) elif uKey == u'language': # Changes the languages, reloads all strings and reloads the settings dialog Globals.uLanguage = uValue Globals.oApp.InitPathes() Globals.oNotifications.SendNotification( uNotification="on_language_change") elif uKey == u'locales': Globals.uLocalesName = uValue Globals.oTheScreen.LoadLocales() elif uKey == u'startrepeatdelay': Globals.fStartRepeatDelay = float(uValue) elif uKey == u'longpresstime': Globals.fLongPressTime = float(uValue) elif uKey == u'contrepeatdelay': Globals.fContRepeatDelay = float(uValue) elif uKey == u'clockwithseconds': Globals.bClockWithSeconds = (uValue == '1') elif uKey == u'longdate': Globals.bLongDate = (uValue == '1') elif uKey == u'longday': Globals.bLongDay = (uValue == '1') elif uKey == u'longmonth': Globals.bLongMonth = (uValue == '1') elif uKey == u'checkfornetwork': Globals.bConfigCheckForNetwork = (uValue == '1') elif uKey == u'vibrate': Globals.bVibrate = (uValue == '1') elif uKey == u'button_configureinterface': uButton, Globals.oTheScreen.uInterFaceToConfig, Globals.oTheScreen.uConfigToConfig = uValue.split( ':') Globals.oTheScreen.AddActionShowPageToQueue( uPageName=u'Page_InterfaceSettings') elif uKey == u'button_configurescripts': uAction: str uScriptName: str uAction, uScriptName = uValue.split(':') if uAction == "button_configure": Globals.oTheScreen.uScriptToConfig = uScriptName Globals.oTheScreen.AddActionShowPageToQueue( uPageName=u'Page_ScriptSettings') elif uAction == "button_run": kwargs = {"caller": "settings"} Globals.oScripts.RunScript(uScriptName, **kwargs) elif uKey == u'definition': ShowQuestionPopUp( uTitle='$lvar(599)', uMessage='$lvar(5026)', fktYes=Globals.oApp.on_config_change_change_definition, uStringYes='$lvar(5001)', uStringNo='$lvar(5002)') elif uKey == u'skin': Globals.oApp.ReStart() elif uKey == u'rootpath': if not Globals.bInit: Globals.oApp.close_settings() Globals.oApp._app_settings = None kivyConfig.write() Clock.schedule_once(Globals.oApp.Init_ReadConfig, 0) else: ShowMessagePopUp(uMessage=u'$lvar(5011)') elif uKey == u'sound_muteall': Globals.oSound.bMute = ToBool(uValue) elif uKey.startswith(u'soundvolume_'): uSoundName = uKey[12:] Globals.oSound.SetSoundVolume(uSoundName=uSoundName, iValue=ToInt(uValue)) Globals.oSound.PlaySound(uSoundName=uSoundName) elif uKey == u'button_changedefinitionsetting': Globals.uDefinitionToConfigure = uValue[7:] Globals.oTheScreen.AddActionShowPageToQueue( uPageName=u'Page_DefinitionSettings') if uKey in Globals.oDefinitions.aDefinitionSettingVars: SetVar(uVarName=uKey, oVarValue=uValue) else: pass
def Discover(self, **kwargs) -> Dict: self.dReq.clear() uConfigName: str = kwargs.get('configname', self.uConfigName) oSetting: cBaseScriptSettings = self.GetSettingObjectForConfigName( uConfigName=uConfigName) fTimeOut: float = ToFloat( kwargs.get('timeout', oSetting.aIniSettings.fTimeOut)) self.dReq.uModels = kwargs.get('models', "") bOnlyOnce: bool = ToBool(kwargs.get('onlyonce', "1")) uIPVersion: str = kwargs.get('ipversion', "IPv4Only") self.bDoNotWait = ToBool(kwargs.get('donotwait', "0")) self.ShowDebug( uMsg=u'Try to discover Onkyo device by EISCP: Models: %s ' % self.dReq.uModels) del self.aResults[:] del self.aThreads[:] try: oThread: cThread_Discover_EISCP if uIPVersion == "IPv4Only" or uIPVersion == "All" or ( uIPVersion == "Auto" and Globals.uIPAddressV6 == ""): oThread = cThread_Discover_EISCP(bOnlyOnce=bOnlyOnce, dReq=self.dReq, uIPVersion="IPv4Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if uIPVersion == "IPv6Only" or uIPVersion == "All" or ( uIPVersion == "Auto" and Globals.uIPAddressV6 != ""): oThread = cThread_Discover_EISCP(bOnlyOnce=bOnlyOnce, dReq=self.dReq, uIPVersion="IPv6Only", fTimeOut=fTimeOut, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if not self.bDoNotWait: for oT in self.aThreads: oT.join() self.SendEndNotification() if len(self.aResults) > 0: return { 'Model': self.aResults[0].uFoundModel, 'Host': self.aResults[0].uFoundIP, 'Port': self.aResults[0].uFoundPort, 'Category': self.aResults[0].uFoundCategory, 'Exception': None } else: self.ShowWarning(uMsg='No device found, Models: %s' % self.dReq.uModels) else: self.ClockCheck = Clock.schedule_interval( self.CheckFinished, 0.1) return { 'Model': '', 'Host': '', 'Port': '', 'Category': '', 'Exception': None } except Exception as e: self.ShowDebug(uMsg=u'No EISCP device found, possible timeout') return { 'Model': '', 'Host': '', 'Port': '', 'Category': '', 'Exception': e }
def ExecuteActionDefineTimer(self, oAction: cAction) -> eReturnCode: """ WikiDoc:Doc WikiDoc:Context:ActionsDetails WikiDoc:Page:Actions-DefineTimer WikiDoc:TOCTitle:definetimer = definetimer = Sets or removes a timer for actions. With a timer, you can perform actions in intervals. A predefined timer is a timer to update clock widgets. This action will modify the error code (0=success, 1=failure) <div style="overflow:auto; "> {| border=1 class="wikitable" ! align="left" | string ! align="left" | timername ! align="left" | interval ! align="left" | switch ! align="left" | actionname ! align="left" | doonpause |- |definetimer |Timer Name (Mandantory) |Time Interval in seconds |on / off : on to enable/set a timer, off to remove the timer |Action to execute by the timer |Execute the timer, even if the device is on sleep |}</div> If you want to change a timer, ou need to remove the timer and add it with the new settings WikiDoc:End """ self.oEventDispatcher.LogAction(uTxt=u'DefineTimer', oAction=oAction) uTimerName: str = ReplaceVars(oAction.dActionPars.get("timername", "")) uInterval: str = ReplaceVars(oAction.dActionPars.get("interval", "")) uSwitch: str = ReplaceVars(oAction.dActionPars.get("switch", "")) uActionName: str = ReplaceVars( oAction.dActionPars.get("actionname", "")) bDoOnPause: bool = ToBool( ReplaceVars(oAction.dActionPars.get("doonpause", "0"))) if uSwitch == u'on': if not self.oEventDispatcher.oAllTimer.HasTimer( uTimerName=uTimerName): oCustomTimer: cCustomTimer = cCustomTimer( uTimerName=uTimerName, uActionName=uActionName, fTimerIntervall=ToFloat(uInterval), bDoOnPause=bDoOnPause) self.oEventDispatcher.oAllTimer.AddTimer(uTimerName=uTimerName, oTimer=oCustomTimer) oCustomTimer.StartTimer() return eReturnCode.Success else: Logger.warning(u'Action: DefineTimer, timer already exist:' + uTimerName) return eReturnCode.Error if uSwitch == u'off': if self.oEventDispatcher.oAllTimer.HasTimer(uTimerName=uTimerName): self.oEventDispatcher.oAllTimer.DeleteTimer( uTimerName=uTimerName) return eReturnCode.Success else: Logger.warning(u'Action: DefineTimer, timer does not exist:' + uTimerName) return eReturnCode.Error uMsg: str = u'Action: DefineTimer, you need to on/off the timer:' + uTimerName Logger.warning(uMsg) ShowErrorPopUp(uTitle='Warning', uMessage=uMsg) return eReturnCode.Error
def GetXMLBoolAttributeVar(oXMLNode, uTag, bMandantory, bDefault): """ Returns an bool from a xml attribute (given as var) """ return ToBool( ReplaceVars( GetXMLTextAttribute(oXMLNode, uTag, bMandantory, ToUnicode(bDefault))))
def ReadConfigFromIniFile(self, *, uConfigName: str) -> None: """ Reads the object config file :param string uConfigName: The configuration name to read :return: None """ if self.aIniSettings.bInitCompleted: return self.aIniSettings.bInitCompleted = True if uConfigName != u'': self.uConfigName = uConfigName self.uContext = self.oObject.uObjectName + u'/' + self.uConfigName self.SetContextVar(uVarName="context", uVarValue=self.uContext) self.uSection = self.uConfigName try: self.oObject.oObjectConfig.LoadConfig() if self.oObject.uObjectType == "interface": SetVar(uVarName=u'InterfaceCodesetList', oVarValue=self.oObject.CreateCodesetListJSONString()) SetVar(uVarName=u'ObjectConfigSection', oVarValue=uConfigName) dIniDef: Dict[ str, Dict] = self.oObject.oObjectConfig.CreateSettingJsonCombined( oSetting=self) for uKey2 in dIniDef: dLine: Dict = dIniDef[uKey2] uType: str = dLine.get("type") uKey: str = dLine.get("key") uDefault: str = dLine.get("default") if uKey is None or uDefault is None: continue # we replace JSON defaults by interface-settings defaults, if exists if self.aIniSettings.queryget(uKey) is not None: uDefault = self.aIniSettings.queryget(uKey) uResult: str = Config_GetDefault_Str( oConfig=self.oObject.oObjectConfig.oConfigParser, uSection=self.uSection, uOption=uKey, vDefaultValue=uDefault) if uType == "scrolloptions" or uType == "string": self.aIniSettings[uKey] = ReplaceVars(uResult) elif uType == "numeric" or uType == "numericslider": self.aIniSettings[uKey] = ToInt(uResult) elif uType == "numericfloat": self.aIniSettings[uKey] = ToFloat(uResult) elif uType == "bool": self.aIniSettings[uKey] = ToBool(uResult) elif uType == "varstring": self.aIniSettings[uKey] = ReplaceVars(uResult) elif uType == "path": if isinstance(uResult, str): self.aIniSettings[uKey] = cPath(uResult) else: self.aIniSettings[uKey] = uResult elif uType == "title" or uType == "buttons": pass else: self.ShowError( uMsg=u'Cannot read config name (base), wrong attribute:' + self.oObject.oObjectConfig.oFnConfig.string + u' Section:' + self.uSection + " " + dLine["type"]) if uKey == 'FNCodeset': self.ReadCodeset() self.oObject.oObjectConfig.oConfigParser.write() except Exception as e: self.ShowError(uMsg=u'Cannot read config name (base):' + self.oObject.oObjectConfig.oFnConfig.string + u' Section:' + self.uSection, oException=e) return
def ExecuteActionGetSaveOrcaSetting(self, oAction: cAction) -> eReturnCode: """ WikiDoc:Doc WikiDoc:Context:ActionsDetails WikiDoc:Page:Actions-GetSaveOrcaSetting WikiDoc:TOCTitle:getsaveorcasetting = getsaveorcasetting = Reads or write a parameter from or into the definition.ini file or the ORCA ini file <div style="overflow:auto; "> {| class="wikitable" ! align="left" | Attribute ! align="left" | Description |- |string |getsaveorcasetting |- |configtype |type of the config: "ORCA" to read/write the ORCA ini file, otherwise the definition ini file will be used |- |varname |The value to write, if we do not read |- |retvar |The varname, where the ini file value should be read into. If retvar is empty, we just write a value without reading it. |- |nowrite |Doesn't write the setting immediatly. Helpful for bulk operations |}</div> A short example: <div style="overflow-x: auto;"><syntaxhighlight lang="xml"> <action name="" string="getsaveorcasetting" configtype="$var(DEFINITIONNAME)" varname="$dvar(definition_alias_enigma2)_GETCURRENTVOL" varvalue="1" /> </syntaxhighlight></div> WikiDoc:End """ self.oEventDispatcher.LogAction(uTxt=u'GetSaveOrcaSetting', oAction=oAction) uConfigType: str = ReplaceVars( oAction.dActionPars.get("configtype", "")) uVarName: str = ReplaceVars(oAction.dActionPars.get("varname", "")) uVarValue: str = oAction.dActionPars.get("varvalue", "") uRetVar: str = ReplaceVars(oAction.dActionPars.get("retvar", "")) bNoWrite: bool = ToBool( ReplaceVars(oAction.dActionPars.get("nowrite", ""))) uSection: str if uVarValue != u'': if not "$lvar(" in uVarValue: uVarValue = ReplaceVars(uVarValue) else: uVarValue = uVarValue else: uVarValue = GetVar(uVarName=uVarName) # if uRetVar = "", we want to write if uRetVar == "": if uConfigType == "ORCA": Globals.oOrcaConfigParser.set(uConfigType, uVarName, uVarValue) if not bNoWrite: Globals.oOrcaConfigParser.write() else: uSection = uConfigType uSection = uSection.replace(u' ', u'_') #todo: temporary hack to bypass configparser unicode error uVarValue = EscapeUnicode(uVarValue) Globals.oDefinitionConfigParser.set(uSection, uVarName, uVarValue) Logger.debug("Writing Config Var [%s]:[%s] into [%s] " % (uVarName, uVarValue, uConfigType)) if not bNoWrite: Globals.oDefinitionConfigParser.write() SetVar(uVarName=uVarName, oVarValue=uVarValue) return eReturnCode.Nothing # otherwise we want to read try: if uConfigType == "ORCA": uVarValue = Globals.oOrcaConfigParser.get(u'ORCA', uVarName) else: uSection = uConfigType uSection = uSection.replace(u' ', u'_') try: uVarValue = Globals.oDefinitionConfigParser.get( uSection, uVarName) except Exception: Logger.warning( "getsaveorcasetting: not var to read: [%s] from [%s] into Var [%s], returning empty value" % (uVarName, uConfigType, uRetVar)) #todo: temporary hack to bypass configparser unicode error uVarValue = UnEscapeUnicode(uVarValue) SetVar(uVarName=uRetVar, oVarValue=uVarValue) SetVar(uVarName=uRetVar, oVarValue=uVarValue, uContext=uConfigType) Logger.debug( "Pulled Config Var [%s]:[%s] from [%s] into Var [%s]" % (uVarName, uVarValue, uConfigType, uRetVar)) except Exception as e: LogError(uMsg=u'Action: GetSaveOrcaSetting', oException=e) SetVar(uVarName=uRetVar, oVarValue=u'') return eReturnCode.Nothing
def Discover(self, **kwargs): self.oReq.clear() uConfigName = kwargs.get('configname', self.uConfigName) oSetting = self.GetSettingObjectForConfigName(uConfigName=uConfigName) self.oReq.uManufacturer = kwargs.get('manufacturer', "") self.oReq.uModels = kwargs.get('models', "") self.oReq.uFriendlyName = kwargs.get('prettyname', "") self.oReq.bReturnPort = ToBool(kwargs.get('returnport', "0")) fTimeOut = ToFloat( kwargs.get('timeout', oSetting.aScriptIniSettings.fTimeOut)) uParST = kwargs.get('servicetypes', "ssdp:all") uIPVersion = kwargs.get('ipversion', "IPv4Only") aST = uParST.split(',') bOnlyOnce = ToBool(kwargs.get('onlyonce', "1")) Logger.debug( u'Try to discover %s device by UPNP: Models: %s , PrettyName: %s ' % (self.oReq.uManufacturer, self.oReq.uModels, self.oReq.uFriendlyName)) del self.aResults[:] del self.aThreads[:] try: for uST in aST: oThread = None if uIPVersion == "IPv4Only" or uIPVersion == "All" or ( uIPVersion == "Auto" and Globals.uIPAddressV6 == ""): oThread = cThread_Discover_UPNP(bOnlyOnce=bOnlyOnce, oReq=self.oReq, uIPVersion="IPv4Only", fTimeOut=fTimeOut, uST=uST, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() if uIPVersion == "IPv6Only" or uIPVersion == "All" or ( uIPVersion == "Auto" and Globals.uIPAddressV6 != ""): oThread = cThread_Discover_UPNP(bOnlyOnce=bOnlyOnce, oReq=self.oReq, uIPVersion="IPv6Only", fTimeOut=fTimeOut, uST=uST, oCaller=self) self.aThreads.append(oThread) self.aThreads[-1].start() for oT in self.aThreads: oT.join() if len(self.aResults) > 0: return { "Host": self.aResults[0].sFoundIP, "Hostname": self.aResults[0].uFoundHostName, "Model": self.aResults[0].uFoundModel, "FriendlyName": self.aResults[0].uFoundFriendlyName, "Manufacturer": self.aResults[0].uFoundManufacturer, "ServiceType": self.aResults[0].uFoundServiceType, "IPVersion": self.aResults[0].uIPVersion, 'Exception': None } else: Logger.warning(u'No device found device %s:%s:%s' % (self.oReq.uManufacturer, self.oReq.uModels, self.oReq.uFriendlyName)) return { "Host": "", "Hostname": "", "Model": "", "FriendlyName": "", "Manufacturer": "", "ServiceType": "", "IPVersion": "", 'Exception': None } except Exception as e: LogError(u'Error on discover uPnP', e) return { "Host": "", "Hostname": "", "Model": "", "FriendlyName": "", "Manufacturer": "", "ServiceType": "", "IPVersion": "", 'Exception': e }
def ExecuteActionCodeset(self, oAction: cAction) -> eReturnCode: """ WikiDoc:Doc WikiDoc:Context:ActionsDetails WikiDoc:Page:Actions-Codeset WikiDoc:TOCTitle:codeset = codeset = A helper action for interfaces. If an interface supports codesets, then all codeset actions will be executed by this action. The name is mandatory Not for public use! <div style="overflow:auto; "> {| class="wikitable" ! align="left" | Attribute ! align="left" | Description |- |string |codeset |}</div> A short example: <div style="overflow-x: auto;"><syntaxhighlight lang="xml"> <action string="codeset" name='left' waitforresponse='0' cmd='Shell' params="input keyevent 21" /> </syntaxhighlight></div> WikiDoc:End """ uInterFace: str = u"" uConfigName: str = u"" bNoLogOut: bool try: uInterFace = oAction.dActionPars.get(u'interface') uConfigName = oAction.dActionPars.get(u'configname') oInterface: cBaseInterFace = Globals.oInterFaces.GetInterface( uInterFace) if oInterface: Logger.debug( u'Action: codeset: [%s] Interface: %s Config: %s' % (oAction.uActionName, uInterFace, uConfigName)) oSetting: cBaseInterFaceSettings = oInterface.GetSettingObjectForConfigName( uConfigName=uConfigName) bNoLogOut = ToBool(oAction.dActionPars.get('nologout', '0')) for uKey in oAction.dActionPars: oSetting.SetContextVar(uVarName="codesetvar_" + uKey, uVarValue=oAction.dActionPars[uKey]) eRet: eReturnCode = oInterface.SendCommand( oAction=oAction, oSetting=oSetting, uRetVar=oAction.uRetVar, bNoLogOut=bNoLogOut) SetVar(uVarName=u'INTERFACEERRORCODE_' + uInterFace + u'_' + uConfigName, oVarValue=ToUnicode(eRet)) return eRet except Exception as e: SetVar(uVarName=u'INTERFACEERRORCODE_' + uInterFace + u'_' + uConfigName, oVarValue=u"1") LogError( uMsg=u'Action: codeset failed #2: [%s] Interface: %s Config: %s' % (oAction.uActionName, uInterFace, uConfigName), oException=e) return eReturnCode.Error
def GetConfigJSON(self): return {"FTPPath": {"type": "varstring", "active":"enabled", "order":16, "title": "$lvar(SCRIPT_TOOLS_REPMANAGER_5)", "desc": "$lvar(SCRIPT_TOOLS_REPMANAGER_6)","key": "FTPPath", "default":Globals.oParameter.uFTPServerPath, "section": "$var(ScriptConfigSection)"}, "FTPSSL": {"type": "bool", "active":"enabled", "order":17, "title": "$lvar(SCRIPT_TOOLS_REPMANAGER_7)", "desc": "$lvar(SCRIPT_TOOLS_REPMANAGER_8)","key": "FTPSSL", "default":ToBool(Globals.oParameter.uFTPSSL),"section": "$var(ScriptConfigSection)"}, "PathRepSource": {"type": "path", "active": "enabled", "order": 18, "title": "$lvar(SCRIPT_TOOLS_REPMANAGER_9)", "desc": "$lvar(SCRIPT_TOOLS_REPMANAGER_10)", "key": "PathRepSource", "default": Globals.oParameter.oPathRepSource.unixstring, "section": "$var(ScriptConfigSection)"}, "WWWServerPath": {"type": "varstring", "active": "enabled", "order": 19, "title": "$lvar(SCRIPT_TOOLS_REPMANAGER_11)", "desc": "$lvar(SCRIPT_TOOLS_REPMANAGER_12)", "key": "WWWServerPath", "default": Globals.oParameter.uWWWServerPath,"section": "$var(ScriptConfigSection)"} }