Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
self._cur_temp = cur_temp
except ValueError as ex:
_LOGGER.error("Unable to update from sensor: %s", ex)

Expand Down
9 changes: 9 additions & 0 deletions tests/components/generic_thermostat/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,16 @@ 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 temp == state.attributes.get("current_temperature")
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

_setup_sensor(hass, "inf")
await hass.async_block_till_done()
state = hass.states.get(ENTITY)
assert temp == state.attributes.get("current_temperature")

_setup_sensor(hass, "nan")
await hass.async_block_till_done()
state = hass.states.get(ENTITY)
assert temp == state.attributes.get("current_temperature")

Expand Down