Gate: remove MQTT

This commit is contained in:
tkl 2022-02-21 17:34:38 +01:00
parent d1f6944216
commit d1f952b87e

View File

@ -154,14 +154,14 @@ class Gate(object):
self.__engine_1.down() self.__engine_1.down()
# workaround for high power after starting engine # workaround for high power after starting engine
time.sleep(1) time.sleep(1)
msg = str(time.time()) + " Initialization" # msg = str(time.time()) + " Initialization"
try: # try:
self.__client.connect(MQTT_HOST, MQTT_PORT) # self.__client.connect(MQTT_HOST, MQTT_PORT)
self.__client.loop_start() # self.__client.loop_start()
self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) # self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True)
self.__client.loop_stop() # self.__client.loop_stop()
except (ValueError, TypeError, socket.error, ssl.CertificateError): # except (ValueError, TypeError, socket.error, ssl.CertificateError):
logging.info('unable to publish to mqtt') # logging.info('unable to publish to mqtt')
pwr = self.__power_sensor.power_mw() pwr = self.__power_sensor.power_mw()
msg = 'e1: {} mW'.format(pwr) msg = 'e1: {} mW'.format(pwr)
logging.debug(msg) logging.debug(msg)
@ -232,13 +232,13 @@ class Gate(object):
time.sleep(1) time.sleep(1)
self.__engine_2.stop() self.__engine_2.stop()
msg = str(time.time()) + " Opened" msg = str(time.time()) + " Opened"
try: # try:
self.__client.connect(MQTT_HOST, MQTT_PORT) # self.__client.connect(MQTT_HOST, MQTT_PORT)
self.__client.loop_start() # self.__client.loop_start()
self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) # self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True)
self.__client.loop_stop() # self.__client.loop_stop()
except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: # except (ValueError, TypeError, socket.error, ssl.CertificateError) as err:
logging.info('unable to publish to mqtt ({})'.format(err)) # logging.info('unable to publish to mqtt ({})'.format(err))
if check_to_close(light_avg) is True: if check_to_close(light_avg) is True:
next_state = STATE_CLOSING_1 next_state = STATE_CLOSING_1
self.__update_state(next_state) self.__update_state(next_state)
@ -247,14 +247,14 @@ class Gate(object):
next_state = self.__next_state next_state = self.__next_state
if self.__is_transition(): if self.__is_transition():
self.__engine_2.stop() self.__engine_2.stop()
msg = str(time.time()) + " Closed" # msg = str(time.time()) + " Closed"
try: # try:
self.__client.connect(MQTT_HOST, MQTT_PORT) # self.__client.connect(MQTT_HOST, MQTT_PORT)
self.__client.loop_start() # self.__client.loop_start()
self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) # self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True)
self.__client.loop_stop() # self.__client.loop_stop()
except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: # except (ValueError, TypeError, socket.error, ssl.CertificateError) as err:
logging.info('unable to publish to mqtt ({})'.format(err)) # logging.info('unable to publish to mqtt ({})'.format(err))
if check_to_open(light_avg) is True: if check_to_open(light_avg) is True:
next_state = STATE_OPENING_1 next_state = STATE_OPENING_1
self.__update_state(next_state) self.__update_state(next_state)
@ -263,14 +263,14 @@ class Gate(object):
next_state = self.__next_state next_state = self.__next_state
if self.__is_transition(): if self.__is_transition():
self.__engine_1.up() self.__engine_1.up()
msg = str(time.time()) + " Opening" + str(light_avg) + " lx" # msg = str(time.time()) + " Opening" + str(light_avg) + " lx"
try: # try:
self.__client.connect(MQTT_HOST, MQTT_PORT) # self.__client.connect(MQTT_HOST, MQTT_PORT)
self.__client.loop_start() # self.__client.loop_start()
self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) # self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True)
self.__client.loop_stop() # self.__client.loop_stop()
except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: # except (ValueError, TypeError, socket.error, ssl.CertificateError) as err:
logging.info('unable to publish to mqtt ({})'.format(err)) # logging.info('unable to publish to mqtt ({})'.format(err))
self.__gate_run_time = time.time() self.__gate_run_time = time.time()
# workaround for high power after starting engine # workaround for high power after starting engine
@ -312,14 +312,14 @@ class Gate(object):
next_state = self.__next_state next_state = self.__next_state
if self.__is_transition(): if self.__is_transition():
self.__engine_1.down() self.__engine_1.down()
msg = str(time.time()) + " Closing " + str(light_avg) + " lx" # msg = str(time.time()) + " Closing " + str(light_avg) + " lx"
try: # try:
self.__client.connect(MQTT_HOST, MQTT_PORT) # self.__client.connect(MQTT_HOST, MQTT_PORT)
self.__client.loop_start() # self.__client.loop_start()
self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) # self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True)
self.__client.loop_stop() # self.__client.loop_stop()
except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: # except (ValueError, TypeError, socket.error, ssl.CertificateError) as err:
logging.info('unable to publish to mqtt ({})'.format(err)) # logging.info('unable to publish to mqtt ({})'.format(err))
self.__gate_run_time = time.time() self.__gate_run_time = time.time()
# workaround for high power after starting engine # workaround for high power after starting engine