added disco imformation, fixed some bugs in device
This commit is contained in:
parent
c85f2494a8
commit
8fd3781ef5
@ -9,6 +9,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
class Device(object):
|
class Device(object):
|
||||||
"""
|
"""
|
||||||
@ -20,16 +21,17 @@ class Device(object):
|
|||||||
request_fields
|
request_fields
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, nodeId):
|
def __init__(self, nodeId, fields={}):
|
||||||
self.nodeId = nodeId;
|
self.nodeId = nodeId
|
||||||
self.fields = {};
|
self.fields = fields # see fields described below
|
||||||
# {'type':'numeric',
|
# {'type':'numeric',
|
||||||
# 'name':'myname',
|
# 'name':'myname',
|
||||||
# 'value': 42,
|
# 'value': 42,
|
||||||
# 'unit':'Z'}];
|
# 'unit':'Z'}];
|
||||||
self.timestamp_data = {};
|
self.timestamp_data = {}
|
||||||
self.momentary_data = {};
|
self.momentary_data = {}
|
||||||
self.momentary_timestamp = "";
|
self.momentary_timestamp = ""
|
||||||
|
logging.debug("Device object started nodeId %s",nodeId)
|
||||||
|
|
||||||
def has_field(self, field):
|
def has_field(self, field):
|
||||||
"""
|
"""
|
||||||
@ -38,9 +40,17 @@ class Device(object):
|
|||||||
Arguments:
|
Arguments:
|
||||||
field -- The field name
|
field -- The field name
|
||||||
"""
|
"""
|
||||||
if field in self.fields:
|
if field in self.fields.keys():
|
||||||
return True;
|
return True;
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
|
def refresh(self, fields):
|
||||||
|
"""
|
||||||
|
override method to do the refresh work
|
||||||
|
refresh values from hardware or other
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def request_fields(self, fields, flags, session, callback):
|
def request_fields(self, fields, flags, session, callback):
|
||||||
"""
|
"""
|
||||||
@ -85,20 +95,22 @@ class Device(object):
|
|||||||
Error details when a request failed.
|
Error details when a request failed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
logging.debug("request_fields called looking for fields %s",fields)
|
||||||
if len(fields) > 0:
|
if len(fields) > 0:
|
||||||
# Check availiability
|
# Check availiability
|
||||||
for f in fields:
|
for f in fields:
|
||||||
if f not in self.fields:
|
if f not in self.fields.keys():
|
||||||
self._send_reject(session, callback)
|
self._send_reject(session, callback)
|
||||||
return False;
|
return False;
|
||||||
else:
|
else:
|
||||||
# Request all fields
|
# Request all fields
|
||||||
fields = self.fields;
|
fields = self.fields.keys();
|
||||||
|
|
||||||
|
|
||||||
# Refresh data from device
|
# Refresh data from device
|
||||||
# ...
|
# ...
|
||||||
|
logging.debug("about to refresh device fields %s",fields)
|
||||||
|
self.refresh(fields)
|
||||||
|
|
||||||
if "momentary" in flags and flags['momentary'] == "true" or \
|
if "momentary" in flags and flags['momentary'] == "true" or \
|
||||||
"all" in flags and flags['all'] == "true":
|
"all" in flags and flags['all'] == "true":
|
||||||
@ -114,11 +126,11 @@ class Device(object):
|
|||||||
for f in self.momentary_data:
|
for f in self.momentary_data:
|
||||||
if f in fields:
|
if f in fields:
|
||||||
field_block.append({"name": f,
|
field_block.append({"name": f,
|
||||||
"type": self.fields[f]["type"],
|
"type": self.fields[f]["type"],
|
||||||
"unit": self.fields[f]["unit"],
|
"unit": self.fields[f]["unit"],
|
||||||
"dataType": self.fields[f]["dataType"],
|
"dataType": self.fields[f]["dataType"],
|
||||||
"value": self.momentary_data[f]["value"],
|
"value": self.momentary_data[f]["value"],
|
||||||
"flags": self.momentary_data[f]["flags"]});
|
"flags": self.momentary_data[f]["flags"]});
|
||||||
ts_block["timestamp"] = timestamp;
|
ts_block["timestamp"] = timestamp;
|
||||||
ts_block["fields"] = field_block;
|
ts_block["fields"] = field_block;
|
||||||
|
|
||||||
@ -145,11 +157,11 @@ class Device(object):
|
|||||||
for f in self.timestamp_data[ts]:
|
for f in self.timestamp_data[ts]:
|
||||||
if f in fields:
|
if f in fields:
|
||||||
field_block.append({"name": f,
|
field_block.append({"name": f,
|
||||||
"type": self.fields[f]["type"],
|
"type": self.fields[f]["type"],
|
||||||
"unit": self.fields[f]["unit"],
|
"unit": self.fields[f]["unit"],
|
||||||
"dataType": self.fields[f]["dataType"],
|
"dataType": self.fields[f]["dataType"],
|
||||||
"value": self.timestamp_data[ts][f]["value"],
|
"value": self.timestamp_data[ts][f]["value"],
|
||||||
"flags": self.timestamp_data[ts][f]["flags"]});
|
"flags": self.timestamp_data[ts][f]["flags"]});
|
||||||
|
|
||||||
ts_block["timestamp"] = ts;
|
ts_block["timestamp"] = ts;
|
||||||
ts_block["fields"] = field_block;
|
ts_block["fields"] = field_block;
|
||||||
@ -208,7 +220,7 @@ class Device(object):
|
|||||||
flags -- [optional] data classifier flags for the field, e.g. momentary
|
flags -- [optional] data classifier flags for the field, e.g. momentary
|
||||||
Formatted as a dictionary like { "flag name": "flag value" ... }
|
Formatted as a dictionary like { "flag name": "flag value" ... }
|
||||||
"""
|
"""
|
||||||
if not name in self.fields:
|
if not name in self.fields.keys():
|
||||||
return False;
|
return False;
|
||||||
if not timestamp in self.timestamp_data:
|
if not timestamp in self.timestamp_data:
|
||||||
self.timestamp_data[timestamp] = {};
|
self.timestamp_data[timestamp] = {};
|
||||||
@ -226,7 +238,7 @@ class Device(object):
|
|||||||
flags -- [optional] data classifier flags for the field, e.g. momentary
|
flags -- [optional] data classifier flags for the field, e.g. momentary
|
||||||
Formatted as a dictionary like { "flag name": "flag value" ... }
|
Formatted as a dictionary like { "flag name": "flag value" ... }
|
||||||
"""
|
"""
|
||||||
if self.fields[name] is None:
|
if not self.fields.has_key(name):
|
||||||
return False;
|
return False;
|
||||||
if flags is None:
|
if flags is None:
|
||||||
flags = {};
|
flags = {};
|
||||||
|
@ -174,6 +174,12 @@ class XEP_0323(BasePlugin):
|
|||||||
""" Return a new session ID. """
|
""" Return a new session ID. """
|
||||||
return str(time.time()) + '-' + self.xmpp.new_id()
|
return str(time.time()) + '-' + self.xmpp.new_id()
|
||||||
|
|
||||||
|
def session_bind(self, jid):
|
||||||
|
logging.debug("setting the Disco discovery for %s" % Sensordata.namespace)
|
||||||
|
self.xmpp['xep_0030'].add_feature(Sensordata.namespace)
|
||||||
|
self.xmpp['xep_0030'].set_items(node=Sensordata.namespace, items=tuple())
|
||||||
|
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
""" Stop the XEP-0323 plugin """
|
""" Stop the XEP-0323 plugin """
|
||||||
self.sessions.clear();
|
self.sessions.clear();
|
||||||
@ -184,7 +190,6 @@ class XEP_0323(BasePlugin):
|
|||||||
self.xmpp.remove_handler('Sensordata Event:Cancelled')
|
self.xmpp.remove_handler('Sensordata Event:Cancelled')
|
||||||
self.xmpp.remove_handler('Sensordata Event:Fields')
|
self.xmpp.remove_handler('Sensordata Event:Fields')
|
||||||
self.xmpp['xep_0030'].del_feature(feature=Sensordata.namespace)
|
self.xmpp['xep_0030'].del_feature(feature=Sensordata.namespace)
|
||||||
self.xmpp['xep_0030'].set_items(node=Sensordata.namespace, items=tuple());
|
|
||||||
|
|
||||||
|
|
||||||
# =================================================================
|
# =================================================================
|
||||||
|
@ -1 +0,0 @@
|
|||||||
jocke@Joachim-Lindborg.local.29709
|
|
Loading…
x
Reference in New Issue
Block a user