mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Handle generic_thermostat state unavailable (#32852)
* fix sensor unavailable error * fix climate.py
This commit is contained in:
@@ -22,6 +22,8 @@ from homeassistant.const import (
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
@@ -271,6 +273,44 @@ async def test_sensor_bad_value(hass, setup_comp_2):
|
||||
assert temp == state.attributes.get("current_temperature")
|
||||
|
||||
|
||||
async def test_sensor_unknown(hass):
|
||||
"""Test when target sensor is Unknown."""
|
||||
hass.states.async_set("sensor.unknown", STATE_UNKNOWN)
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"climate",
|
||||
{
|
||||
"climate": {
|
||||
"platform": "generic_thermostat",
|
||||
"name": "unknown",
|
||||
"heater": ENT_SWITCH,
|
||||
"target_sensor": "sensor.unknown",
|
||||
}
|
||||
},
|
||||
)
|
||||
state = hass.states.get("climate.unknown")
|
||||
assert state.attributes.get("current_temperature") is None
|
||||
|
||||
|
||||
async def test_sensor_unavailable(hass):
|
||||
"""Test when target sensor is Unavailable."""
|
||||
hass.states.async_set("sensor.unavailable", STATE_UNAVAILABLE)
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"climate",
|
||||
{
|
||||
"climate": {
|
||||
"platform": "generic_thermostat",
|
||||
"name": "unavailable",
|
||||
"heater": ENT_SWITCH,
|
||||
"target_sensor": "sensor.unavailable",
|
||||
}
|
||||
},
|
||||
)
|
||||
state = hass.states.get("climate.unavailable")
|
||||
assert state.attributes.get("current_temperature") is None
|
||||
|
||||
|
||||
async def test_set_target_temp_heater_on(hass, setup_comp_2):
|
||||
"""Test if target temperature turn heater on."""
|
||||
calls = _setup_switch(hass, False)
|
||||
|
||||
Reference in New Issue
Block a user