mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Migrate gree tests to use unit system (#140358)
This commit is contained in:
parent
b160ce21fc
commit
289e94f270
@ -67,6 +67,11 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
from homeassistant.util.unit_system import (
|
||||||
|
METRIC_SYSTEM,
|
||||||
|
US_CUSTOMARY_SYSTEM,
|
||||||
|
UnitSystem,
|
||||||
|
)
|
||||||
|
|
||||||
from .common import async_setup_gree, build_device_mock
|
from .common import async_setup_gree, build_device_mock
|
||||||
|
|
||||||
@ -411,19 +416,19 @@ async def test_send_power_off_device_timeout(
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("units", "temperature"),
|
("units", "temperature"),
|
||||||
[(UnitOfTemperature.CELSIUS, 26), (UnitOfTemperature.FAHRENHEIT, 73)],
|
[(METRIC_SYSTEM, 26), (US_CUSTOMARY_SYSTEM, 73)],
|
||||||
)
|
)
|
||||||
async def test_send_target_temperature(
|
async def test_send_target_temperature(
|
||||||
hass: HomeAssistant, discovery, device, units, temperature
|
hass: HomeAssistant, discovery, device, units: UnitSystem, temperature
|
||||||
) -> None:
|
) -> None:
|
||||||
"""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 = units
|
||||||
|
|
||||||
device().power = True
|
device().power = True
|
||||||
device().mode = HVAC_MODES_REVERSE.get(HVACMode.AUTO)
|
device().mode = HVAC_MODES_REVERSE.get(HVACMode.AUTO)
|
||||||
|
|
||||||
fake_device = device()
|
fake_device = device()
|
||||||
if units == UnitOfTemperature.FAHRENHEIT:
|
if units.temperature_unit == UnitOfTemperature.FAHRENHEIT:
|
||||||
fake_device.temperature_units = 1
|
fake_device.temperature_units = 1
|
||||||
|
|
||||||
await async_setup_gree(hass)
|
await async_setup_gree(hass)
|
||||||
@ -435,7 +440,7 @@ async def test_send_target_temperature(
|
|||||||
ENTITY_ID,
|
ENTITY_ID,
|
||||||
"off",
|
"off",
|
||||||
{
|
{
|
||||||
ATTR_UNIT_OF_MEASUREMENT: units,
|
ATTR_UNIT_OF_MEASUREMENT: units.temperature_unit,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -451,10 +456,6 @@ async def test_send_target_temperature(
|
|||||||
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
|
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
|
||||||
assert state.state == HVAC_MODES.get(fake_device.mode)
|
assert state.state == HVAC_MODES.get(fake_device.mode)
|
||||||
|
|
||||||
# Reset config temperature_unit back to CELSIUS, required for
|
|
||||||
# additional tests outside this component.
|
|
||||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("temperature", "hvac_mode"),
|
("temperature", "hvac_mode"),
|
||||||
@ -493,17 +494,17 @@ async def test_send_target_temperature_with_hvac_mode(
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("units", "temperature"),
|
("units", "temperature"),
|
||||||
[
|
[
|
||||||
(UnitOfTemperature.CELSIUS, 25),
|
(METRIC_SYSTEM, 25),
|
||||||
(UnitOfTemperature.FAHRENHEIT, 73),
|
(US_CUSTOMARY_SYSTEM, 73),
|
||||||
(UnitOfTemperature.FAHRENHEIT, 74),
|
(US_CUSTOMARY_SYSTEM, 74),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_send_target_temperature_device_timeout(
|
async def test_send_target_temperature_device_timeout(
|
||||||
hass: HomeAssistant, discovery, device, units, temperature
|
hass: HomeAssistant, discovery, device, units: UnitSystem, temperature
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for sending target temperature command to the device with a device timeout."""
|
"""Test for sending target temperature command to the device with a device timeout."""
|
||||||
hass.config.units.temperature_unit = units
|
hass.config.units = units
|
||||||
if units == UnitOfTemperature.FAHRENHEIT:
|
if units.temperature_unit == UnitOfTemperature.FAHRENHEIT:
|
||||||
device().temperature_units = 1
|
device().temperature_units = 1
|
||||||
device().push_state_update.side_effect = DeviceTimeoutError
|
device().push_state_update.side_effect = DeviceTimeoutError
|
||||||
|
|
||||||
@ -520,24 +521,21 @@ async def test_send_target_temperature_device_timeout(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
|
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 = UnitOfTemperature.CELSIUS
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("units", "temperature"),
|
("units", "temperature"),
|
||||||
[
|
[
|
||||||
(UnitOfTemperature.CELSIUS, 25),
|
(METRIC_SYSTEM, 25),
|
||||||
(UnitOfTemperature.FAHRENHEIT, 73),
|
(US_CUSTOMARY_SYSTEM, 73),
|
||||||
(UnitOfTemperature.FAHRENHEIT, 74),
|
(US_CUSTOMARY_SYSTEM, 74),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_update_target_temperature(
|
async def test_update_target_temperature(
|
||||||
hass: HomeAssistant, discovery, device, units, temperature
|
hass: HomeAssistant, discovery, device, units: UnitSystem, temperature
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for updating target temperature from the device."""
|
"""Test for updating target temperature from the device."""
|
||||||
hass.config.units.temperature_unit = units
|
hass.config.units = units
|
||||||
if units == UnitOfTemperature.FAHRENHEIT:
|
if units.temperature_unit == UnitOfTemperature.FAHRENHEIT:
|
||||||
device().temperature_units = 1
|
device().temperature_units = 1
|
||||||
device().target_temperature = temperature
|
device().target_temperature = temperature
|
||||||
|
|
||||||
@ -554,9 +552,6 @@ async def test_update_target_temperature(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.attributes.get(ATTR_TEMPERATURE) == temperature
|
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 = UnitOfTemperature.CELSIUS
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"preset", [PRESET_AWAY, PRESET_ECO, PRESET_SLEEP, PRESET_BOOST, PRESET_NONE]
|
"preset", [PRESET_AWAY, PRESET_ECO, PRESET_SLEEP, PRESET_BOOST, PRESET_NONE]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user