Avoid homekit crash when temperature is clamped above max value (#37746)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-07-14 22:21:10 +02:00
1 parent 9ecaa10e51
commit f5cbae0cd5
2 files changed
+90 -39

No files matched your search

@@ -1617,3 +1617,57 @@ async def test_thermostat_with_no_off_after_recheck(hass, hk_driver, cls, events
assert acc.char_target_heat_cool.value == 3
assert acc.char_current_temp.value == 18.0
assert acc.char_display_units.value == 0
async def test_thermostat_with_temp_clamps(hass, hk_driver, cls, events):
"""Test that tempatures are clamped to valid values to prevent homekit crash."""
entity_id = "climate.test"
hass.states.async_set(
entity_id,
HVAC_MODE_COOL,
{
ATTR_SUPPORTED_FEATURES: SUPPORT_TARGET_TEMPERATURE
| SUPPORT_TARGET_TEMPERATURE_RANGE,
ATTR_HVAC_MODES: [],
ATTR_MAX_TEMP: 50,
ATTR_MIN_TEMP: 100,
},
)
await hass.async_block_till_done()
acc = cls.thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.char_cooling_thresh_temp.value == 100
assert acc.char_heating_thresh_temp.value == 100
assert acc.char_cooling_thresh_temp.properties[PROP_MAX_VALUE] == 100
assert acc.char_cooling_thresh_temp.properties[PROP_MIN_VALUE] == 100
assert acc.char_cooling_thresh_temp.properties[PROP_MIN_STEP] == 0.1
assert acc.char_heating_thresh_temp.properties[PROP_MAX_VALUE] == 100
assert acc.char_heating_thresh_temp.properties[PROP_MIN_VALUE] == 100
assert acc.char_heating_thresh_temp.properties[PROP_MIN_STEP] == 0.1
assert acc.char_target_heat_cool.value == 2
hass.states.async_set(
entity_id,
HVAC_MODE_HEAT_COOL,
{
ATTR_TARGET_TEMP_HIGH: 822.0,
ATTR_TARGET_TEMP_LOW: 20.0,
ATTR_CURRENT_TEMPERATURE: 9918.0,
ATTR_HVAC_ACTION: CURRENT_HVAC_HEAT,
ATTR_HVAC_MODES: [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO],
},
)
await hass.async_block_till_done()
assert acc.char_heating_thresh_temp.value == 100.0
assert acc.char_cooling_thresh_temp.value == 100.0
assert acc.char_current_heat_cool.value == 1
assert acc.char_target_heat_cool.value == 3
assert acc.char_current_temp.value == 1000
assert acc.char_display_units.value == 0