Exemple #1
0
 def fromJSON(cls, data):
   """Create a timer initiator from a JSON-decoded struture."""
   if "begin_year_day" not in data and "begin_date" in data:
     data["begin_year_day"] = utils.datestring_to_x10_year_day(data["begin_date"])
   if "end_year_day" not in data and "end_date" in data:
     data["end_year_day"] = utils.datestring_to_x10_year_day(data["end_date"])
   def setTimes(key):
     timeSpec = data.get("%(key)s_time" % locals())
     # TODO: test null start/stop times
     if timeSpec is not None:
       data["%(key)s_double_hour" % locals()], data["%(key)s_min" % locals()] = utils.timespec_to_x10_time(timeSpec, True)
   setTimes("start")
   setTimes("stop")
   data["week_day_mask"] = utils.string_to_week_mask(data["week_day_mask"])
         
   return cls(codec.TIMER_INITIATOR.createDataMap(data))
Exemple #2
0
 def __init__(self, bytes=None, offset=0, data=None):
   if bytes is not None:
     super(self.__class__, self).__init__(bytes, offset)
     data = codec.MACRO_INITIATOR_CLAUSE_BODY_DATE_TYPE.decode(bytes, 1+offset)
   else:
     data = dict(data)
     super(self.__class__, self).__init__(data=data)
     if "year_day" not in data:
       if "date" in data:
         data["year_day"] = utils.datestring_to_x10_year_day(data["date"])
       else:
         raise UnsuitableDataException()
     data = codec.MACRO_INITIATOR_CLAUSE_BODY_DATE_TYPE.createDataMap(data)
   vars(self).update(data)
   self.codelength = codec.MACRO_INITIATOR_CLAUSE_HEADER.codelength + codec.MACRO_INITIATOR_CLAUSE_BODY_DATE_TYPE.codelength