Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion homeassistant/components/generic_thermostat/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Adds support for generic thermostat units."""
import asyncio
import logging
import math

import voluptuous as vol

Expand Down Expand Up @@ -419,7 +420,10 @@ def _async_switch_changed(self, event):
def _async_update_temp(self, state):
"""Update thermostat with latest state from sensor."""
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:
_LOGGER.error("Unable to update from sensor: %s", ex)

Expand Down
11 changes: 10 additions & 1 deletion tests/components/generic_thermostat/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,18 @@ async def test_sensor_bad_value(hass, setup_comp_2):

_setup_sensor(hass, None)
await hass.async_block_till_done()
state = hass.states.get(ENTITY)
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 temp == state.attributes.get("current_temperature")
assert state.attributes.get("current_temperature") == temp


async def test_sensor_unknown(hass):
Expand Down