Skip to content

Commit

Permalink
Dedup the set_macro_variables calls so that it won't flood the console
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethjiang committed May 6, 2024
1 parent 06c2941 commit 9a5e40b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions moonraker_obico/moonraker_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, config, sentry, on_event):
self.request_callbacks_lock = threading.RLock() # Because OrderedDict is not thread-safe
self.available_printer_objects = []
self.remote_event_handlers = {}
self._last_set_macro_variables_call = None

def block_until_klippy_ready(self):
run_in_thread(self._start)
Expand Down Expand Up @@ -184,6 +185,10 @@ def macro_is_configured(self, macro_name):
return any(f'gcode_macro {macro_name.lower()}' in item.lower() for item in self.available_printer_objects)

def set_macro_variables(self, macro_name, **kwargs):
current_call = (macro_name, tuple(kwargs.items()))
if self._last_set_macro_variables_call == current_call:
return

if not self.macro_is_configured(macro_name):
_logger.warning(f'{macro_name} not configured as a macro. Check your printer.cfg file.')
return
Expand All @@ -197,6 +202,7 @@ def set_macro_variables(self, macro_name, **kwargs):
raise_for_status=True,
script=script
)
self._last_set_macro_variables_call = current_call
except:
_logger.warning(f'set_macro_variable failed! - SET_GCODE_VARIABLE MACRO={macro_name} VARIABLE={var_name} VALUE={var_value}')

Expand Down

0 comments on commit 9a5e40b

Please sign in to comment.