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

Missing float data #262

Merged
merged 2 commits into from
Jan 23, 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: 4 additions & 4 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MoonrakerSensorDescription(SensorEntityDescription):
key="extruder_temp",
name="Extruder Temperature",
value_fn=lambda sensor: float(
sensor.coordinator.data["status"]["extruder"]["temperature"]
sensor.coordinator.data["status"]["extruder"]["temperature"] or 0.0
),
subscriptions=[("extruder", "temperature")],
icon="mdi:printer-3d-nozzle-heat",
Expand All @@ -91,7 +91,7 @@ class MoonrakerSensorDescription(SensorEntityDescription):
key="extruder_target",
name="Extruder Target",
value_fn=lambda sensor: float(
sensor.coordinator.data["status"]["extruder"]["target"]
sensor.coordinator.data["status"]["extruder"]["target"] or 0.0
),
subscriptions=[("extruder", "target")],
icon="mdi:printer-3d-nozzle-heat",
Expand All @@ -101,7 +101,7 @@ class MoonrakerSensorDescription(SensorEntityDescription):
key="bed_target",
name="Bed Target",
value_fn=lambda sensor: float(
sensor.coordinator.data["status"]["heater_bed"]["target"]
sensor.coordinator.data["status"]["heater_bed"]["target"] or 0.0
),
subscriptions=[("heater_bed", "target")],
icon="mdi:radiator",
Expand All @@ -111,7 +111,7 @@ class MoonrakerSensorDescription(SensorEntityDescription):
key="bed_temp",
name="Bed Temperature",
value_fn=lambda sensor: float(
sensor.coordinator.data["status"]["heater_bed"]["temperature"]
sensor.coordinator.data["status"]["heater_bed"]["temperature"] or 0.0
),
subscriptions=[("heater_bed", "temperature")],
icon="mdi:radiator",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ async def test_opt_sensor_missing(hass, get_data, get_printer_objects_list):
assert state is None


async def test_missing_heater_bed(hass, get_data):
"""test."""
get_data["status"]["heater_bed"]["target"] = None

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

assert hass.states.get("sensor.mainsail_bed_target").state == "0.0"


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