mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Use unknown state for octoprint temperature sensors with None value (#59130)
* Mark octoprint temperature sensors as unavaible when value is not supplied * Check for none explictly * Do not mark the entity as unavailable * Swap to using er.get_async
This commit is contained in:
parent
86b12af3dc
commit
5e2d71dc90
@ -211,12 +211,15 @@ class OctoPrintTemperatureSensor(OctoPrintSensorBase):
|
||||
|
||||
for temp in printer.temperatures:
|
||||
if temp.name == self._api_tool:
|
||||
return round(
|
||||
val = (
|
||||
temp.actual_temp
|
||||
if self._temp_type == "actual"
|
||||
else temp.target_temp,
|
||||
2,
|
||||
else temp.target_temp
|
||||
)
|
||||
if val is None:
|
||||
return None
|
||||
|
||||
return round(val, 2)
|
||||
|
||||
return None
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import init_integration
|
||||
|
||||
|
||||
@ -24,7 +26,7 @@ async def test_sensors(hass):
|
||||
):
|
||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("sensor.octoprint_job_percentage")
|
||||
assert state is not None
|
||||
@ -74,3 +76,34 @@ async def test_sensors(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_no_target_temp(hass):
|
||||
"""Test the underlying sensors."""
|
||||
printer = {
|
||||
"state": {
|
||||
"flags": {},
|
||||
"text": "Operational",
|
||||
},
|
||||
"temperature": {"tool1": {"actual": 18.83136, "target": None}},
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
||||
):
|
||||
await init_integration(hass, "sensor", printer=printer)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("sensor.octoprint_actual_tool1_temp")
|
||||
assert state is not None
|
||||
assert state.state == "18.83"
|
||||
assert state.name == "OctoPrint actual tool1 temp"
|
||||
entry = entity_registry.async_get("sensor.octoprint_actual_tool1_temp")
|
||||
assert entry.unique_id == "actual tool1 temp-uuid"
|
||||
|
||||
state = hass.states.get("sensor.octoprint_target_tool1_temp")
|
||||
assert state is not None
|
||||
assert state.state == "unknown"
|
||||
assert state.name == "OctoPrint target tool1 temp"
|
||||
entry = entity_registry.async_get("sensor.octoprint_target_tool1_temp")
|
||||
assert entry.unique_id == "target tool1 temp-uuid"
|
||||
|
Loading…
x
Reference in New Issue
Block a user