Skip to content

Commit

Permalink
only add diffs to last diff messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Sep 12, 2024
1 parent 0d7641b commit 0f8b91d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 2 additions & 3 deletions farmbot/functions/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,14 @@ def on_message(_client, _userdata, msg):
add_message(path_channel, payload)

if diff_only:
diff = payload
key = path_channel if len(path) > 0 else channel_key
last_messages = self.state.last_messages.get(key, [])
if len(last_messages) > 1:
current = last_messages[-1]
previous = last_messages[-2]
diff, _is_different = difference(current, previous)
payload = diff
add_message(f"{channel_key}_diffs", payload)
payload = diff
add_message(f"{channel_key}_diffs", payload)

self.state.print_status(description="", update_only=True)
description = "New message"
Expand Down
1 change: 0 additions & 1 deletion tests/tests_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ def patched_sleep(_seconds):
{'location_data': {'position': {'x': 4, 'y': 14, 'z': 100}}}
])
self.assertEqual(self.fb.state.last_messages['status_diffs'], [
{'x': 0, 'y': 10, 'z': 100},
{'x': 1, 'y': 11},
{'extra': {'idx': 2}, 'x': 2, 'y': 12},
{'extra': {'idx': 3}, 'x': 3, 'y': 13},
Expand Down

0 comments on commit 0f8b91d

Please sign in to comment.