From 42331d76ab07db61779bff8fc88875bd89b43bba Mon Sep 17 00:00:00 2001 From: tkl Date: Sat, 7 Jan 2017 13:26:00 +0100 Subject: [PATCH] minimum runtime for gate open/close defined --- src/gate/gate_state.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gate/gate_state.py b/src/gate/gate_state.py index 96b9f33..edd773d 100644 --- a/src/gate/gate_state.py +++ b/src/gate/gate_state.py @@ -33,6 +33,7 @@ POWER_CONSECUTIVE_READS = 1000 MAX_ENGINE_POWER = {"up":310, "down":290} MAX_GATE_RUNTIME = {"open":300, "close":300} +MIN_GATE_RUNTIME = {"open":10, "close":10} class GateState(object): @@ -57,6 +58,8 @@ class GateState(object): self.__gate_move_timeout = 0 self.__light_read_timeout = 0 self.__error_count = 0 + self.__runtime_open = 0 + self.__runtime_close = 0 def poll(self): current_time = time() @@ -124,6 +127,7 @@ class GateState(object): def __opening_handler(self, light_avg): next_state = self.__next_state if self.__is_transition(): + self.__runtime_open = time() + MIN_GATE_RUNTIME["open"] self.__gate_handler.open() self.__gate_move_timeout = time() + MAX_GATE_RUNTIME["open"] self.__comserver.transmit(MQTT_TOPIC, str(time()) + \ @@ -136,13 +140,15 @@ class GateState(object): current_avg = self.__power_data.average() if current_avg != None: if current_avg > MAX_ENGINE_POWER["up"]: - next_state = STATE_OPENED + if time() > self.__runtime_open: + next_state = STATE_OPENED self.__update_state(next_state) def __closing_handler(self, light_avg): next_state = self.__next_state if self.__is_transition(): + self.__runtime_close = time() + MIN_GATE_RUNTIME["close"] self.__gate_handler.close() self.__gate_move_timeout = time() + MAX_GATE_RUNTIME["close"] self.__comserver.transmit(MQTT_TOPIC, str(time()) + \ @@ -155,7 +161,8 @@ class GateState(object): current_avg = self.__power_data.average() if current_avg != None: if current_avg > MAX_ENGINE_POWER["down"]: - next_state = STATE_CLOSED + if time() > self.__runtime_close: + next_state = STATE_CLOSED self.__update_state(next_state)