Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add temperature_probe and round temperatures #450

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading