diff --git a/octoprint_autobim/async_command.py b/octoprint_autobim/async_command.py index 1d6c65d..b20ddca 100644 --- a/octoprint_autobim/async_command.py +++ b/octoprint_autobim/async_command.py @@ -47,9 +47,9 @@ def _set_running(self): # Do not touch the rest of the implementation def handle(self, line): - if not self.__running: + if not self.__running or not line: return - self._handle_internal(line) + self._handle_internal(line.strip()) def _register_result(self, result): self.__running = False diff --git a/octoprint_autobim/g30.py b/octoprint_autobim/g30.py index 711b45a..a6ecb0b 100644 --- a/octoprint_autobim/g30.py +++ b/octoprint_autobim/g30.py @@ -4,7 +4,7 @@ from octoprint_autobim.utils import filter_commands -MARLIN_PATTERN = re.compile(r"^Bed X: -?\d+\.\d+ Y: -?\d+\.\d+ Z: (-?\d+\.\d+)$") +MARLIN_PATTERN = re.compile(r"^Bed X: ?-?\d+\.\d+ Y: ?-?\d+\.\d+ Z: ?(-?\d+\.\d+)$") KLIPPER_PATTERN = re.compile(r"^// Result is z=(-?\d+\.\d+)$") @@ -51,11 +51,11 @@ def _start(self, point): self._printer.commands(command) def _handle_internal(self, line): - if "Error:Probing Failed" == line.strip(): + if "Error:Probing Failed" == line: self._register_result(Result.error()) return - if self._ok_is_error and "ok" == line.strip(): + if self._ok_is_error and "ok" == line: self._register_result(Result.error()) return diff --git a/octoprint_autobim/templates/autobim_settings.jinja2 b/octoprint_autobim/templates/autobim_settings.jinja2 index 4d9f84f..6da9efe 100644 --- a/octoprint_autobim/templates/autobim_settings.jinja2 +++ b/octoprint_autobim/templates/autobim_settings.jinja2 @@ -142,7 +142,7 @@ G0 Z15

diff --git a/tests/g30_test.py b/tests/g30_test.py index e8363b9..1fa128c 100644 --- a/tests/g30_test.py +++ b/tests/g30_test.py @@ -95,12 +95,12 @@ def test_pattern_selection(g30): # Default is Marlin printer.firmware_info = {"name": ""} g30._start((1, 2)) - assert g30.pattern.pattern == "^Bed X: -?\\d+\\.\\d+ Y: -?\\d+\\.\\d+ Z: (-?\\d+\\.\\d+)$" + assert g30.pattern.pattern == "^Bed X: ?-?\\d+\\.\\d+ Y: ?-?\\d+\\.\\d+ Z: ?(-?\\d+\\.\\d+)$" # Marlin printer.firmware_info = {"name": "Marlin 2.0.9.1"} g30._start((1, 2)) - assert g30.pattern.pattern == "^Bed X: -?\\d+\\.\\d+ Y: -?\\d+\\.\\d+ Z: (-?\\d+\\.\\d+)$" + assert g30.pattern.pattern == "^Bed X: ?-?\\d+\\.\\d+ Y: ?-?\\d+\\.\\d+ Z: ?(-?\\d+\\.\\d+)$" # Klipper printer.firmware_info = {"name": "Klipper"} @@ -152,3 +152,12 @@ def test_retry_on_error(g30): assert result.has_value() is False assert result.error is True assert result.abort is False + + +def test_pattern_without_spaces(g30): + g30._start((30, 30)) + g30.handle("Bed X:32.0 Y:202.0 Z:0.15\n") + g30.handle("ok") + result = g30._get(0) + assert result.has_value() + assert result.value == 0.15