Skip to content

Commit

Permalink
add temperature_probe and round temperatures (#450)
Browse files Browse the repository at this point in the history
* add temperature_probe

* round temperatures

* WIP: add test for probe

---------

Co-authored-by: Marc-Olivier Arsenault <[email protected]>
  • Loading branch information
hannut and marcolivierarsenault authored Dec 9, 2024
1 parent 9e25bc3 commit 6890a98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities):
temperature_keys = [
"temperature_sensor",
"temperature_fan",
"temperature_probe",
"tmc2240",
"bme280",
"htu21d",
Expand All @@ -351,9 +352,10 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities):
status_key=obj,
name=split_obj[1].removesuffix("_temp").replace("_", " ").title()
+ " Temp",
value_fn=lambda sensor: sensor.coordinator.data["status"][
sensor.status_key
]["temperature"],
value_fn=lambda sensor: round(
sensor.coordinator.data["status"][sensor.status_key]["temperature"],
2,
),
subscriptions=[(obj, "temperature")],
icon="mdi:thermometer",
unit=UnitOfTemperature.CELSIUS,
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def get_data_fixture():
"speed": 0.1234,
"rpm": 4500,
},
"temperature_probe eddy_temp": {
"temperature": 32.43,
},
"temperature_host host_temp": {
"temperature": 32.43,
},
Expand Down Expand Up @@ -293,6 +296,7 @@ def get_printer_objects_list_fixture():
"bed_mesh",
"screws_tilt_adjust",
"temperature_sensor mcu_temp",
"temperature_probe eddy_temp",
"stepper_enable",
"motion_report",
"query_endstops",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async def test_sensor_services_update(hass, get_data):
"sensor, value",
[
("mainsail_mcu_temp", "32.43"),
("mainsail_eddy_temp", "32.43"),
("mainsail_bed_target", "60.0"),
("mainsail_bed_temperature", "60.01"),
("mainsail_extruder_target", "205.0"),
Expand Down Expand Up @@ -215,6 +216,20 @@ async def test_opt_sensor_missing(hass, get_data, get_printer_objects_list):
assert state is None


async def test_opt_probe_missing(hass, get_data, get_printer_objects_list):
"""Test."""
get_data["status"].pop("temperature_probe eddy_temp", None)
get_printer_objects_list["objects"].remove("temperature_probe eddy_temp")

config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

state = hass.states.get("sensor.mainsail_eddy_temp")
assert state is None


async def test_eta(hass):
"""Test."""
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
Expand Down

0 comments on commit 6890a98

Please sign in to comment.