Package: homegear
python3-homegearpython3-homegear is a python extension to connect to Homegear over Unix Domain Sockets. It supports all of Homegear's RPC methods and live event reception.PrerequisitesThe extension requireslibhomegear-ipcto be installed and it needs at least Python version 3. To install it, add the Homegear APT repository for your distribution (seehttps://homegear.eu/downloads.html) and executeaptinstalllibhomegear-ipcAlternatively on non Debian-like systems you can compile libhomegear-ipc manually:gitclonehttps://github.com/Homegear/libhomegear-ipccdlibhomegear-ipc
./makeRelease.shSetupif you have pip, just do:sudopython3-mpipinstallhomegearTo compile and install the extension manually, download it from GibHut and executesudopython3setup.pyinstallMethodsThere is only one object available:Homegear. It takes two parameters in it's constructor: The path to the Homegear IPC socket (normally/var/run/homegear/homegearIPC.sock) and a callback method. The callback method is executed when a device variable is updated in Homegear. On instantiation the class waits until it is connected succesfully to Homegear. After 2 seconds it returns even if there is no connection. To check, if the object is still connected, you can callconnected(). Apart from this method, you can call all RPC methods available in Homegear (see ref.homegear.eu).Behaviour on no connectionWhen there is no connection to Homegear, the constructor returns after 2 seconds. It indefinitely tries to reconnect until it is able to establish a connection. The same happens on connection loss. To check if the module is connected, callconnected(). Even when there is no connection, you can still call all RPC methods without exception. The return value will beNone.Type conversionPython variable to Homegear variablePythonHomegearNoneVoidBoolBooleanLongIntegerFloatFloatUnicodeStringBytesBinaryListArrayTupleArrayDictStructHomegear variable to Python variableHomegearPythonVoidNoneBooleanBoolIntegerLongFloatFloatStringUnicodeBinaryBytesArrayListStructDictUsage exampleA minimal example:fromhomegearimportHomegear# This callback method is called on Homegear variable changesdefeventHandler(eventSource,peerId,channel,variableName,value):# Note that the event handler is called by a different thread than the main thread. I. e. thread synchronization is# needed when you access non local variables.print("Event handler called with arguments: source: "+eventSource+" peerId: "+str(peerId)+"; channel: "+str(channel)+"; variable name: "+variableName+"; value: "+str(value));hg=Homegear("/var/run/homegear/homegearIPC.sock",eventHandler);Please note that the callback method is called from a different thread. Please use thread synchronization when accessing shared variables.To execute a RPC method, just typehg.<method name>. For example to set the system variable "TEST" to "6" and retrieve it again:hg.setSystemVariable("TEST",6);print(hg.getSystemVariable("TEST"));A full example:importtimefromhomegearimportHomegear# This callback method is called on Homegear variable changesdefeventHandler(eventSource,peerId,channel,variableName,value):# Note that the event handler is called by a different thread than the main thread. I. e. thread synchronization is# needed when you access non local variables.print("Event handler called with arguments: source: "+eventSource+" peerId: "+str(peerId)+"; channel: "+str(channel)+"; variable name: "+variableName+"; value: "+str(value));hg=Homegear("/var/run/homegear/homegearIPC.sock",eventHandler);# hg waits until the connection is established (but for a maximum of 2 seonds).hg.setSystemVariable("TEST",6);print("getSystemVariable(\"TEST\") after setting\"TEST\"to 6: ",hg.getSystemVariable("TEST"));hg.setSystemVariable("TEST",["One",2,3.3]);print("getSystemVariable(\"TEST\") after setting\"TEST\"to an array: ",hg.getSystemVariable("TEST"));hg.setSystemVariable("TEST",{"One":1,2:"Two",3:[3,3,3]});print("getSystemVariable(\"TEST\") after setting\"TEST\"to a struct: ",hg.getSystemVariable("TEST"));counter=0;while(hg.connected()):time.sleep(1);counter+=1;hg.setSystemVariable("TEST",counter);LinksGitHub ProjectHomegear WebsiteHomegear ReferenceHomegear Documentation