Esempio n. 1
0
 def _fire_events_for_input_id(self, event_names, input_id):
     if input_id not in self.inputs: return False
     for event_variation in self._create_event_variations(
             self.inputs[input_id].technical_name, event_names):
         DOORPI.events(self._id,
                       event_variation,
                       kwargs=self.inputs[input_id].__dict__.update(
                           self.interface_info))
     for event_variation in self._create_event_variations(
             self.inputs[input_id].name, event_names):
         DOORPI.events(self._id,
                       event_variation,
                       kwargs=self.inputs[input_id].__dict__.update(
                           self.interface_info))
     return True
Esempio n. 2
0
 def _fire_output_event(self, technical_name, event_names):
     for output_id in self.outputs:
         if self.outputs[output_id].technical_name != technical_name:
             continue
         for event_variation in self._create_event_variations(
                 self.outputs[output_id].technical_name, event_names):
             DOORPI.events(self._id,
                           event_variation,
                           kwargs=self.inputs[input_id].__dict__.update(
                               self.interface_info))
         for event_variation in self._create_event_variations(
                 self.outputs[output_id].name, event_names):
             DOORPI.events(self._id,
                           event_variation,
                           kwargs=self.inputs[input_id].__dict__.update(
                               self.interface_info))
         return True
     return False
Esempio n. 3
0
    def heart_beat(self):

        timestamp_now = time.time()
        timestamp_past = self._last_time_tick

        datetime_now = datetime.datetime.fromtimestamp(timestamp_now)
        datetime_past = datetime.datetime.fromtimestamp(timestamp_past)

        if datetime_now.year != datetime_past.year:
            DOORPI.events('OnTimeYear', __name__)
            if datetime_now.year % 2 is 0:
                self('OnTimeYearEvenNumber', __name__)
            else:
                self('OnTimeYearUnevenNumber', __name__)

        if datetime_now.month != datetime_past.month:
            DOORPI.events('OnTimeMonth', __name__)
            if datetime_now.month % 2 is 0:
                self('OnTimeMonthEvenNumber', __name__)
            else:
                self('OnTimeMonthUnevenNumber', __name__)

        if datetime_now.day != datetime_past.day:
            DOORPI.events('OnTimeDay', __name__)
            if datetime_now.day % 2 is 0: self('OnTimeDayEvenNumber', __name__)
            else: self('OnTimeDayUnevenNumber', __name__)

        if datetime_now.hour != datetime_past.hour:
            DOORPI.events('OnTimeHour', __name__)
            if datetime_now.hour % 2 is 0:
                self('OnTimeHourEvenNumber', __name__)
            else:
                self('OnTimeHourUnevenNumber', __name__)

            for hour in DOORPI.CONST.HOUR_RANGE:
                if hour is datetime_now.hour:
                    self('OnTimeHour%s' % hour, __name__)

        if datetime_now.minute != datetime_past.minute:
            DOORPI.events('OnTimeMinute', __name__)
            if datetime_now.minute % 2 is 0:
                self('OnTimeMinuteEvenNumber', __name__)
            else:
                self('OnTimeMinuteUnevenNumber', __name__)

            for minute in DOORPI.CONST.MINUTE_RANGE:
                if minute is datetime_now.minute:
                    self('OnTimeMinute%s' % minute, __name__)

            if datetime_now.minute % 5 is 0:
                self('OnTimeMinuteEvery5', __name__)

        if datetime_now.second != datetime_past.second:
            DOORPI.events('OnTimeSecond', __name__)
            if datetime_now.second % 2 is 0:
                self('OnTimeSecondEvenNumber', __name__)
            else:
                self('OnTimeSecondUnevenNumber', __name__)

        microsecond = datetime_now.microsecond / 100000
        if (microsecond % 2 is 0 or microsecond is 0
            ) and microsecond is not self._last_realtime_event:
            self._last_realtime_event = microsecond
            DOORPI.events('OnTimeTick', __name__)

        sleep_time = (self._last_heart_beat * 0.5 +
                      DOORPI.CONST.HEART_BEAT_BASE_VALUE) - (timestamp_now -
                                                             time.time())
        if sleep_time > 0: time.sleep(sleep_time)

        self._last_time_tick = timestamp_now
        self._last_heart_beat = time.time() - timestamp_now
        return not self._destroy
Esempio n. 4
0
    def do_tick_tack(self, time_for_this_tick=0.2):

        timestamp_now = time.time()
        timestamp_past = self.last_time_tick

        datetime_now = datetime.datetime.fromtimestamp(timestamp_now)
        datetime_past = datetime.datetime.fromtimestamp(timestamp_past)

        if datetime_now.year != datetime_past.year:
            DOORPI.events('OnTimeYear', __name__)
            if datetime_now.year % 2 is 0:
                DOORPI.events('OnTimeYearEvenNumber', __name__)
            else:
                DOORPI.events('OnTimeYearUnevenNumber', __name__)

        if datetime_now.month != datetime_past.month:
            DOORPI.events('OnTimeMonth', __name__)
            if datetime_now.month % 2 is 0:
                DOORPI.events('OnTimeMonthEvenNumber', __name__)
            else:
                DOORPI.events('OnTimeMonthUnevenNumber', __name__)

        if datetime_now.day != datetime_past.day:
            DOORPI.events('OnTimeDay', __name__)
            if datetime_now.day % 2 is 0:
                DOORPI.events('OnTimeDayEvenNumber', __name__)
            else:
                DOORPI.events('OnTimeDayUnevenNumber', __name__)

        if datetime_now.hour != datetime_past.hour:
            DOORPI.events('OnTimeHour', __name__)
            if datetime_now.hour % 2 is 0:
                DOORPI.events('OnTimeHourEvenNumber', __name__)
            else:
                DOORPI.events('OnTimeHourUnevenNumber', __name__)

            for hour in DOORPI.CONST.HOUR_RANGE:
                if hour is datetime_now.hour:
                    DOORPI.events('OnTimeHour%s' % hour, __name__)

        if datetime_now.minute != datetime_past.minute:
            DOORPI.events('OnTimeMinute', __name__)
            if datetime_now.minute % 2 is 0:
                DOORPI.events('OnTimeMinuteEvenNumber', __name__)
            else:
                DOORPI.events('OnTimeMinuteUnevenNumber', __name__)

            for minute in DOORPI.CONST.MINUTE_RANGE:
                if minute is datetime_now.minute:
                    DOORPI.events('OnTimeMinute%s' % minute, __name__)

            if datetime_now.minute % 5 is 0:
                DOORPI.events('OnTimeMinuteEvery5', __name__)

        if datetime_now.second != datetime_past.second:
            DOORPI.events('OnTimeSecond', __name__)
            if datetime_now.second % 2 is 0:
                DOORPI.events('OnTimeSecondEvenNumber', __name__)
            else:
                DOORPI.events('OnTimeSecondUnevenNumber', __name__)

        microsecond = datetime_now.microsecond / 100000
        if (microsecond % 2 is 0 or microsecond is 0
            ) and microsecond is not self.last_realtime_event:
            self.last_realtime_event = microsecond
            DOORPI.events('OnTimeTick', __name__)

        self.last_time_tick = timestamp_now
        sleep_time = time_for_this_tick - (timestamp_now - time.time())
        if sleep_time > 0: time.sleep(sleep_time)

        return True