From 62f3775cb783a027c8bfb00f4db009dfcdaec2b7 Mon Sep 17 00:00:00 2001 From: Jeff Koenig Date: Fri, 24 Nov 2023 22:04:08 -0500 Subject: [PATCH] feat: add speed factor sensor (#208) * feat: add speed factor sensor * fix: tests * chore: update fixture to test sensor and correct linting --- custom_components/moonraker/sensor.py | 14 ++++++++++++++ tests/conftest.py | 3 +++ tests/test_sensor.py | 1 + 3 files changed, 18 insertions(+) diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index 132f47d..6e2c7a8 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -395,6 +395,20 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities): unit=PERCENTAGE, ) sensors.append(desc) + elif obj == "gcode_move": + desc = MoonrakerSensorDescription( + key="speed_factor", + name="Speed factor", + value_fn=lambda sensor: round( + sensor.coordinator.data["status"]["gcode_move"]["speed_factor"] + * 100, + 2, + ), + subscriptions=[("gcode_move", "speed_factor")], + icon="mdi:speedometer", + unit=PERCENTAGE, + ) + sensors.append(desc) coordinator.load_sensor_data(sensors) await coordinator.async_refresh() diff --git a/tests/conftest.py b/tests/conftest.py index 3e06889..ca05534 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -138,6 +138,9 @@ def get_data_fixture(): "output_pin pwm": { "value": 0.5, }, + "gcode_move": { + "speed_factor": 2.0, + }, }, "printer.info": { "result": { diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 18b20c0..5a3c2d5 100755 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -105,6 +105,7 @@ async def test_sensor_services_update(hass, get_data): ("mainsail_toolhead_position_z", "10.2"), ("mainsail_slicer_print_duration_estimate", "8232.0"), ("mainsail_object_height", "62.6"), + ("mainsail_speed_factor", "200.0"), ], ) async def test_sensors(