diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index d0be4a5..f5bdb96 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -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"] ), diff --git a/tests/test_sensor.py b/tests/test_sensor.py index d87f910..dfd4f58 100755 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -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 = {