minimum runtime for gate open/close defined
This commit is contained in:
parent
c8dd92415f
commit
42331d76ab
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user