decorate
This commit is contained in:
parent
7e96d60ed1
commit
f1b37139ef
@ -17,9 +17,9 @@ STATE_OPENING = "opening"
|
|||||||
STATE_CLOSING = "closing"
|
STATE_CLOSING = "closing"
|
||||||
STATE_ERROR = "error"
|
STATE_ERROR = "error"
|
||||||
|
|
||||||
LIGHT_READ_DELAY_S = 60
|
LIGHT_READ_DELAY_S = 30
|
||||||
LIGHT_CONSECUTIVE_READS = 10
|
LIGHT_CONSECUTIVE_READS = 10
|
||||||
LIGHT_LX_THRESHOLD = {"open":0, "close":0}
|
LIGHT_LX_THRESHOLD = {"open":10, "close":0}
|
||||||
|
|
||||||
MQTT_HOST = "gitlab"
|
MQTT_HOST = "gitlab"
|
||||||
MQTT_TOPIC = "outdoor/chickenhouse/gate"
|
MQTT_TOPIC = "outdoor/chickenhouse/gate"
|
||||||
@ -31,7 +31,7 @@ POWER_SENSOR_I2C_BUS = 1
|
|||||||
POWER_SENSOR_I2C_ADDRESS = 0x40
|
POWER_SENSOR_I2C_ADDRESS = 0x40
|
||||||
CONSECUTIVE_CURRENT_READS = 100
|
CONSECUTIVE_CURRENT_READS = 100
|
||||||
|
|
||||||
MAX_ENGINE_POWER = {"up":320, "down":290}
|
MAX_ENGINE_POWER = {"up":330, "down":300}
|
||||||
MAX_GATE_RUNTIME = {"open":250, "close":250}
|
MAX_GATE_RUNTIME = {"open":250, "close":250}
|
||||||
|
|
||||||
|
|
||||||
@ -92,9 +92,9 @@ class GateState(object):
|
|||||||
next_state = self.__next_state
|
next_state = self.__next_state
|
||||||
if self.__is_transition():
|
if self.__is_transition():
|
||||||
self.__gate_handler.stop()
|
self.__gate_handler.stop()
|
||||||
|
self.__comserver.transmit(MQTT_TOPIC, str(time()) + " Opened " + \
|
||||||
|
str(self.__power_data.average()) + " mW")
|
||||||
self.__power_data.clear()
|
self.__power_data.clear()
|
||||||
self.__comserver.transmit(MQTT_TOPIC, str(time()) + \
|
|
||||||
" Opening gate finished")
|
|
||||||
|
|
||||||
if light_avg <= LIGHT_LX_THRESHOLD["close"]:
|
if light_avg <= LIGHT_LX_THRESHOLD["close"]:
|
||||||
next_state = STATE_CLOSING
|
next_state = STATE_CLOSING
|
||||||
@ -106,9 +106,9 @@ class GateState(object):
|
|||||||
next_state = self.__next_state
|
next_state = self.__next_state
|
||||||
if self.__is_transition():
|
if self.__is_transition():
|
||||||
self.__gate_handler.stop()
|
self.__gate_handler.stop()
|
||||||
|
self.__comserver.transmit(MQTT_TOPIC, str(time()) + " Closed " + \
|
||||||
|
str(self.__power_data.average()) + " mW")
|
||||||
self.__power_data.clear()
|
self.__power_data.clear()
|
||||||
self.__comserver.transmit(MQTT_TOPIC, str(time()) + \
|
|
||||||
" Closing gate finished")
|
|
||||||
|
|
||||||
if light_avg > LIGHT_LX_THRESHOLD["open"]:
|
if light_avg > LIGHT_LX_THRESHOLD["open"]:
|
||||||
next_state = STATE_OPENING
|
next_state = STATE_OPENING
|
||||||
@ -117,13 +117,11 @@ class GateState(object):
|
|||||||
|
|
||||||
|
|
||||||
def __opening_handler(self, light_avg):
|
def __opening_handler(self, light_avg):
|
||||||
#pylint: disable=unused-argument
|
|
||||||
next_state = self.__next_state
|
|
||||||
if self.__is_transition():
|
if self.__is_transition():
|
||||||
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()) + \
|
||||||
" Opening gate beginning")
|
" Opening " + str(light_avg) + " lx")
|
||||||
|
|
||||||
if time() > self.__gate_move_timeout:
|
if time() > self.__gate_move_timeout:
|
||||||
next_state = STATE_ERROR
|
next_state = STATE_ERROR
|
||||||
@ -138,13 +136,12 @@ class GateState(object):
|
|||||||
self.__update_state(next_state)
|
self.__update_state(next_state)
|
||||||
|
|
||||||
def __closing_handler(self, light_avg):
|
def __closing_handler(self, light_avg):
|
||||||
#pylint: disable=unused-argument
|
|
||||||
next_state = self.__next_state
|
next_state = self.__next_state
|
||||||
if self.__is_transition():
|
if self.__is_transition():
|
||||||
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()) + \
|
||||||
" Closing gate beginning")
|
" Closing " + str(light_avg) + " lx")
|
||||||
|
|
||||||
if time() > self.__gate_move_timeout:
|
if time() > self.__gate_move_timeout:
|
||||||
next_state = STATE_ERROR
|
next_state = STATE_ERROR
|
||||||
@ -155,8 +152,6 @@ class GateState(object):
|
|||||||
print "current_avg: " + str(current_avg)
|
print "current_avg: " + str(current_avg)
|
||||||
if current_avg > MAX_ENGINE_POWER["down"]:
|
if current_avg > MAX_ENGINE_POWER["down"]:
|
||||||
next_state = STATE_CLOSED
|
next_state = STATE_CLOSED
|
||||||
elif current_avg > MAX_ENGINE_POWER["up"]:
|
|
||||||
''' TODO: Screwed up! while closing we are reaching the upper limit!!!'''
|
|
||||||
|
|
||||||
self.__update_state(next_state)
|
self.__update_state(next_state)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user