mirror of
https://github.com/home-assistant/core.git
synced 2025-06-28 00:47:10 +00:00
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:
parent
25cfd6ceda
commit
593ae48aa2
@ -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,25 +1887,25 @@ 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)
|
||||||
assert state.attributes.get("temperature") == initial
|
assert state.attributes.get("temperature") == initial
|
||||||
assert state.attributes.get("min_temp") == min
|
assert state.attributes.get("min_temp") == min
|
||||||
assert state.attributes.get("max_temp") == max
|
assert state.attributes.get("max_temp") == max
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "current_temperature", "77")
|
async_fire_mqtt_message(hass, "current_temperature", "77")
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get("current_temperature") == current
|
assert state.attributes.get("current_temperature") == current
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_attribute_via_mqtt_json_message(
|
async def test_setting_attribute_via_mqtt_json_message(
|
||||||
|
@ -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,25 +760,25 @@ 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)
|
||||||
assert state.attributes.get("temperature") == initial
|
assert state.attributes.get("temperature") == initial
|
||||||
assert state.attributes.get("min_temp") == min_temp
|
assert state.attributes.get("min_temp") == min_temp
|
||||||
assert state.attributes.get("max_temp") == max_temp
|
assert state.attributes.get("max_temp") == max_temp
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "current_temperature", "120")
|
async_fire_mqtt_message(hass, "current_temperature", "120")
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_WATER_HEATER)
|
state = hass.states.get(ENTITY_WATER_HEATER)
|
||||||
assert state.attributes.get("current_temperature") == current
|
assert state.attributes.get("current_temperature") == current
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_attribute_via_mqtt_json_message(
|
async def test_setting_attribute_via_mqtt_json_message(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user