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()
    

    This is the preferred method.

  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 module:

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!

The API consists of two classes.

class PluginWrapper

This class implements the Plugin itself:

class lib.plugin.PluginWrapper(smarthome, name, classname, classpath, args, instance, meta, configfile)[Quellcode]

Wrapper class for loading plugins

Parameter:
  • 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) –

class PluginWrapper

class Plugins

This class implements the loading and management of the plugins.

class lib.plugin.Plugins(smarthome, configfile)[Quellcode]

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

Parameter:
  • smarthome – Instance of the smarthome master-object

  • configfile (str) – Basename of the plugin configuration file

class Plugins