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 method to get instance of plugin #181

Closed
wants to merge 1 commit into from
Closed

Add method to get instance of plugin #181

wants to merge 1 commit into from

Conversation

thernst-de
Copy link
Contributor

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
Copy link

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 pushed a commit to thernst-de/smarthome.plugin.autoblind that referenced this pull request Sep 13, 2015
Adds commands as_list and as_detail to the available commands of CLI plugin.
Requires two changes in smarthome.py:
 - Pull request #181 ("Add method to get instance of plugin"): mknx/smarthome#181
 - Pull request #182 ("CLI Plugin: Allow other plugins to add custom commands"): mknx/smarthome#182
If these pull requests are missing, no cli commands are added. Instead a message (loglevel debug) will be written. No error
will occur in this case.

More CLI commands are expected to be added
@thernst-de
Copy link
Contributor Author

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.

thernst-de pushed a commit to thernst-de/smarthome.plugin.autoblind that referenced this pull request Dec 26, 2015
When using an separate item to cumulate all triggers for manual changes, it may be required to ignore some changes based on caller/source if the change.
The main AutoBlind class now contains two methods that can be used for this.

    is_changed_by(self, caller, source, changed_by) returns True if the root change comes from certain callers/sources
    is_changed_by(self, caller, source, changed_by) return True if the root change comes not from certain callers/sources

"caller" and "source" are provided by eval and can just be used.
changed_by is a list of callers and sources which should be checked. The format is ["<first_caller>:<first_source>", "<next_caller>:<next:source>", ...]
callers and sources can be replaced by "*" meaning "any caller"/"any source".

Examples:

    [[[manuell]]]
    type = bool
    eval = not sh.test.rollo.manuell() if sh.return_plugin("AutoBlind").not_changed_by(caller, source, ["Init:*", "KNX:1.1.7"]) else sh.test.rollo.manuell()
    eval_trigger = test.rollo.move | test.rollo.stop

-> the value if item "test.rollo.manuell" will be inverted on every change if test.rollo.move or test.rollo.stop unless the change came from the Initialization (caller="Init", any source) or the chance came from a certain KNX device (caller="KNX", source="1.1.7" (physical address)).

In order to access the main AutoBlind-Class from eval ("sh.return_plugin("AutoBlind")"), a change in smarthome.py is required which is documented in pull request #181 on github (mknx/smarthome#181)
@ohinckel
Copy link

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

@thernst-de thernst-de closed this by deleting the head repository Feb 5, 2023
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

2 participants