Migrate mqtt tests to use unit system (#140376)

* Migrate mqtt tests to use unit system

* Fix param list

* Missed one

---------

Co-authored-by: jbouwh <jan@jbsoft.nl>
This commit is contained in:
epenet 2025-03-12 08:47:34 +01:00 committed by GitHub
parent 25cfd6ceda
commit 593ae48aa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 62 deletions

View File

@ -33,9 +33,14 @@ from homeassistant.components.mqtt.climate import (
MQTT_CLIMATE_ATTRIBUTES_BLOCKED, MQTT_CLIMATE_ATTRIBUTES_BLOCKED,
VALUE_TEMPLATE_KEYS, VALUE_TEMPLATE_KEYS,
) )
from homeassistant.const import ATTR_TEMPERATURE, STATE_UNKNOWN, UnitOfTemperature from homeassistant.const import ATTR_TEMPERATURE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from homeassistant.util.unit_system import (
METRIC_SYSTEM,
US_CUSTOMARY_SYSTEM,
UnitSystem,
)
from .common import ( from .common import (
help_custom_config, help_custom_config,
@ -1823,7 +1828,7 @@ async def test_temperature_unit(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("hass_config", "temperature_unit", "initial", "min", "max", "current"), ("hass_config", "units", "initial", "min", "max", "current"),
[ [
( (
help_custom_config( help_custom_config(
@ -1836,7 +1841,7 @@ async def test_temperature_unit(
}, },
), ),
), ),
UnitOfTemperature.CELSIUS, METRIC_SYSTEM,
DEFAULT_INITIAL_TEMPERATURE, DEFAULT_INITIAL_TEMPERATURE,
DEFAULT_MIN_TEMP, DEFAULT_MIN_TEMP,
DEFAULT_MAX_TEMP, DEFAULT_MAX_TEMP,
@ -1854,7 +1859,7 @@ async def test_temperature_unit(
}, },
), ),
), ),
UnitOfTemperature.CELSIUS, METRIC_SYSTEM,
20.5, 20.5,
DEFAULT_MIN_TEMP, DEFAULT_MIN_TEMP,
DEFAULT_MAX_TEMP, DEFAULT_MAX_TEMP,
@ -1871,24 +1876,7 @@ async def test_temperature_unit(
}, },
), ),
), ),
UnitOfTemperature.KELVIN, US_CUSTOMARY_SYSTEM,
294,
280,
308,
298,
),
(
help_custom_config(
climate.DOMAIN,
DEFAULT_CONFIG,
(
{
"temperature_unit": "F",
"current_temperature_topic": "current_temperature",
},
),
),
UnitOfTemperature.FAHRENHEIT,
70, 70,
45, 45,
95, 95,
@ -1899,14 +1887,14 @@ async def test_temperature_unit(
async def test_alt_temperature_unit( async def test_alt_temperature_unit(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
temperature_unit: UnitOfTemperature, units: UnitSystem,
initial: float, initial: float,
min: float, min: float,
max: float, max: float,
current: float, current: float,
) -> None: ) -> None:
"""Test deriving the systems temperature unit.""" """Test deriving the systems temperature unit."""
with patch.object(hass.config.units, "temperature_unit", temperature_unit): hass.config.units = units
await mqtt_mock_entry() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)

View File

@ -33,6 +33,11 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.util.unit_conversion import TemperatureConverter from homeassistant.util.unit_conversion import TemperatureConverter
from homeassistant.util.unit_system import (
METRIC_SYSTEM,
US_CUSTOMARY_SYSTEM,
UnitSystem,
)
from .common import ( from .common import (
help_custom_config, help_custom_config,
@ -714,7 +719,7 @@ async def test_temperature_unit(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("hass_config", "temperature_unit", "initial", "min_temp", "max_temp", "current"), ("hass_config", "units", "initial", "min_temp", "max_temp", "current"),
[ [
( (
help_custom_config( help_custom_config(
@ -727,7 +732,7 @@ async def test_temperature_unit(
}, },
), ),
), ),
UnitOfTemperature.CELSIUS, METRIC_SYSTEM,
_DEFAULT_MIN_TEMP_CELSIUS, _DEFAULT_MIN_TEMP_CELSIUS,
_DEFAULT_MIN_TEMP_CELSIUS, _DEFAULT_MIN_TEMP_CELSIUS,
_DEFAULT_MAX_TEMP_CELSIUS, _DEFAULT_MAX_TEMP_CELSIUS,
@ -744,24 +749,7 @@ async def test_temperature_unit(
}, },
), ),
), ),
UnitOfTemperature.KELVIN, US_CUSTOMARY_SYSTEM,
316,
316,
333,
322,
),
(
help_custom_config(
water_heater.DOMAIN,
DEFAULT_CONFIG,
(
{
"temperature_unit": "F",
"current_temperature_topic": "current_temperature",
},
),
),
UnitOfTemperature.FAHRENHEIT,
DEFAULT_MIN_TEMP, DEFAULT_MIN_TEMP,
DEFAULT_MIN_TEMP, DEFAULT_MIN_TEMP,
DEFAULT_MAX_TEMP, DEFAULT_MAX_TEMP,
@ -772,14 +760,14 @@ async def test_temperature_unit(
async def test_alt_temperature_unit( async def test_alt_temperature_unit(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
temperature_unit: UnitOfTemperature, units: UnitSystem,
initial: float, initial: float,
min_temp: float, min_temp: float,
max_temp: float, max_temp: float,
current: float, current: float,
) -> None: ) -> None:
"""Test deriving the systems temperature unit.""" """Test deriving the systems temperature unit."""
with patch.object(hass.config.units, "temperature_unit", temperature_unit): hass.config.units = units
await mqtt_mock_entry() await mqtt_mock_entry()
state = hass.states.get(ENTITY_WATER_HEATER) state = hass.states.get(ENTITY_WATER_HEATER)