Plugins-API

There are two ways to access the API

  1. Directly

    Use it the following way to access the api, if you have no access to the sh object in your method or function:

    # to get access to the object instance:
    from lib.plugin import Plugins
    plugins = plugins.get_instance()
    
    # to access a method (eg. return_plugins()):
    plugins.return_plugins()
    
  2. Through the main SmartHome object

    If you have access to the sh object in your method or function, you can use the following way:

    # to access a method (eg. return_plugins()):
    sh.plugins.return_plugins()
    

The API is implemented through the following library:

lib.plugin

This library implements loading and starting of plugins of SmartHomeNG.

The methods of the class Plugins implement the API for plugins. They can be used the following way: To call eg. xxx(), use the following syntax:

from lib.plugin import Plugins
plugins = Plugins.get_instance()

# to access a method (eg. xxx()):
plugins.xxx()
Warning:This library is part of the core of SmartHomeNG. It should not be called directly from plugins!
lib.plugin.namestr(obj, namespace)[source]
class lib.plugin.Plugins(smarthome, configfile)[source]

Bases: object

Plugin loader Class. Parses config file and creates a worker thread for each plugin

Parameters:
  • smarthome – Instance of the smarthome master-object
  • configfile (str) – Basename of the plugin configuration file
static get_instance()[source]

Returns the instance of the Plugins class, to be used to access the plugin-api

Use it the following way to access the api:

from lib.plugin import Plugins
plugins = Plugins.get_instance()

# to access a method (eg. xxx()):
plugins.xxx()
Returns:logics instance
Return type:object of None
return_plugin(configname)[source]

Returns (the object of) one loaded plugin with given configname

Parameters:name (str) – name of the plugin to get
Returns:object of the plugin
Return type:object
return_plugins()[source]

Returns a list with the instances of all loaded plugins

Returns:list of plugin names
Return type:list
class PyObject[source]

Bases: _ctypes.Structure

refcnt

Structure/Union member

unload_plugin(configname)[source]

Unloads (the object of) one loaded plugin with given configname

Parameters:name (str) – name of the plugin to unload
Returns:success or failure
Return type:bool
start()[source]
stop()[source]
get_pluginthread(configname)[source]

Returns one plugin with given name

Returns:Thread object for the given plugin name
Return type:object
class lib.plugin.PluginWrapper(smarthome, name, classname, classpath, args, instance, meta, gtranslations)[source]

Bases: threading.Thread

Wrapper class for loading plugins

Parameters:
  • smarthome – Instance of the smarthome master-object
  • name (str) – Section name in plugin configuration file (etc/plugin.yaml)
  • classname (str) – Name of the (main) class in the plugin
  • classpath (str) – Path to the Python file containing the class
  • args (dict) – Parameter as specified in the configuration file (etc/plugin.yaml)
  • instance (str) – Name of the instance of the plugin
  • meta (object) –
run()[source]

Starts this plugin instance

stop()[source]

Stops this plugin instance

get_name()[source]

Returns the name of current plugin instance

Returns:name of the current plugin instance
Return type:str
get_ident()[source]

Returns the thread ident of current plugin instance

Returns:Thread identifier of current plugin instance
Return type:int
get_implementation()[source]

Returns the implementation of current plugin instance

Returns:the current plugin instance
Return type:object