Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lnussbaum opened this issue Feb 13, 2023 · 3 comments
Open

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

lnussbaum opened this issue Feb 13, 2023 · 3 comments

Comments

@lnussbaum
Copy link

... it outputs a text table.

@lnussbaum
Copy link
Author

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
Copy link
Collaborator

epenet commented Mar 13, 2024

Why didn't you create a Pull Request?

@epenet
Copy link
Collaborator

epenet commented Mar 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants