Skip to content

Commit

Permalink
fix results in run query
Browse files Browse the repository at this point in the history
  • Loading branch information
pszafer committed Sep 11, 2024
1 parent 8cafda0 commit 3bfd74b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions bosch_thermostat_client/bosch_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import asyncio
from functools import wraps
from yaml import load

try:
from yaml import CLoader as Loader
except ImportError:
Expand Down Expand Up @@ -59,11 +60,12 @@ def set_debug(debug: int) -> None:

def set_default(ctx, param, value):
if os.path.exists(value):
with open(value, 'r') as f:
with open(value, "r") as f:
config = load(f.read(), Loader=Loader)
ctx.default_map = config
return value


def add_options(options):
def _add_options(func):
for option in reversed(options):
Expand All @@ -74,7 +76,9 @@ def _add_options(func):


async def _scan(gateway, smallscan, output, stdout):
_LOGGER.info("Successfully connected to gateway. Found UUID: %s", gateway.uuid)
_LOGGER.info(
"Successfully connected to gateway. Found UUID: %s", gateway.uuid
)
if smallscan:
result = await gateway.smallscan(_type=smallscan.lower())
out_file = output if output else f"smallscan_{gateway.uuid}.json"
Expand All @@ -100,7 +104,7 @@ async def _runquery(gateway, path):
await asyncio.sleep(0.3)
if results:
_LOGGER.info("Query succeed: %s", path)
click.secho(json.dumps(result, indent=4, sort_keys=True), fg="green")
click.secho(json.dumps(results, indent=4, sort_keys=True), fg="green")
else:
_LOGGER.warning("No results from queries: %s", path)

Expand Down Expand Up @@ -199,7 +203,9 @@ async def cli(ctx):
required=False,
help="Path to output file of scan. Default to [raw/small]scan_uuid.json",
),
click.option("--stdout", default=False, count=True, help="Print scan to stdout"),
click.option(
"--stdout", default=False, count=True, help="Print scan to stdout"
),
click.option("-d", "--debug", default=False, count=True),
click.option(
"-i",
Expand All @@ -211,7 +217,9 @@ async def cli(ctx):
click.option(
"-s",
"--smallscan",
type=click.Choice(["HC", "DHW", "SENSORS", "RECORDINGS"], case_sensitive=False),
type=click.Choice(
["HC", "DHW", "SENSORS", "RECORDINGS"], case_sensitive=False
),
help="Scan only single circuit of thermostat.",
),
]
Expand Down Expand Up @@ -312,7 +320,7 @@ async def query(
):
"""Query values of Bosch thermostat."""
set_debug(debug=debug)

if device.upper() in (NEFIT, IVT, EASYCONTROL):
BoschGateway = bosch.gateway_chooser(device_type=device)
else:
Expand Down Expand Up @@ -345,6 +353,7 @@ async def query(
finally:
await gateway.close(force=True)


_path_put_options = [
click.option(
"-p",
Expand All @@ -356,6 +365,7 @@ async def query(
)
]


@cli.command()
@add_options(_cmd1_options)
@add_options(_path_put_options)
Expand Down

0 comments on commit 3bfd74b

Please sign in to comment.