Skip to content

Commit

Permalink
update version, inform available on reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioHR committed Nov 22, 2024
1 parent da7a586 commit b2a0cf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion diematic_server/diematicd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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('/')
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit b2a0cf0

Please sign in to comment.