Plugin library part¶
TODO : “helpers” for special pages
Purpose¶
The library part of a plugin can be the first step of your plugin. It you write it in the good way, this library may be usable out of Domogik!
In most cases, a library will contain a class. This class will have a constructor, some functions for actuators features (these functions will be called from the binary part when some xPL messages are catched), some functions for the sensor part (in most cases, it will be an eternal loop to listen to the hardware or to call some services). The sensor functions will be able to send xPL messages by calling some callback functions which refers to functions in the binary part.
Template¶
- ..todo ::
- inifinite loop
- timer
Focus on the logs¶
You already learned how to use the log functions in the library part documentation. Let’s see how to do this in the library part.
- ..todo ::
- TODO :)
Focus on xPL : send xPL messages and listen for xPL messages¶
Send xPL messages¶
As seen in the library part documentation, the function to send xPL messages are sent to the library class constructor as a parameter:
my_object = MyLibraryClass(self.log, self.send_xpl, self.get_stop())
In the class, set the parameter name to callback (so it will be clear for everybody) and store it in an instance variables named self._callback.
class MyLibraryClass:
""" My class
"""
def __init__(self, log, callback, stop):
""" Init MyLibraryClass
@param log : log instance
@param callback : callback
@param stop : stop flag
"""
self._log = log
self._callback = callback
self._stop = stop
Then, you can use this callback in any function when needed. Example:
def a_function(self):
""" My function
"""
# do some things
arg1 = "abc"
arg2 = 234
self._callback(arg1, arg2)
Listen for xPL messages¶
As explained in the binary part, there is nothing to do in the library about catching some xPL messages. The xPL messages are catched in the binary part, they are analysed and to finish, some functions or methods from the library are directly called from the binary part. So, you just need to prepare the needed function with the parameters you need and call these functions from the binary part.
Focus on devices¶
Stop the plugin if no device has been created ?¶
Todo
It depends on the plugin :). If there is devices detection, it should not stop for example. Give some examples
Detected devices¶
In some plugins, the hardware or service is able to see all devices, even if the user didn’t create a Domogik device for it! If so, you should implement the automatic devices detection. So, all detected devices informations will be sent over MQ and the user interfaces will be able to display them.