示例#1
0
 def __date_time_range(self, request):
     try:
         dtVal = request.get_value(TimerModule._PARAM_DT_RANGE.get_kbx_param_name())
         startDateTime = dtVal.get_start_date_time()
         endDateTime = dtVal.get_end_date_time()
         
         execTime = request.get_arg(AppConstants.KEY_CONDITION_TIMESTAMP)
         execTime = int(execTime)
         
         if execTime > endDateTime:
             # Allow a time delta of 59 seconds
             response = bool(abs(execTime - endDateTime) <= 59)
         else:
             response =  bool(startDateTime <= execTime <= endDateTime)
         
         if not response:
             raise AutomationException(11800)
             
         self.send_response({}, request.requestId)
     except AutomationException as ae:
         Logger.log_error("TimerModule date_time range failed on comparison:", str(ae))
         self.send_response({}, request.requestId, ae.get_error_code(), ae.get_error_message())
     except Exception as e:
         Logger.log_error("TimerModule date_time range failed on comparison (unexpected):", str(e))
         ae = AutomationException(11099, str(e))
         self.send_response({}, request.requestId, ae.get_error_code(), ae.get_error_message())
示例#2
0
    def __day_of_week(self, request):
        try:
            dows = request.get_value(
                TimerModule._PARAM_DOW.get_kbx_param_name())

            execTime = request.get_arg(AppConstants.KEY_CONDITION_TIMESTAMP)
            execTime = datetime.datetime.fromtimestamp(execTime)
            execDow = execTime.isoweekday() % 7

            response = bool(execDow in dows)

            if not response:
                raise AutomationException(11800)

            self.send_response({}, request.requestId)
        except AutomationException as ae:
            Logger.log_error("TimerModule day_of_week failed on comparison:",
                             str(ae))
            self.send_response({}, request.requestId, ae.get_error_code(),
                               ae.get_error_message())
        except Exception as e:
            Logger.log_error(
                "TimerModule day_of_week failed on comparison (unexpected):",
                str(e))
            ae = AutomationException(11099, str(e))
            self.send_response({}, request.requestId, ae.get_error_code(),
                               ae.get_error_message())
示例#3
0
    def __date_time_range(self, request):
        try:
            dtVal = request.get_value(
                TimerModule._PARAM_DT_RANGE.get_kbx_param_name())
            startDateTime = dtVal.get_start_date_time()
            endDateTime = dtVal.get_end_date_time()

            execTime = request.get_arg(AppConstants.KEY_CONDITION_TIMESTAMP)
            execTime = int(execTime)

            if execTime > endDateTime:
                # Allow a time delta of 59 seconds
                response = bool(abs(execTime - endDateTime) <= 59)
            else:
                response = bool(startDateTime <= execTime <= endDateTime)

            if not response:
                raise AutomationException(11800)

            self.send_response({}, request.requestId)
        except AutomationException as ae:
            Logger.log_error(
                "TimerModule date_time range failed on comparison:", str(ae))
            self.send_response({}, request.requestId, ae.get_error_code(),
                               ae.get_error_message())
        except Exception as e:
            Logger.log_error(
                "TimerModule date_time range failed on comparison (unexpected):",
                str(e))
            ae = AutomationException(11099, str(e))
            self.send_response({}, request.requestId, ae.get_error_code(),
                               ae.get_error_message())
示例#4
0
    def __time_range(self, request):
        try:
            try:
                tVal = request.get_value(
                    TimerModule._PARAM_TIME_RANGE.get_kbx_param_name())
                startTime = tVal.get_start_time()
                endTime = tVal.get_end_time()
            except:
                # Backward compatible to daily_task
                kbxTime = KBXTime(kbxParamName="time")
                startTime = endTime = kbxTime.cast(request.get_arg("time"))

            execTime = request.get_arg(AppConstants.KEY_CONDITION_TIMESTAMP)
            execTime = datetime.datetime.fromtimestamp(execTime)
            execTime = (execTime.hour * 3600) + (execTime.minute *
                                                 60) + (execTime.second)

            if endTime < startTime:
                checkRange = [(startTime, 86400), (0, endTime + 59)]
            else:
                checkRange = [(startTime, endTime + 59)]

            for startVal, endVal in checkRange:
                if startVal <= execTime <= endVal:
                    response = True
                    break
            else:
                response = False

            if not response:
                raise AutomationException(11800)

            self.send_response({}, request.requestId)
        except AutomationException as ae:
            Logger.log_error("TimerModule time range failed on comparison:",
                             str(ae))
            self.send_response({}, request.requestId, ae.get_error_code(),
                               ae.get_error_message())
        except Exception as e:
            Logger.log_error(
                "TimerModule time range failed on comparison (unexpected):",
                str(e))
            ae = AutomationException(11099, str(e))
            self.send_response({}, request.requestId, ae.get_error_code(),
                               ae.get_error_message())
示例#5
0
 def __day_of_week(self, request):
     try:
         dows = request.get_value(TimerModule._PARAM_DOW.get_kbx_param_name())
         
         execTime = request.get_arg(AppConstants.KEY_CONDITION_TIMESTAMP)
         execTime = datetime.datetime.fromtimestamp(execTime)
         execDow = execTime.isoweekday() % 7
         
         response = bool(execDow in dows)
         
         if not response:
             raise AutomationException(11800)
         
         self.send_response({}, request.requestId)
     except AutomationException as ae:
         Logger.log_error("TimerModule day_of_week failed on comparison:", str(ae))
         self.send_response({}, request.requestId, ae.get_error_code(), ae.get_error_message())
     except Exception as e:
         Logger.log_error("TimerModule day_of_week failed on comparison (unexpected):", str(e))
         ae = AutomationException(11099, str(e))
         self.send_response({}, request.requestId, ae.get_error_code(), ae.get_error_message())
示例#6
0
 def __time_range(self, request):
     try:
         try:
             tVal = request.get_value(TimerModule._PARAM_TIME_RANGE.get_kbx_param_name())
             startTime = tVal.get_start_time()
             endTime = tVal.get_end_time()
         except:
             # Backward compatible to daily_task
             kbxTime = KBXTime(kbxParamName="time")
             startTime = endTime = kbxTime.cast(request.get_arg("time"))
         
         execTime = request.get_arg(AppConstants.KEY_CONDITION_TIMESTAMP)
         execTime = datetime.datetime.fromtimestamp(execTime)
         execTime = (execTime.hour * 3600) + (execTime.minute * 60) + (execTime.second)
         
         if endTime < startTime:
             checkRange = [(startTime, 86400), (0, endTime + 59)]
         else:
             checkRange = [(startTime, endTime + 59)]
             
         for startVal, endVal in checkRange:
             if startVal <= execTime <= endVal:
                 response = True
                 break
         else:
             response = False
             
         if not response:
             raise AutomationException(11800)
         
         self.send_response({}, request.requestId)
     except AutomationException as ae:
         Logger.log_error("TimerModule time range failed on comparison:", str(ae))
         self.send_response({}, request.requestId, ae.get_error_code(), ae.get_error_message())
     except Exception as e:
         Logger.log_error("TimerModule time range failed on comparison (unexpected):", str(e))
         ae = AutomationException(11099, str(e))
         self.send_response({}, request.requestId, ae.get_error_code(), ae.get_error_message())