Skip to content

Commit

Permalink
Merge pull request #2960 from casse-boubou/Add-'Availability'-topic-t…
Browse files Browse the repository at this point in the history
…o-MQTT-connection

Add 'Availability' topic to MQTT connection
  • Loading branch information
nicolargo authored Oct 6, 2024
2 parents b2a2a96 + 2af34b3 commit 702b747
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions glances/exports/glances_mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ def init(self):
client_id='glances_' + self.devicename,
clean_session=False,
)

def on_connect(client, userdata, flags, reason_code, properties):
"""Action to perform when connecting."""
self.client.publish(topic='/'.join([self.topic, self.devicename, "availability"]), payload="Online")

def on_disconnect(client, userdata, flags, reason_code, properties):
"""Action to perform when the connection is over."""
self.client.publish(topic='/'.join([self.topic, self.devicename, "availability"]), payload="Offline")

client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.will_set(topic='/'.join([self.topic, self.devicename, "availability"]), payload="Offline")

client.username_pw_set(username=self.user, password=self.password)
if self.tls:
client.tls_set(certifi.where())
Expand Down

0 comments on commit 702b747

Please sign in to comment.