A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
854 B

  1. import datetime
  2. try:
  3. from reprlib import repr
  4. except ImportError:
  5. from repr import repr
  6. class BaseMessage(object):
  7. """
  8. Base class for messages.
  9. """
  10. raw = None
  11. """The raw message text"""
  12. timestamp = None
  13. """The timestamp of the message"""
  14. def __init__(self, data=None):
  15. """
  16. Constructor
  17. """
  18. self.timestamp = datetime.datetime.now()
  19. self.raw = data
  20. def __str__(self):
  21. """
  22. String conversion operator.
  23. """
  24. return self.raw
  25. def dict(self, **kwargs):
  26. """
  27. Dictionary representation.
  28. """
  29. return dict(
  30. time=self.timestamp,
  31. mesg=self.raw,
  32. **kwargs
  33. )
  34. def __repr__(self):
  35. """
  36. String representation.
  37. """
  38. return repr(self.dict())