nv setting time format check before commit

This commit is contained in:
Ayush Saini 2024-02-25 16:28:23 +05:30
parent 371d4b1f94
commit 6eeb6377ff

View file

@ -7,7 +7,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from functools import lru_cache
import datetime
import json
import _ba
@ -43,7 +43,18 @@ def commit(data: dict) -> None:
data : dict
data to be commited
"""
if is_invalid_time_format(data['autoNightMode']['startTime']) or is_invalid_time_format(data['autoNightMode']['endTime']):
data['autoNightMode']['startTime'] = "18:30"
data['autoNightMode']['endTime'] = "6:30"
print("resetting night mode time")
with open(SETTINGS_PATH, mode="w", encoding="utf-8") as setting_file:
json.dump(data, setting_file, indent=4)
# settings updated ok now update the cache
refresh_cache()
def is_invalid_time_format(time_string, time_format='%H:%M'):
try:
datetime.datetime.strptime(time_string, time_format)
return False
except ValueError:
return True