From d85d93d1a1217308d266b1d3de4fc40d5aa9fdde Mon Sep 17 00:00:00 2001 From: Aidan Timson Date: Mon, 3 Jan 2022 12:53:25 +0000 Subject: [PATCH] Downgrade OctoPrint printer disconnected errors (#63076) Co-authored-by: Franck Nijhof --- .../components/octoprint/__init__.py | 2 +- homeassistant/components/octoprint/sensor.py | 2 +- tests/components/octoprint/test_sensor.py | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/octoprint/__init__.py b/homeassistant/components/octoprint/__init__.py index bf0322b6c6d..47d2bc51932 100644 --- a/homeassistant/components/octoprint/__init__.py +++ b/homeassistant/components/octoprint/__init__.py @@ -225,7 +225,7 @@ class OctoprintDataUpdateCoordinator(DataUpdateCoordinator): printer = await self._octoprint.get_printer_info() except PrinterOffline: if not self._printer_offline: - _LOGGER.error("Unable to retrieve printer information: Printer offline") + _LOGGER.debug("Unable to retrieve printer information: Printer offline") self._printer_offline = True except ApiError as err: raise UpdateFailed(err) from err diff --git a/homeassistant/components/octoprint/sensor.py b/homeassistant/components/octoprint/sensor.py index 58187e52e4d..8057de55966 100644 --- a/homeassistant/components/octoprint/sensor.py +++ b/homeassistant/components/octoprint/sensor.py @@ -62,7 +62,7 @@ async def async_setup_entry( ) ) else: - _LOGGER.error("Printer appears to be offline, skipping temperature sensors") + _LOGGER.debug("Printer appears to be offline, skipping temperature sensors") entities.append(OctoPrintStatusSensor(coordinator, device_id)) entities.append(OctoPrintJobPercentageSensor(coordinator, device_id)) diff --git a/tests/components/octoprint/test_sensor.py b/tests/components/octoprint/test_sensor.py index a7da0579c10..5f8a0edd373 100644 --- a/tests/components/octoprint/test_sensor.py +++ b/tests/components/octoprint/test_sensor.py @@ -144,3 +144,46 @@ async def test_sensors_paused(hass): assert state.name == "OctoPrint Estimated Finish Time" entry = entity_registry.async_get("sensor.octoprint_estimated_finish_time") assert entry.unique_id == "Estimated Finish Time-uuid" + + +async def test_sensors_printer_disconnected(hass): + """Test the underlying sensors.""" + job = { + "job": {}, + "progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000}, + "state": "Paused", + } + with patch( + "homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0) + ): + await init_integration(hass, "sensor", printer=None, job=job) + + entity_registry = er.async_get(hass) + + state = hass.states.get("sensor.octoprint_job_percentage") + assert state is not None + assert state.state == "50" + assert state.name == "OctoPrint Job Percentage" + entry = entity_registry.async_get("sensor.octoprint_job_percentage") + assert entry.unique_id == "Job Percentage-uuid" + + state = hass.states.get("sensor.octoprint_current_state") + assert state is not None + assert state.state == "unavailable" + assert state.name == "OctoPrint Current State" + entry = entity_registry.async_get("sensor.octoprint_current_state") + assert entry.unique_id == "Current State-uuid" + + state = hass.states.get("sensor.octoprint_start_time") + assert state is not None + assert state.state == "unknown" + assert state.name == "OctoPrint Start Time" + entry = entity_registry.async_get("sensor.octoprint_start_time") + assert entry.unique_id == "Start Time-uuid" + + state = hass.states.get("sensor.octoprint_estimated_finish_time") + assert state is not None + assert state.state == "unknown" + assert state.name == "OctoPrint Estimated Finish Time" + entry = entity_registry.async_get("sensor.octoprint_estimated_finish_time") + assert entry.unique_id == "Estimated Finish Time-uuid"