hacf-fr / renault-api

https://readthedocs.org/projects/renault-api/
MIT License
106 stars 38 forks source link

`renault-api --json charge sessions` does not output JSON #799

Open lnussbaum opened 1 year ago

lnussbaum commented 1 year ago

... it outputs a text table.

lnussbaum commented 1 year ago

here is a tested patch:

diff --git a/src/renault_api/cli/charge/history.py b/src/renault_api/cli/charge/history.py
index 7cbf988..9311f7c 100644
--- a/src/renault_api/cli/charge/history.py
+++ b/src/renault_api/cli/charge/history.py
@@ -1,4 +1,5 @@
 """CLI function for a vehicle."""
+import json
 from typing import Any
 from typing import Dict
 from typing import List
@@ -33,6 +34,9 @@ async def sessions(
     details = await vehicle.get_details()
     response = await vehicle.get_charges(start=parsed_start, end=parsed_end)
     charges: List[Dict[str, Any]] = response.raw_data["charges"]
+    if ctx_data["json"]:
+        click.echo(json.dumps(charges))
+        return
     if not charges:  # pragma: no cover
         click.echo("No data available.")
         return
epenet commented 6 months ago

Why didn't you create a Pull Request?

epenet commented 6 months ago

Note: the json option was originally intended for the raw http requests, but I'm happy to merge your code if you provide a pull request.