Class SmartPlugin

The class SmartPlugin implements the base class of all smart-plugins. The implemented methods are described below.

In adition the methods implemented in lib.utils.Utils are inhereted.

class lib.model.smartplugin.SmartPlugin(**kwargs)[source]

Bases: lib.model.smartobject.SmartObject, lib.utils.Utils

The class SmartPlugin implements the base class of call smart-plugins. The implemented methods are described below.

In adition the methods implemented in lib.utils.Utils are inhereted.

ALLOW_MULTIINSTANCE = None
shtime = None

Variable containing a pointer to the SmartHomeNG time handling object; is initialized during loading of the plugin; :Warning: Don’t change it

logger = <logging.Logger object>
deinit()[source]

If the Plugin needs special code to be executed before it is unloaded, this method has to be overwirtten with the code needed for de-initialization

get_configname()[source]

return the name of the plugin instance as defined in plugin.yaml (section name)

Note:Only available in SmartHomeNG versions beyond v1.4
Returns:name of the plugin instance as defined in plugin.yaml
Return type:str
get_shortname()[source]

return the shortname of the plugin (name of it’s directory)

Note:Only available in SmartHomeNG versions beyond v1.3
Returns:shortname of the plugin
Return type:str
get_instance_name()[source]

Returns the name of this instance of the plugin

Returns:instance name
Return type:str
get_fullname()[source]

return the full name of the plugin (shortname & instancename)

Note:Only available in SmartHomeNG versions v1.3c and up
Returns:full name of the plugin
Return type:str
get_classname()[source]

return the classname of the plugin

Note:Only available in SmartHomeNG versions beyond v1.3
Returns:classname of the plugin
Return type:str
get_version(extended=False)[source]

Return plugin version

Parameters:extended (bool) – If True, returned version string contains (pv) if not the latest version is loaded
Returns:plugin version
Return type:str
is_multi_instance_capable()[source]

Returns information if plugin is capable of multi instance handling

Returns:True: If multiinstance capable
Return type:bool
get_plugin_dir()[source]

return the directory where the pluing files are stored in

Note:Only available in SmartHomeNG versions beyond v1.3
Returns:name of the directory
Return type:str
get_info()[source]

Returns a small plugin info like: class, version and instance name

Returns:plugin Info
Return type:str
get_parameter_value(parameter_name)[source]

Returns the configured value for the given parameter name

If the parameter is not defined, None is returned

Parameters:parameter_name (str) – Name of the parameter for which the value should be retrieved
Returns:Configured value
Return type:depends on the type of the parameter definition
get_parameter_value_for_display(parameter_name)[source]

Returns the configured value for the given parameter name

If the parameter is not defined, None is returned If the parameter is marked as ‘hide’, only ‘*’s are returned

Parameters:parameter_name (str) – Name of the parameter for which the value should be retrieved
Returns:Configured value
Return type:depends on the type of the parameter definition
get_loginstance()[source]

Returns a prefix for logmessages of multi instance capable plugins.

The result is an empty string, if the instancename is empty. Otherwise the result is a string containing the instance name preseeded by a ‘@’ and traild by ‘: ‘.

This way it is easy to show the instance name in log messages. Just write

self.logger.info(self.get_loginstance()+”Your text”)

and the logmessage is preseeded by the instance name, if needed.

Returns:instance name for logstring
Return type:str
has_iattr(conf, attr)[source]

checks item configuration for an attribute

Parameters:
  • conf (str) – item configuration
  • attr (str) – attribute name
Returns:

True, if attribute is in item configuration

Return type:

Boolean

get_iattr_value(conf, attr)[source]

Returns value for an attribute from item config

Parameters:
  • conf (str) – item configuration
  • attr (str) – attribute name
Returns:

value of an attribute

Return type:

str

set_attr_value(conf, attr, value)[source]

Set value for an attribute in item configuration

Parameters:
  • conf (str) – item configuration
  • attr (str) – attribute name
  • value (str) – value to set the atteibute to
get_sh()[source]

Return the main object of smarthomeNG (usually refered to as smarthome or sh) You can reference the main object of SmartHomeNG by using self.get_sh() in your plugin

Note:Only available in SmartHomeNG versions beyond v1.3
Returns:the main object of smarthomeNG (usually refered to as smarthome or sh)
Return type:object
get_module(modulename)[source]

Test if module http is loaded and if loaded, return a handle to the module

path_join(path, dir)[source]

Join an existing path and a directory

parse_logic(logic)[source]

This method is used to parse the configuration of a logic for this plugin. It is called for all plugins before the plugins are started (calling all run methods).

Note:This method should to be overwritten by the plugin implementation.
parse_item(item)[source]

This method is used to parse the configuration of an item for this plugin. It is called for all plugins before the plugins are started (calling all run methods).

Note:This method should to be overwritten by the plugin implementation.
now()[source]

Returns SmartHomeNGs current time (timezone aware)

scheduler_add(name, obj, prio=3, cron=None, cycle=None, value=None, offset=None, next=None)[source]

This methods adds a scheduler entry for a plugin-scheduler

A plugin identification is added to the scheduler name

The parameters are identical to the scheduler.add method from lib.scheduler

scheduler_change(name, **kwargs)[source]

This methods changes a scheduler entry of a plugin-scheduler

scheduler_remove(name)[source]

This methods removes a scheduler entry of a plugin-scheduler

A plugin identifiction is added to the scheduler name

The parameters are identical to the scheduler.remove method from lib.scheduler

scheduler_get(name)[source]

This methods gets a scheduler entry of a plugin-scheduler

A plugin identifiction is added to the scheduler name

The parameters are identical to the scheduler.get method from lib.scheduler

run()[source]

This method of the plugin is called to start the plugin

Note:This method needs to be overwritten by the plugin implementation. Otherwise an error will be raised
stop()[source]

This method of the plugin is called to stop the plugin when SmartHomeNG shuts down

Note:This method needs to be overwritten by the plugin implementation. Otherwise an error will be raised
translate(txt)[source]

Returns translated text