Skip to content

Commit

Permalink
[Bugfix] Strip line and rework regex.
Browse files Browse the repository at this point in the history
Signed-off-by: Juri Berlanda <[email protected]>

# Conflicts:
#	octoprint_autobim/g30.py
  • Loading branch information
j-be committed Sep 29, 2023
1 parent f547052 commit 369ddbe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions octoprint_autobim/async_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions octoprint_autobim/g30.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)$")


Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion octoprint_autobim/templates/autobim_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ G0 Z15</pre>
</p>
<ul>
<li>Klipper: <pre>^// Result is z=(-?\d+\.\d+)$</pre></li>
<li>All other (incl. Marlin)<pre>^Bed X: -?\d+\.\d+ Y: -?\d+\.\d+ Z: (-?\d+\.\d+)$</pre></li>
<li>All other (incl. Marlin)<pre>^Bed X: ?-?\d+\.\d+ Y: ?-?\d+\.\d+ Z: ?(-?\d+\.\d+)$</pre></li>
</ul>
</div>
</form>
13 changes: 11 additions & 2 deletions tests/g30_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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

0 comments on commit 369ddbe

Please sign in to comment.