Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin methods to smarthome #81

Closed
wants to merge 9 commits into from

Conversation

ohinckel
Copy link

@ohinckel ohinckel commented Feb 2, 2014

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
  • get_plugin_name(instance)' - returns the plugin name (which is the section name inplugin.conf`)

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 something like this:
sh.scheduler.add("ThePlugin-" + str(sh.get_plugin_name(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.

… register

  this plugin multiple times
# e.g. when having more than one power meter device and serial devices
@ohinckel
Copy link
Author

Just made the SML plugin able to register multiple times (e.g. when having multiple power meter devices or serial devices connected).

…trieve the plugin name

  for given plugin instance
# can also be used instead of plugin ident (which is the thread`s identifier) for
# better readability
…eduler with

  the plugin name instead of plugin ident, which can not be used to identify the
  plugin instance
@ohinckel
Copy link
Author

Created new PR smarthomeNG/smarthome#50 in new project and will close this issue now. Thanks for your great application!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant