diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index e59e9ad..ec69303 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -518,6 +518,8 @@ def calculate_pct_job(data) -> float: filament_used = data["status"]["print_stats"]["filament_used"] expected_filament = data["filament_total"] devider = 0 + time_pct = 0 + filament_pct = 0 if print_expected_duration != 0: time_pct = data["status"]["display_status"]["progress"] diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 5a3c2d5..c615450 100755 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -217,11 +217,17 @@ async def test_calculate_pct_job(data_for_calculate_pct): async def test_calculate_pct_job_no_time(data_for_calculate_pct): data_for_calculate_pct["estimated_time"] = 0 - assert calculate_pct_job(data_for_calculate_pct) == 0 + assert calculate_pct_job(data_for_calculate_pct) == 0.5 async def test_calculate_pct_job_no_filament(data_for_calculate_pct): data_for_calculate_pct["filament_total"] = 0 + assert calculate_pct_job(data_for_calculate_pct) == 0.6 + + +async def test_calculate_pct_job_no_filament_no_time(data_for_calculate_pct): + data_for_calculate_pct["filament_total"] = 0 + data_for_calculate_pct["estimated_time"] = 0 assert calculate_pct_job(data_for_calculate_pct) == 0