39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import asyncio
|
|
import argparse
|
|
import json
|
|
|
|
from enclave_shelly import ShellyBase
|
|
|
|
async def main():
|
|
parser = argparse.ArgumentParser(description="Queries the status of a Shelly device.")
|
|
parser.add_argument("url", type=str, help="The IP or hostname of the Shelly device.")
|
|
|
|
subparsers = parser.add_subparsers(title="commands")
|
|
list_parser = subparsers.add_parser("list", help="List all scripts.")
|
|
list_parser.set_defaults(command="list")
|
|
|
|
create_parser = subparsers.add_parser("create", help="Create a script.")
|
|
create_parser.add_argument("name", type=str, help="Name of the script.")
|
|
create_parser.set_defaults(command="create")
|
|
|
|
delete_parser = subparsers.add_parser("delete", help="Delete a script.")
|
|
delete_parser.add_argument("id", type=int, help="ID of the script.")
|
|
delete_parser.set_defaults(command="delete")
|
|
|
|
args = parser.parse_args()
|
|
|
|
shelly = ShellyBase(args.url)
|
|
|
|
if args.command == "list":
|
|
result = await shelly.get_script_list()
|
|
print(json.dumps(result, indent=4))
|
|
elif args.command == "create":
|
|
result = await shelly.create_script(args.name)
|
|
print(json.dumps(result, indent=4))
|
|
elif args.command == "delete":
|
|
result = await shelly.delete_script(args.id)
|
|
print(json.dumps(result, indent=4))
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|