Skip to content

Commit

Permalink
feat: add speed factor sensor (#208)
Browse files Browse the repository at this point in the history
* feat: add speed factor sensor

* fix: tests

* chore: update fixture to test sensor and correct linting
  • Loading branch information
TheJefe authored Nov 25, 2023
1 parent f44870c commit 62f3775
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def get_data_fixture():
"output_pin pwm": {
"value": 0.5,
},
"gcode_move": {
"speed_factor": 2.0,
},
},
"printer.info": {
"result": {
Expand Down
1 change: 1 addition & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 62f3775

Please sign in to comment.