summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sleekxmpp/plugins/__init__.py1
-rw-r--r--sleekxmpp/plugins/xep_0323/__init__.py18
-rw-r--r--sleekxmpp/plugins/xep_0323/sensordata.py65
l---------sleekxmpp/plugins/xep_0323/stanza/.#sensordata.py1
-rw-r--r--sleekxmpp/plugins/xep_0323/stanza/__init__.py12
-rw-r--r--sleekxmpp/plugins/xep_0323/stanza/base.py12
-rw-r--r--sleekxmpp/plugins/xep_0323/stanza/sensordata.py64
-rwxr-xr-xtestall.py20
-rw-r--r--tests/test_stanza_xep_0323.py57
9 files changed, 247 insertions, 3 deletions
diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py
index 36fb6dad..10a79439 100644
--- a/sleekxmpp/plugins/__init__.py
+++ b/sleekxmpp/plugins/__init__.py
@@ -79,4 +79,5 @@ __all__ = [
'xep_0302', # XMPP Compliance Suites 2012
'xep_0308', # Last Message Correction
'xep_0313', # Message Archive Management
+ 'xep_0323', # IoT Sensor Data
]
diff --git a/sleekxmpp/plugins/xep_0323/__init__.py b/sleekxmpp/plugins/xep_0323/__init__.py
new file mode 100644
index 00000000..e4e2d0ee
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0323/__init__.py
@@ -0,0 +1,18 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Implementation of xeps for Internet of Things
+ http://wiki.xmpp.org/web/Tech_pages/IoT_systems
+ Copyright (C) 2013 Joachim Lindborg, Joachim.lindborg@lsys.se
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp.plugins.base import register_plugin
+
+from sleekxmpp.plugins.xep_0323.sensordata import XEP_0323
+from sleekxmpp.plugins.xep_0323 import stanza
+
+register_plugin(XEP_0323)
+
+xep_0323=XEP_0323
diff --git a/sleekxmpp/plugins/xep_0323/sensordata.py b/sleekxmpp/plugins/xep_0323/sensordata.py
new file mode 100644
index 00000000..1343069d
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0323/sensordata.py
@@ -0,0 +1,65 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Implementation of xeps for Internet of Things
+ http://wiki.xmpp.org/web/Tech_pages/IoT_systems
+ Copyright (C) 2013 Joachim Lindborg, Joachim.lindborg@lsys.se
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+import logging
+
+from sleekxmpp.xmlstream import JID
+from sleekxmpp.xmlstream.handler import Callback
+from sleekxmpp.xmlstream.matcher import StanzaPath
+from sleekxmpp.plugins.base import BasePlugin
+from sleekxmpp.plugins.xep_0323 import stanza
+
+
+log = logging.getLogger(__name__)
+
+
+class XEP_0323(BasePlugin):
+
+ """
+ XEP-0323 IoT Sensor Data
+ """
+
+ name = 'xep_0323'
+ description = 'XEP-0323 Internet of Things - Sensor Data'
+ dependencies = set(['xep_0030']) # set(['xep_0030', 'xep_0004', 'xep_0082', 'xep_0131'])
+ stanza = stanza
+
+ def plugin_init(self):
+ pass
+ # self.node_event_map = {}
+
+ # self.xmpp.register_handler(
+ # Callback('Sensordata Event: Get',
+ # StanzaPath('message/sensordata_event/get'),
+ # self._handle_event_get))
+
+ def plugin_end(self):
+ # self.xmpp.remove_handler('Sensordata Event: Get')
+ pass
+
+ def get_value(self, jid, msg):
+ """
+ Recieving a stanza for erading values
+ # verify provisioning
+
+ # verify requested values and categories
+
+ # Send accepted
+ # Thread of the readout
+
+ # send started
+
+ # send data messages
+
+ # send done
+ """
+ pass
+
+
diff --git a/sleekxmpp/plugins/xep_0323/stanza/.#sensordata.py b/sleekxmpp/plugins/xep_0323/stanza/.#sensordata.py
new file mode 120000
index 00000000..c6761e8f
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0323/stanza/.#sensordata.py
@@ -0,0 +1 @@
+jocke@Joachim-Lindborg.local.29709 \ No newline at end of file
diff --git a/sleekxmpp/plugins/xep_0323/stanza/__init__.py b/sleekxmpp/plugins/xep_0323/stanza/__init__.py
new file mode 100644
index 00000000..82dc9eea
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0323/stanza/__init__.py
@@ -0,0 +1,12 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Implementation of xeps for Internet of Things
+ http://wiki.xmpp.org/web/Tech_pages/IoT_systems
+ Copyright (C) 2013 Joachim Lindborg, Joachim.lindborg@lsys.se
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp.plugins.xep_0323.stanza.sensordata import *
+
diff --git a/sleekxmpp/plugins/xep_0323/stanza/base.py b/sleekxmpp/plugins/xep_0323/stanza/base.py
new file mode 100644
index 00000000..4caf07b2
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0323/stanza/base.py
@@ -0,0 +1,12 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+
+ Implementation of xeps for Internet of Things
+ http://wiki.xmpp.org/web/Tech_pages/IoT_systems
+ Copyright (C) 2013 Joachim Lindborg, Joachim.lindborg@lsys.se
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp.xmlstream import ET
+
+pass
diff --git a/sleekxmpp/plugins/xep_0323/stanza/sensordata.py b/sleekxmpp/plugins/xep_0323/stanza/sensordata.py
new file mode 100644
index 00000000..9567ef87
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0323/stanza/sensordata.py
@@ -0,0 +1,64 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Implementation of xeps for Internet of Things
+ http://wiki.xmpp.org/web/Tech_pages/IoT_systems
+ Copyright (C) 2013 Joachim Lindborg, Joachim.lindborg@lsys.se
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp import Iq, Message
+from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
+
+
+class Sensordata(ElementBase):
+ namespace = 'http://xmpp.org/iot/sensordata'
+ name = 'sensordata'
+ plugin_attrib = name
+ interfaces = set(tuple())
+
+class Request(ElementBase):
+ namespace = 'http://xmpp.org/iot/sensordata'
+ name = 'req'
+ plugin_attrib = name
+ interfaces = set(('seqnr','momentary'))
+
+
+class Accepted(ElementBase):
+ namespace = 'http://xmpp.org/iot/sensordata'
+ name = 'accepted'
+ plugin_attrib = name
+ interfaces = set(('seqnr'))
+
+
+class Failure(ElementBase):
+ namespace = 'http://xmpp.org/iot/sensordata'
+ name = 'failure'
+ plugin_attrib = name
+ interfaces = set(('seqnr','done'))
+
+
+
+register_stanza_plugin(Iq, Sensordata)
+register_stanza_plugin(Sensordata, Request)
+register_stanza_plugin(Sensordata, Accepted)
+register_stanza_plugin(Sensordata, Failure)
+# register_stanza_plugin(Pubsub, Default)
+# register_stanza_plugin(Pubsub, Items)
+# register_stanza_plugin(Pubsub, Options)
+# register_stanza_plugin(Pubsub, Publish)
+# register_stanza_plugin(Pubsub, PublishOptions)
+# register_stanza_plugin(Pubsub, Retract)
+# register_stanza_plugin(Pubsub, Subscribe)
+# register_stanza_plugin(Pubsub, Subscription)
+# register_stanza_plugin(Pubsub, Subscriptions)
+# register_stanza_plugin(Pubsub, Unsubscribe)
+# register_stanza_plugin(Affiliations, Affiliation, iterable=True)
+# register_stanza_plugin(Configure, xep_0004.Form)
+# register_stanza_plugin(Items, Item, iterable=True)
+# register_stanza_plugin(Publish, Item, iterable=True)
+# register_stanza_plugin(Retract, Item)
+# register_stanza_plugin(Subscribe, Options)
+# register_stanza_plugin(Subscription, SubscribeOptions)
+# register_stanza_plugin(Subscriptions, Subscription, iterable=True)
diff --git a/testall.py b/testall.py
index c9ad5448..6685b8a1 100755
--- a/testall.py
+++ b/testall.py
@@ -2,15 +2,18 @@
import os
import sys
+sys.path=['/Users/jocke/Dropbox/06_dev/SleekXMPP']+sys.path
+
import logging
import unittest
import distutils.core
+
from glob import glob
from os.path import splitext, basename, join as pjoin
-def run_tests():
+def run_tests(exlude=None, include=[]):
"""
Find and run all tests in the tests/ directory.
@@ -22,7 +25,18 @@ def run_tests():
if True not in [t.endswith(ex) for ex in exclude]:
if basename(t).startswith('test_'):
testfiles.append('tests.%s' % splitext(basename(t))[0])
-
+ testsToUse=[]
+ if not(include==[]):
+ # use only test that has any text include in them
+ for match in include:
+ for test in testfiles:
+ if test.find(match)>-1:
+ # add the test'
+ # print "REMOVE "+match + " test " + test + " " + str(test.find(match))
+ testsToUse.append(test)
+
+
+ testfiles=testsToUse
suites = []
for file in testfiles:
__import__(file)
@@ -56,7 +70,7 @@ class TestCommand(distutils.core.Command):
if __name__ == '__main__':
- result = run_tests()
+ result = run_tests(include=['323'])
print("<tests %s ran='%s' errors='%s' fails='%s' success='%s' />" % (
"xmlns='http//andyet.net/protocol/tests'",
result.testsRun, len(result.errors),
diff --git a/tests/test_stanza_xep_0323.py b/tests/test_stanza_xep_0323.py
new file mode 100644
index 00000000..a052fced
--- /dev/null
+++ b/tests/test_stanza_xep_0323.py
@@ -0,0 +1,57 @@
+from sleekxmpp.test import *
+import sleekxmpp.plugins.xep_0323 as xep_0323
+
+namespace='sn'
+
+class TestChatStates(SleekTest):
+
+
+ def setUp(self):
+ register_stanza_plugin(Message, xep_0323.stanza.Request)
+ register_stanza_plugin(Message, xep_0323.stanza.Accepted)
+ register_stanza_plugin(Message, xep_0323.stanza.Failure)
+ # register_stanza_plugin(Message, xep_0323.stanza.Result)
+ # register_stanza_plugin(Message, xep_0323.stanza.Gone)
+ # register_stanza_plugin(Message, xep_0323.stanza.Inactive)
+ # register_stanza_plugin(Message, xep_0323.stanza.Paused)
+
+ def testRequest(self):
+ """
+ test of request stanza
+ """
+ iq = self.Iq()
+ iq['type'] = 'get'
+ iq['id'] = '1'
+ iq['sensordata']['req']['seqnr'] = '1'
+ iq['sensordata']['req']['momentary'] = 'true'
+
+ self.check(iq,"""
+ """
+ )
+
+ def testAccepted(self):
+ """
+ test of request stanza
+ """
+ iq = self.Iq()
+ iq['type'] = 'result'
+ iq['id'] = '2'
+ iq['sensordata']['accepted']['seqnr'] = '2'
+
+ print(str(iq))
+ self.check(iq,"""
+ """
+ )
+
+ def testReadOutMomentary_multiple(self):
+ """
+ test of reading momentary value from a nde with multiple responses
+ """
+ iq = self.Iq()
+ print(str(iq))
+
+ self.check(iq,"""
+ """
+ )
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates)