Reject nan, inf from generic_thermostat sensor (#48771)
parent
f2ef9e7505
commit
61b38baf2e
|
@ -1,6 +1,7 @@
|
||||||
"""Adds support for generic thermostat units."""
|
"""Adds support for generic thermostat units."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -419,7 +420,10 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
||||||
def _async_update_temp(self, state):
|
def _async_update_temp(self, state):
|
||||||
"""Update thermostat with latest state from sensor."""
|
"""Update thermostat with latest state from sensor."""
|
||||||
try:
|
try:
|
||||||
self._cur_temp = float(state.state)
|
cur_temp = float(state.state)
|
||||||
|
if math.isnan(cur_temp) or math.isinf(cur_temp):
|
||||||
|
raise ValueError(f"Sensor has illegal state {state.state}")
|
||||||
|
self._cur_temp = cur_temp
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
_LOGGER.error("Unable to update from sensor: %s", ex)
|
_LOGGER.error("Unable to update from sensor: %s", ex)
|
||||||
|
|
||||||
|
|
|
@ -331,9 +331,18 @@ async def test_sensor_bad_value(hass, setup_comp_2):
|
||||||
|
|
||||||
_setup_sensor(hass, None)
|
_setup_sensor(hass, None)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(ENTITY)
|
state = hass.states.get(ENTITY)
|
||||||
assert temp == state.attributes.get("current_temperature")
|
assert state.attributes.get("current_temperature") == temp
|
||||||
|
|
||||||
|
_setup_sensor(hass, "inf")
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get(ENTITY)
|
||||||
|
assert state.attributes.get("current_temperature") == temp
|
||||||
|
|
||||||
|
_setup_sensor(hass, "nan")
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get(ENTITY)
|
||||||
|
assert state.attributes.get("current_temperature") == temp
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_unknown(hass):
|
async def test_sensor_unknown(hass):
|
||||||
|
|
Loading…
Reference in New Issue