From c61eb24f01a996b9901e398c97e0e20ca250e2ab Mon Sep 17 00:00:00 2001 From: Jesse Schoepfer Date: Fri, 31 Mar 2023 02:08:40 -0400 Subject: [PATCH] Added CLI entrypoint and updated help --- README.md | 4 ++-- docs/packages.dot | 2 ++ hubitatcontrol/__main__.py | 21 +++++++++++++++++++-- pyproject.toml | 5 ++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1e316a6..06efdc1 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,9 @@ print(device.switch) ### CLI Interface (WIP) - If you have all the needed env vars loaded you can use the env related options - - If not, just use the cli arg based approach + - If not, just use the cli arg based approach, this should be installed system wide ```bash -python3 -m hubitatcontrol print-devices-env +hubitatcontrol print-devices-env ``` ## Docs diff --git a/docs/packages.dot b/docs/packages.dot index 6a0673d..9cca72b 100644 --- a/docs/packages.dot +++ b/docs/packages.dot @@ -2,12 +2,14 @@ digraph "packages" { rankdir=BT charset="utf-8" "hubitatcontrol" [color="black", label=, shape="box", style="solid"]; +"hubitatcontrol.__main__" [color="black", label=, shape="box", style="solid"]; "hubitatcontrol.generic" [color="black", label=, shape="box", style="solid"]; "hubitatcontrol.hub" [color="black", label=, shape="box", style="solid"]; "hubitatcontrol.lights" [color="black", label=, shape="box", style="solid"]; "hubitatcontrol.sensors" [color="black", label=, shape="box", style="solid"]; "hubitatcontrol" -> "hubitatcontrol.generic" [arrowhead="open", arrowtail="none"]; "hubitatcontrol" -> "hubitatcontrol.hub" [arrowhead="open", arrowtail="none"]; +"hubitatcontrol.__main__" -> "hubitatcontrol" [arrowhead="open", arrowtail="none"]; "hubitatcontrol.generic" -> "hubitatcontrol.hub" [arrowhead="open", arrowtail="none"]; "hubitatcontrol.lights" -> "hubitatcontrol.generic" [arrowhead="open", arrowtail="none"]; "hubitatcontrol.sensors" -> "hubitatcontrol.hub" [arrowhead="open", arrowtail="none"]; diff --git a/hubitatcontrol/__main__.py b/hubitatcontrol/__main__.py index 8401a6f..f78c595 100644 --- a/hubitatcontrol/__main__.py +++ b/hubitatcontrol/__main__.py @@ -1,12 +1,25 @@ +from importlib import metadata + import typer + from hubitatcontrol import get_hub -app = typer.Typer(no_args_is_help=True) +version = metadata.version("hubitatcontrol") + +app = typer.Typer( + no_args_is_help=True, + help='Hubitat Control CLI Interface', + epilog=f'Version: {version} \n Project: https://github.com/Jelloeater/hubitatcontrol', +) @app.command() def print_devices_env(): + """ + Loads .env file at current location and prints current devices + """ import os + from dotenv import load_dotenv load_dotenv() @@ -21,15 +34,19 @@ def print_devices_env(): @app.command() def print_devices_cli(host_env, token_env, app_id_env: int, cloud_token_env=typer.Argument(None)): + """ + Prints current devices from CLI input + """ h = get_hub(host=host_env, token=token_env, app_id=app_id_env, cloud_token=cloud_token_env) print_device_list_types(h) def print_device_list_types(hub_in): """Converts hub object input to pretty table console output""" - import prettytable import json + import prettytable + obj_to_table = hub_in.devices for i in obj_to_table: # Clear out extra info diff --git a/pyproject.toml b/pyproject.toml index 3dad819..d564132 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hubitatcontrol" -version = "1.1.1" +version = "1.1.2" description = "Hubitat Maker API Interface" authors = ["Jesse Schoepfer "] license = "MIT License" @@ -14,6 +14,9 @@ classifiers = ["Development Status :: 5 - Production/Stable", "Operating System :: OS Independent", ] +[tool.poetry.scripts] +hubitatcontrol = "hubitatcontrol.__main__:app" + [tool.poetry.dependencies] python = "^3.10"