From 34c5fb6450502c222aafb9f50f62d9c406e87336 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sat, 15 Feb 2014 15:09:12 +0100 Subject: [PATCH] validierung Fix --- state.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/state.py b/state.py index 8fea3bb..52450bc 100644 --- a/state.py +++ b/state.py @@ -17,9 +17,8 @@ except: else: # Status lessen data = response.read(1) - try: - data = int(data) - except: + # Data validieren + if len(data) != 1 or data not in ("0", "1"): logging.exception("ungueltigen Zustand gelesen") data = None @@ -37,10 +36,11 @@ state = raw["state"] # letzte Verarbeitungszeit setzen state["lastchange"] = int(time.time()) # Status setzen -if data and data == 0: - state["open"] = False -elif data and data == 1: - state["open"] = True +if data: + if data == "0": + state["open"] = False + else: + state["open"] = True else: state["open"] = None