From 756541a29f31f315d19597beed8360169b0f8dd8 Mon Sep 17 00:00:00 2001 From: Hannu Teulahti Date: Sun, 8 Dec 2024 12:55:09 +0200 Subject: [PATCH 1/3] add temperature_probe --- custom_components/moonraker/sensor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index 70af335..690ca45 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -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", From 4c3d471b249ca1638cfcea3493affe76ad8848d1 Mon Sep 17 00:00:00 2001 From: Hannu Teulahti Date: Sun, 8 Dec 2024 12:55:45 +0200 Subject: [PATCH 2/3] round temperatures --- custom_components/moonraker/sensor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index 690ca45..44d8891 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -352,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, From 11f412544320bf9571e3e0ec39d47244e9201884 Mon Sep 17 00:00:00 2001 From: Hannu Teulahti Date: Mon, 9 Dec 2024 16:16:58 +0200 Subject: [PATCH 3/3] WIP: add test for probe --- tests/conftest.py | 4 ++++ tests/test_sensor.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 38cb6af..489e1ef 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, }, @@ -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", diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 840ac8f..6cbbeb6 100755 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -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"), @@ -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")