Move get_connection_options as classmethod into PrinterInterface
This commit is contained in:
parent
cf496662e9
commit
b39bb4c961
4 changed files with 39 additions and 34 deletions
|
|
@ -23,31 +23,15 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
|||
|
||||
import re
|
||||
|
||||
import octoprint.util.comm as comm
|
||||
from octoprint.settings import settings
|
||||
from octoprint.util import deprecated
|
||||
|
||||
|
||||
@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():
|
||||
"""
|
||||
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
|
||||
"""
|
||||
return {
|
||||
"ports": comm.serialList(),
|
||||
"baudrates": comm.baudrateList(),
|
||||
"portPreference": settings().get(["serial", "port"]),
|
||||
"baudratePreference": settings().getInt(["serial", "baudrate"]),
|
||||
"autoconnect": settings().getBoolean(["serial", "autoconnect"])
|
||||
}
|
||||
return PrinterInterface.get_connection_options()
|
||||
|
||||
|
||||
class PrinterInterface(object):
|
||||
|
|
@ -65,6 +49,31 @@ class PrinterInterface(object):
|
|||
valid_heater_regex = re.compile("^(tool\d+|bed)$")
|
||||
"""Regex for valid heater identifiers."""
|
||||
|
||||
@classmethod
|
||||
def get_connection_options(cls):
|
||||
"""
|
||||
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": comm.serialList(),
|
||||
"baudrates": comm.baudrateList(),
|
||||
"portPreference": settings().get(["serial", "port"]),
|
||||
"baudratePreference": settings().getInt(["serial", "baudrate"]),
|
||||
"autoconnect": settings().getBoolean(["serial", "autoconnect"])
|
||||
}
|
||||
|
||||
def connect(self, port=None, baudrate=None, profile=None):
|
||||
"""
|
||||
Connects to the printer, using the specified serial ``port``, ``baudrate`` and printer ``profile``. If a
|
||||
|
|
@ -200,7 +209,7 @@ class PrinterInterface(object):
|
|||
|
||||
Arguments:
|
||||
factor (int, float): The factor for the feed rate to send to the firmware. Percentage expressed as either an
|
||||
int between 0 and 100 or a float between 0 and 1.
|
||||
int between 0 and 100 or a float between 0 and 1.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
@ -210,7 +219,7 @@ class PrinterInterface(object):
|
|||
|
||||
Arguments:
|
||||
factor (int, float): The factor for the flow rate to send to the firmware. Percentage expressed as either an
|
||||
int between 0 and 100 or a float between 0 and 1.
|
||||
int between 0 and 100 or a float between 0 and 1.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ user_permission = Permission(RoleNeed("user"))
|
|||
|
||||
# only import the octoprint stuff down here, as it might depend on things defined above to be initialized already
|
||||
from octoprint import __version__, __branch__, __display_version__, __revision__
|
||||
from octoprint.printer import get_connection_options
|
||||
from octoprint.printer.profile import PrinterProfileManager
|
||||
from octoprint.printer.standard import Printer
|
||||
from octoprint.settings import settings
|
||||
|
|
@ -469,7 +468,7 @@ class Server(object):
|
|||
if self._settings.getBoolean(["serial", "autoconnect"]):
|
||||
(port, baudrate) = self._settings.get(["serial", "port"]), self._settings.getInt(["serial", "baudrate"])
|
||||
printer_profile = printerProfileManager.get_default()
|
||||
connectionOptions = get_connection_options()
|
||||
connectionOptions = printer.__class__.get_connection_options()
|
||||
if port in connectionOptions["ports"]:
|
||||
printer.connect(port=port, baudrate=baudrate, profile=printer_profile["id"] if "id" in printer_profile else "_default")
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
|||
from flask import request, jsonify, make_response
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.printer import get_connection_options
|
||||
from octoprint.server import printer, printerProfileManager, NO_CONTENT
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.util.flask import restricted_access, get_json_command_from_request
|
||||
import octoprint.util as util
|
||||
|
||||
|
||||
@api.route("/connection", methods=["GET"])
|
||||
|
|
@ -42,7 +40,7 @@ def connectionCommand():
|
|||
return response
|
||||
|
||||
if command == "connect":
|
||||
connection_options = get_connection_options()
|
||||
connection_options = printer.__class__.get_connection_options()
|
||||
|
||||
port = None
|
||||
baudrate = None
|
||||
|
|
@ -75,7 +73,7 @@ def connectionCommand():
|
|||
return NO_CONTENT
|
||||
|
||||
def _get_options():
|
||||
connection_options = get_connection_options()
|
||||
connection_options = printer.__class__.get_connection_options()
|
||||
profile_options = printerProfileManager.get_all()
|
||||
default_profile = printerProfileManager.get_default()
|
||||
|
||||
|
|
@ -88,4 +86,4 @@ def _get_options():
|
|||
printerProfilePreference=default_profile["id"] if "id" in default_profile else None
|
||||
)
|
||||
|
||||
return options
|
||||
return options
|
||||
|
|
|
|||
|
|
@ -12,9 +12,8 @@ from werkzeug.exceptions import BadRequest
|
|||
|
||||
from octoprint.events import eventManager, Events
|
||||
from octoprint.settings import settings
|
||||
from octoprint.printer import get_connection_options
|
||||
|
||||
from octoprint.server import admin_permission
|
||||
from octoprint.server import admin_permission, printer
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.util.flask import restricted_access
|
||||
|
||||
|
|
@ -30,7 +29,7 @@ def getSettings():
|
|||
|
||||
s = settings()
|
||||
|
||||
connectionOptions = get_connection_options()
|
||||
connectionOptions = printer.__class__.get_connection_options()
|
||||
|
||||
data = {
|
||||
"api": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue