✨ Add hook to extend serial port names

This commit is contained in:
Gina Häußge committed 2020-06-04 18:58:09 +02:00
1 parent 488a75737c
commit 2206b84f3e
2 files changed
+26

No files matched your search

+19
View File
@@ -890,6 +890,25 @@ octoprint.comm.protocol.temperatures.received
:tab-width: 4
:caption: `sanitize_temperatures.py <https://github.com/OctoPrint/Plugin-Examples/blob/master/sanitize_temperatures.py>`_
.. _sec-plugins-hook-comm-transport-serial-additonal-port-names:
octoprint.comm.transport.serial.additional_port_names
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. py:function:: additional_port_names_hook(candidates, *args, **kwargs)
Return additional port names (not glob patterns!) to use as a serial connection to the printer. Expected to be
``list`` of ``string``s.
Useful in combination with :ref:`octoprint.comm.transport.serial.factory <sec-plugins-hook-comm-transport-serial-factory>`
to implement custom serial-like ports through plugins.
For an example of use see the bundled ``virtual_printer`` plugin.
:param list candidates: The port names already found on the system available for connection.
:return: Additional port names to offer up for connection.
:rtype: list
.. _sec-plugins-hook-comm-transport-serial-factory:
octoprint.comm.transport.serial.factory
+7
View File
@@ -188,6 +188,13 @@ def serialList():
for additional in additionalPorts:
candidates += glob.glob(additional)
hooks = octoprint.plugin.plugin_manager().get_hooks("octoprint.comm.transport.serial.additional_port_names")
for name, hook in hooks.items():
try:
candidates += hook(candidates)
except Exception:
logging.getLogger(__name__).exception("Error while retrieving additional "
"serial port names from hook {}".format(name))
# special treatment for virtual printer
# TODO: Move that exclusively into the plugin