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 #50

Closed
wants to merge 9 commits into from
9 changes: 9 additions & 0 deletions bin/smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ def return_plugins(self):
for plugin in self._plugins:
yield plugin

def return_plugin(self, name):
return self._plugins.get_plugin(name)

def get_plugin_ident(self, plugin):
return self._plugins.get_plugin_ident(plugin)

def get_plugin_name(self, plugin):
return self._plugins.get_plugin_name(plugin)

#################################################################
# Logic Methods
#################################################################
Expand Down
17 changes: 17 additions & 0 deletions lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ def __iter__(self):
for plugin in self._plugins:
yield plugin

def get_plugin(self, name):
for thread in self._threads:
if thread.name == name:
return thread.plugin
return None

def get_plugin_ident(self, plugin):
for thread in self._threads:
if thread.plugin == plugin:
return thread.ident
return None

def get_plugin_name(self, plugin):
for thread in self._threads:
if thread.plugin == plugin:
return thread.name

def start(self):
logger.info('Start Plugins')
for plugin in self._threads:
Expand Down
31 changes: 31 additions & 0 deletions plugins/sml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ Description of the attributes:
* `host` - instead of serial port you can use a network connection
* `port` - additionally to the host configuration you can specify a port

If you have more then one power meter device or serial device in use,
please configure this plugin multiple times and restrict the items to
the different plugin instances using the `plugin` setting:

<pre>
[sml1]
class_name = Sml
class_path = plugins.sml
serialport = /dev/ttyUSB0

[sml2]
class_name = Sml
class_path = plugins.sml
serialport = /dev/ttyUSB1
</pre>

<pre>
[power]
[[home]]
[[[total]]]
type = num
plugin = sml1
sml_obis = 1-0:1.8.0*255
[[pv]]
[[[total]]]
type = num
plugin = sml2
sml_obis = 1-0:1.8.0*255
</pre>


## items.conf

You can assign a value retrieved by the plugin to some of your items
Expand Down
3 changes: 2 additions & 1 deletion plugins/sml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import logging
import time
import socket
import re
import serial
import threading
Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(self, smarthome, host=None, port=0, serialport=None, cycle=300):

def run(self):
self.alive = True
self._sh.scheduler.add('Sml', self._refresh, cycle=self.cycle)
self._sh.scheduler.add('Sml-' + str(self._sh.get_plugin_name(self)), self._refresh, cycle=self.cycle)

def stop(self):
self.alive = False
Expand Down