Skip to content

Commit

Permalink
configfile: Add support for reporting runtime_warnings via the API se…
Browse files Browse the repository at this point in the history
…rver

Add a new runtime_warning() method that will add a 'runtime_warning'
type message to the printer.configfile.warnings object.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
  • Loading branch information
KevinOConnor committed Mar 14, 2024
1 parent d99d1a8 commit 0291a15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def __init__(self, printer):
self.printer = printer
self.autosave = None
self.deprecated = {}
self.runtime_warnings = []
self.deprecate_warnings = []
self.status_raw_config = {}
self.status_save_pending = {}
self.status_settings = {}
Expand Down Expand Up @@ -314,6 +316,11 @@ def log_config(self, config):
"======================="]
self.printer.set_rollover_info("config", "\n".join(lines))
# Status reporting
def runtime_warning(self, msg):
logging.warn(msg)
res = {'type': 'runtime_warning', 'message': msg}
self.runtime_warnings.append(res)
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
def deprecate(self, section, option, value=None, msg=None):
self.deprecated[(section, option, value)] = msg
def _build_status(self, config):
Expand All @@ -325,7 +332,7 @@ def _build_status(self, config):
self.status_settings = {}
for (section, option), value in config.access_tracking.items():
self.status_settings.setdefault(section, {})[option] = value
self.status_warnings = []
self.deprecate_warnings = []
for (section, option, value), msg in self.deprecated.items():
if value is None:
res = {'type': 'deprecated_option'}
Expand All @@ -334,7 +341,8 @@ def _build_status(self, config):
res['message'] = msg
res['section'] = section
res['option'] = option
self.status_warnings.append(res)
self.deprecate_warnings.append(res)
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
def get_status(self, eventtime):
return {'config': self.status_raw_config,
'settings': self.status_settings,
Expand Down
6 changes: 4 additions & 2 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,10 @@ def _ready(self):
mcu_freq_mhz = int(mcu_freq / 1000000. + 0.5)
calc_freq_mhz = int(calc_freq / 1000000. + 0.5)
if mcu_freq_mhz != calc_freq_mhz:
logging.warn("MCU '%s' configured for %dMhz but running at %dMhz!",
self._name, mcu_freq_mhz, calc_freq_mhz)
pconfig = self._printer.lookup_object('configfile')
msg = ("MCU '%s' configured for %dMhz but running at %dMhz!"
% (self._name, mcu_freq_mhz, calc_freq_mhz))
pconfig.runtime_warning(msg)
# Config creation helpers
def setup_pin(self, pin_type, pin_params):
pcs = {'endstop': MCU_endstop,
Expand Down

0 comments on commit 0291a15

Please sign in to comment.