Class Plugins

This class implements the following methods and properties:

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

Bases: object

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

refresh_plugin_config()[Quellcode]

Re-read the plugin configuration file and update the plugin usage count from it

The usage count decides whether a plugin section gets the default instance or an instance named after the section. Call this before loading plugins at runtime, so that sections added or removed since startup are taken into account.

Rückgabetyp:

PluginConfigRefresh

Rückgabe:

the parsed configuration and warnings for the user (also logged as warnings)

get_loaded_plugins()[Quellcode]

Returns a list with the names of all loaded plugins

if multiple instances of a plugin are loaded, the plugin name is returned only once

Rückgabe:

list of plugin names

Rückgabetyp:

list

get_loaded_plugin_instances()[Quellcode]

Returns a list of tuples of all loaded plugins with the plugin name and the instance name

Rückgabe:

list of (plugin name, instance name)

Rückgabetyp:

list of tuples

static get_instance()[Quellcode]

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()
Rückgabe:

logics instance

Rückgabetyp:

object of None

get(plugin_name, instance=None)[Quellcode]

Get plugin object by plugin name and instance (optional)

Parameter:
  • plugin_name – name of the plugin (not the plugin configuration)

  • instance – name of the instance of the plugin (optional)

Rückgabe:

plugin object

return_plugin(configname)[Quellcode]

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

Parameter:

name (str) – name of the plugin to get

Rückgabe:

object of the plugin

Rückgabetyp:

object

return_plugins()[Quellcode]

Returns each of all loaded plugins (including instances)

Rückgabe:

list of plugin names

Rückgabetyp:

list

get_logic_parameters()[Quellcode]

Returns the list of all logic parameter definitions of all configured/loaded plugins

Rückgabe:

load_plugin(configname, conf)[Quellcode]

load plugin for given section with given config

return True if plugin was loaded successfully, False if not (even if disabled)

Rückgabetyp:

bool

unload_plugin(configname)[Quellcode]

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

Parameter:

name (str) – name of the plugin to unload

Rückgabe:

success or failure

Rückgabetyp:

bool

reload_plugin(configname)[Quellcode]

attempt to reload plugin code

plugin will be unloaded, code reloaded and re-loaded. It it was running, it will be restarted.

Rückgabetyp:

bool

start()[Quellcode]
stop()[Quellcode]
start_plugin(configname)[Quellcode]

Starts an already-loaded plugin via its dedicated PluginWrapper thread - the same path bulk startup uses - instead of calling the plugin’s run() directly on the caller’s thread.

Parameter:

configname (str) – name of the plugin configuration section

Rückgabetyp:

bool

Rückgabe:

True if the thread was started, False otherwise

get_pluginthread(configname)[Quellcode]

Returns one plugin with given name

Rückgabe:

Thread object for the given plugin name

Rückgabetyp:

object