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 #50
Conversation
and get_plugin_ident() to return the thead ident for a given plugin instance
… register this plugin multiple times # e.g. when having more than one power meter device and serial devices
…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
@i-am-offline You added some methods to retrieve plugin instances (see mknx/smarthome#181) which seems to be replaced with the implementation of this PR. Do you think you can update your implementation and create a new PR here when this PR will be merged? |
Yes, I can do so. But it can take some weeks until I find the time for this. |
I could use that PR for my two Plugins (Enigma2, AVM) pretty well. But i am not sure about conflicts in case i merge it. |
there are no risks. this methods are new, but there is an other solution in knx plugin pulled by @encbladexp see #22 |
In my opinion this: or maybe it is possible to get this information from obj. |
AFAIS @encbladexp implementation adds only a instance parameter (e.g. for logging) and an option knx_instance to items to attach them to a given instance. Both can be done by using stuff from this PR (e.g. for logging one could use the A default scheduler task does not make sense, since a plugin may require multiple scheduler tasks - or no task at all. And I would provide such functionality (e.g. adding a task) within a base class which could be used by all plugins instead of letting them use the scheduler directly. Further this base class implementation could make use of the menionted PRs. |
ich switche mal die Sprache. bei einer zweiten Instanz des Plugins würde das dann so aussehen: |
Diese Art der Implementierung ist etwas unschön, zu viel redundanter Code und nicht objektorientiert:
Ich würde da eher den objektorientierten Ansatz bevorzugen.
Im Code wäre es dann so zu verwenden:
|
@cstrassburg danke fuer dein Feedback. Ich kann das gerne so anpassen und den PR entsprechend aktualisieren. War schon >2 Jahre her, als ich den Original-PR erstellt habe und gerade ich mich fuer ca. 4 Monate mit SmartHome.py beschaeftigt hatte 😉 Aber hier bekommt man wenigstens auch mal Feedback, was die letzten zwei Jahre ausgeblieben ist. |
Es geht voran! |
implementiert |
(copied from mknx/smarthome#81)
This patch will add the following function to smarthome instance:
return_plugin(name)
- returns the plugin instance for given plugin nameget_plugin_ident(instance)
- returns the thread identifier of the given plugin instance, which should be uniqueget_plugin_name(instance)' - returns the plugin name (which is the section name in
plugin.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
:In this case the plugin is registered two times (one with
sh.name1
and another one withsh.name2
). When this plugin is registering a scheduler task, usually it will do something like thissh.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.
This will also made the SML plugin able to register multiple times (e.g. when having multiple power meter devices or serial devices connected).