Allow setting of hvac_mode when setting temperature in ozw (#39853)

This commit is contained in:
Chris 2020-09-09 08:08:43 -07:00 committed by GitHub
parent 74219663d6
commit 1f000e2c3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 11 deletions

View file

@ -5,6 +5,7 @@ from typing import Optional, Tuple
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN, ClimateEntity
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_COOL,
@ -252,6 +253,11 @@ class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity):
Must know if single or double setpoint.
"""
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode is not None:
await self.async_set_hvac_mode(hvac_mode)
if len(self._current_mode_setpoint_values) == 1:
setpoint = self._current_mode_setpoint_values[0]
target_temp = kwargs.get(ATTR_TEMPERATURE)

View file

@ -57,6 +57,24 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
assert round(msg["payload"]["Value"], 2) == 78.98
assert msg["payload"]["ValueIDKey"] == 281475099443218
# Test hvac_mode with set_temperature
await hass.services.async_call(
"climate",
"set_temperature",
{
"entity_id": "climate.ct32_thermostat_mode",
"temperature": 24.1,
"hvac_mode": "cool",
},
blocking=True,
)
assert len(sent_messages) == 3 # 2 messages
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
# Celsius is converted to Fahrenheit here!
assert round(msg["payload"]["Value"], 2) == 75.38
assert msg["payload"]["ValueIDKey"] == 281475099443218
# Test set mode
await hass.services.async_call(
"climate",
@ -64,7 +82,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
{"entity_id": "climate.ct32_thermostat_mode", "hvac_mode": HVAC_MODE_HEAT_COOL},
blocking=True,
)
assert len(sent_messages) == 2
assert len(sent_messages) == 4
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 3, "ValueIDKey": 122683412}
@ -76,7 +94,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
{"entity_id": "climate.ct32_thermostat_mode", "hvac_mode": "fan_only"},
blocking=True,
)
assert len(sent_messages) == 2
assert len(sent_messages) == 4
assert "Received an invalid hvac mode: fan_only" in caplog.text
# Test set fan mode
@ -86,7 +104,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
{"entity_id": "climate.ct32_thermostat_mode", "fan_mode": "On Low"},
blocking=True,
)
assert len(sent_messages) == 3
assert len(sent_messages) == 5
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 1, "ValueIDKey": 122748948}
@ -98,7 +116,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
{"entity_id": "climate.ct32_thermostat_mode", "fan_mode": "invalid fan mode"},
blocking=True,
)
assert len(sent_messages) == 3
assert len(sent_messages) == 5
assert "Received an invalid fan mode: invalid fan mode" in caplog.text
# Test incoming mode change to auto,
@ -123,7 +141,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 5 # 2 messages !
assert len(sent_messages) == 7 # 2 messages !
msg = sent_messages[-2] # low setpoint
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert round(msg["payload"]["Value"], 2) == 68.0
@ -162,7 +180,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 6
assert len(sent_messages) == 8
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {
@ -180,7 +198,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 7
assert len(sent_messages) == 9
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {
@ -199,7 +217,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 8
assert len(sent_messages) == 10
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {
@ -217,7 +235,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 8
assert len(sent_messages) == 10
assert "Received an invalid preset mode: invalid preset mode" in caplog.text
# test thermostat device without a mode commandclass
@ -244,7 +262,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 9
assert len(sent_messages) == 11
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {
@ -261,5 +279,5 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog):
},
blocking=True,
)
assert len(sent_messages) == 9
assert len(sent_messages) == 11
assert "does not support setting a mode" in caplog.text