Fix some bugs.

- Commandreplies format their timestamp like events

Change-Id: I388b9f26bb8b0234d9209b05732e98f9ce1d01c7
This commit is contained in:
Enrico Faulhaber
2016-12-21 16:59:32 +01:00
parent 78bb3b5f96
commit 68f73b5aa1
4 changed files with 39 additions and 21 deletions

View File

@ -241,13 +241,8 @@ class Dispatcher(object):
# note: exceptions are handled in handle_request, not here!
func = getattr(moduleobj, 'do' + command)
res = func(*arguments)
res = CommandReply(
module=modulename,
command=command,
result=[
res,
dict(
t=time.time())])
res = CommandReply(module=modulename, command=command,
result=res, qualifiers=dict(t=time.time()))
# res = Value(modulename, command=command, value=func(*arguments), t=time.time())
return res

View File

@ -76,6 +76,12 @@ ERRORCLASSES = ['NoSuchDevice', 'NoSuchParameter', 'NoSuchCommand',
# starts with another
def encode_cmd_result(msgobj):
q = msgobj.qualifiers.copy()
if 't' in q:
q['t'] = format_time(q['t'])
return msgobj.result, q
def encode_value_data(vobj):
q = vobj.qualifiers.copy()
if 't' in q:
@ -95,7 +101,7 @@ class DemoEncoder(MessageEncoder):
DeactivateRequest: (DISABLEEVENTSREQUEST,),
DeactivateReply: (DISABLEEVENTSREPLY,),
CommandRequest: (COMMANDREQUEST, lambda msg: "%s:%s" % (msg.module, msg.command), 'arguments',),
CommandReply: (COMMANDREPLY, lambda msg: "%s:%s" % (msg.module, msg.command), 'result',),
CommandReply: (COMMANDREPLY, lambda msg: "%s:%s" % (msg.module, msg.command), encode_cmd_result,),
WriteRequest: (WRITEREQUEST, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, 'value',),
WriteReply: (WRITEREPLY, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, 'value',),
PollRequest: (TRIGGERREQUEST, lambda msg: "%s:%s" % (msg.module, msg.parameter) if msg.parameter else msg.module, ),

View File

@ -28,6 +28,7 @@ class Message(object):
is_request = False
is_reply = False
is_error = False
qualifiers = {}
def __init__(self, **kwds):
self.ARGS = set()