Skip to content

Commit b6d7dec

Browse files
add option to disable json output
1 parent d236570 commit b6d7dec

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

farmbot_sidecar_starter_pack/functions/broker.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def publish(self, message):
7979
if rpc["args"]["label"] == "":
8080
rpc["args"]["label"] = uuid.uuid4().hex if not self.state.test_env else "test"
8181

82-
self.state.print_status(description="Publishing to 'from_clients':")
82+
self.state.print_status(description="Publishing to 'from_clients'")
8383
self.state.print_status(endpoint_json=rpc, update_only=True)
8484
if self.state.dry_run:
8585
self.state.print_status(description="Sending disabled, message not sent.", update_only=True)
@@ -114,7 +114,7 @@ def on_message(_client, _userdata, msg):
114114
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
115115
self.state.print_status(
116116
endpoint_json=json.loads(msg.payload),
117-
description=f"TOPIC: {msg.topic} ({timestamp})\n")
117+
description=f"New message from {msg.topic} ({timestamp})")
118118

119119
self.client.on_message = on_message
120120

@@ -184,7 +184,6 @@ def listen(self, channel, duration=None, publish_payload=None):
184184
self.state.last_messages[channel] = None
185185
continue
186186
seconds = (datetime.now() - start_time).seconds
187-
self.state.print_status(description="", update_only=True)
188187
self.state.print_status(
189188
description=f"Message received after {seconds} seconds",
190189
update_only=True)

farmbot_sidecar_starter_pack/state.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self):
3535
self.last_messages = {}
3636
self.last_published = {}
3737
self.verbosity = 2
38+
self.json_printing = True
3839
self.timeout = {
3940
"api": 15,
4041
"listen": 15,
@@ -64,7 +65,7 @@ def print_status(self, endpoint_json=None, description=None, update_only=False,
6465
print()
6566
if description is not None:
6667
print(indent + description, end=end, flush=(end == ""))
67-
if endpoint_json:
68+
if endpoint_json is not None and self.json_printing:
6869
json_str = json.dumps(endpoint_json, indent=4)
6970
indented_str = indent + json_str.replace("\n", "\n" + indent)
7071
print(indented_str)

0 commit comments

Comments
 (0)