Don't raise when setting HVAC mode without a mode ZwaveValue (#52444)
* Don't raise an error when setting HVAC mode without a value * change logic based on discord convo and add tests * tweak
This commit is contained in:
parent
6e779855f7
commit
81fe3583c9
2 changed files with 32 additions and 8 deletions
|
@ -469,15 +469,15 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity):
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
if not self._current_mode:
|
hvac_mode_id = self._hvac_modes.get(hvac_mode)
|
||||||
# Thermostat(valve) with no support for setting a mode
|
if hvac_mode_id is None:
|
||||||
raise ValueError(
|
|
||||||
f"Thermostat {self.entity_id} does not support setting a mode"
|
|
||||||
)
|
|
||||||
hvac_mode_value = self._hvac_modes.get(hvac_mode)
|
|
||||||
if hvac_mode_value is None:
|
|
||||||
raise ValueError(f"Received an invalid hvac mode: {hvac_mode}")
|
raise ValueError(f"Received an invalid hvac mode: {hvac_mode}")
|
||||||
await self.info.node.async_set_value(self._current_mode, hvac_mode_value)
|
|
||||||
|
if not self._current_mode:
|
||||||
|
# Thermostat(valve) has no support for setting a mode, so we make it a no-op
|
||||||
|
return
|
||||||
|
|
||||||
|
await self.info.node.async_set_value(self._current_mode, hvac_mode_id)
|
||||||
|
|
||||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set new target preset mode."""
|
"""Set new target preset mode."""
|
||||||
|
|
|
@ -382,6 +382,30 @@ async def test_setpoint_thermostat(hass, client, climate_danfoss_lc_13, integrat
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test setting illegal mode raises an error
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
await hass.services.async_call(
|
||||||
|
CLIMATE_DOMAIN,
|
||||||
|
SERVICE_SET_HVAC_MODE,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: CLIMATE_DANFOSS_LC13_ENTITY,
|
||||||
|
ATTR_HVAC_MODE: HVAC_MODE_COOL,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test that setting HVAC_MODE_HEAT works. If the no-op logic didn't work, this would
|
||||||
|
# raise an error
|
||||||
|
await hass.services.async_call(
|
||||||
|
CLIMATE_DOMAIN,
|
||||||
|
SERVICE_SET_HVAC_MODE,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: CLIMATE_DANFOSS_LC13_ENTITY,
|
||||||
|
ATTR_HVAC_MODE: HVAC_MODE_HEAT,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
assert len(client.async_send_command_no_wait.call_args_list) == 1
|
assert len(client.async_send_command_no_wait.call_args_list) == 1
|
||||||
args = client.async_send_command_no_wait.call_args_list[0][0][0]
|
args = client.async_send_command_no_wait.call_args_list[0][0][0]
|
||||||
assert args["command"] == "node.set_value"
|
assert args["command"] == "node.set_value"
|
||||||
|
|
Loading…
Add table
Reference in a new issue