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

Make it possible to attach items to a given plugin #53

Closed
wants to merge 7 commits into from

Conversation

ohinckel
Copy link
Member

(copied from mknx/smarthome#83)

Hint: this pull requests depends on the new functionality introduced in pull request #81 (plugin methods), which should be merged first.

With this patch it will be possible to restrict the item attachment to a given plugin. This is useful when you have registered a plugin multiple times.

E.g. having something like this in plugin.conf which configures the KNX plugin for two environments (it's just an example, don't know if it works this way):

[knx1]
  class_name = KNX
  class_path = plugins.knx
  host = myhome.dyndns.org
  ...
[knx2]
   class_name = KNX
   class_path = plugins.knx
   host = otherhome.dyndns.org

Attaching the different items to the different plugin is now possible using this in items.conf:

[home1]
  [[light]]
    plugin = knx1
    knx_addr = 1/0/1
[home2]
  [[light]]
    plugin = knx2
    knx_addr = 1/0/1

This will only attach the item home1.light to the KNX plugin instance knx1 and home2.light to the plugin instance knx2 to make it possible to use two completely different environments using two different KNX devices (e.g. eibd on different hosts).

Notice that when using the plugin setting, only the plugins are skipped using the same plugin class. All other plugin will be attached too. So when having multiple KNX plugin instance configured (knx1 and knx2) and using plugin = knx1, only the plugin instance knx2 will be skipped. Other plugins (like SQLite or DBLog or anything else which could be used too) will be attached too. So it depends on the plugin`s class!

I don't know if SmartHome.py was designed to register a plugin multiple times, but it seems it's not forbidden at the moment. Registering a plugin two times could also solve the problem "How to use two different devices when a plugin can only handle one device?" - e.g. using two power meter devices with the SML plugin (see also my comment in pull request #63).

Further I commited a change to the plugin setup:

  • when not using plugin setting, all plugin will be attached as before (by inspecting the items configuration)
  • when using plugin setting, it works like above except that the plugins using the same class as the plugins configured will be skipped

Examples: having DBLog (dblog), SQLite (sqlite) and KNX (knx1, 'knx2`) plugins configured:

  • plugin = ... setting not used in item: all plugins will be attached
  • plugin = knx1 setting in item: only dblog, sqlite (both because class not listed in plugin setting) and knx1 will be attached (because KNX class listed in plugin setting)
  • plugin = knx1|knx2 setting in item: all plugins will be attched (the KNX plugins are listed explicitely, so they will be configured of course)

  and get_plugin_ident() to return the thead ident for a given plugin
  instance
…pdates) to

  a given plugin
# useful when registering a plugin multiple time with different names
  . configure all plugins not listed in the plugin setting
  . skip plugins of the same class of listed plugins in plugin settings
@cstrassburg
Copy link
Member

thanks for the pr, but binding a whole item is not fine enough. If you use two 1-wire and knx plugins and bind a knx and 1-wire to the item your solution does not work.

@cstrassburg
Copy link
Member

become obsolete by plugin multi instance implementation

@ohinckel
Copy link
Member Author

Attaching multiple different plugins to one item is also supported by this patch. Only attaching multiple plugins with the same class is not supported (but is this really useful - I think no).

Further you do not need the magic "setting@plugin" syntax and can use the attributes like before (still I don't like the has_iattr() and get_iattr_value() methods since it is IMHO a litle bit too much boilerplate - but this is another discussion).

And this patch will also only invoke the parse_plugin method of attached plugin and not of all plugins.

At least your solution is flexible when different plugins are using the same configuration setting. You can then use "ip@plugin1 = ...." and "ip@plugin2 = ...".

@ohinckel ohinckel deleted the dev-plugin-items branch December 23, 2016 18:01
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