Skip to content

Commit

Permalink
Added CLI entrypoint and updated help
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelloeater committed Mar 31, 2023
1 parent 363aae0 commit c61eb24
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/packages.dot
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ digraph "packages" {
rankdir=BT
charset="utf-8"
"hubitatcontrol" [color="black", label=<hubitatcontrol>, shape="box", style="solid"];
"hubitatcontrol.__main__" [color="black", label=<hubitatcontrol.__main__>, shape="box", style="solid"];
"hubitatcontrol.generic" [color="black", label=<hubitatcontrol.generic>, shape="box", style="solid"];
"hubitatcontrol.hub" [color="black", label=<hubitatcontrol.hub>, shape="box", style="solid"];
"hubitatcontrol.lights" [color="black", label=<hubitatcontrol.lights>, shape="box", style="solid"];
"hubitatcontrol.sensors" [color="black", label=<hubitatcontrol.sensors>, 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"];
Expand Down
21 changes: 19 additions & 2 deletions hubitatcontrol/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hubitatcontrol"
version = "1.1.1"
version = "1.1.2"
description = "Hubitat Maker API Interface"
authors = ["Jesse Schoepfer <jelloeater@gmail.com>"]
license = "MIT License"
Expand All @@ -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"
Expand Down

0 comments on commit c61eb24

Please sign in to comment.