From 6a39f84f1613b77ceb06df5eee124e62c4332360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 12 Feb 2021 18:47:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20No=20more=20connection=20options?= =?UTF-8?q?=20on=20printers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/comm/TODO.md | 2 + src/octoprint/printer/__init__.py | 38 +--------------- src/octoprint/server/__init__.py | 62 +++++++++++++------------- src/octoprint/server/api/connection.py | 7 +-- src/octoprint/server/api/settings.py | 12 +---- 5 files changed, 36 insertions(+), 85 deletions(-) diff --git a/src/octoprint/comm/TODO.md b/src/octoprint/comm/TODO.md index 2d00ab3a3..af6fa5513 100644 --- a/src/octoprint/comm/TODO.md +++ b/src/octoprint/comm/TODO.md @@ -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 diff --git a/src/octoprint/printer/__init__.py b/src/octoprint/printer/__init__.py index 2f320bdd6..e9ef9b229 100644 --- a/src/octoprint/printer/__init__.py +++ b/src/octoprint/printer/__init__.py @@ -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: - baudrates: - portPreference: - baudratePreference: - autoconnect: - - 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, diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index b9f61d424..032dea249 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -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: diff --git a/src/octoprint/server/api/connection.py b/src/octoprint/server/api/connection.py index 428e3142b..63e45581b 100644 --- a/src/octoprint/server/api/connection.py +++ b/src/octoprint/server/api/connection.py @@ -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, diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 58fcc2d7b..26d6fbd4c 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -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"]),