From b5db8b943ddef1a2d7ff9ba04dab69d2ded5c688 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Tue, 29 Mar 2022 16:37:12 +0200 Subject: [PATCH] some fixes --- control/_Control.py | 25 ++++++++++++++----------- gardencontrol/main.py | 2 +- setup.py | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/control/_Control.py b/control/_Control.py index 2f83600..72574bf 100644 --- a/control/_Control.py +++ b/control/_Control.py @@ -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) diff --git a/gardencontrol/main.py b/gardencontrol/main.py index 594fe11..8a5b11d 100644 --- a/gardencontrol/main.py +++ b/gardencontrol/main.py @@ -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(): diff --git a/setup.py b/setup.py index c0e7875..819fbdd 100755 --- a/setup.py +++ b/setup.py @@ -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']