some fixes

This commit is contained in:
Thomas Klaehn 2022-03-29 16:37:12 +02:00
parent 4e25b921c4
commit b5db8b943d
3 changed files with 16 additions and 13 deletions

View File

@ -30,13 +30,13 @@ class Control(threading.Thread):
def load_config(self):
try:
with open(self.__config_file, "r") as handle:
with open(self.__config_file, "r", encoding="UTF-8") 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:
with open(self.__config_file, "r", encoding="UTF-8") as handle:
self.__config = json.load(handle)
self.__heat = heat.Heat(int(self.__config['heat'][0]['pin']))
for _ in range(len(self.__config['water'])):
@ -58,7 +58,10 @@ class Control(threading.Thread):
self.__trigger_read_config = False
self.load_config()
self.__temperature = float(self.__sensor.get_temperature())
tmp = float(self.__sensor.get_temperature())
if tmp != self.__temperature:
self.__temperature = tmp
self.__log.info("Temperature: %.1f °C", self.__temperature)
# handle heat
if self.__config['heat'][0]['autostate']:
@ -66,10 +69,10 @@ class Control(threading.Thread):
off_temperature = float(self.__config['heat'][0]['off_temperature'])
if self.__temperature < on_temperature and not self.__heat.state():
self.__heat.on()
self.__log.info("Switch heat on by temperature level: %.1f °C", self.__temperature)
self.__log.info("heat on")
elif self.__temperature > off_temperature and self.__heat.state():
self.__heat.off()
self.__log.info("Switch heat off by temperature level: %.1f °C", self.__temperature)
self.__log.info("heat off")
# handle water entries
water = self.__config['water']
@ -97,11 +100,11 @@ class Control(threading.Thread):
if now > on_time and now <= off_time and not self.__water_state[water_index]:
GPIO.output(pin, 0)
self.__water_state[water_index] = True
self.__log.info("Switch water on by time")
self.__log.info("water on")
elif now > off_time and self.__water_state[water_index]:
GPIO.output(pin, 1)
self.__water_state[water_index] = False
self.__log.info("Switch water off by time")
self.__log.info("water off")
water_index += 1
@ -126,18 +129,18 @@ class Control(threading.Thread):
def set_heat_state(self, ident: str):
self.__heat.on()
self.__log.info("Switch heat on by button")
self.__log.info("heat on by button")
def clear_heat_state(self, ident: str):
self.__heat.off()
self.__log.info("Switch heat off by button")
self.__log.info("heat off by button")
def set_water_state(self, ident: str):
ident = int(ident)
if ident > 0 and ident < len(self.__water_state):
pin = int(self.__config['water'][ident - 1]['pin'])
self.__water_state[ident - 1] = True
self.__log.info("Switch water on by button")
self.__log.info("water on by button")
GPIO.output(pin, 0)
def clear_water_state(self, ident: str):
@ -145,5 +148,5 @@ class Control(threading.Thread):
if ident > 0 and ident < len(self.__water_state):
pin = int(self.__config['water'][ident - 1]['pin'])
self.__water_state[ident - 1] = False
self.__log.info("Switch water off by button")
self.__log.info("water off by button")
GPIO.output(pin, 1)

View File

@ -6,7 +6,7 @@ import sys
import remotecontrol
LOG_LEVEL = logging.INFO
LOG_FILE = "/var/log/sauna.log"
LOG_FILE = "/var/log/gardencontrol.log"
LOG_FORMAT = "%(asctime)s %(levelname)s %(message)s"
def main():

View File

@ -6,7 +6,7 @@ from setuptools import setup
from setuptools.command.install import install
NAME = 'gardencontrol'
VERSION = '1'
VERSION = '2'
AUTHOR = 'Thomas Klaehn'
EMAIL = 'tkl@blackfinn.de'
PACKAGES = ['config', 'control', 'gardencontrol', 'heat', 'remotecontrol']