🔥 No more connection options on printers

This commit is contained in:
Gina Häußge committed 2021-02-12 18:47:39 +01:00
1 parent e60c8db43b
commit 6a39f84f16
5 files changed
+36 -85

No files matched your search

+2
View File
@@ -1,6 +1,8 @@
# General TODOs
* firmware info propagation & FirmwareCheck
* auto connect on start
* save and connect
* SerialTransport:
* additional ports & baudrates for SerialTransport
* port & baudrate blacklist for SerialTransport
+1 -37
View File
@@ -22,17 +22,7 @@ import re
from octoprint.comm.scripts import UnknownScript # noqa: F401,F403
from octoprint.filemanager import FileDestinations
from octoprint.settings import settings
from octoprint.util import deprecated, natural_key
@deprecated(
message="get_connection_options has been replaced by PrinterInterface.get_connection_options",
includedoc="Replaced by :func:`PrinterInterface.get_connection_options`",
since="1.3.0",
)
def get_connection_options():
return PrinterInterface.get_connection_options()
from octoprint.util import deprecated
class PrinterInterface:
@@ -50,32 +40,6 @@ class PrinterInterface:
valid_heater_regex = re.compile(r"^(tool\d+|bed|chamber)$")
"""Regex for valid heater identifiers."""
@classmethod
def get_connection_options(cls, *args, **kwargs):
"""
Retrieves the available ports, baudrates, preferred port and baudrate for connecting to the printer.
Returned ``dict`` has the following structure::
ports: <list of available serial ports>
baudrates: <list of available baudrates>
portPreference: <configured default serial port>
baudratePreference: <configured default baudrate>
autoconnect: <whether autoconnect upon server startup is enabled or not>
Returns:
(dict): A dictionary holding the connection options in the structure specified above
"""
import octoprint.util.comm as comm
return {
"ports": sorted(comm.serialList(), key=natural_key),
"baudrates": sorted(comm.baudrateList(), reverse=True),
"portPreference": settings().get(["serial", "port"]),
"baudratePreference": settings().getInt(["serial", "baudrate"]),
"autoconnect": settings().getBoolean(["serial", "autoconnect"]),
}
def connect(
self,
protocol=None,
+31 -31
View File
@@ -1079,37 +1079,37 @@ class Server:
# analysis backlog
fileManager.process_backlog()
# auto connect
if self._settings.getBoolean(["serial", "autoconnect"]):
self._logger.info(
"Autoconnect on startup is configured, trying to connect to the printer..."
)
try:
(port, baudrate) = (
self._settings.get(["serial", "port"]),
self._settings.getInt(["serial", "baudrate"]),
)
printer_profile = printerProfileManager.get_default()
connectionOptions = printer.__class__.get_connection_options()
if port in connectionOptions["ports"] or port == "AUTO" or port is None:
self._logger.info(
"Trying to connect to configured serial port {}".format(port)
)
printer.connect(
port=port,
baudrate=baudrate,
profile=printer_profile["id"]
if "id" in printer_profile
else "_default",
)
else:
self._logger.info(
"Could not find configured serial port {} in the system, cannot automatically connect to a non existing printer. Is it plugged in and booted up yet?"
)
except Exception:
self._logger.exception(
"Something went wrong while attempting to automatically connect to the printer"
)
# TODO auto connect
# if self._settings.getBoolean(["serial", "autoconnect"]):
# self._logger.info(
# "Autoconnect on startup is configured, trying to connect to the printer..."
# )
# try:
# (port, baudrate) = (
# self._settings.get(["serial", "port"]),
# self._settings.getInt(["serial", "baudrate"]),
# )
# printer_profile = printerProfileManager.get_default()
# connectionOptions = printer.__class__.get_connection_options()
# if port in connectionOptions["ports"] or port == "AUTO" or port is None:
# self._logger.info(
# "Trying to connect to configured serial port {}".format(port)
# )
# printer.connect(
# port=port,
# baudrate=baudrate,
# profile=printer_profile["id"]
# if "id" in printer_profile
# else "_default",
# )
# else:
# self._logger.info(
# "Could not find configured serial port {} in the system, cannot automatically connect to a non existing printer. Is it plugged in and booted up yet?"
# )
# except Exception:
# self._logger.exception(
# "Something went wrong while attempting to automatically connect to the printer"
# )
# start up watchdogs
try:
+1 -6
View File
@@ -77,7 +77,7 @@ def connectionCommand():
return make_response("Invalid printer profile: %s" % printerProfile, 400)
kwargs["profile"] = printerProfile
if "save" in data and data["save"]:
if "save" in data and data["save"]: # TODO
"""
settings().set(["serial", "port"], port)
settings().setInt(["serial", "baudrate"], baudrate)
@@ -130,7 +130,6 @@ def _get_options():
}
)
connection_options = printer.__class__.get_connection_options()
profile_options = printerProfileManager.get_all()
default_profile = printerProfileManager.get_default()
@@ -138,8 +137,6 @@ def _get_options():
default_connection = connectionProfileManager.get_default()
options = {
"ports": connection_options["ports"],
"baudrates": connection_options["baudrates"],
"printerProfiles": [
{
"id": printer_profile["id"],
@@ -154,8 +151,6 @@ def _get_options():
connection_profile.as_dict()
for connection_profile in connection_profiles.values()
],
"portPreference": connection_options["portPreference"],
"baudratePreference": connection_options["baudratePreference"],
"printerProfilePreference": default_profile["id"]
if "id" in default_profile
else None,
+1 -11
View File
@@ -11,7 +11,7 @@ from werkzeug.exceptions import BadRequest
import octoprint.plugin
import octoprint.util
from octoprint.access.permissions import Permissions
from octoprint.server import pluginManager, printer, userManager
from octoprint.server import pluginManager, userManager
from octoprint.server.api import api
from octoprint.server.util.flask import no_firstrun_access, with_revalidation_checking
from octoprint.settings import settings, valid_boolean_trues
@@ -30,7 +30,6 @@ def _etag(lm=None):
if lm is None:
lm = _lastmodified()
connection_options = printer.__class__.get_connection_options()
plugins = sorted(octoprint.plugin.plugin_manager().enabled_plugins)
plugin_settings = _get_plugin_settings()
@@ -63,9 +62,6 @@ def _etag(lm=None):
# output that are not stored in config.yaml
hash_update(repr(sorted_plugin_settings))
# connection options are also part of the settings
hash_update(repr(connection_options))
# if the list of plugins changes, the settings structure changes too
hash_update(repr(plugins))
@@ -92,8 +88,6 @@ def getSettings():
s = settings()
connectionOptions = printer.__class__.get_connection_options()
# NOTE: Remember to adjust the docs of the data model on the Settings API if anything
# is changed, added or removed here
@@ -150,11 +144,7 @@ def getSettings():
},
"gcodeAnalysis": {"runAt": s.get(["gcodeAnalysis", "runAt"])},
"serial": {
"port": connectionOptions["portPreference"],
"baudrate": connectionOptions["baudratePreference"],
"exclusive": s.getBoolean(["serial", "exclusive"]),
"portOptions": connectionOptions["ports"],
"baudrateOptions": connectionOptions["baudrates"],
"autoconnect": s.getBoolean(["serial", "autoconnect"]),
"timeoutConnection": s.getFloat(["serial", "timeout", "connection"]),
"timeoutDetectionFirst": s.getFloat(["serial", "timeout", "detectionFirst"]),