Skip to content

Commit

Permalink
Starting on CLI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelloeater committed Feb 13, 2023
1 parent a05a082 commit 14d3592
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 27 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pip install git+https://github.com/Jelloeater/hubitatcontrol.git

## Usage

**CLI Interface**
```bash
# If you do not have a .env file to load, you will have to input the required vars via CLI
python3 hubitatcontrol/cli.py
```

**Local Example**
```python
import hubitatcontrol as hc
Expand Down
2 changes: 2 additions & 0 deletions docs/hubitatcontrol/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Module hubitatcontrol.cli
=========================
5 changes: 1 addition & 4 deletions docs/hubitatcontrol/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Hubitat Maker API

Sub-modules
-----------
* hubitatcontrol.cli
* hubitatcontrol.generic
* hubitatcontrol.hub
* hubitatcontrol.lights
Expand All @@ -17,8 +18,4 @@ Functions


`lookup_device(hub_in, device_lookup)`
:


`print_device_list_types(hub_in)`
:
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.cli" [color="black", label=<hubitatcontrol.cli>, 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" -> "hubitatcontrol.generic" [arrowhead="open", arrowtail="none"];
"hubitatcontrol" -> "hubitatcontrol.hub" [arrowhead="open", arrowtail="none"];
"hubitatcontrol" -> "hubitatcontrol.lights" [arrowhead="open", arrowtail="none"];
"hubitatcontrol.cli" -> "hubitatcontrol" [arrowhead="open", arrowtail="none"];
"hubitatcontrol.generic" -> "hubitatcontrol.hub" [arrowhead="open", arrowtail="none"];
"hubitatcontrol.lights" -> "hubitatcontrol.generic" [arrowhead="open", arrowtail="none"];
}
36 changes: 33 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ classifiers = ["Development Status :: 5 - Production/Stable",
[tool.poetry.dependencies]
python = "^3.10"
requests = "*"
click = "*"
prettytable= "*"

[tool.pytest.ini_options]
pythonpath = ["src"]
Expand Down
20 changes: 0 additions & 20 deletions src/hubitatcontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,3 @@ def lookup_device(hub_in, device_lookup):
if "Switch" in d["capabilities"]:
return Switch(device_from_hub=d, hub=hub_in)
return d # Fall through return


def print_device_list_types(hub_in):
import os

from dotenv import load_dotenv

envs = load_dotenv()
if envs:
host_env = os.getenv("HUBITAT_HOST")
token_env = os.getenv("HUBITAT_API_TOKEN")
app_id_env = os.getenv("HUBITAT_API_APP_ID")
else:
# TODO Add CLI input if .env not present
host_env = ""
token_env = ""
app_id_env = ""
h = get_hub(host=host_env, token=token_env, app_id=app_id_env)
for i in hub_in.devices:
d = hub_in.get_device(i)
34 changes: 34 additions & 0 deletions src/hubitatcontrol/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import click

from hubitatcontrol import get_hub


@click.command()
def print_device_list_types():
import os

from dotenv import load_dotenv

envs = load_dotenv()
if envs:
host_env = os.getenv("HUBITAT_HOST")
token_env = os.getenv("HUBITAT_API_TOKEN")
app_id_env = os.getenv("HUBITAT_API_APP_ID")
h = get_hub(host=host_env, token=token_env, app_id=app_id_env)
else:
h = hub_creds()
for i in h.devices:
d = h.get_device(i)


# https://click.palletsprojects.com/en/8.1.x/setuptools/#setuptools-integration
@click.command()
@click.argument("host_env")
@click.argument("token_env")
@click.argument("app_id_env")
def hub_creds(host_env, token_env, app_id_env):
return get_hub(host=host_env, token=token_env, app_id=app_id_env)


if __name__ == "__main__":
print_device_list_types()

0 comments on commit 14d3592

Please sign in to comment.