Skip to content

Commit

Permalink
Disable default debug logging, allow status for one VIN only
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Feb 11, 2024
1 parent 5eb68d8 commit de08873
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions bimmer_connected/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@

def main_parser() -> argparse.ArgumentParser:
"""Create the ArgumentParser with all relevant subparsers."""
logging.basicConfig(level=logging.DEBUG)

parser = argparse.ArgumentParser(description="A simple executable to use and test the library.")
parser.add_argument("--debug", help="Print debug logs.", action="store_true")
subparsers = parser.add_subparsers(dest="cmd")
subparsers.required = True

status_parser = subparsers.add_parser("status", description="Get the current status of the vehicle.")
status_parser.add_argument(
"-j", "--json", help="Output as JSON only. Removes all other output.", action="store_true"
)
status_parser.add_argument("-v", "--vin", help="Output data for specified VIN only.", type=str, nargs="?")

_add_default_arguments(status_parser)
_add_position_arguments(status_parser)

Expand Down Expand Up @@ -136,11 +137,16 @@ async def get_status(args) -> None:
await account.get_vehicles()

if args.json:
print(json.dumps(account.vehicles, cls=MyBMWJSONEncoder))
if args.vin:
print(json.dumps(account.get_vehicle(args.vin), cls=MyBMWJSONEncoder))
else:
print(json.dumps(account.vehicles, cls=MyBMWJSONEncoder))
else:
print(f"Found {len(account.vehicles)} vehicles: {','.join([v.name for v in account.vehicles])}")

for vehicle in account.vehicles:
if args.vin and vehicle.vin != args.vin:
continue
print(f"VIN: {vehicle.vin}")
print(f"Mileage: {vehicle.mileage.value} {vehicle.mileage.unit}")
print("Vehicle data:")
Expand Down Expand Up @@ -327,6 +333,10 @@ def main():
parser = main_parser()
args = parser.parse_args()

if args.debug:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("asyncio").setLevel(logging.WARNING)

loop = asyncio.get_event_loop()
loop.run_until_complete(args.func(args))

Expand Down

0 comments on commit de08873

Please sign in to comment.