Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duration device class for total print time and longest print sensors #344

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,13 @@ async def async_setup_history_sensors(coordinator, entry, async_add_entities):
MoonrakerSensorDescription(
key="total_print_time",
name="Totals Print Time",
value_fn=lambda sensor: convert_time(
sensor.coordinator.data["history"]["job_totals"]["total_print_time"]
),
value_fn=lambda sensor: sensor.coordinator.data["history"]["job_totals"][
"total_print_time"
],
subscriptions=[],
icon="mdi:clock-outline",
device_class=SensorDeviceClass.DURATION,
unit=UnitOfTime.SECONDS,
),
MoonrakerSensorDescription(
key="total_filament_used",
Expand All @@ -573,11 +575,13 @@ async def async_setup_history_sensors(coordinator, entry, async_add_entities):
MoonrakerSensorDescription(
key="longest_print",
name="Longest Print",
value_fn=lambda sensor: convert_time(
sensor.coordinator.data["history"]["job_totals"]["longest_print"]
),
value_fn=lambda sensor: sensor.coordinator.data["history"]["job_totals"][

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the failing test you probably need to round the value

"longest_print"
],
subscriptions=[],
icon="mdi:clock-outline",
device_class=SensorDeviceClass.DURATION,
unit=UnitOfTime.SECONDS,
),
]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
("mainsail_heater_fan", "51.23"),
("mainsail_controller_fan", "51.23"),
("mainsail_nevermore_fan", "12.34"),
("mainsail_totals_print_time", "3h 9m 9s"),
("mainsail_totals_print_time", "11348.79"),
("mainsail_totals_jobs", "3"),
("mainsail_totals_filament_used", "11.62"),
("mainsail_longest_print", "3h 9m 9s"),
("mainsail_longest_print", "11348.79"),
("mainsail_total_layer", "313"),
("mainsail_current_layer", "51"),
("mainsail_toolhead_position_x", "23.3"),
Expand All @@ -129,7 +129,7 @@
assert await async_setup_entry(hass, config_entry)
await hass.async_block_till_done()

assert hass.states.get(f"sensor.{sensor}").state == value

Check failure on line 132 in tests/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests

test_sensors[mainsail_totals_print_time-11348.79] AssertionError: assert '11348.794790097' == '11348.79' - 11348.79 + 11348.794790097

Check failure on line 132 in tests/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests

test_sensors[mainsail_longest_print-11348.79] AssertionError: assert '11348.794790097' == '11348.79' - 11348.79 + 11348.794790097


# test all sensors
Expand Down
Loading