From ef946460836a09c8a4b18ae9c8a9aface306fc15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 19 Dec 2018 13:17:45 +0100 Subject: [PATCH 1/2] printer_safety: Added version restriction to anycubic detection Had to refactor check system to make this possible. Checks are now implemented in classes that allow to track state. --- .../plugins/printer_safety_check/__init__.py | 257 +++++++++++++++--- 1 file changed, 214 insertions(+), 43 deletions(-) diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py index 01b118ced..c42ed7ae8 100644 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/__init__.py @@ -24,58 +24,213 @@ Learn more at https://faq.octoprint.org/warning-{warning_type} """ -# Anet A8 -ANETA8_M115_TEST = ("aneta8", lambda name, data: name and name.lower().startswith("anet_a8_")) +class Check(object): + name = None -# Anycubic MEGA -ANYCUBIC_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() -ANYCUBIC_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() -ANYCUBIC_RECEIVED_TEST = ("anycubic", lambda line: line and (ANYCUBIC_AUTHOR1 in line.lower() or ANYCUBIC_AUTHOR2 in line.lower())) + def __init__(self): + self._active = True + self._triggered = False -# Creality CR-10s -CR10S_AUTHOR = " | Author: (CR-10Slanguage)".lower() -CR10S_RECEIVED_TEST = ("cr10s", lambda line: line and CR10S_AUTHOR in line.lower()) + def received(self, line): + """Called when receiving a new line from the printer""" + pass -# Creality Ender 3 -ENDER3_AUTHOR = " | Author: (Ender3)".lower() -ENDER3_RECEIVED_TEST = ("ender3", lambda line: line and ENDER3_AUTHOR in line.lower()) + def m115(self, name, data): + """Called when receiving the response to an M115 from the printer""" + pass -# iMe on Micro3D -IME_M115_TEST = ("ime", lambda name, data: name and name.lower().startswith("ime")) + def cap(self, cap, enabled): + """Called when receiving a capability report line""" + pass -# Malyan M200 aka Monoprice Select Mini, versions less than 4.0 -MALYANM200_M115_TEST = ("malyan_m200", lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < get_comparable_version("4.0")) + @property + def active(self): + """Whether this check is still active""" + return self._active -# Stock Micro3D -MICRO3D_M115_TEST = ("micro3d", lambda name, data: name and name.lower().startswith("micro3d")) + @property + def triggered(self): + """Whether the check has been triggered""" + return self._triggered -# Any Repetier versions < 0.92 -REPETIER_BEFORE_092_M115_TEST = ("repetier_before_092", lambda name, data: name and name.lower().startswith("repetier") and extract_repetier_version(name) is not None and extract_repetier_version(name) < get_comparable_version("0.92")) +class AuthorCheck(Check): + authors = () -# THERMAL_PROTECTION capability reported as disabled -THERMAL_PROTECTION_CAP_TEST = ("capability", lambda cap, enabled: cap == "THERMAL_PROTECTION" and not enabled) + AUTHOR = "| Author: ".lower() + + def received(self, line): + if not line: + return + + lower_line = line.lower() + if self.AUTHOR in lower_line: + self._triggered = any(map(lambda x: x in lower_line, self.authors)) + self._active = False + +class AnetA8Check(Check): + """ + Anet A8 stock firmware + + Identified through firmware name "ANET_A8_". + """ + name = "anet_a8" + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("anet_a8_") + self._active = False + +class AnycubicCheck(Check): + """ + Anycubic MEGA stock firmware + + Identified through "Author: (Jolly, xxxxxxxx.CO.)" or "| Author: (**Jolly, xxxxxxxx.CO.**)" in startup messages + combined with "echo:Vx.y.z" in startup messages, with x.y.z < 1.1.2. + """ + name = "anycubic" + + AUTHOR = "| Author: " + VERSION = "echo:V" + + CRITICAL_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() + CRITICAL_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() + + FIXED_VERSION = get_comparable_version("1.1.2") + + def __init__(self): + Check.__init__(self) + self._author_matches = None + self._version_matches = None + + def received(self, line): + if not line: + return + + lower_line = line.lower() + if self.AUTHOR in lower_line: + self._author_matches = self.CRITICAL_AUTHOR1 in lower_line or self.CRITICAL_AUTHOR2 in lower_line + elif line.startswith(self.VERSION): + self._version_matches = self._broken_version(line) + else: + return + + self._evaluate() + + def _broken_version(self, line): + version_str = line[len(self.VERSION):] + version = get_comparable_version(version_str, base=True) + if version is not None and version <= self.FIXED_VERSION: + return True + else: + return False + + def _evaluate(self): + if self._author_matches is None or self._version_matches is None: + return + self._triggered = self._author_matches and self._version_matches + self._active = False + +class CrealityCR10sCheck(AuthorCheck): + """ + Creality CR10s + + Identified through " | Author: (CR-10Slanguage)" in startup messages. + """ + name = "creality_cr10s" + authors = (" | Author: (CR-10Slanguage)".lower(),) + +class CrealityEnder3Check(AuthorCheck): + """ + Creality Ender3 + + Identified through " | Author: (Ender3)" in startup messages. + """ + name = "creality_ender3" + authors = (" | Author: (Ender3)".lower(),) + +class MalyanM200Check(Check): + """ + Malyan M200 stock firmware prior to version 4.0 + + Identified through firmware name "Malyan*", model "M200" and version < 4.0. + """ + name = "malyan_m200" + + FIXED_VERSION = get_comparable_version("4.0") + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < self.FIXED_VERSION + self._active = False + +class Micro3DIMECheck(Check): + """ + Micro3D with IME firmware + + Identified through firmware name "iME*". + """ + name = "micro3d_ime" + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("ime") + self._active = False + +class Micro3DStockCheck(Check): + """ + Micro3D with IME firmware + + Identified through firmware name "Micro3D*". + """ + name = "micro3d" + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("micro3d") + self._active = False + +class RepetierBefore092Check(Check): + """ + Repetier firmware prior to version 0.92 + + Identified through firmware name "Repetier_x.y.z" with x.y.z < 0.92 + """ + name = "repetier_before_092" + + FIXED_VERSION = get_comparable_version("0.92") + + def m115(self, name, data): + if name and name.lower().startswith("repetier"): + version = self._extract_repetier_version(name) + self._triggered = version is not None and version < self.FIXED_VERSION + self._active = False + + def _extract_repetier_version(self, name): + """ + Extracts the Repetier version number from the firmware name. + + Example: "Repetier_0.91" => 0.91 + """ + version = None + if "_" in name: + _, version = name.split("_", 1) + version = get_comparable_version(version, base=True) + return version + +class ThermalProtectionCapCheck(Check): + """ + Firmware reporting disabled THERMAL_PROTECTION capability + """ + name = "capability" + + def cap(self, cap, enabled): + if cap == "THERMAL_PROTECTION": + self._triggered = not enabled SAFETY_CHECKS = { - "firmware-unsafe": dict(m115=(ANETA8_M115_TEST, IME_M115_TEST, MALYANM200_M115_TEST, MICRO3D_M115_TEST, - REPETIER_BEFORE_092_M115_TEST), - received=(ANYCUBIC_RECEIVED_TEST, CR10S_RECEIVED_TEST, ENDER3_RECEIVED_TEST), - cap=(THERMAL_PROTECTION_CAP_TEST,), + "firmware-unsafe": dict(checks=(AnetA8Check(), AnycubicCheck(), CrealityCR10sCheck(), CrealityEnder3Check(), + MalyanM200Check(), Micro3DIMECheck(), Micro3DStockCheck(), RepetierBefore092Check(), + ThermalProtectionCapCheck()), message=gettext(u"Your printer's firmware is known to lack mandatory safety features (e.g. " u"thermal runaway protection). This is a fire risk.")) } -def extract_repetier_version(name): - """ - Extracts the Repetier version number from the firmware name. - - Example: "Repetier_0.91" => 0.91 - """ - version = None - if "_" in name: - _, version = name.split("_", 1) - version = get_comparable_version(version, base=True) - return version - class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, octoprint.plugin.EventHandlerPlugin, octoprint.plugin.SimpleApiPlugin, @@ -142,16 +297,32 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, changes = False for warning_type, check_data in SAFETY_CHECKS.items(): - checks = check_data.get(check_type) + checks = check_data.get("checks") message = check_data.get("message") if not checks or not message: continue - for check_name, check in checks: - if check(*args, **kwargs): + for check in checks: + if not check.active: + # skip non active checks + continue + + method = getattr(check, check_type, None) + if not callable(method): + # skip uncallable checks + continue + + # execute method + try: + method(*args, **kwargs) + except: + self._logger.exception("There was an error running method {} on check {!r}".format(check_type, check)) + continue + + # check if now triggered + if check.triggered: self._register_warning(warning_type, message) - self._event_bus.fire("plugin_printer_safety_check_warning", dict(check_type=check_type, - check_name=check_name, + self._event_bus.fire("plugin_printer_safety_check_warning", dict(check_name=check.name, warning_type=warning_type)) changes = True break From 8e6773d19f243e772e45b1f82b5b6077a12195ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 20 Feb 2019 14:39:21 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20printer=5Fsafety=5Fcheck:=20?= =?UTF-8?q?Fix=20some=20issues=20with=20new=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/printer_safety_check/__init__.py | 226 ++---------------- .../printer_safety_check/checks/__init__.py | 55 +++++ .../checks/firmware_unsafe.py | 180 ++++++++++++++ 3 files changed, 254 insertions(+), 207 deletions(-) create mode 100644 src/octoprint/plugins/printer_safety_check/checks/__init__.py create mode 100644 src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py index c42ed7ae8..f7c8b2fb4 100644 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/__init__.py @@ -1,5 +1,5 @@ -# coding=utf-8 -from __future__ import absolute_import, division, print_function +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' __copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms of the AGPLv3 License" @@ -8,7 +8,8 @@ import octoprint.plugin from octoprint.events import Events from octoprint.server import user_permission -from octoprint.util.version import get_comparable_version + +from .checks.firmware_unsafe import FirmwareUnsafeChecks import flask from flask_babel import gettext @@ -24,211 +25,8 @@ Learn more at https://faq.octoprint.org/warning-{warning_type} """ -class Check(object): - name = None - - def __init__(self): - self._active = True - self._triggered = False - - def received(self, line): - """Called when receiving a new line from the printer""" - pass - - def m115(self, name, data): - """Called when receiving the response to an M115 from the printer""" - pass - - def cap(self, cap, enabled): - """Called when receiving a capability report line""" - pass - - @property - def active(self): - """Whether this check is still active""" - return self._active - - @property - def triggered(self): - """Whether the check has been triggered""" - return self._triggered - -class AuthorCheck(Check): - authors = () - - AUTHOR = "| Author: ".lower() - - def received(self, line): - if not line: - return - - lower_line = line.lower() - if self.AUTHOR in lower_line: - self._triggered = any(map(lambda x: x in lower_line, self.authors)) - self._active = False - -class AnetA8Check(Check): - """ - Anet A8 stock firmware - - Identified through firmware name "ANET_A8_". - """ - name = "anet_a8" - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("anet_a8_") - self._active = False - -class AnycubicCheck(Check): - """ - Anycubic MEGA stock firmware - - Identified through "Author: (Jolly, xxxxxxxx.CO.)" or "| Author: (**Jolly, xxxxxxxx.CO.**)" in startup messages - combined with "echo:Vx.y.z" in startup messages, with x.y.z < 1.1.2. - """ - name = "anycubic" - - AUTHOR = "| Author: " - VERSION = "echo:V" - - CRITICAL_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() - CRITICAL_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() - - FIXED_VERSION = get_comparable_version("1.1.2") - - def __init__(self): - Check.__init__(self) - self._author_matches = None - self._version_matches = None - - def received(self, line): - if not line: - return - - lower_line = line.lower() - if self.AUTHOR in lower_line: - self._author_matches = self.CRITICAL_AUTHOR1 in lower_line or self.CRITICAL_AUTHOR2 in lower_line - elif line.startswith(self.VERSION): - self._version_matches = self._broken_version(line) - else: - return - - self._evaluate() - - def _broken_version(self, line): - version_str = line[len(self.VERSION):] - version = get_comparable_version(version_str, base=True) - if version is not None and version <= self.FIXED_VERSION: - return True - else: - return False - - def _evaluate(self): - if self._author_matches is None or self._version_matches is None: - return - self._triggered = self._author_matches and self._version_matches - self._active = False - -class CrealityCR10sCheck(AuthorCheck): - """ - Creality CR10s - - Identified through " | Author: (CR-10Slanguage)" in startup messages. - """ - name = "creality_cr10s" - authors = (" | Author: (CR-10Slanguage)".lower(),) - -class CrealityEnder3Check(AuthorCheck): - """ - Creality Ender3 - - Identified through " | Author: (Ender3)" in startup messages. - """ - name = "creality_ender3" - authors = (" | Author: (Ender3)".lower(),) - -class MalyanM200Check(Check): - """ - Malyan M200 stock firmware prior to version 4.0 - - Identified through firmware name "Malyan*", model "M200" and version < 4.0. - """ - name = "malyan_m200" - - FIXED_VERSION = get_comparable_version("4.0") - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < self.FIXED_VERSION - self._active = False - -class Micro3DIMECheck(Check): - """ - Micro3D with IME firmware - - Identified through firmware name "iME*". - """ - name = "micro3d_ime" - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("ime") - self._active = False - -class Micro3DStockCheck(Check): - """ - Micro3D with IME firmware - - Identified through firmware name "Micro3D*". - """ - name = "micro3d" - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("micro3d") - self._active = False - -class RepetierBefore092Check(Check): - """ - Repetier firmware prior to version 0.92 - - Identified through firmware name "Repetier_x.y.z" with x.y.z < 0.92 - """ - name = "repetier_before_092" - - FIXED_VERSION = get_comparable_version("0.92") - - def m115(self, name, data): - if name and name.lower().startswith("repetier"): - version = self._extract_repetier_version(name) - self._triggered = version is not None and version < self.FIXED_VERSION - self._active = False - - def _extract_repetier_version(self, name): - """ - Extracts the Repetier version number from the firmware name. - - Example: "Repetier_0.91" => 0.91 - """ - version = None - if "_" in name: - _, version = name.split("_", 1) - version = get_comparable_version(version, base=True) - return version - -class ThermalProtectionCapCheck(Check): - """ - Firmware reporting disabled THERMAL_PROTECTION capability - """ - name = "capability" - - def cap(self, cap, enabled): - if cap == "THERMAL_PROTECTION": - self._triggered = not enabled - SAFETY_CHECKS = { - "firmware-unsafe": dict(checks=(AnetA8Check(), AnycubicCheck(), CrealityCR10sCheck(), CrealityEnder3Check(), - MalyanM200Check(), Micro3DIMECheck(), Micro3DStockCheck(), RepetierBefore092Check(), - ThermalProtectionCapCheck()), - message=gettext(u"Your printer's firmware is known to lack mandatory safety features (e.g. " - u"thermal runaway protection). This is a fire risk.")) + "firmware-unsafe": FirmwareUnsafeChecks.as_dict() } class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, @@ -265,6 +63,8 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, def on_event(self, event, payload): if event == Events.DISCONNECTED: self._reset_warnings() + self._reset_state() + self._reset_checks() ##~~ SimpleApiPlugin API @@ -339,6 +139,18 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, self._warnings.clear() self._ping_clients() + def _reset_state(self): + self._scan_received = True + + def _reset_checks(self): + for warning_type, check_data in SAFETY_CHECKS.items(): + checks = check_data.get("checks") + if not checks: + continue + + for check in checks: + check.reset() + def _log_to_terminal(self, message): if self._printer: lines = message.split("\n") diff --git a/src/octoprint/plugins/printer_safety_check/checks/__init__.py b/src/octoprint/plugins/printer_safety_check/checks/__init__.py new file mode 100644 index 000000000..fbc4a22e4 --- /dev/null +++ b/src/octoprint/plugins/printer_safety_check/checks/__init__.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' +__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License" + + +class Check(object): + name = None + + def __init__(self): + self._active = True + self._triggered = False + + def received(self, line): + """Called when receiving a new line from the printer""" + pass + + def m115(self, name, data): + """Called when receiving the response to an M115 from the printer""" + pass + + def cap(self, cap, enabled): + """Called when receiving a capability report line""" + pass + + @property + def active(self): + """Whether this check is still active""" + return self._active + + @property + def triggered(self): + """Whether the check has been triggered""" + return self._triggered + + def reset(self): + self._active = True + self._triggered = False + + +class AuthorCheck(Check): + authors = () + + AUTHOR = "| Author: ".lower() + + def received(self, line): + if not line: + return + + lower_line = line.lower() + if self.AUTHOR in lower_line: + self._triggered = any(map(lambda x: x in lower_line, self.authors)) + self._active = False + diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py new file mode 100644 index 000000000..f0b0d24c3 --- /dev/null +++ b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py @@ -0,0 +1,180 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' +__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License" + +from flask_babel import gettext +from octoprint.util.version import get_comparable_version +from . import Check, AuthorCheck + +class FirmwareUnsafeChecks(object): + @classmethod + def as_dict(cls): + return dict(checks=(AnetA8Check(), AnycubicCheck(), CrealityCR10sCheck(), CrealityEnder3Check(), + MalyanM200Check(), Micro3DIMECheck(), Micro3DStockCheck(), RepetierBefore092Check(), + ThermalProtectionCapCheck()), + message=gettext("Your printer's firmware is known to lack mandatory safety features (e.g. " + "thermal runaway protection). This is a fire risk.")) + +class AnetA8Check(Check): + """ + Anet A8 stock firmware + + Identified through firmware name "ANET_A8_". + """ + name = "anet_a8" + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("anet_a8_") + self._active = False + +class AnycubicCheck(Check): + """ + Anycubic MEGA stock firmware + + Identified through "Author: (Jolly, xxxxxxxx.CO.)" or "| Author: (**Jolly, xxxxxxxx.CO.**)" in startup messages + combined with "echo:Vx.y.z" in startup messages, with x.y.z < 1.1.2. + """ + name = "anycubic" + + AUTHOR = "| Author: ".lower() + VERSION = "echo:V" + + CRITICAL_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() + CRITICAL_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() + + FIXED_VERSION = get_comparable_version("1.1.2") + + def __init__(self): + Check.__init__(self) + self._author_matches = None + self._version_matches = None + + def received(self, line): + if not line: + return + + lower_line = line.lower() + if self.AUTHOR in lower_line: + self._author_matches = self.CRITICAL_AUTHOR1 in lower_line or self.CRITICAL_AUTHOR2 in lower_line + elif line.startswith(self.VERSION): + self._version_matches = self._broken_version(line) + else: + return + + self._evaluate() + + def _broken_version(self, line): + version_str = line[len(self.VERSION):] + version = get_comparable_version(version_str, base=True) + if version is not None and version <= self.FIXED_VERSION: + return True + else: + return False + + def _evaluate(self): + if self._author_matches is None or self._version_matches is None: + return + self._triggered = self._author_matches and self._version_matches + self._active = False + + def reset(self): + Check.reset(self) + self._author_matches = None + self._version_matches = None + +class CrealityCR10sCheck(AuthorCheck): + """ + Creality CR10s + + Identified through " | Author: (CR-10Slanguage)" in startup messages. + """ + name = "creality_cr10s" + authors = (" | Author: (CR-10Slanguage)".lower(),) + +class CrealityEnder3Check(AuthorCheck): + """ + Creality Ender3 + + Identified through " | Author: (Ender3)" in startup messages. + """ + name = "creality_ender3" + authors = (" | Author: (Ender3)".lower(),) + +class MalyanM200Check(Check): + """ + Malyan M200 stock firmware prior to version 4.0 + + Identified through firmware name "Malyan*", model "M200" and version < 4.0. + """ + name = "malyan_m200" + + FIXED_VERSION = get_comparable_version("4.0") + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < self.FIXED_VERSION + self._active = False + +class Micro3DIMECheck(Check): + """ + Micro3D with IME firmware + + Identified through firmware name "iME*". + """ + name = "micro3d_ime" + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("ime") + self._active = False + +class Micro3DStockCheck(Check): + """ + Micro3D with IME firmware + + Identified through firmware name "Micro3D*". + """ + name = "micro3d" + + def m115(self, name, data): + self._triggered = name and name.lower().startswith("micro3d") + self._active = False + +class RepetierBefore092Check(Check): + """ + Repetier firmware prior to version 0.92 + + Identified through firmware name "Repetier_x.y.z" with x.y.z < 0.92 + """ + name = "repetier_before_092" + + FIXED_VERSION = get_comparable_version("0.92") + + def m115(self, name, data): + if name and name.lower().startswith("repetier"): + version = self._extract_repetier_version(name) + self._triggered = version is not None and version < self.FIXED_VERSION + self._active = False + + def _extract_repetier_version(self, name): + """ + Extracts the Repetier version number from the firmware name. + + Example: "Repetier_0.91" => 0.91 + """ + version = None + if "_" in name: + _, version = name.split("_", 1) + version = get_comparable_version(version, base=True) + return version + +class ThermalProtectionCapCheck(Check): + """ + Firmware reporting disabled THERMAL_PROTECTION capability + """ + name = "capability" + + def cap(self, cap, enabled): + if cap == "THERMAL_PROTECTION": + self._triggered = not enabled + self._active = False