From b2a0cf0986a5c7ebdacffaa194b8993bcd7a5e19 Mon Sep 17 00:00:00 2001 From: IgnacioHR Date: Fri, 22 Nov 2024 23:12:55 +0100 Subject: [PATCH] update version, inform available on reconnection --- diematic_server/diematicd.py | 10 +++++++++- setup.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/diematic_server/diematicd.py b/diematic_server/diematicd.py index 3c14f91..9c7d315 100644 --- a/diematic_server/diematicd.py +++ b/diematic_server/diematicd.py @@ -348,6 +348,10 @@ def run_sync_client(self): if self.args.backend and (self.args.backend == 'mqtt' or self.args.backend == 'configured'): try: + if self.mqtt_inform_available: + self.mqttc.publish(self.mqtt_topic_available, 'online').wait_for_publish() + self.mqtt_inform_available = False + if self.ha_discovery and self.shall_run_discovery: self.home_assistant_discovery(data) self.shall_run_discovery = False @@ -840,6 +844,7 @@ def mqtt_client(self): client.on_connect = self.on_mqtt_connect client.on_disconnect = self.on_mqtt_disconnect client.on_message = self.on_mqtt_message + client.on_connect_fail = self.on_mqtt_connect_fail client.will_set(self.mqtt_topic_available, 'offline', 1) except Exception as e: log.error('mqtt found in configuration file but connection raised the following error:',e) @@ -863,7 +868,6 @@ def mqtt_connect(self): connection = self.mqttc.connect(broker, port, 60, clean_start=True) if broker is not None and port is not None else 'Connection parameters are missing' if connection == mqtt.MQTTErrorCode.MQTT_ERR_SUCCESS: self.mqttc.loop_start() - self.mqttc.publish(self.mqtt_topic_available, 'online').wait_for_publish() else: log.error(f'Can\'t connect to mqtt broker, error code is {connection}') except Exception as e: @@ -872,12 +876,16 @@ def mqtt_connect(self): def on_mqtt_connect(self, client, userdata, flags, rc, properties): self.mqtt_connected = True self.mqtt_connecting = False + self.mqtt_inform_available = True log.info('MQTT Connected successfully') def on_mqtt_disconnect(self, client, userdata, flags, rc, properties): self.mqtt_connected = False log.info('MQTT Disconncted!') + def on_mqtt_connect_fail(self, client, userdata): + log.info('MQTT connect fail!') + def on_mqtt_message(self, client, userdata, msg: mqtt.MQTTMessage): log.info(f'Message: userdata:{userdata} topic:{msg.topic} payload:{str(msg.payload)} retained:{msg.retain}') topic_parts = msg.topic.split('/') diff --git a/setup.py b/setup.py index 69cce0b..12496cb 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name = 'diematic_server', - version = '3.0', + version = '3.1', description = 'Unix daemon and supporting models for publishing data from Diematic DeDietrich boiler', long_description = long_description, long_description_content_type = 'text/markdown; charset=UTF-8', @@ -16,7 +16,7 @@ packages = ['diematic_server'], license='MIT', url = 'https://github.com/IgnacioHR/diematic_server', - download_url = 'https://github.com/IgnacioHR/diematic_server/archive/refs/tags/v3.0.tar.gz', + download_url = 'https://github.com/IgnacioHR/diematic_server/archive/refs/tags/v3.1.tar.gz', keywords = ['python', 'home-automation', 'iot', 'influxdb', 'restful', 'modbus', 'de-dietrich', 'diematic', 'mqtt'], install_requires=[ 'daemon==1.2',