Skip to content

Commit

Permalink
add None usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolivierarsenault committed Aug 30, 2024
1 parent 0b0b936 commit 0f3f26d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class MoonrakerSensorDescription(SensorEntityDescription):
sensor.coordinator.data["status"]["print_stats"]["info"]["total_layer"]
if "total_layer" in sensor.coordinator.data["status"]["print_stats"]["info"]
and sensor.coordinator.data["status"]["print_stats"]["info"]["total_layer"]
is not None
and sensor.coordinator.data["status"]["print_stats"]["info"]["total_layer"]
> 0
else sensor.coordinator.data["layer_count"]
),
Expand Down
13 changes: 13 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,19 @@ async def test_total_layer_in_info_0(hass, get_data):
assert state.state == "313"


async def test_total_layer_in_info_is_none(hass, get_data):
"""Test."""
get_data["status"]["print_stats"]["info"]["total_layer"] = None

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_total_layer")
assert state.state == "313"


async def test_current_layer_calculated():
"""Test."""
data = {
Expand Down

0 comments on commit 0f3f26d

Please sign in to comment.