More bugfixes. Getting there..

This commit is contained in:
Paulus Schoutsen committed 2013-09-19 22:32:08 -07:00
1 parent 0ff00ae5e0
commit cfc6708283
4 files changed
+14 -11

No files matched your search

+5 -5
View File
@@ -14,7 +14,7 @@ SUN_STATE_BELOW_HORIZON = "below_horizon"
class WeatherWatcher:
def __init__(self, config, eventbus, statemachine):
self.logger = logging.getLogger("WeatherWatcher")
self.logger = logging.getLogger(__name__)
self.config = config
self.eventbus = eventbus
self.statemachine = statemachine
@@ -25,7 +25,7 @@ class WeatherWatcher:
self.sun = ephem.Sun()
statemachine.add_category(STATE_CATEGORY_SUN, SOLAR_STATE_BELOW_HORIZON)
statemachine.add_category(STATE_CATEGORY_SUN, SUN_STATE_BELOW_HORIZON)
self.update_sun_state()
@@ -35,7 +35,7 @@ class WeatherWatcher:
def next_sun_setting(self):
return ephem.localtime(self.observer.next_setting(self.sun))
def update_sun_state(self, update_callback):
def update_sun_state(self, now=None):
next_rising = ephem.localtime(self.observer.next_rising(self.sun))
next_setting = ephem.localtime(self.observer.next_setting(self.sun))
@@ -47,11 +47,11 @@ class WeatherWatcher:
new_state = SUN_STATE_BELOW_HORIZON
next_change = next_rising
self.logger.info("Updating solar state for {} to {}. Next change: {}".format(STATE_CATEGORY_SUN, new_state, next_change))
self.logger.info("Updating sun state to {}. Next change: {}".format(new_state, next_change))
self.statemachine.set_state(STATE_CATEGORY_SUN, new_state)
# +10 seconds to be sure that the change has occured
track_time_change(self.eventbus, update_callback, datetime=next_change + timedelta(seconds=10))
track_time_change(self.eventbus, self.update_sun_state, datetime=next_change + timedelta(seconds=10))