Skip to content

Instantly share code, notes, and snippets.

@pschmitt
Created February 19, 2023 21:04
Show Gist options
  • Save pschmitt/d63e0e1053e0be87b70d95a30621a369 to your computer and use it in GitHub Desktop.
Save pschmitt/d63e0e1053e0be87b70d95a30621a369 to your computer and use it in GitHub Desktop.
home-assistant-cli read JSON from stdin patch
diff --git a/homeassistant_cli/plugins/raw.py b/homeassistant_cli/plugins/raw.py
index 46c544e..62e6a1a 100644
--- a/homeassistant_cli/plugins/raw.py
+++ b/homeassistant_cli/plugins/raw.py
@@ -61,7 +61,9 @@ def get(ctx: Configuration, method):
def post(ctx: Configuration, method, json):
"""Do a POST request against api/<method>."""
if json:
- data = json_.loads(json)
+ data = json_.loads(
+ json if json != "-" else click.get_text_stream('stdin').read()
+ )
else:
data = {}
@@ -86,7 +88,9 @@ def websocket(ctx: Configuration, wstype, json): # noqa: D301
Example: --json='{ "area_id":"2c8bf93c8082492f99c989896962f207" }'
"""
if json:
- data = json_.loads(json)
+ data = json_.loads(
+ json if json != "-" else click.get_text_stream('stdin').read()
+ )
else:
data = {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment