diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-12-16 22:44:42 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-12-16 22:44:42 +0000 |
commit | 8ff27687d163423726f50f2a94fd59ac93cbb0b6 (patch) | |
tree | 4d0895b47e1fb726cd7aee9b28084e244d8706c6 /tasmota-cli.py | |
parent | 58b73d720dad5b4375b3e8a37782ac716f23311e (diff) | |
download | TasmotaCLI-8ff27687d163423726f50f2a94fd59ac93cbb0b6.tar.gz TasmotaCLI-8ff27687d163423726f50f2a94fd59ac93cbb0b6.zip |
Added MQTT CLI
Diffstat (limited to 'tasmota-cli.py')
-rw-r--r-- | tasmota-cli.py | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/tasmota-cli.py b/tasmota-cli.py deleted file mode 100644 index c151f3f..0000000 --- a/tasmota-cli.py +++ /dev/null @@ -1,54 +0,0 @@ -import asyncio -import tasmotadevicecontroller -import argparse -import getpass -import json -import time - -async def main(host, username, password, toggle): - if username is None: - device = await tasmotadevicecontroller.TasmotaDevice.connect(host) - else: - device = await tasmotadevicecontroller.TasmotaDevice.connect(url = host, username = username, password = password) - - if toggle: - await device.setPower(tasmotadevicecontroller.tasmota_types.PowerType.TOGGLE) - time.sleep(2) - - friendlyname = await device.getFriendlyName() - power = await device.getPower() - status8 = await device.sendRawRequest("status 8") - watts = status8["StatusSNS"]["ENERGY"] - print(json.dumps(watts, indent = 4)) - - if power: - print("'%s' is currently ON" % friendlyname) - else: - print("'%s' is currently OFF" % friendlyname) - -parser = argparse.ArgumentParser() -parser.add_argument( - "-d", "--device-host", - type = str, - help = "Tasmota host port", - required = True -) -parser.add_argument( - "-u", "--user", - type = str, - help = "Username to login with" -) -parser.add_argument( - "-t", "--toggle", - action = "store_true", - help = "Toggle current power status" -) - -if __name__ == "__main__": - args = vars(parser.parse_args()) - if args["user"] is not None: - args["password"] = getpass.getpass("Input password for %s@%s: " % (args["user"], args["device_host"])) - else: - args["password"] = None - loop = asyncio.get_event_loop() - loop.run_until_complete(main(args["device_host"], args["user"], args["password"], args["toggle"])) |