Skip to content

Commit

Permalink
updated pct logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolivierarsenault committed Nov 28, 2023
1 parent 17292de commit e3286e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 7 additions & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit e3286e1

Please sign in to comment.