saunacontrol/config/_Config.py

44 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-04-19 05:57:29 +00:00
import os
import json
class Config():
def __init__(self):
self.__config_file = os.path.join(os.path.expanduser('~'), ".config/sauna/config.json")
self.__config = None
try:
with open(self.__config_file, "r") as handle:
self.__config = json.load(handle)
except FileNotFoundError:
os.makedirs(os.path.dirname(self.__config_file), exist_ok=True)
self.__config = {
"target_temperature": "80",
"temperature_step": "5",
"max_temperature": "120",
"runtime": "2:30",
"heat_pin": "26"
}
with open(self.__config_file, "w") as handle:
json.dump(self.__config, handle)
def target_temperature(self):
return self.__config['target_temperature']
def temperature_step(self):
res =self.__config['temperature_step']
print(res)
return res
def heat_pin(self):
return self.__config['heat_pin']
def runtime(self):
return self.__config['runtime']
def update_target_temperature(self, temperature: int):
if temperature <= int(self.__config['max_temperature']):
self.__config['target_temperature'] = str(temperature)
with open(self.__config_file, "w") as handle:
json.dump(self.__config, handle)