Skip to content

Commit

Permalink
lower the object when accessing the configfile.settings object for ou…
Browse files Browse the repository at this point in the history
…tput_pin

On some device, notably the creality k1, some output_pin configuration
are capitalized. When reading the configfile.settings object those
same configuration are in lower case, make sure to always check with
the lower string for output_pin
  • Loading branch information
cashew22 committed Nov 25, 2023
1 parent 62f3775 commit 0a35e8a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/moonraker/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def async_setup_output_pin(coordinator, entry, async_add_entities):
if "output_pin" not in obj:
continue

if not settings["status"]["configfile"]["settings"][obj]["pwm"]:
if not settings["status"]["configfile"]["settings"][obj.lower()]["pwm"]:
continue

desc = MoonrakerNumberSensorDescription(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/moonraker/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def async_setup_output_pin(coordinator, entry, async_add_entities):
if "output_pin" not in obj:
continue

if settings["status"]["configfile"]["settings"][obj]["pwm"]:
if settings["status"]["configfile"]["settings"][obj.lower()]["pwm"]:
continue

desc = MoonrakerSwitchSensorDescription(
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def get_data_fixture():
"output_pin pwm": {
"pwm": True,
},
"output_pin capitalized": {
"pwm": True,
},
},
},
"print_stats": {
Expand Down Expand Up @@ -138,6 +141,9 @@ def get_data_fixture():
"output_pin pwm": {
"value": 0.5,
},
"output_pin CAPITALIZED": {
"value": 1.0,
},
"gcode_move": {
"speed_factor": 2.0,
},
Expand Down Expand Up @@ -270,6 +276,7 @@ def get_printer_objects_list_fixture():
"filament_switch_sensor filament_sensor_2",
"output_pin digital",
"output_pin pwm",
"output_pin CAPITALIZED",
"fan_generic nevermore_fan",
]
}
Expand Down
4 changes: 1 addition & 3 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def bypass_connect_client_fixture():
# test number
@pytest.mark.parametrize(
"number",
[
("mainsail_output_pin_pwm"),
],
[("mainsail_output_pin_pwm"), ("mainsail_output_pin_CAPITALIZED")],
)
async def test_number_set_value(hass, number, get_default_api_response):
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
Expand Down

0 comments on commit 0a35e8a

Please sign in to comment.