def __init__(self, latitude, longitude, tz='US/Eastern', mode=MODE.STANDARD, is_dst=True, *args, **kwargs): super(Location, self).__init__(*args, **kwargs) self.obs = ephem.Observer() self.obs.lat = latitude self.obs.long = longitude self.tz = pytz.timezone(tz) self.is_dst = is_dst self.sun = ephem.Sun(self.obs) self._horizon = mode self._sunset_timer = CronTimer() self._sunrise_timer = CronTimer() self._local_time = None self._recalc()
def time(self, *args, **kwargs): # time, command times = kwargs.get('time', None) command = kwargs.get('command', State.UNKNOWN) if times: if not isinstance( times, tuple) or (isinstance(times, tuple) and isinstance(times[0], int)): times = (times, ) for time in times: timer = CronTimer() if isinstance(time, tuple): timer.interval(*time) else: timer.interval(*CronTimer.to_cron(time)) timer.action(self.command, (command)) timer.start() self._times.append((command, timer))
def setUp(self): self.called = False self.ct = CronTimer()