From 1de2a671e7260314708a239f8f27cc9457b8140e Mon Sep 17 00:00:00 2001 From: jwansek Date: Wed, 3 Dec 2025 15:07:27 +0000 Subject: Added optionally adding a password for MQTT, allowing noninteractive running in scripts --- requirements.txt | 2 ++ tasmotaMQTTClient.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index f8fd590..22dd085 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ tasmotadevicecontroller aiohttp paho-mqtt==1.6.1 +docker + diff --git a/tasmotaMQTTClient.py b/tasmotaMQTTClient.py index e8a43b8..07f7fae 100644 --- a/tasmotaMQTTClient.py +++ b/tasmotaMQTTClient.py @@ -72,6 +72,11 @@ parser.add_argument( help = "Username to login with", required = True ) +parser.add_argument( + "-p", "--password", + type = str, + help = "Password to use in scripts. If ran interactively, omit this option otherwise the password will appear in logs" +) parser.add_argument( "-t", "--toggle", action = "store_true", @@ -88,10 +93,8 @@ if __name__ == "__main__": args = vars(parser.parse_args()) if args["mqtt_host"] == "": args["mqtt_host"] = docker_net.get_mqtt_addr()[0] - if args["user"] is not None: + if args["password"] is None: args["password"] = getpass.getpass("Input password for %s@%s: " % (args["user"], args["mqtt_host"])) - else: - args["password"] = None if args["toggle"]: client = MQTTClient(args["mqtt_host"], args["friendlyname"], args["user"], args["password"], "TOGGLE") -- cgit v1.2.3