mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 08:26:41 +01:00
Minor improvements of temperature trigger tests (#166259)
This commit is contained in:
@@ -618,80 +618,6 @@ async def test_temperature_trigger_weather_crossed_threshold_behavior_last(
|
||||
)
|
||||
|
||||
|
||||
# --- Device class exclusion test ---
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_labs_preview_features")
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
"trigger_key",
|
||||
"trigger_options",
|
||||
"sensor_initial",
|
||||
"sensor_target",
|
||||
),
|
||||
[
|
||||
(
|
||||
"temperature.changed",
|
||||
{},
|
||||
"20",
|
||||
"25",
|
||||
),
|
||||
(
|
||||
"temperature.crossed_threshold",
|
||||
{"threshold_type": "above", "lower_limit": 10, "unit": "°C"},
|
||||
"5",
|
||||
"20",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_temperature_trigger_excludes_non_temperature_sensor(
|
||||
hass: HomeAssistant,
|
||||
service_calls: list[ServiceCall],
|
||||
trigger_key: str,
|
||||
trigger_options: dict[str, Any],
|
||||
sensor_initial: str,
|
||||
sensor_target: str,
|
||||
) -> None:
|
||||
"""Test temperature trigger does not fire for sensor entities without device_class temperature."""
|
||||
entity_id_temperature = "sensor.test_temperature"
|
||||
entity_id_humidity = "sensor.test_humidity"
|
||||
|
||||
temp_attrs = {
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
}
|
||||
humidity_attrs = {ATTR_DEVICE_CLASS: "humidity"}
|
||||
|
||||
# Set initial states
|
||||
hass.states.async_set(entity_id_temperature, sensor_initial, temp_attrs)
|
||||
hass.states.async_set(entity_id_humidity, sensor_initial, humidity_attrs)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await arm_trigger(
|
||||
hass,
|
||||
trigger_key,
|
||||
trigger_options,
|
||||
{
|
||||
CONF_ENTITY_ID: [
|
||||
entity_id_temperature,
|
||||
entity_id_humidity,
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
# Temperature sensor changes - should trigger
|
||||
hass.states.async_set(entity_id_temperature, sensor_target, temp_attrs)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data[CONF_ENTITY_ID] == entity_id_temperature
|
||||
service_calls.clear()
|
||||
|
||||
# Humidity sensor changes - should NOT trigger (wrong device class)
|
||||
hass.states.async_set(entity_id_humidity, sensor_target, humidity_attrs)
|
||||
await hass.async_block_till_done()
|
||||
assert len(service_calls) == 0
|
||||
|
||||
|
||||
# --- Unit conversion tests ---
|
||||
|
||||
|
||||
@@ -708,7 +634,7 @@ async def test_temperature_trigger_unit_conversion_sensor_celsius_to_fahrenheit(
|
||||
entity_id,
|
||||
"20",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
@@ -730,7 +656,7 @@ async def test_temperature_trigger_unit_conversion_sensor_celsius_to_fahrenheit(
|
||||
entity_id,
|
||||
"20",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
@@ -742,7 +668,7 @@ async def test_temperature_trigger_unit_conversion_sensor_celsius_to_fahrenheit(
|
||||
entity_id,
|
||||
"22",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
@@ -764,7 +690,7 @@ async def test_temperature_trigger_unit_conversion_sensor_fahrenheit_to_celsius(
|
||||
entity_id,
|
||||
"70",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
)
|
||||
@@ -786,7 +712,7 @@ async def test_temperature_trigger_unit_conversion_sensor_fahrenheit_to_celsius(
|
||||
entity_id,
|
||||
"70",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
)
|
||||
@@ -798,7 +724,7 @@ async def test_temperature_trigger_unit_conversion_sensor_fahrenheit_to_celsius(
|
||||
entity_id,
|
||||
"80",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
)
|
||||
@@ -820,7 +746,7 @@ async def test_temperature_trigger_unit_conversion_changed(
|
||||
entity_id,
|
||||
"18",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
@@ -842,7 +768,7 @@ async def test_temperature_trigger_unit_conversion_changed(
|
||||
entity_id,
|
||||
"19",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
@@ -854,7 +780,7 @@ async def test_temperature_trigger_unit_conversion_changed(
|
||||
entity_id,
|
||||
"22",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
@@ -867,7 +793,7 @@ async def test_temperature_trigger_unit_conversion_changed(
|
||||
entity_id,
|
||||
"26",
|
||||
{
|
||||
ATTR_DEVICE_CLASS: "temperature",
|
||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user