mknx / smarthome

http://mknx.github.io/smarthome/
GNU General Public License v3.0
126 stars 69 forks source link

Add method to get instance of plugin #181

Closed thernst-de closed 1 year ago

thernst-de commented 8 years ago

In order to access methods of plugins it is required to have a method which returns the instance of a certain plugin. Allthough the "return_plugins" method can be used to iterate over all plugins a more convenient method would return the instance of a named plugin.

With this pull request a new method "return_plugin" is added which returns either the instance of the given plugin or None of no matching plugin is found. The plugin to return needs to be given using it's main class name (e.g. "CLI" for the cli plugin.)

ohinckel commented 8 years ago

I have also wrote an enhancement to get plugin instances (see #81). And there is also a ˋreturn_plugin()ˋ method. The difference in #81 is, that the name passed to the function is not the class, it's the instance name (the name used as the secition name in the ˋplugin.confˋ) instead.

When using the class name I would expect a list of plugins which will be returned, because I think there could be usecases where one want to register a plugin multiple times. For example in my setup I've configured the SML plugin two times (one for house powermeter, one for heatpump powermeter).

If you need to have a ˋreturn_plugin()ˋ method in to get plugins by class I could extend my pull request and implement a ˋreturn_plugins_by_class()ˋ method to return a list of plugin instances

thernst-de commented 8 years ago

Your methods would do well for my purpose, too. I was just requiring a method that could easily return the instance of the CLI plugin to add additional commands (pull request #182). Identifying the plugin by its name instead of its main class is quite simpler. So if #81 makes it into the develop branch, this push request is no longer needed.

ohinckel commented 8 years ago

I think this can be close since it will not be get merged. I also created a new PR https://github.com/smarthomeNG/smarthome/pull/50 which will add the plugin methods I talked about in the previous comments. Further details about this in new PR.