aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2025-12-08 17:00:25 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2025-12-08 17:00:25 +0000
commit96b7ce92db31f70072eb7949f76b120fd542b552 (patch)
treebde95566c92effcc810799fc99ac004fa1bfc376
parent1de2a671e7260314708a239f8f27cc9457b8140e (diff)
downloadTasmotaCLI-96b7ce92db31f70072eb7949f76b120fd542b552.tar.gz
TasmotaCLI-96b7ce92db31f70072eb7949f76b120fd542b552.zip
Made a non-verbose modeHEADmaster
-rw-r--r--tasmotaMQTTClient.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/tasmotaMQTTClient.py b/tasmotaMQTTClient.py
index 07f7fae..40ff000 100644
--- a/tasmotaMQTTClient.py
+++ b/tasmotaMQTTClient.py
@@ -13,11 +13,12 @@ class MQTTClient:
switch_energy = None
switch_power = None
- def __init__(self, host, friendlyname, username, password, message = None):
+ def __init__(self, host, friendlyname, username, password, verbose = True, message = None):
self.host = host
self.friendlyname = friendlyname
self.username = username
self.password = password
+ self.verbose = verbose
self.message = message
# print("Instantiated. Message:", message)
@@ -31,17 +32,21 @@ class MQTTClient:
self.mqtt_c.username_pw_set(username = username, password = password)
self.mqtt_c.connect(self.host, 1883, 60)
self.mqtt_c.loop_forever()
+
+ def _print(self, *args, **kwargs):
+ if self.verbose:
+ print(*args, **kwargs)
def _on_connect_cb(self, mqtt, userdata, flags, rc):
# print("Connected to broker")
topic = "tele/TasmotaPlug/%s/+" % self.friendlyname
if self.message is None:
- print("Waiting for '%s'" % topic)
+ self._print("Waiting for '%s'" % topic)
self.mqtt_c.subscribe(topic)
else:
self.mqtt_c.publish("cmnd/TasmotaPlug/%s/Power" % self.friendlyname, payload = self.message)
- print("Sent message '%s' to topic 'cmnd/TasmotaPlug/%s/Power'" % (self.message, self.friendlyname))
+ self._print("Sent message '%s' to topic 'cmnd/TasmotaPlug/%s/Power'" % (self.message, self.friendlyname))
SENT_EVENT.set()
self.mqtt_c.disconnect()