mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-08 13:41:40 +02:00
Merge pull request #524 from fred777/main
compute sunrise correctly after midnight
This commit is contained in:
commit
5b8a94cd94
1 changed files with 11 additions and 6 deletions
|
@ -51,6 +51,9 @@ class SunsetHandler:
|
||||||
self.suntimes = SunTimes(longitude=longitude, latitude=latitude, altitude=altitude)
|
self.suntimes = SunTimes(longitude=longitude, latitude=latitude, altitude=altitude)
|
||||||
self.nextSunset = self.suntimes.setutc(datetime.utcnow())
|
self.nextSunset = self.suntimes.setutc(datetime.utcnow())
|
||||||
logging.info (f'Todays sunset is at {self.nextSunset} UTC')
|
logging.info (f'Todays sunset is at {self.nextSunset} UTC')
|
||||||
|
else:
|
||||||
|
logging.info('Sunset disabled.')
|
||||||
|
|
||||||
|
|
||||||
def checkWaitForSunrise(self):
|
def checkWaitForSunrise(self):
|
||||||
if not self.suntimes:
|
if not self.suntimes:
|
||||||
|
@ -58,15 +61,17 @@ class SunsetHandler:
|
||||||
# if the sunset already happened for today
|
# if the sunset already happened for today
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
if self.nextSunset < now:
|
if self.nextSunset < now:
|
||||||
# wait until the sun rises tomorrow
|
# wait until the sun rises again. if it's already after midnight, this will be today
|
||||||
tomorrow = now + timedelta(days=1)
|
nextSunrise = self.suntimes.riseutc(now)
|
||||||
nextSunrise = self.suntimes.riseutc(tomorrow)
|
if nextSunrise < now:
|
||||||
self.nextSunset = self.suntimes.setutc(tomorrow)
|
tomorrow = now + timedelta(days=1)
|
||||||
|
nextSunrise = self.suntimes.riseutc(tomorrow)
|
||||||
|
self.nextSunset = self.suntimes.setutc(nextSunrise)
|
||||||
time_to_sleep = int((nextSunrise - datetime.utcnow()).total_seconds())
|
time_to_sleep = int((nextSunrise - datetime.utcnow()).total_seconds())
|
||||||
logging.info (f'Waiting for sunrise at {nextSunrise} UTC ({time_to_sleep} seconds)')
|
logging.info (f'Next sunrise is at {nextSunrise} UTC, next sunset is at {self.nextSunset} UTC, sleeping for {time_to_sleep} seconds.')
|
||||||
if time_to_sleep > 0:
|
if time_to_sleep > 0:
|
||||||
time.sleep(time_to_sleep)
|
time.sleep(time_to_sleep)
|
||||||
logging.info (f'Woke up... next sunset is at {self.nextSunset} UTC')
|
logging.info (f'Woke up...')
|
||||||
|
|
||||||
def main_loop(ahoy_config):
|
def main_loop(ahoy_config):
|
||||||
"""Main loop"""
|
"""Main loop"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue