diff --git a/hochbeet/app.py b/hochbeet/app.py index af536a8..04f5df5 100644 --- a/hochbeet/app.py +++ b/hochbeet/app.py @@ -20,8 +20,8 @@ log_level = logging.INFO LOG_FILE = "/var/log/hochbeet.log" LOG_FORMAT = "%(asctime)s %(levelname)s %(message)s" -# logging.basicConfig(format=LOG_FORMAT, level=log_level, filename=LOG_FILE) -logging.basicConfig(format=LOG_FORMAT, level=log_level) +logging.basicConfig(format=LOG_FORMAT, level=log_level, filename=LOG_FILE) +#logging.basicConfig(format=LOG_FORMAT, level=log_level) log = logging.getLogger('hochbeet') @@ -85,15 +85,27 @@ class GreenControl(Thread): log.info("Switch water off by time") sleep(1) + def state(self): return self.__water_state + + def set_state(self, state: bool): + if state: + GPIO.output(self.__pin, 1) + self.__water_state = True + else: + GPIO.output(self.__pin, 0) + self.__water_state = False + + def get_auto_state(self): state = False if self.__config['water'][0]['autostate']: state = self.__config['water'][0]['autostate'] return state + def set_auto_state(self, state): self.__config['water'][0]['autostate'] = state with open(self.__config_file, "w") as handle: @@ -140,10 +152,12 @@ def get_sample(): def patch_sample(): global green_ctrl record = json.loads(request.data) - if "water" in record: - if record["water"]: + if "waterstate" in record: + if record["waterstate"]: + green_ctrl.set_state(True) log.info("Switch water on by button: %s", datetime.datetime.now()) else: + green_ctrl.set_state(False) log.info("Switch water off by button: %s", datetime.datetime.now()) return make_response("", 204) diff --git a/setup.py b/setup.py index aad792e..1edfb90 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import setup from setuptools.command.install import install NAME = 'Hochbeet' -VERSION = '1' +VERSION = '2' AUTHOR = 'Thomas Klaehn' EMAIL = 'tkl@blackfinn.de' PACKAGES = ['hochbeet']