Initial commit
This commit is contained in:
135
config/_Config.py
Normal file
135
config/_Config.py
Normal file
@@ -0,0 +1,135 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
|
||||
class Config():
|
||||
def __init__(self, configfile):
|
||||
self.__config_file = configfile
|
||||
self.__config = None
|
||||
|
||||
try:
|
||||
with open(self.__config_file, "r") as handle:
|
||||
self.__config = json.load(handle)
|
||||
except FileNotFoundError:
|
||||
# create default config
|
||||
os.makedirs(os.path.dirname(self.__config_file), exist_ok=True)
|
||||
|
||||
shutil.copyfile("config/config.json", self.__config_file)
|
||||
with open(self.__config_file, "r") as handle:
|
||||
self.__config = json.load(handle)
|
||||
|
||||
def hostinfo(self):
|
||||
res = self.__config['hostname'], int(self.__config['port'])
|
||||
return res
|
||||
|
||||
def get_heat_autostate(self, ident: int):
|
||||
for entry in self.__config['heat']:
|
||||
if int(entry['id']) == ident:
|
||||
return entry['autostate']
|
||||
return None
|
||||
|
||||
def set_heat_autostate(self, ident: str):
|
||||
for idx in range(len(self.__config['heat'])):
|
||||
if self.__config['heat'][idx]['id'] == ident:
|
||||
self.__config['heat'][idx]['autostate'] = True
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def clear_heat_autostate(self, ident: str):
|
||||
for idx in range(len(self.__config['heat'])):
|
||||
if self.__config['heat'][idx]['id'] == ident:
|
||||
self.__config['heat'][idx]['autostate'] = False
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def increase_on_temperature(self, ident: str):
|
||||
for idx in range(len(self.__config['heat'])):
|
||||
if self.__config['heat'][idx]['id'] == ident:
|
||||
on_temp = int(self.__config['heat'][idx]['on_temperature'])
|
||||
on_temp += 1
|
||||
self.__config['heat'][idx]['on_temperature'] = str(on_temp)
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def decrease_on_temperature(self, ident: str):
|
||||
for idx in range(len(self.__config['heat'])):
|
||||
if self.__config['heat'][idx]['id'] == ident:
|
||||
on_temp = int(self.__config['heat'][idx]['on_temperature'])
|
||||
on_temp -= 1
|
||||
self.__config['heat'][idx]['on_temperature'] = str(on_temp)
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def increase_off_temperature(self, ident: str):
|
||||
for idx in range(len(self.__config['heat'])):
|
||||
if self.__config['heat'][idx]['id'] == ident:
|
||||
off_temp = int(self.__config['heat'][idx]['off_temperature'])
|
||||
off_temp += 1
|
||||
self.__config['heat'][idx]['off_temperature'] = str(off_temp)
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def decrease_off_temperature(self, ident: str):
|
||||
for idx in range(len(self.__config['heat'])):
|
||||
if self.__config['heat'][idx]['id'] == ident:
|
||||
off_temp = int(self.__config['heat'][idx]['off_temperature'])
|
||||
off_temp -= 1
|
||||
self.__config['heat'][idx]['off_temperature'] = str(off_temp)
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
|
||||
def get_on_temperature(self, ident: int):
|
||||
for entry in self.__config['heat']:
|
||||
if int(entry['id']) == ident:
|
||||
return entry['on_temperature']
|
||||
return None
|
||||
|
||||
def get_off_temperature(self, ident: int):
|
||||
for entry in self.__config['heat']:
|
||||
if int(entry['id']) == ident:
|
||||
return entry['off_temperature']
|
||||
return None
|
||||
|
||||
def get_water_autostate(self, ident: int):
|
||||
for entry in self.__config['water']:
|
||||
if int(entry['id']) == ident:
|
||||
return entry['autostate']
|
||||
return None
|
||||
|
||||
def get_water_times(self, ident: int):
|
||||
for entry in self.__config['water']:
|
||||
if int(entry['id']) == ident:
|
||||
return entry['times']
|
||||
return None
|
||||
|
||||
def set_water_autostate(self, ident: str):
|
||||
for idx in range(len(self.__config['water'])):
|
||||
if self.__config['water'][idx]['id'] == ident:
|
||||
self.__config['water'][idx]['autostate'] = True
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def clear_water_autostate(self, ident: str):
|
||||
for idx in range(len(self.__config['water'])):
|
||||
if self.__config['water'][idx]['id'] == ident:
|
||||
self.__config['water'][idx]['autostate'] = False
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
||||
|
||||
def set_water_times(self, ident: str, times):
|
||||
for idx in range(len(self.__config['water'])):
|
||||
if self.__config['water'][idx]['id'] == ident:
|
||||
self.__config['water'][idx]['times'] = times
|
||||
with open(self.__config_file, "w") as handle:
|
||||
json.dump(self.__config, handle)
|
||||
return
|
1
config/__init__.py
Normal file
1
config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from ._Config import Config
|
60
config/config.json
Normal file
60
config/config.json
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"hostname": "localhost",
|
||||
"port": "64001",
|
||||
"water": [
|
||||
{
|
||||
"id": "1",
|
||||
"autostate": false,
|
||||
"pin": "22",
|
||||
"times": [
|
||||
{
|
||||
"on_time": "7:00",
|
||||
"off_time": "7:20"
|
||||
},
|
||||
{
|
||||
"on_time": "19:00",
|
||||
"off_time": "19:20"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"autostate": false,
|
||||
"pin": "17",
|
||||
"times": [
|
||||
{
|
||||
"on_time": "7:20",
|
||||
"off_time": "7:40"
|
||||
},
|
||||
{
|
||||
"on_time": "19:20",
|
||||
"off_time": "19:40"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"autostate": false,
|
||||
"pin": "27",
|
||||
"times": [
|
||||
{
|
||||
"on_time": "7:40",
|
||||
"off_time": "8:00"
|
||||
},
|
||||
{
|
||||
"on_time": "19:40",
|
||||
"off_time": "20:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"heat": [
|
||||
{
|
||||
"id": "1",
|
||||
"autostate": false,
|
||||
"pin": "26",
|
||||
"on_temperature": "3",
|
||||
"off_temperature": "5"
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user