minimum runtime for gate open/close defined

This commit is contained in:
tkl 2017-01-07 13:26:00 +01:00 committed by Thomas Klaehn
parent c8dd92415f
commit 42331d76ab

View File

@ -33,6 +33,7 @@ POWER_CONSECUTIVE_READS = 1000
MAX_ENGINE_POWER = {"up":310, "down":290} MAX_ENGINE_POWER = {"up":310, "down":290}
MAX_GATE_RUNTIME = {"open":300, "close":300} MAX_GATE_RUNTIME = {"open":300, "close":300}
MIN_GATE_RUNTIME = {"open":10, "close":10}
class GateState(object): class GateState(object):
@ -57,6 +58,8 @@ class GateState(object):
self.__gate_move_timeout = 0 self.__gate_move_timeout = 0
self.__light_read_timeout = 0 self.__light_read_timeout = 0
self.__error_count = 0 self.__error_count = 0
self.__runtime_open = 0
self.__runtime_close = 0
def poll(self): def poll(self):
current_time = time() current_time = time()
@ -124,6 +127,7 @@ class GateState(object):
def __opening_handler(self, light_avg): def __opening_handler(self, light_avg):
next_state = self.__next_state next_state = self.__next_state
if self.__is_transition(): if self.__is_transition():
self.__runtime_open = time() + MIN_GATE_RUNTIME["open"]
self.__gate_handler.open() self.__gate_handler.open()
self.__gate_move_timeout = time() + MAX_GATE_RUNTIME["open"] self.__gate_move_timeout = time() + MAX_GATE_RUNTIME["open"]
self.__comserver.transmit(MQTT_TOPIC, str(time()) + \ self.__comserver.transmit(MQTT_TOPIC, str(time()) + \
@ -136,6 +140,7 @@ class GateState(object):
current_avg = self.__power_data.average() current_avg = self.__power_data.average()
if current_avg != None: if current_avg != None:
if current_avg > MAX_ENGINE_POWER["up"]: if current_avg > MAX_ENGINE_POWER["up"]:
if time() > self.__runtime_open:
next_state = STATE_OPENED next_state = STATE_OPENED
self.__update_state(next_state) self.__update_state(next_state)
@ -143,6 +148,7 @@ class GateState(object):
def __closing_handler(self, light_avg): def __closing_handler(self, light_avg):
next_state = self.__next_state next_state = self.__next_state
if self.__is_transition(): if self.__is_transition():
self.__runtime_close = time() + MIN_GATE_RUNTIME["close"]
self.__gate_handler.close() self.__gate_handler.close()
self.__gate_move_timeout = time() + MAX_GATE_RUNTIME["close"] self.__gate_move_timeout = time() + MAX_GATE_RUNTIME["close"]
self.__comserver.transmit(MQTT_TOPIC, str(time()) + \ self.__comserver.transmit(MQTT_TOPIC, str(time()) + \
@ -155,6 +161,7 @@ class GateState(object):
current_avg = self.__power_data.average() current_avg = self.__power_data.average()
if current_avg != None: if current_avg != None:
if current_avg > MAX_ENGINE_POWER["down"]: if current_avg > MAX_ENGINE_POWER["down"]:
if time() > self.__runtime_close:
next_state = STATE_CLOSED next_state = STATE_CLOSED
self.__update_state(next_state) self.__update_state(next_state)