1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 08:26:41 +01:00
Files
core/tests/components/humidity/test_condition.py

278 lines
8.8 KiB
Python

"""Test humidity conditions."""
from typing import Any
import pytest
from homeassistant.components.climate import (
ATTR_CURRENT_HUMIDITY as CLIMATE_ATTR_CURRENT_HUMIDITY,
HVACMode,
)
from homeassistant.components.humidifier import (
ATTR_CURRENT_HUMIDITY as HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
)
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, STATE_ON
from homeassistant.core import HomeAssistant
from tests.components.common import (
ConditionStateDescription,
assert_condition_behavior_all,
assert_condition_behavior_any,
assert_condition_gated_by_labs_flag,
parametrize_numerical_attribute_condition_above_below_all,
parametrize_numerical_attribute_condition_above_below_any,
parametrize_numerical_condition_above_below_all,
parametrize_numerical_condition_above_below_any,
parametrize_target_entities,
target_entities,
)
_HUMIDITY_UNIT_ATTRS = {ATTR_UNIT_OF_MEASUREMENT: "%"}
@pytest.fixture
async def target_sensors(hass: HomeAssistant) -> dict[str, list[str]]:
"""Create multiple sensor entities associated with different targets."""
return await target_entities(hass, "sensor")
@pytest.fixture
async def target_climates(hass: HomeAssistant) -> dict[str, list[str]]:
"""Create multiple climate entities associated with different targets."""
return await target_entities(hass, "climate")
@pytest.fixture
async def target_humidifiers(hass: HomeAssistant) -> dict[str, list[str]]:
"""Create multiple humidifier entities associated with different targets."""
return await target_entities(hass, "humidifier")
@pytest.mark.parametrize(
"condition",
[
"humidity.is_value",
],
)
async def test_humidity_conditions_gated_by_labs_flag(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, condition: str
) -> None:
"""Test the humidity conditions are gated by the labs flag."""
await assert_condition_gated_by_labs_flag(hass, caplog, condition)
@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("condition_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities("sensor"),
)
@pytest.mark.parametrize(
("condition", "condition_options", "states"),
parametrize_numerical_condition_above_below_any(
"humidity.is_value",
device_class="humidity",
unit_attributes=_HUMIDITY_UNIT_ATTRS,
),
)
async def test_humidity_sensor_condition_behavior_any(
hass: HomeAssistant,
target_sensors: dict[str, list[str]],
condition_target_config: dict,
entity_id: str,
entities_in_target: int,
condition: str,
condition_options: dict[str, Any],
states: list[ConditionStateDescription],
) -> None:
"""Test the humidity sensor condition with 'any' behavior."""
await assert_condition_behavior_any(
hass,
target_entities=target_sensors,
condition_target_config=condition_target_config,
entity_id=entity_id,
entities_in_target=entities_in_target,
condition=condition,
condition_options=condition_options,
states=states,
)
@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("condition_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities("sensor"),
)
@pytest.mark.parametrize(
("condition", "condition_options", "states"),
parametrize_numerical_condition_above_below_all(
"humidity.is_value",
device_class="humidity",
unit_attributes=_HUMIDITY_UNIT_ATTRS,
),
)
async def test_humidity_sensor_condition_behavior_all(
hass: HomeAssistant,
target_sensors: dict[str, list[str]],
condition_target_config: dict,
entity_id: str,
entities_in_target: int,
condition: str,
condition_options: dict[str, Any],
states: list[ConditionStateDescription],
) -> None:
"""Test the humidity sensor condition with 'all' behavior."""
await assert_condition_behavior_all(
hass,
target_entities=target_sensors,
condition_target_config=condition_target_config,
entity_id=entity_id,
entities_in_target=entities_in_target,
condition=condition,
condition_options=condition_options,
states=states,
)
@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("condition_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities("climate"),
)
@pytest.mark.parametrize(
("condition", "condition_options", "states"),
parametrize_numerical_attribute_condition_above_below_any(
"humidity.is_value",
HVACMode.AUTO,
CLIMATE_ATTR_CURRENT_HUMIDITY,
),
)
async def test_humidity_climate_condition_behavior_any(
hass: HomeAssistant,
target_climates: dict[str, list[str]],
condition_target_config: dict,
entity_id: str,
entities_in_target: int,
condition: str,
condition_options: dict[str, Any],
states: list[ConditionStateDescription],
) -> None:
"""Test the humidity climate condition with 'any' behavior."""
await assert_condition_behavior_any(
hass,
target_entities=target_climates,
condition_target_config=condition_target_config,
entity_id=entity_id,
entities_in_target=entities_in_target,
condition=condition,
condition_options=condition_options,
states=states,
)
@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("condition_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities("climate"),
)
@pytest.mark.parametrize(
("condition", "condition_options", "states"),
parametrize_numerical_attribute_condition_above_below_all(
"humidity.is_value",
HVACMode.AUTO,
CLIMATE_ATTR_CURRENT_HUMIDITY,
),
)
async def test_humidity_climate_condition_behavior_all(
hass: HomeAssistant,
target_climates: dict[str, list[str]],
condition_target_config: dict,
entity_id: str,
entities_in_target: int,
condition: str,
condition_options: dict[str, Any],
states: list[ConditionStateDescription],
) -> None:
"""Test the humidity climate condition with 'all' behavior."""
await assert_condition_behavior_all(
hass,
target_entities=target_climates,
condition_target_config=condition_target_config,
entity_id=entity_id,
entities_in_target=entities_in_target,
condition=condition,
condition_options=condition_options,
states=states,
)
@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("condition_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities("humidifier"),
)
@pytest.mark.parametrize(
("condition", "condition_options", "states"),
parametrize_numerical_attribute_condition_above_below_any(
"humidity.is_value",
STATE_ON,
HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
),
)
async def test_humidity_humidifier_condition_behavior_any(
hass: HomeAssistant,
target_humidifiers: dict[str, list[str]],
condition_target_config: dict,
entity_id: str,
entities_in_target: int,
condition: str,
condition_options: dict[str, Any],
states: list[ConditionStateDescription],
) -> None:
"""Test the humidity humidifier condition with 'any' behavior."""
await assert_condition_behavior_any(
hass,
target_entities=target_humidifiers,
condition_target_config=condition_target_config,
entity_id=entity_id,
entities_in_target=entities_in_target,
condition=condition,
condition_options=condition_options,
states=states,
)
@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("condition_target_config", "entity_id", "entities_in_target"),
parametrize_target_entities("humidifier"),
)
@pytest.mark.parametrize(
("condition", "condition_options", "states"),
parametrize_numerical_attribute_condition_above_below_all(
"humidity.is_value",
STATE_ON,
HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
),
)
async def test_humidity_humidifier_condition_behavior_all(
hass: HomeAssistant,
target_humidifiers: dict[str, list[str]],
condition_target_config: dict,
entity_id: str,
entities_in_target: int,
condition: str,
condition_options: dict[str, Any],
states: list[ConditionStateDescription],
) -> None:
"""Test the humidity humidifier condition with 'all' behavior."""
await assert_condition_behavior_all(
hass,
target_entities=target_humidifiers,
condition_target_config=condition_target_config,
entity_id=entity_id,
entities_in_target=entities_in_target,
condition=condition,
condition_options=condition_options,
states=states,
)