1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Correctly support use of Farenheit in Gree Climate component (#50260)

This commit is contained in:
Clifford Roche
2021-06-07 18:21:03 -04:00
committed by GitHub
parent aad90b8644
commit bc30920824
6 changed files with 48 additions and 19 deletions

View File

@@ -55,6 +55,8 @@ from homeassistant.const import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_UNAVAILABLE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@@ -376,26 +378,42 @@ async def test_send_power_off_device_timeout(hass, discovery, device, mock_now):
assert state.state == HVAC_MODE_OFF
async def test_send_target_temperature(hass, discovery, device, mock_now):
@pytest.mark.parametrize(
"units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)]
)
async def test_send_target_temperature(hass, discovery, device, units, temperature):
"""Test for sending target temperature command to the device."""
hass.config.units.temperature_unit = units
if units == TEMP_FAHRENHEIT:
device().temperature_units = 1
await async_setup_gree(hass)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 25.1},
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: temperature},
blocking=True,
)
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.attributes.get(ATTR_TEMPERATURE) == 25
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
# Reset config temperature_unit back to CELSIUS, required for additional tests outside this component.
hass.config.units.temperature_unit = TEMP_CELSIUS
@pytest.mark.parametrize(
"units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)]
)
async def test_send_target_temperature_device_timeout(
hass, discovery, device, mock_now
hass, discovery, device, units, temperature
):
"""Test for sending target temperature command to the device with a device timeout."""
hass.config.units.temperature_unit = units
if units == TEMP_FAHRENHEIT:
device().temperature_units = 1
device().push_state_update.side_effect = DeviceTimeoutError
await async_setup_gree(hass)
@@ -403,24 +421,36 @@ async def test_send_target_temperature_device_timeout(
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 25.1},
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: temperature},
blocking=True,
)
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.attributes.get(ATTR_TEMPERATURE) == 25
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
# Reset config temperature_unit back to CELSIUS, required for additional tests outside this component.
hass.config.units.temperature_unit = TEMP_CELSIUS
async def test_update_target_temperature(hass, discovery, device, mock_now):
@pytest.mark.parametrize(
"units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)]
)
async def test_update_target_temperature(hass, discovery, device, units, temperature):
"""Test for updating target temperature from the device."""
device().target_temperature = 32
hass.config.units.temperature_unit = units
if units == TEMP_FAHRENHEIT:
device().temperature_units = 1
device().target_temperature = temperature
await async_setup_gree(hass)
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.attributes.get(ATTR_TEMPERATURE) == 32
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
# Reset config temperature_unit back to CELSIUS, required for additional tests outside this component.
hass.config.units.temperature_unit = TEMP_CELSIUS
@pytest.mark.parametrize(