mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Migrate google_assistant tests to use unit system (#140357)
This commit is contained in:
parent
98cf936ff5
commit
b160ce21fc
@ -79,6 +79,11 @@ from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, St
|
||||
from homeassistant.core_config import async_process_ha_core_config
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||
from homeassistant.util.unit_system import (
|
||||
METRIC_SYSTEM,
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
UnitSystem,
|
||||
)
|
||||
|
||||
from . import BASIC_CONFIG, MockConfig
|
||||
|
||||
@ -1072,7 +1077,7 @@ async def test_temperature_setting_climate_onoff(hass: HomeAssistant) -> None:
|
||||
assert helpers.get_google_type(climate.DOMAIN, None) is not None
|
||||
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None)
|
||||
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||
hass.config.units = US_CUSTOMARY_SYSTEM
|
||||
|
||||
trt = trait.TemperatureSettingTrait(
|
||||
hass,
|
||||
@ -1123,8 +1128,6 @@ async def test_temperature_setting_climate_no_modes(hass: HomeAssistant) -> None
|
||||
assert helpers.get_google_type(climate.DOMAIN, None) is not None
|
||||
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None)
|
||||
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
trt = trait.TemperatureSettingTrait(
|
||||
hass,
|
||||
State(
|
||||
@ -1153,7 +1156,7 @@ async def test_temperature_setting_climate_range(hass: HomeAssistant) -> None:
|
||||
assert helpers.get_google_type(climate.DOMAIN, None) is not None
|
||||
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None)
|
||||
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||
hass.config.units = US_CUSTOMARY_SYSTEM
|
||||
|
||||
trt = trait.TemperatureSettingTrait(
|
||||
hass,
|
||||
@ -1261,7 +1264,6 @@ async def test_temperature_setting_climate_range(hass: HomeAssistant) -> None:
|
||||
ATTR_ENTITY_ID: "climate.bla",
|
||||
climate.ATTR_TEMPERATURE: 75,
|
||||
}
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
|
||||
async def test_temperature_setting_climate_setpoint(hass: HomeAssistant) -> None:
|
||||
@ -1269,8 +1271,6 @@ async def test_temperature_setting_climate_setpoint(hass: HomeAssistant) -> None
|
||||
assert helpers.get_google_type(climate.DOMAIN, None) is not None
|
||||
assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None)
|
||||
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
trt = trait.TemperatureSettingTrait(
|
||||
hass,
|
||||
State(
|
||||
@ -1356,8 +1356,6 @@ async def test_temperature_setting_climate_setpoint_auto(hass: HomeAssistant) ->
|
||||
|
||||
Setpoint in auto mode.
|
||||
"""
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
trt = trait.TemperatureSettingTrait(
|
||||
hass,
|
||||
State(
|
||||
@ -1407,8 +1405,6 @@ async def test_temperature_setting_climate_setpoint_auto(hass: HomeAssistant) ->
|
||||
|
||||
async def test_temperature_control(hass: HomeAssistant) -> None:
|
||||
"""Test TemperatureControl trait support for sensor domain."""
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
trt = trait.TemperatureControlTrait(
|
||||
hass,
|
||||
State("sensor.temp", 18),
|
||||
@ -1431,13 +1427,13 @@ async def test_temperature_control(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("unit_in", "unit_out", "temp_in", "temp_out", "current_in", "current_out"),
|
||||
[
|
||||
(UnitOfTemperature.CELSIUS, "C", "120", 120, "130", 130),
|
||||
(UnitOfTemperature.FAHRENHEIT, "F", "248", 120, "266", 130),
|
||||
(METRIC_SYSTEM, "C", "120", 120, "130", 130),
|
||||
(US_CUSTOMARY_SYSTEM, "F", "248", 120, "266", 130),
|
||||
],
|
||||
)
|
||||
async def test_temperature_control_water_heater(
|
||||
hass: HomeAssistant,
|
||||
unit_in: UnitOfTemperature,
|
||||
unit_in: UnitSystem,
|
||||
unit_out: str,
|
||||
temp_in: str,
|
||||
temp_out: float,
|
||||
@ -1445,17 +1441,17 @@ async def test_temperature_control_water_heater(
|
||||
current_out: float,
|
||||
) -> None:
|
||||
"""Test TemperatureControl trait support for water heater domain."""
|
||||
hass.config.units.temperature_unit = unit_in
|
||||
hass.config.units = unit_in
|
||||
|
||||
min_temp = TemperatureConverter.convert(
|
||||
water_heater.DEFAULT_MIN_TEMP,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
unit_in,
|
||||
unit_in.temperature_unit,
|
||||
)
|
||||
max_temp = TemperatureConverter.convert(
|
||||
water_heater.DEFAULT_MAX_TEMP,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
unit_in,
|
||||
unit_in.temperature_unit,
|
||||
)
|
||||
|
||||
trt = trait.TemperatureControlTrait(
|
||||
@ -1489,30 +1485,30 @@ async def test_temperature_control_water_heater(
|
||||
@pytest.mark.parametrize(
|
||||
("unit", "temp_init", "temp_in", "temp_out", "current_init"),
|
||||
[
|
||||
(UnitOfTemperature.CELSIUS, "180", 220, 220, "180"),
|
||||
(UnitOfTemperature.FAHRENHEIT, "356", 220, 428, "356"),
|
||||
(METRIC_SYSTEM, "180", 220, 220, "180"),
|
||||
(US_CUSTOMARY_SYSTEM, "356", 220, 428, "356"),
|
||||
],
|
||||
)
|
||||
async def test_temperature_control_water_heater_set_temperature(
|
||||
hass: HomeAssistant,
|
||||
unit: UnitOfTemperature,
|
||||
unit: UnitSystem,
|
||||
temp_init: str,
|
||||
temp_in: float,
|
||||
temp_out: float,
|
||||
current_init: str,
|
||||
) -> None:
|
||||
"""Test TemperatureControl trait support for water heater domain - SetTemperature."""
|
||||
hass.config.units.temperature_unit = unit
|
||||
hass.config.units = unit
|
||||
|
||||
min_temp = TemperatureConverter.convert(
|
||||
40,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
unit,
|
||||
unit.temperature_unit,
|
||||
)
|
||||
max_temp = TemperatureConverter.convert(
|
||||
230,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
unit,
|
||||
unit.temperature_unit,
|
||||
)
|
||||
|
||||
trt = trait.TemperatureControlTrait(
|
||||
@ -3633,17 +3629,17 @@ async def test_temperature_control_sensor(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("unit_in", "unit_out", "state", "ambient"),
|
||||
[
|
||||
(UnitOfTemperature.FAHRENHEIT, "F", "70", 21.1),
|
||||
(UnitOfTemperature.CELSIUS, "C", "21.1", 21.1),
|
||||
(UnitOfTemperature.FAHRENHEIT, "F", "unavailable", None),
|
||||
(UnitOfTemperature.FAHRENHEIT, "F", "unknown", None),
|
||||
(US_CUSTOMARY_SYSTEM, "F", "70", 21.1),
|
||||
(METRIC_SYSTEM, "C", "21.1", 21.1),
|
||||
(US_CUSTOMARY_SYSTEM, "F", "unavailable", None),
|
||||
(US_CUSTOMARY_SYSTEM, "F", "unknown", None),
|
||||
],
|
||||
)
|
||||
async def test_temperature_control_sensor_data(
|
||||
hass: HomeAssistant, unit_in, unit_out, state, ambient
|
||||
hass: HomeAssistant, unit_in: UnitSystem, unit_out, state, ambient
|
||||
) -> None:
|
||||
"""Test TemperatureControl trait support for temperature sensor."""
|
||||
hass.config.units.temperature_unit = unit_in
|
||||
hass.config.units = unit_in
|
||||
|
||||
trt = trait.TemperatureControlTrait(
|
||||
hass,
|
||||
@ -3668,7 +3664,6 @@ async def test_temperature_control_sensor_data(
|
||||
}
|
||||
else:
|
||||
assert trt.query_attributes() == {}
|
||||
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
|
||||
async def test_humidity_setting_sensor(hass: HomeAssistant) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user