mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-30 02:36:20 +02:00
RPI: fix SunsetHandler - use correct (utc) timestamp for comparision
This commit is contained in:
parent
4c52f07889
commit
a13fc1d92a
1 changed files with 5 additions and 5 deletions
|
@ -48,24 +48,24 @@ class SunsetHandler:
|
||||||
longitude = sunset_config.get('longitude')
|
longitude = sunset_config.get('longitude')
|
||||||
altitude = sunset_config.get('altitude')
|
altitude = sunset_config.get('altitude')
|
||||||
self.suntimes = SunTimes(longitude=longitude, latitude=latitude, altitude=altitude)
|
self.suntimes = SunTimes(longitude=longitude, latitude=latitude, altitude=altitude)
|
||||||
self.nextSunset = self.suntimes.setutc(datetime.now())
|
self.nextSunset = self.suntimes.setutc(datetime.utcnow())
|
||||||
print (f'Todays sunset is at {self.nextSunset}')
|
print (f'Todays sunset is at {self.nextSunset} UTC')
|
||||||
|
|
||||||
def checkWaitForSunrise(self):
|
def checkWaitForSunrise(self):
|
||||||
if not self.suntimes:
|
if not self.suntimes:
|
||||||
return
|
return
|
||||||
# if the sunset already happened for today
|
# if the sunset already happened for today
|
||||||
now = datetime.now()
|
now = datetime.utcnow()
|
||||||
if self.nextSunset < now:
|
if self.nextSunset < now:
|
||||||
# wait until the sun rises tomorrow
|
# wait until the sun rises tomorrow
|
||||||
tomorrow = now + timedelta(days=1)
|
tomorrow = now + timedelta(days=1)
|
||||||
nextSunrise = self.suntimes.riseutc(tomorrow)
|
nextSunrise = self.suntimes.riseutc(tomorrow)
|
||||||
self.nextSunset = self.suntimes.setutc(tomorrow)
|
self.nextSunset = self.suntimes.setutc(tomorrow)
|
||||||
time_to_sleep = (nextSunrise - datetime.now()).total_seconds()
|
time_to_sleep = (nextSunrise - datetime.now()).total_seconds()
|
||||||
print (f'Waiting for sunrise at {nextSunrise} ({time_to_sleep} seconds)')
|
print (f'Waiting for sunrise at {nextSunrise} UTC ({time_to_sleep} seconds)')
|
||||||
if time_to_sleep > 0:
|
if time_to_sleep > 0:
|
||||||
time.sleep(time_to_sleep)
|
time.sleep(time_to_sleep)
|
||||||
print (f'Woke up... next sunset is at {self.nextSunset}')
|
print (f'Woke up... next sunset is at {self.nextSunset} UTC')
|
||||||
return
|
return
|
||||||
|
|
||||||
def main_loop(ahoy_config):
|
def main_loop(ahoy_config):
|
||||||
|
|
Loading…
Add table
Reference in a new issue