Message timestamp refactored

This commit is contained in:
Fabio Manganiello 2018-10-08 13:30:00 +00:00
parent 948f3dc37d
commit 68aaf9cd61
4 changed files with 7 additions and 3 deletions

View file

@ -9,6 +9,9 @@ logger = logging.getLogger(__name__)
class Message(object):
""" Message generic class """
def __init__(self, timestamp=None, *args, **kwargs):
self.timestamp = timestamp or time.time()
def __str__(self):
"""
Overrides the str() operator and converts

View file

@ -23,13 +23,13 @@ class Event(Message):
kwargs -- Additional arguments for the event [kwDict]
"""
super().__init__(timestamp=timestamp)
self.id = id if id else self._generate_id()
self.target = target if target else Config.get('device_id')
self.origin = origin if origin else Config.get('device_id')
self.type = '{}.{}'.format(self.__class__.__module__,
self.__class__.__name__)
self.args = kwargs
self.timestamp = timestamp or time.time()
@classmethod
def build(cls, msg):

View file

@ -35,6 +35,8 @@ class Request(Message):
timestamp -- Message creation timestamp [Float]
"""
super().__init__(timestamp=timestamp)
self.id = id if id else self._generate_id()
self.target = target
self.action = action
@ -42,7 +44,6 @@ class Request(Message):
self.args = args if args else {}
self.backend = backend
self.token = token
self.timestamp = timestamp or time.time()
@classmethod
def build(cls, msg):

View file

@ -18,11 +18,11 @@ class Response(Message):
timestamp -- Message timestamp [Float]
"""
super().__init__(timestamp=timestamp)
self.target = target
self.output = self._parse_msg(output)
self.errors = self._parse_msg(errors)
self.origin = origin
self.timestamp = timestamp or time.time()
self.id = id
def is_error(self):