def UpdateWidget(self) -> None: """ Updates the silder pos, based on the assigned Var """ uValue: str fMax: float fMin: float super().UpdateWidget() if not self.uDestVar == u'': uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) if GetVar(uVarName=self.uMax) != u'': fMax = ToFloat(GetVar(uVarName=self.uMax)) else: fMax = self.fMax if GetVar(uVarName=self.uMin) != u'': fMin = ToFloat(GetVar(uVarName=self.uMin)) else: fMin = self.fMin if fNewValue > fMax: fNewValue = fMax if fNewValue < fMin: fNewValue = fMin if self.oObject: self.oObject.SetValue(fNewValue) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
def Create(self, oParent: Widget) -> bool: """ creates the Widget """ try: self.fMin = ToFloat(ReplaceVars(self.uMin)) self.fMax = ToFloat(ReplaceVars(self.uMax)) self.AddArg('min', self.fMin) self.AddArg('max', self.fMax) self.AddArg('orientation', self.uDeviceOrientation) self.AddArg('value', self.fMin) self.AddArg('background_pic', ToAtlas(oFileName=self.oFnPictureNormal)) self.AddArg('button_pic', ToAtlas(oFileName=self.oFnPictureButton)) if self.CreateBase(Parent=oParent, Class=cSliderEx): self.fDataRange = abs(self.fMax - self.fMin) self.oObject.bind(on_slider_moved=self.OnNotifyChange) # Capability to click on Knobs as well (needs to be implemented) if not self.uActionName == u'': self.oObject.bind(on_release=self.On_Button_Up) self.oObject.bind(on_press=self.On_Button_Down) self.oParent.add_widget(self.oObject) self.UpdateWidget() return True return False except Exception as e: LogError(uMsg=u'cWidgetSlider:Unexpected error Creating Object:', oException=e) return False
def Var_Power(uVarName: str, uPower: str) -> str: """ Exponentiate a given variable value. The changed variable value will be return and stored in the user vars (Triggers raised if set) :param str uVarName: The variable name for the action, from where the value is pulled :param str uPower: The value to exponentiate the original value with, can be a variable itself :return: The changed variable value """ try: uValue: str = GetVar(uVarName=uVarName) uValueOrg: str = uValue if uValue == u'': return u'' uPowerToUse: str = GetVar(uVarName=uPower) if uPowerToUse == u'': uPowerToUse = uPower uPowerToUse = ReplaceVars(uPowerToUse) fPower: float = ToFloat(uPowerToUse) fValue: float = ToFloat(uValue) fValue = fValue**fPower uValue = ToUnicode(fValue) uValue = Var_NormalizeInt(uValue) SetVar(uVarName=uVarName, oVarValue=uValue) Logger.debug( u'Var_Power: [%s] ^ [%s] returned [%s] (stored in [%s])' % (uValueOrg, uPowerToUse, uValue, uVarName)) return uValue except Exception as e: LogError(uMsg=u'Var_Power: Invalid Argument', oException=e) return u'Error'
def Var_Format(uVarName: str, uFormat: str): """ Formats a variable content to a given format The changed variable value will be return and stored in the user vars (Triggers raised if set) :param str uVarName: The variable name for the action, from where the value is pulled :param str uFormat: The format to use (python syntax) :return: The changed variable value """ try: uValue: str = GetVar(uVarName=uVarName) if uValue is None: return u'' uFormatToUse: str = ORCA.vars.Globals.dUserVars.get(uFormat) if uFormatToUse is None: uFormatToUse = uFormat if uFormatToUse.startswith('(int)'): uFormatToUse = uFormatToUse[5:] uValue = uFormatToUse.format(int(ToFloat(uValue))) elif uFormatToUse.startswith('(float)'): uFormatToUse = uFormatToUse[7:] uValue = uFormatToUse.format(ToFloat(uValue)) SetVar(uVarName=uVarName, oVarValue=uValue) return uValue except Exception as e: LogError(uMsg=u'Var_Format: Invalid Argument', oException=e) return u''
def __init__(self, **kwargs): self.register_event_type('on_release') super(SettingNumericSlider, self).__init__(**RemoveNoClassArgs(kwargs, SettingNumeric)) self.fMin = ToFloat(kwargs["min"]) self.fMax = ToFloat(kwargs["max"]) self.iRoundPos = int(kwargs["roundpos"]) self.slider = None self.textvalue = None
def __init__(self, **kwargs): self.register_event_type('on_release') super().__init__( **RemoveNoClassArgs(dInArgs=kwargs, oObject=SettingNumeric)) self.fMin: float = ToFloat(kwargs["min"]) self.fMax: float = ToFloat(kwargs["max"]) self.iRoundPos: int = int(kwargs["roundpos"]) self.slider: Union[Slider, None] = None self.textvalue: Union[TextInput, None] = None
def LogToSplashScreen2(self, *, uText: str, uPercentage: str = '') -> None: """ Logs a sub text message to the splash screen """ self.oSplashLogger2.size = (Globals.iAppWidth * 0.95, Globals.iAppHeight / 3) self.oSplashLogger2.text_size = (Globals.iAppWidth * 0.95, None) self.oSplashLogger2.text = ReplaceVars(uText) if uPercentage != '': fPercentage: float if uPercentage.startswith('+'): fPercentage = self.oProgessBar.value + ToFloat(uPercentage[1:]) else: fPercentage = ToFloat(uPercentage) self.oProgessBar.value = fPercentage return None
def LogToSplashScreen2(self,uText,uPercentage=''): """ Logs a sub text message to the splash screen """ self.oSplashLogger2.size =(Globals.iAppWidth*0.95,Globals.iAppHeight/3) self.oSplashLogger2.text_size =(Globals.iAppWidth*0.95,None) self.oSplashLogger2.text = ReplaceVars(uText) if uPercentage!='': fPercentage=0 if isinstance(uPercentage, string_types): if uPercentage.startswith('+'): fPercentage=self.oProgessBar.value+ToFloat(uPercentage[1:]) else: fPercentage=ToFloat(uPercentage) else: fPercentage=ToFloat(uPercentage) self.oProgessBar.value=fPercentage
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 Discover(self, **kwargs): uConfigName = self.uConfigName if "configname" in kwargs: uConfigName = kwargs['configname'] oSetting = self.GetSettingObjectForConfigName(uConfigName=uConfigName) fTimeOut = oSetting.aScriptIniSettings.fTimeOut if "timeout" in kwargs: fTimeOut = ToFloat(kwargs['timeout']) self.fTimeOut = fTimeOut if self.oThread is None: self.StartThread() if not self.oThread.is_alive(): self.StartThread() iCount = self.fTimeOut * 100 while len(self.aiTachDevices ) == 0 and iCount > 0 and self.oThread.is_alive(): sleep(0.01) iCount = iCount - 1 self.StopThread() if len(self.aiTachDevices) == 0: return {"Host": ""} else: uKey = self.aiTachDevices.keys()[0] return {"Host": self.aiTachDevices[uKey].uIP}
def Var_Round(uVarName: str, uPos: str) -> str: """ Rounds a var value to the given round position. The changed variable value will be return and stored in the user vars (Triggers raised if set) Example: Round(1.81,0) return 2. Round(1.81,1) returns 1.80 :param str uVarName: The variable name for the action, from where the value is pulled :param str uPos: The round position :return: The changed variable value """ uValue: str = GetVar(uVarName=uVarName) try: if uValue == u'': return u'' uPosToUse: str = GetVar(uVarName=uPos) if uPosToUse == u'': uPosToUse = uPos iPos: int = int(uPosToUse) uValue = ToUnicode(Round(ToFloat(uValue), iPos)) SetVar(uVarName=uVarName, oVarValue=uValue) return uValue except Exception as e: LogError(uMsg=u'Var_Round: Invalid Argument [' + uVarName + u'=' + uValue + u']:', oException=e) return u'Error'
def InitWidgetFromXml(self, *, oXMLNode: Element, oParentScreenPage: cScreenPage, uAnchor: str) -> bool: """ Reads further Widget attributes from a xml node """ bRet: bool = self.ParseXMLBaseNode(oXMLNode, oParentScreenPage, uAnchor) if bRet: self.uLineWidth = GetXMLTextAttributeVar(oXMLNode=oXMLNode, uTag=u'linewidth', bMandatory=False, uDefault="1.0") if self.uBackGroundColor == "#00000000": self.aBackGroundColor = Globals.oTheScreen.oSkin.dSkinAttributes.get( 'color border') fPercentage: float = -1.0 if not self.uLineWidth == u'': if self.uLineWidth.startswith('of:'): self.iLineWidth = self._ParseDimPosValue(self.uLineWidth) elif self.uLineWidth[0] == u'%': fPercentage = ToFloat(self.uLineWidth[1:]) elif self.uLineWidth[0] == u'd': self.iLineWidth = dp(ToInt( self.uLineWidth[1:])) + self.iAnchorPosX else: self.iLineWidth = ToInt(self.uLineWidth) if not fPercentage == -1.0: self.iLineWidth = ToInt(self.iAnchorPosX + ( (fPercentage / 100) * self.iAnchorWidth) - (self.iWidth * (fPercentage / 100))) self.iLineWidth = max(1, self.iLineWidth) return bRet
def Config_GetDefault_Float(*, oConfig: ConfigParser, uSection: str, uOption: str, uDefaultValue: str) -> float: return ToFloat( Config_GetDefault_Str(oConfig=oConfig, uSection=uSection, uOption=uOption, vDefaultValue=uDefaultValue))
def GetXMLFloatAttribute(*, oXMLNode: Element, uTag: str, bMandatory: bool, fDefault: float) -> float: """ Returns an float from a xml attribute """ return ToFloat( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=uTag, bMandatory=bMandatory, vDefault=fDefault))
def XY2RGB(self, **kwargs) -> None: """ Converts HUE xy to rgb and dumps it into vars """ try: r: float g: float b: float fX: float fY: float fX = ToFloat(kwargs.get('x', 1.0)) fY = ToFloat(kwargs.get('y', 1.0)) uPrefix = kwargs.get('retvar', '') uLightKey = kwargs.get('index', '') uType = kwargs.get('type', 'Light') if uType == "Group": uType = "groups" else: uType = "lights" tGammut: Tuple = self._GetGamut(self.dStatus[uType][uLightKey].get( 'modelid', "")) oConverter = self.oHueConverter.Converter(tGammut) r, g, b = oConverter.xy_to_rgb(fX, fY) dStatusLight: Dict = self.dStatus.get(uLightKey, {}) if len(dStatusLight) > 0: uType = dStatusLight["lightstype"] self.oResultParser.SetVar2(str(r), "", uPrefix, u'Storing R-Value', uAddName=u"_r") self.oResultParser.SetVar2(str(g), "", uPrefix, u'Storing G-Value', uAddName=u"_g") self.oResultParser.SetVar2(str(b), "", uPrefix, u'Storing B-Value', uAddName=u"_b") return None except Exception as e: LogErrorSmall(uMsg="XY2RGB: Error parsing parameter", oException=e) return None
def GetXMLFloatAttributeVar(*, oXMLNode: Element, uTag: str, bMandatory: bool, fDefault: float) -> float: """ Returns an float from a xml attribute (given as var)""" return ToFloat( ReplaceVars( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=uTag, bMandatory=bMandatory, vDefault=ToUnicode(fDefault))))
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 Var_Increase(uVarName, uStep='1', uMax=''): """ Increase a given variable value. The changed variable value will be return and stored in the user vars (Triggers raised if set) :rtype: string :param string uVarName: The variable name for the action, from where the value is pulled :param string uStep: The value to added to the original value, can be a variable itself :param string uMax: The maximum value, which can't be exceeded, can be a variable itself, If empty, no limit is used :return: The changed variable value """ uValue = u'' try: uValue = GetVar(uVarName=uVarName) uValueOrg = uValue if uValue == u'': uValue = '0' uStepToUse = GetVar(uVarName=uStep) if uStepToUse == u'': uStepToUse = uStep uStepToUse = ReplaceVars(uStepToUse) uMaxToUse = GetVar(uVarName=uMax) if uMaxToUse == u'': uMaxToUse = uMax fValue = ToFloat(uValue) fValue += ToFloat(uStepToUse) if not uMaxToUse == u'': fMaxToUse = ToFloat(uMaxToUse) if fValue > fMaxToUse: fValue = fMaxToUse uValue = ToUnicode(fValue) uValue = Var_NormalizeInt(uValue) SetVar(uVarName=uVarName, oVarValue=uValue) Logger.debug( u'Var_Increase: [%s] plus [%s] returned [%s] (stored in [%s])' % (uValueOrg, uStepToUse, uValue, uVarName)) except Exception as e: LogError(u'Var_Increase: Invalid Argument', e) return u'Error' return uValue
def UpdateWidget(self): if not self.uDestVar == u'': if not self.fDataRange == 0: uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) iNewProz = (fNewValue - self.fMin) / self.fDataRange iNewDegree = self.iLeftBoundaryAngle + self.iRange * iNewProz self.oObject.SetValue(iNewDegree) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
def Var_Decrease(uVarName: str, uStep: str, uMin: str) -> str: """ Decrease a given variable value. The changed variable value will be return and stored in the user vars (Triggers raised if set) :param str uVarName: The variable name for the action, from where the value is pulled :param str uStep: The value to added to the original value, can be a variable itself :param str uMin: The minimum value, which can't be deceeded, can be a variable itself, If empty, no limit is used :return: The changed variable value """ try: uValue: str = GetVar(uVarName=uVarName) uValueOrg: str = uValue if uValue == u'': uValue = '0' uStepToUse: str = GetVar(uVarName=uStep) if uStepToUse == u'': uStepToUse = uStep uMinToUse: str = GetVar(uVarName=uMin) uMinToUse = ReplaceVars(uMinToUse) if uMinToUse == u'': uMinToUse = uMin fValue: float = ToFloat(uValue) fValue -= ToFloat(uStepToUse) if not uMinToUse == u'': fMinToUse = ToFloat(uMinToUse) if fValue < fMinToUse: fValue = fMinToUse uValue = ToUnicode(fValue) uValue = Var_NormalizeInt(uValue) SetVar(uVarName=uVarName, oVarValue=uValue) Logger.debug( u'Var_Decrease: [%s] minus [%s] returned [%s] (stored in [%s])' % (uValueOrg, uStepToUse, uValue, uVarName)) return uValue except Exception as e: LogError(uMsg=u'Var_Decrease: Invalid Argument', oException=e) return u'Error'
def UpdateWidget(self): if not self.uDestVar==u'': h=GetVar(uVarName = self.uDestVar+u'_h') s=GetVar(uVarName = self.uDestVar+u'_s') v=GetVar(uVarName = self.uDestVar+u'_v') r='' if h!='': h=ToFloat(h)/255 s=ToFloat(s)/255 v=ToFloat(v)/255 r,g,b=hsv_to_rgb(h,s,v) else: r=GetVar(uVarName = self.uDestVar+u'_r') g=GetVar(uVarName = self.uDestVar+u'_g') b=GetVar(uVarName = self.uDestVar+u'_b') if r=='': oColor=GetColorFromHex(GetVar(uVarName = self.uDestVar)) if len(oColor)==0: oColor= Color(1, 1, 1, 1) else: r,g,b,a=GetColorFromHex(GetVar(uVarName = self.uDestVar)) if r!='': r = ToFloat(r) / 255 g = ToFloat(g) / 255 b = ToFloat(b) / 255 self.oObjectColorPicker.color=(r,g,b,1)
def PlaySound(self, *, uSoundName: str, vSoundVolume: Union[float, str] = -1.0) -> bool: """ plays a given sound with a given volume """ iSoundVolume: int fVolume: float vVolume: Union[str, float] dSound: Optional[Dict[str, Union[cFileName, int]]] oFnSound: cFileName if self.bMute: return True try: dSound = self.aSounds.get(uSoundName) vVolume = vSoundVolume if dSound is not None: oFnSound = dSound["oFnSound"] iSoundVolume = dSound["iSoundVolume"] else: oFnSound = cFileName('').ImportFullPath(uFnFullName=uSoundName) iSoundVolume = 100 if oFnSound and not oFnSound.IsEmpty(): oSound = self.dSoundObjects.get(oFnSound.string) # temporary disabled if oSound is None or True: oSound = SoundLoader.load(oFnSound.string) self.dSoundObjects[oFnSound.string] = oSound if oSound: if oSound.state != 'stop': oSound.stop() if isinstance(vSoundVolume, str): if vSoundVolume != u'': vVolume = ToFloat(vSoundVolume) if not vVolume == -1.0 and not vVolume == u'': fVolume = cast(float, vVolume) * (iSoundVolume / 100.0) else: fVolume = iSoundVolume * 1.0 fVolume = fVolume / 100.0 oSound.volume = fVolume if fVolume > 0: oSound.play() return True except Exception as e: LogError(uMsg=u'Playing sound failed:' + uSoundName, oException=e) return False
def Var_Divide(uVarName, uDivisor): """ Divides a given variable value. The changed variable value will be return and stored in the user vars (Triggers raised if set) :rtype: string :param string uVarName: The variable name for the action, from where the value is pulled :param string uDivisor: The value to divide the original value with, can be a variable itself :return: The changed variable value """ uValue = u'' try: uValue = GetVar(uVarName=uVarName) uValueOrg = uValue if uValue == u'': return u'' uDivisorToUse = GetVar(uVarName=uDivisor) if uDivisorToUse == '': uDivisorToUse = uDivisor uDivisorToUse = ReplaceVars(uDivisorToUse) fDivisor = ToFloat(uDivisorToUse) if fDivisor == 0: return uValue fValue = ToFloat(uValue) fValue = fValue / fDivisor uValue = ToUnicode(fValue) uValue = Var_NormalizeInt(uValue) SetVar(uVarName=uVarName, oVarValue=uValue) Logger.debug( u'Var_Divide: [%s] / [%s] returned [%s] (stored in [%s])' % (uValueOrg, uDivisorToUse, uValue, uVarName)) except Exception as e: LogError(u'Var_Divide: Invalid Argument', e) return u'Error' return uValue
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): 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 RGB2XY(self, **kwargs) -> None: """ Converts rgb values to hue xy and dumps it into vars """ try: fR: float = ToFloat(ReplaceVars(kwargs.get('r', 1.0))) fG: float = ToFloat(ReplaceVars(kwargs.get('g', 1.0))) fB: float = ToFloat(ReplaceVars(kwargs.get('b', 1.0))) uPrefix: str = ReplaceVars(kwargs.get('retvar', '')) uLightKey: str = ReplaceVars(kwargs.get('index', '')) uType: str = ReplaceVars(kwargs.get('type', 'Light')) if uType == "Group": uType = "groups" else: uType = "lights" tGammut: Tuple = self._GetGamut(self.dStatus[uType][uLightKey].get( 'modelid', "")) oConverter = self.oHueConverter.Converter(tGammut) x, y = oConverter.rgb_to_xy(fR, fG, fB) if uPrefix == '': oAction = kwargs['oAction'] if oAction is not None: uPrefix = oAction.uRetVar self.oResultParser.SetVar2(str(x), "", uPrefix, u'Storing X-Value', uAddName=u"_x") self.oResultParser.SetVar2(str(y), "", uPrefix, u'Storing Y-Value', uAddName=u"_y") return None except Exception as e: LogErrorSmall(uMsg="RGB2XY: Error parsing parameter", oException=e) return None
def UpdateWidget(self): """ Updates the silder pos, based on the assigned Var """ if not self.uDestVar == u'': uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) if isinstance(self.fMax, float): fMax = self.fMax else: fMax = ToFloat(GetVar(uVarName=self.fMax)) if isinstance(self.fMin, float): fMin = self.fMin else: fMin = ToFloat(GetVar(uVarName=self.fMin)) if fNewValue > fMax: fNewValue = fMax if fNewValue < fMin: fNewValue = fMin if self.oObject: self.oObject.SetValue(fNewValue) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()
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 Discover(self, **kwargs) -> Dict[str, str]: uConfigName: str = kwargs.get('configname', self.uConfigName) oSetting: cBaseScriptSettings = self.GetSettingObjectForConfigName( uConfigName=uConfigName) self.fTimeOut: float = ToFloat( kwargs.get('timeout', oSetting.aIniSettings.fTimeOut)) self.dReq.uModels = kwargs.get('models', "") self.uIPVersion: str = kwargs.get('ipversion', "IPv4Only") self.bDoNotWait = ToBool(kwargs.get('donotwait', "0")) self.ShowDebug(uMsg=u'Try to discover iTach device') del self.aResults[:] try: oThread: cThread_Discover_iTach if len(self.aThreads) == 0: self.StartThread() if not self.aThreads[0].is_alive(): self.StartThread() for oT in self.aThreads: oT.join() self.SendEndNotification() if len(self.aResults) > 0: return {"Host": self.aResults[0].uFoundIP} if len(self.aResults) > 0: #for dDevice in self.aResults: # Globals.oNotifications.SendNotification(uNotification="DISCOVER_SCRIPTFOUND",**{"script":self,"scriptname":self.uObjectName,"line":[dDevice.uIP , dDevice.uUUID , dDevice.uModel ,dDevice.uRevision ],"device":dRet}) return { 'Model': self.aResults[0].uModel, 'Host': self.aResults[0].uIP, 'Port': '4998', 'Exception': None } else: self.ShowWarning(uMsg='No iTach device found') except Exception as e: self.ShowError(uMsg=u'No iTach device found, possible timeout', oException=e) return {"Host": ""}
def UpdateWidget(self) -> None: super().UpdateWidget() fNewValue: float fNewProz: float fNewDegree: float uValue: str if not self.uDestVar == u'': if not self.fDataRange == 0: uValue = GetVar(uVarName=self.uDestVar) fNewValue = ToFloat(uValue) fNewProz = (fNewValue - self.fMin) / self.fDataRange fNewDegree = self.iLeftBoundaryAngle + self.iRange * fNewProz self.oObject.SetValue(fNewDegree) self.fValue = Round(fNewValue, self.iRoundPos) self.UpdateVars()