From d1f952b87e134afae5438a0c9cd24a4290a17fdd Mon Sep 17 00:00:00 2001 From: tkl Date: Mon, 21 Feb 2022 17:34:38 +0100 Subject: [PATCH] Gate: remove MQTT --- gate_guard/gate.py | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/gate_guard/gate.py b/gate_guard/gate.py index 7e7d9d8..8e8872b 100644 --- a/gate_guard/gate.py +++ b/gate_guard/gate.py @@ -154,14 +154,14 @@ class Gate(object): self.__engine_1.down() # workaround for high power after starting engine time.sleep(1) - msg = str(time.time()) + " Initialization" - try: - self.__client.connect(MQTT_HOST, MQTT_PORT) - self.__client.loop_start() - self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) - self.__client.loop_stop() - except (ValueError, TypeError, socket.error, ssl.CertificateError): - logging.info('unable to publish to mqtt') +# msg = str(time.time()) + " Initialization" +# try: +# self.__client.connect(MQTT_HOST, MQTT_PORT) +# self.__client.loop_start() +# self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) +# self.__client.loop_stop() +# except (ValueError, TypeError, socket.error, ssl.CertificateError): +# logging.info('unable to publish to mqtt') pwr = self.__power_sensor.power_mw() msg = 'e1: {} mW'.format(pwr) logging.debug(msg) @@ -232,13 +232,13 @@ class Gate(object): time.sleep(1) self.__engine_2.stop() msg = str(time.time()) + " Opened" - try: - self.__client.connect(MQTT_HOST, MQTT_PORT) - self.__client.loop_start() - self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) - self.__client.loop_stop() - except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: - logging.info('unable to publish to mqtt ({})'.format(err)) +# try: +# self.__client.connect(MQTT_HOST, MQTT_PORT) +# self.__client.loop_start() +# self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) +# self.__client.loop_stop() +# except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: +# logging.info('unable to publish to mqtt ({})'.format(err)) if check_to_close(light_avg) is True: next_state = STATE_CLOSING_1 self.__update_state(next_state) @@ -247,14 +247,14 @@ class Gate(object): next_state = self.__next_state if self.__is_transition(): self.__engine_2.stop() - msg = str(time.time()) + " Closed" - try: - self.__client.connect(MQTT_HOST, MQTT_PORT) - self.__client.loop_start() - self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) - self.__client.loop_stop() - except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: - logging.info('unable to publish to mqtt ({})'.format(err)) +# msg = str(time.time()) + " Closed" +# try: +# self.__client.connect(MQTT_HOST, MQTT_PORT) +# self.__client.loop_start() +# self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) +# self.__client.loop_stop() +# except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: +# logging.info('unable to publish to mqtt ({})'.format(err)) if check_to_open(light_avg) is True: next_state = STATE_OPENING_1 self.__update_state(next_state) @@ -263,14 +263,14 @@ class Gate(object): next_state = self.__next_state if self.__is_transition(): self.__engine_1.up() - msg = str(time.time()) + " Opening" + str(light_avg) + " lx" - try: - self.__client.connect(MQTT_HOST, MQTT_PORT) - self.__client.loop_start() - self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) - self.__client.loop_stop() - except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: - logging.info('unable to publish to mqtt ({})'.format(err)) +# msg = str(time.time()) + " Opening" + str(light_avg) + " lx" +# try: +# self.__client.connect(MQTT_HOST, MQTT_PORT) +# self.__client.loop_start() +# self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) +# self.__client.loop_stop() +# except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: +# logging.info('unable to publish to mqtt ({})'.format(err)) self.__gate_run_time = time.time() # workaround for high power after starting engine @@ -312,14 +312,14 @@ class Gate(object): next_state = self.__next_state if self.__is_transition(): self.__engine_1.down() - msg = str(time.time()) + " Closing " + str(light_avg) + " lx" - try: - self.__client.connect(MQTT_HOST, MQTT_PORT) - self.__client.loop_start() - self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) - self.__client.loop_stop() - except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: - logging.info('unable to publish to mqtt ({})'.format(err)) +# msg = str(time.time()) + " Closing " + str(light_avg) + " lx" +# try: +# self.__client.connect(MQTT_HOST, MQTT_PORT) +# self.__client.loop_start() +# self.__client.publish(MQTT_TOPIC, msg, qos=2, retain=True) +# self.__client.loop_stop() +# except (ValueError, TypeError, socket.error, ssl.CertificateError) as err: +# logging.info('unable to publish to mqtt ({})'.format(err)) self.__gate_run_time = time.time() # workaround for high power after starting engine