mknx/smarthome — pull request #81 by ohinckel (2014-02-02 18:29:35+00:00)
Title: Add plugin methods to smarthome

This patch will add the following function to smarthome instance:
* `return_plugin(name)` - returns the plugin instance for given plugin name
* `get_plugin_ident(instance)` - returns the thread identifier of the given plugin instance, which should be unique

These function may help when running multiple instances of one plugin and each want to add a scheduler task. Usually you do something like `sh.scheduler.add("PluginName", ...)`. But when registering a plugin multiple times, only one scheduler task will be registered.

E.g. having something like this in `plugin.conf`:
```
[name1]
class_name = ThePlugin
class_path = plugins.theplugin
option = somevalue
[name2]
class_name = ThePlugin
class_path = plugins.theplugin
option = othervalue
```

In this case the plugin is registered two times (one with `sh.name1` and another one with `sh.name2`). When this plugin is registering a scheduler task, usually it will do something like this `sh.scheduler.add("ThePlugin", ...)` - but this will only register one scheduler task, since the other will overwrite the previous scheduler task because it uses the same name!

To solve this problem, the plugin can use the thread identifier and can do somethin like this:
`sh.scheduler.add("ThePlugin" + str(sh.get_plugin_ident(self)), ...)`, which will register two scheduler tasks now since both includes the unique thread identifier in the scheduler task.

I don't know of any other solution how to configure a plugin multiple times (e.g. for different devices) and having a scheduler task for each of them.