Beispiel #1
0
  def test_interval_next(self):
    helper_five = repeat.interval_helper(timedelta(minutes=5))

    # Basic tests
    now = datetime(2012, 12, 9, 0, 32, 49)
    self.assertEquals(helper_five(now), datetime(2012, 12, 9, 0, 35, 0))
    self.assertEquals(repeat.interval_next(now, timedelta(minutes=8)),
                      datetime(2012, 12, 9, 0, 40, 0))

    # Started on even time
    now = datetime(2012, 12, 9, 0, 0, 0)
    self.assertEquals(helper_five(now), datetime(2012, 12, 9, 0, 0, 0))

    # Hour boundries
    now = datetime(2012, 12, 9, 0, 58, 49)
    self.assertEquals(helper_five(now),
                      datetime(2012, 12, 9, 1, 0, 0))
    self.assertEquals(repeat.interval_next(now, timedelta(minutes=10)),
                      datetime(2012, 12, 9, 1, 0, 0))
    self.assertEquals(repeat.interval_next(now, timedelta(minutes=15)),
                      datetime(2012, 12, 9, 1, 0, 0))

    # Day boundry
    now = datetime(2012, 12, 9, 23, 58, 0)
    self.assertEquals(repeat.interval_next(now, timedelta(minutes=5)),
                      datetime(2012, 12, 10, 0, 0, 0))
Beispiel #2
0
    def setup(self):
        # We expect to receive a list of host names here.
        self._hosts = self.adapter_json.get('hosts')

        self.status.set(self.url, {})

        # Start refreshing SNMP information every 10 seconds.
        timing_helper = repeat.interval_helper(datetime.timedelta(seconds=15))
        repeat.call_repeating(timing_helper, self.update_hosts)
Beispiel #3
0
  def setup(self):
    # We expect to receive a list of host names here.
    self._hosts = self.adapter_json.get('hosts')

    self.status.set(self.url, {})

    # Start refreshing SNMP information every 10 seconds.
    timing_helper = repeat.interval_helper(datetime.timedelta(seconds=15))
    repeat.call_repeating(timing_helper, self.update_hosts)
Beispiel #4
0
  def setup(self):
    # Read our file, and attach it to the status.
    self.root = self.adapter_json.get('root_player')
    self.root_soco = SoCo(self.root)

    logging.info('Sonos with root_player %s', self.root)

    # Start refreshing Sonos information every 10 seconds.
    timing_helper = repeat.interval_helper(datetime.timedelta(seconds=10))
    repeat.call_repeating(timing_helper, self.refresh_players)
Beispiel #5
0
    def setup(self):
        # Read our file, and attach it to the status.
        self.root = self.adapter_json.get('root_player')
        self.root_soco = SoCo(self.root)

        logging.info('Sonos with root_player %s', self.root)

        # Start refreshing Sonos information every 10 seconds.
        timing_helper = repeat.interval_helper(datetime.timedelta(seconds=10))
        repeat.call_repeating(timing_helper, self.refresh_players)
Beispiel #6
0
    def __init__(self, engine, status, url, rule):
        super(_IntervalHelper, self).__init__(engine, status, url, rule)

        # The _find_next_fire_time is a method that returns the datetime in which to
        # next fire if passed utcnow as a datetime. The different implementations of
        # it are how we adjust for different types of daily rules.

        # Multiple times a day. Expect 'time' to be in format 'hh:mm:ss'
        hours, minutes, seconds = [int(i) for i in rule['time'].split(':')]
        interval = datetime.timedelta(hours=hours,
                                      minutes=minutes,
                                      seconds=seconds)
        self._find_next_fire_time = repeat.interval_helper(interval)