Avoid Nest climate set_temperature eating error (#86920)

* Update climate_sdm.py

* Update test case to detect KeyError

* Throw a defined exception if the condition in encoutered

Include keys from device_traits in error message

* Less diagnostic information in error message
pull/86960/head
PeteRager 2023-01-30 11:01:41 -05:00 committed by GitHub
parent 2c12171e25
commit d22e670334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -304,7 +304,9 @@ class ThermostatEntity(ClimateEntity):
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
temp = kwargs.get(ATTR_TEMPERATURE)
if ThermostatTemperatureSetpointTrait.NAME not in self._device.traits:
return
raise HomeAssistantError(
f"Error setting {self.entity_id} temperature to {kwargs}: Unable to find setpoint trait."
)
trait = self._device.traits[ThermostatTemperatureSetpointTrait.NAME]
try:
if self.preset_mode == PRESET_ECO or hvac_mode == HVACMode.HEAT_COOL:

View File

@ -1259,8 +1259,12 @@ async def test_thermostat_missing_temperature_trait(
assert ATTR_FAN_MODE not in thermostat.attributes
assert ATTR_FAN_MODES not in thermostat.attributes
await common.async_set_temperature(hass, temperature=24.0)
with pytest.raises(HomeAssistantError) as e_info:
await common.async_set_temperature(hass, temperature=24.0)
await hass.async_block_till_done()
assert "temperature" in str(e_info)
assert "climate.my_thermostat" in str(e_info)
assert "24.0" in str(e_info)
assert thermostat.attributes[ATTR_TEMPERATURE] is None