Added overnight sleep for Gerty

This commit is contained in:
Black Coffee 2022-10-07 10:25:54 +01:00
parent 40c921c7f5
commit b5c992afd9
2 changed files with 20 additions and 4 deletions

View file

@ -146,5 +146,16 @@ def get_next_update_time(sleep_time_seconds: int = 0, timezone: str = "Europe/Lo
utc_now = pytz.utc.localize(datetime.datetime.utcnow())
next_refresh_time = utc_now + datetime.timedelta(0, sleep_time_seconds)
local_refresh_time = next_refresh_time.astimezone(pytz.timezone(timezone))
# datetime.fromtimestamp(time.time()).strftime("%e %b %Y at %H:%M")
return "Next update at {0}".format(local_refresh_time.strftime("%H:%M on%e %b %Y"))
return "{0} {1}".format("I'll wake up at" if gerty_should_sleep() else "Next update at",local_refresh_time.strftime("%H:%M on%e %b %Y"))
def gerty_should_sleep(timezone: str = "Europe/London"):
utc_now = pytz.utc.localize(datetime.datetime.utcnow())
local_time = utc_now.astimezone(pytz.timezone(timezone))
hours = local_time.strftime("%H")
hours = int(hours)
logger.debug("HOURS")
logger.debug(hours)
if(hours >= 22 and hours <= 23):
return True
else:
return False

View file

@ -137,11 +137,16 @@ async def api_gerty_json(
next_screen_number = 0 if ((p + 1) >= enabled_screen_count) else p + 1;
# get the sleep time
sleep_time = gerty.refresh_time
if gerty_should_sleep():
sleep_time_hours = 7
sleep_time = 60 * sleep_time_hours
return {
"settings": {
"refreshTime": gerty.refresh_time,
"requestTimestamp": get_next_update_time(gerty.refresh_time),
"refreshTime": sleep_time,
"requestTimestamp": get_next_update_time(sleep_time),
"nextScreenNumber": next_screen_number,
"showTextBoundRect": False,
"name": gerty.name