Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting hvac mode through set_temperature climate method in Gree integration #101196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/gree/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)

from homeassistant.components.climate import (
ATTR_HVAC_MODE,
FAN_AUTO,
FAN_HIGH,
FAN_LOW,
Expand Down Expand Up @@ -158,6 +159,9 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
if ATTR_TEMPERATURE not in kwargs:
raise ValueError(f"Missing parameter {ATTR_TEMPERATURE}")

if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
await self.async_set_hvac_mode(hvac_mode)

temperature = kwargs[ATTR_TEMPERATURE]
_LOGGER.debug(
"Setting temperature to %d for %s",
Expand Down
44 changes: 43 additions & 1 deletion tests/components/gree/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
SWING_VERTICAL,
HVACMode,
)
from homeassistant.components.gree.climate import FAN_MODES_REVERSE, HVAC_MODES_REVERSE
from homeassistant.components.gree.climate import (
FAN_MODES_REVERSE,
HVAC_MODES,
HVAC_MODES_REVERSE,
)
from homeassistant.components.gree.const import FAN_MEDIUM_HIGH, FAN_MEDIUM_LOW
from homeassistant.const import (
ATTR_ENTITY_ID,
Expand Down Expand Up @@ -384,6 +388,9 @@ async def test_send_target_temperature(
"""Test for sending target temperature command to the device."""
hass.config.units.temperature_unit = units

device().power = True
device().mode = HVAC_MODES_REVERSE.get(HVACMode.AUTO)

fake_device = device()
if units == UnitOfTemperature.FAHRENHEIT:
fake_device.temperature_units = 1
Expand All @@ -407,12 +414,47 @@ async def test_send_target_temperature(
state.attributes.get(ATTR_CURRENT_TEMPERATURE)
== fake_device.current_temperature
)
assert state.state == HVAC_MODES.get(fake_device.mode)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a check that hvac mode didn't change in existing test for setting the temperature, while the new test checks that both temperature and hvac mode got changed.


# Reset config temperature_unit back to CELSIUS, required for
# additional tests outside this component.
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS


@pytest.mark.parametrize(
("temperature", "hvac_mode"),
[
(26, HVACMode.OFF),
(26, HVACMode.HEAT),
(26, HVACMode.COOL),
(26, HVACMode.AUTO),
(26, HVACMode.DRY),
(26, HVACMode.FAN_ONLY),
],
)
async def test_send_target_temperature_with_hvac_mode(
hass: HomeAssistant, discovery, device, temperature, hvac_mode
) -> None:
"""Test for sending target temperature command to the device alongside hvac mode."""
await async_setup_gree(hass)

await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_TEMPERATURE: temperature,
ATTR_HVAC_MODE: hvac_mode,
},
blocking=True,
)

state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
assert state.state == hvac_mode


@pytest.mark.parametrize(
("units", "temperature"),
[(UnitOfTemperature.CELSIUS, 25), (UnitOfTemperature.FAHRENHEIT, 74)],
Expand Down