time.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import constants
  2. from packet import Packet
  3. class Time(object):
  4. """Class for setting and accessing the time."""
  5. def call(self):
  6. """Call time for insertion into a TEXT file.
  7. :returns: formatted string to use in a TEXT
  8. :rtype: string
  9. """
  10. return "\x13"
  11. def set(self, hour=None, minute=None):
  12. """Sets the hour and minute of the internal clock on the sign.
  13. If the time is not specified in the arguments, the time now will be used.
  14. :param hour: hour in 24-hour format (18 instead of 6 for 6PM)
  15. :param minute: minute (0 - 59)
  16. :rtype: :class:`alphasign.packet.Packet` object
  17. """
  18. now = datetime.datetime.today()
  19. if hour is None:
  20. hour = now.hour
  21. if minute is None:
  22. minute = now.minute
  23. packet = Packet("%s%s%02d%02d" % (constants.WRITE_SPECIAL, "\x20",
  24. hour, minute))
  25. return packet
  26. def set_format(self, format=1):
  27. """Sets the time format on the sign.
  28. :param format: 1 - 24-hour (military) time;
  29. 0 - 12-hour (standard AM/PM) format
  30. :rtype: :class:`alphasign.packet.Packet` object
  31. """
  32. if format < 0 or format > 1:
  33. format = 1
  34. byte = (format == 0) and "S" or "M"
  35. packet = Packet("%s%s%s" % (constants.WRITE_SPECIAL, "\x27", byte))
  36. return packet