Fix: Enable manual on/off switching

This commit is contained in:
Thomas Klaehn 2022-04-14 12:07:04 +02:00
parent abdb3fe00c
commit 508d6aad50
2 changed files with 19 additions and 5 deletions

View File

@ -20,8 +20,8 @@ log_level = logging.INFO
LOG_FILE = "/var/log/hochbeet.log" LOG_FILE = "/var/log/hochbeet.log"
LOG_FORMAT = "%(asctime)s %(levelname)s %(message)s" 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, filename=LOG_FILE)
logging.basicConfig(format=LOG_FORMAT, level=log_level) #logging.basicConfig(format=LOG_FORMAT, level=log_level)
log = logging.getLogger('hochbeet') log = logging.getLogger('hochbeet')
@ -85,15 +85,27 @@ class GreenControl(Thread):
log.info("Switch water off by time") log.info("Switch water off by time")
sleep(1) sleep(1)
def state(self): def state(self):
return self.__water_state 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): def get_auto_state(self):
state = False state = False
if self.__config['water'][0]['autostate']: if self.__config['water'][0]['autostate']:
state = self.__config['water'][0]['autostate'] state = self.__config['water'][0]['autostate']
return state return state
def set_auto_state(self, state): def set_auto_state(self, state):
self.__config['water'][0]['autostate'] = state self.__config['water'][0]['autostate'] = state
with open(self.__config_file, "w") as handle: with open(self.__config_file, "w") as handle:
@ -140,10 +152,12 @@ def get_sample():
def patch_sample(): def patch_sample():
global green_ctrl global green_ctrl
record = json.loads(request.data) record = json.loads(request.data)
if "water" in record: if "waterstate" in record:
if record["water"]: if record["waterstate"]:
green_ctrl.set_state(True)
log.info("Switch water on by button: %s", datetime.datetime.now()) log.info("Switch water on by button: %s", datetime.datetime.now())
else: else:
green_ctrl.set_state(False)
log.info("Switch water off by button: %s", datetime.datetime.now()) log.info("Switch water off by button: %s", datetime.datetime.now())
return make_response("", 204) return make_response("", 204)

View File

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