✨ printer_safety_warning: Detect broken cbd firmware

This commit is contained in:
Gina Häußge committed 2020-03-24 17:05:02 +01:00
1 parent 27bbab9582
commit 610a7ed8a8
6 files changed
+107 -20

No files matched your search

@@ -11,7 +11,9 @@ from octoprint.access import USER_GROUP
from octoprint.access.permissions import Permissions
from octoprint.util import to_unicode
from .checks import Severity
from .checks.firmware_unsafe import FirmwareUnsafeChecks
from .checks.firmware_broken import FirmwareBrokenChecks
import flask
from flask_babel import gettext
@@ -22,13 +24,14 @@ TERMINAL_SAFETY_WARNING = """
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{message}
Learn more at https://faq.octoprint.org/warning-{warning_type}
Learn more at {url}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"""
SAFETY_CHECKS = {
"firmware-unsafe": FirmwareUnsafeChecks.as_dict()
"firmware-unsafe": FirmwareUnsafeChecks.as_dict(),
"firmware-broken": FirmwareBrokenChecks.as_dict()
}
class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
@@ -46,7 +49,7 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
def get_template_configs(self):
return [
dict(type="sidebar",
name=gettext("Printer Safety Warning"),
name=gettext("Attention!"),
data_bind="visible: printerState.isOperational() && loginState.isAdmin() && warnings().length > 0",
icon="exclamation-triangle",
styles_wrapper=["display: none"])
@@ -117,6 +120,8 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
for warning_type, check_data in SAFETY_CHECKS.items():
checks = check_data.get("checks")
message = check_data.get("message")
severity = check_data.get("severity", Severity.CRITICAL)
url = "https://faq.octoprint.org/warning-{warning_type}".format(warning_type=warning_type)
if not checks or not message:
continue
@@ -139,21 +144,29 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin,
# check if now triggered
if check.triggered:
self._register_warning(warning_type, message)
if check.url is not None:
url = check.url
self._register_warning(warning_type, message, severity, url)
# noinspection PyUnresolvedReferences
self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_name=check.name,
warning_type=warning_type))
warning_type=warning_type,
severity=severity,
url=url))
changes = True
break
if changes:
self._ping_clients()
def _register_warning(self, warning_type, message):
def _register_warning(self, warning_type, message, severity, url):
self._log_to_terminal(TERMINAL_SAFETY_WARNING.format(message="\n".join(textwrap.wrap(message, 75)),
warning_type=warning_type))
self._warnings[warning_type] = message
warning_type=warning_type,
url=url))
self._warnings[warning_type] = dict(message=message,
severity=severity,
url=url)
def _reset_warnings(self):
self._warnings.clear()
@@ -190,13 +203,13 @@ __plugin_url__ = "http://docs.octoprint.org/en/master/bundledplugins/printer_saf
__plugin_description__ = "Checks for unsafe printers/printer firmwares"
__plugin_disabling_discouraged__ = gettext("Without this plugin OctoPrint will no longer be able to "
"check if the printer it is connected to has a known safety "
"issue and inform you about that fact.")
"issue or otherwise broken firmware and inform you about that fact.")
__plugin_license__ = "AGPLv3"
__plugin_implementation__ = PrinterSafetyCheckPlugin()
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_gcode_received,
"octoprint.comm.protocol.firmware.info": __plugin_implementation__.on_firmware_info_received,
"octoprint.comm.protocol.firmware.capabilities": __plugin_implementation__.on_firmware_cap_received,
"octoprint.comm.protocol.gcode.received": (__plugin_implementation__.on_gcode_received, 100),
"octoprint.comm.protocol.firmware.info": (__plugin_implementation__.on_firmware_info_received, 100),
"octoprint.comm.protocol.firmware.capabilities": (__plugin_implementation__.on_firmware_cap_received, 100),
"octoprint.events.register_custom_events": register_custom_events,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions
}
@@ -7,6 +7,7 @@ __copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms
class Check(object):
name = None
url = None
def __init__(self):
self._active = True
@@ -53,3 +54,7 @@ class AuthorCheck(Check):
self._triggered = any(map(lambda x: x in lower_line, self.authors))
self._active = False
class Severity(object):
INFO = "info"
CRITICAL = "critical"
@@ -0,0 +1,48 @@
# -*- 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) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License"
from flask_babel import gettext
from . import Check, Severity
class FirmwareBrokenChecks(object):
@classmethod
def as_dict(cls):
return dict(checks=(CbdCheck(),),
message=gettext("Your printer's firmware is known to have a broken implementation of the "
"communication protocol. This will cause print failures. You'll need to "
"take additional steps for OctoPrint to work with it."),
severity=Severity.INFO)
class CbdCheck(Check):
name = "cbd"
url = "https://faq.octoprint.org/warning-firmware-broken-cbd"
CRITICAL_FRAGMENT = "CBD make it".lower()
def __init__(self):
Check.__init__(self)
self._fragment_matches = None
def received(self, line):
if not line:
return
lower_line = line.lower()
if self.CRITICAL_FRAGMENT in lower_line:
self._fragment_matches = True
self._evaluate()
def _evaluate(self):
if self._fragment_matches is None:
return
self._triggered = self._fragment_matches
self._active = False
def reset(self):
Check.reset(self)
self._fragment_matches = None
@@ -6,7 +6,7 @@ __copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms
from flask_babel import gettext
from octoprint.util.version import get_comparable_version
from . import Check, AuthorCheck
from . import Check, AuthorCheck, Severity
class FirmwareUnsafeChecks(object):
@classmethod
@@ -15,7 +15,8 @@ class FirmwareUnsafeChecks(object):
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."))
"thermal runaway protection). This is a fire risk."),
severity=Severity.CRITICAL)
class AnetA8Check(Check):
"""
@@ -23,8 +23,13 @@ $(function() {
self.fromResponse = function(data) {
var warnings = [];
_.each(data, function(message, warning_type) {
warnings.push({type: warning_type, message: gettext(message)});
_.each(data, function(data, warning_type) {
warnings.push({
type: warning_type,
message: gettext(data.message),
severity: data.severity,
url: data.url
});
});
self.warnings(warnings);
};
@@ -44,7 +49,22 @@ $(function() {
if (data.type === "update") {
self.requestData();
}
}
};
self.cssClass = function(data) {
if (data.severity) {
return "printer_safety_warning_" + data.severity;
} else {
return undefined;
}
};
self.warningText = function(data) {
switch (data.severity) {
case "critical": return gettext("Critical Warning");
default: return gettext("Warning");
}
};
}
OCTOPRINT_VIEWMODELS.push({
@@ -1,7 +1,7 @@
<p><strong>{{ _('Warning!') }}</strong></p>
<!-- ko foreach: warnings -->
<p class="printer_safety_warning">
<p><strong data-bind="text: $root.warningText($data)"></strong></p>
<p class="printer_safety_warning" data-bind="class: $root.cssClass($data)">
<span data-bind="text: message"></span><br>
<a target="_blank" rel="noreferrer noopener" data-bind="attr: {href: 'https://faq.octoprint.org/warning-' + type}">{{ _('Learn more...') }}</a>
<a target="_blank" rel="noreferrer noopener" data-bind="attr: {href: url}">{{ _('Learn more...') }}</a>
</p>
<!-- /ko -->