diff --git a/meshtastic_flasher/tests/test_util.py b/meshtastic_flasher/tests/test_util.py index 28bfcb6..ca61b49 100644 --- a/meshtastic_flasher/tests/test_util.py +++ b/meshtastic_flasher/tests/test_util.py @@ -8,7 +8,7 @@ from meshtastic_flasher.util import (get_path, populate_tag_in_firmware_dropdown, tag_to_version, tags_to_versions, get_tags, download_if_zip_does_not_exist, unzip_if_necessary, - check_if_newer_version) + check_if_newer_version, zero_if_blank) def test_get_path(): @@ -185,3 +185,11 @@ def test_check_if_newer_version_when_on_alpha_and_pre_and_match(patched_requests with patch('meshtastic_flasher.version.__version__', '1.3alpha.5'): result = check_if_newer_version() assert result is False + + +def test_zero_if_blank(): + """Test zero_if_blank()""" + assert zero_if_blank("") == "0" + assert zero_if_blank("0") == "0" + assert zero_if_blank("1") == "1" + assert zero_if_blank("1.1") == "1.1" diff --git a/meshtastic_flasher/util.py b/meshtastic_flasher/util.py index 48acec7..8fe9e8e 100644 --- a/meshtastic_flasher/util.py +++ b/meshtastic_flasher/util.py @@ -178,7 +178,10 @@ def zero_if_blank(some_input): retval = 0 else: try: - retval = int(some_input) + if '.' in some_input: + retval = float(some_input) + else: + retval = int(some_input) except: pass return f'{retval}'