Nest improve error message on climate actions (#86853)
* Nest - Climate - Error Messages 1. Error messages were incorrect for some methods, for example async_set_temperature was reporting failure to set hvac_mode. This is corrected. 2. Error messages were incomplete and were not including the entity_id,and the operation being performed that failed. 3. Add unit tests to test the exception handling * Move tests into exiisting error test * Improve readability of error messagepull/86862/head
parent
733798f483
commit
a7ddd592fb
|
@ -290,7 +290,9 @@ class ThermostatEntity(ClimateEntity):
|
|||
try:
|
||||
await trait.set_mode(api_mode)
|
||||
except ApiException as err:
|
||||
raise HomeAssistantError(f"Error setting HVAC mode: {err}") from err
|
||||
raise HomeAssistantError(
|
||||
f"Error setting {self.entity_id} HVAC mode to {hvac_mode}: {err}"
|
||||
) from err
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
|
@ -313,7 +315,9 @@ class ThermostatEntity(ClimateEntity):
|
|||
elif hvac_mode == HVACMode.HEAT and temp:
|
||||
await trait.set_heat(temp)
|
||||
except ApiException as err:
|
||||
raise HomeAssistantError(f"Error setting temperature: {err}") from err
|
||||
raise HomeAssistantError(
|
||||
f"Error setting {self.entity_id} temperature to {kwargs}: {err}"
|
||||
) from err
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Set new target preset mode."""
|
||||
|
@ -325,7 +329,9 @@ class ThermostatEntity(ClimateEntity):
|
|||
try:
|
||||
await trait.set_mode(PRESET_INV_MODE_MAP[preset_mode])
|
||||
except ApiException as err:
|
||||
raise HomeAssistantError(f"Error setting HVAC mode: {err}") from err
|
||||
raise HomeAssistantError(
|
||||
f"Error setting {self.entity_id} preset mode to {preset_mode}: {err}"
|
||||
) from err
|
||||
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
"""Set new target fan mode."""
|
||||
|
@ -342,4 +348,6 @@ class ThermostatEntity(ClimateEntity):
|
|||
try:
|
||||
await trait.set_timer(FAN_INV_MODE_MAP[fan_mode], duration=duration)
|
||||
except ApiException as err:
|
||||
raise HomeAssistantError(f"Error setting HVAC mode: {err}") from err
|
||||
raise HomeAssistantError(
|
||||
f"Error setting {self.entity_id} fan mode to {fan_mode}: {err}"
|
||||
) from err
|
||||
|
|
|
@ -1428,6 +1428,9 @@ async def test_thermostat_hvac_mode_failure(
|
|||
"availableModes": ["HEAT", "COOL", "HEATCOOL", "OFF"],
|
||||
"mode": "COOL",
|
||||
},
|
||||
"sdm.devices.traits.ThermostatTemperatureSetpoint": {
|
||||
"coolCelsius": 25.0,
|
||||
},
|
||||
"sdm.devices.traits.Fan": {
|
||||
"timerMode": "OFF",
|
||||
"timerTimeout": "2019-05-10T03:22:54Z",
|
||||
|
@ -1449,26 +1452,36 @@ async def test_thermostat_hvac_mode_failure(
|
|||
assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
|
||||
|
||||
auth.responses = [aiohttp.web.Response(status=HTTPStatus.BAD_REQUEST)]
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(HomeAssistantError) as e_info:
|
||||
await common.async_set_hvac_mode(hass, HVACMode.HEAT)
|
||||
await hass.async_block_till_done()
|
||||
assert "HVAC mode" in str(e_info)
|
||||
assert "climate.my_thermostat" in str(e_info)
|
||||
assert HVACMode.HEAT in str(e_info)
|
||||
|
||||
auth.responses = [aiohttp.web.Response(status=HTTPStatus.BAD_REQUEST)]
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_set_temperature(
|
||||
hass, hvac_mode=HVACMode.HEAT, temperature=25.0
|
||||
)
|
||||
with pytest.raises(HomeAssistantError) as e_info:
|
||||
await common.async_set_temperature(hass, temperature=25.0)
|
||||
await hass.async_block_till_done()
|
||||
assert "temperature" in str(e_info)
|
||||
assert "climate.my_thermostat" in str(e_info)
|
||||
assert "25.0" in str(e_info)
|
||||
|
||||
auth.responses = [aiohttp.web.Response(status=HTTPStatus.BAD_REQUEST)]
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(HomeAssistantError) as e_info:
|
||||
await common.async_set_fan_mode(hass, FAN_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert "fan mode" in str(e_info)
|
||||
assert "climate.my_thermostat" in str(e_info)
|
||||
assert FAN_ON in str(e_info)
|
||||
|
||||
auth.responses = [aiohttp.web.Response(status=HTTPStatus.BAD_REQUEST)]
|
||||
with pytest.raises(HomeAssistantError):
|
||||
with pytest.raises(HomeAssistantError) as e_info:
|
||||
await common.async_set_preset_mode(hass, PRESET_ECO)
|
||||
await hass.async_block_till_done()
|
||||
assert "preset mode" in str(e_info)
|
||||
assert "climate.my_thermostat" in str(e_info)
|
||||
assert PRESET_ECO in str(e_info)
|
||||
|
||||
|
||||
async def test_thermostat_available(
|
||||
|
|
Loading…
Reference in New Issue