Allow setting hvac mode through set_temperature climate method in Gree integration (#101196)
* Allow setting hvac mode through set_temperature climate method * Suggested code simplification when reading hvac mode Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Remove unnecessary temperature unit handling from set temperature with hvac mode tests --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
d97a030872
commit
84b71c9ddb
2 changed files with 47 additions and 1 deletions
|
@ -17,6 +17,7 @@ from greeclimate.device import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
|
ATTR_HVAC_MODE,
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
FAN_HIGH,
|
FAN_HIGH,
|
||||||
FAN_LOW,
|
FAN_LOW,
|
||||||
|
@ -158,6 +159,9 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
||||||
if ATTR_TEMPERATURE not in kwargs:
|
if ATTR_TEMPERATURE not in kwargs:
|
||||||
raise ValueError(f"Missing parameter {ATTR_TEMPERATURE}")
|
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]
|
temperature = kwargs[ATTR_TEMPERATURE]
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting temperature to %d for %s",
|
"Setting temperature to %d for %s",
|
||||||
|
|
|
@ -34,7 +34,11 @@ from homeassistant.components.climate import (
|
||||||
SWING_VERTICAL,
|
SWING_VERTICAL,
|
||||||
HVACMode,
|
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.components.gree.const import FAN_MEDIUM_HIGH, FAN_MEDIUM_LOW
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
|
@ -384,6 +388,9 @@ async def test_send_target_temperature(
|
||||||
"""Test for sending target temperature command to the device."""
|
"""Test for sending target temperature command to the device."""
|
||||||
hass.config.units.temperature_unit = units
|
hass.config.units.temperature_unit = units
|
||||||
|
|
||||||
|
device().power = True
|
||||||
|
device().mode = HVAC_MODES_REVERSE.get(HVACMode.AUTO)
|
||||||
|
|
||||||
fake_device = device()
|
fake_device = device()
|
||||||
if units == UnitOfTemperature.FAHRENHEIT:
|
if units == UnitOfTemperature.FAHRENHEIT:
|
||||||
fake_device.temperature_units = 1
|
fake_device.temperature_units = 1
|
||||||
|
@ -407,12 +414,47 @@ async def test_send_target_temperature(
|
||||||
state.attributes.get(ATTR_CURRENT_TEMPERATURE)
|
state.attributes.get(ATTR_CURRENT_TEMPERATURE)
|
||||||
== fake_device.current_temperature
|
== fake_device.current_temperature
|
||||||
)
|
)
|
||||||
|
assert state.state == HVAC_MODES.get(fake_device.mode)
|
||||||
|
|
||||||
# Reset config temperature_unit back to CELSIUS, required for
|
# Reset config temperature_unit back to CELSIUS, required for
|
||||||
# additional tests outside this component.
|
# additional tests outside this component.
|
||||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
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(
|
@pytest.mark.parametrize(
|
||||||
("units", "temperature"),
|
("units", "temperature"),
|
||||||
[(UnitOfTemperature.CELSIUS, 25), (UnitOfTemperature.FAHRENHEIT, 74)],
|
[(UnitOfTemperature.CELSIUS, 25), (UnitOfTemperature.FAHRENHEIT, 74)],
|
||||||
|
|
Loading…
Add table
Reference in a new issue