mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 08:26:41 +01:00
Add weather support to humidity conditions (#166599)
This commit is contained in:
committed by
Bram Kragten
parent
cff4cf4d2c
commit
9c1f9ca5c6
@@ -11,6 +11,10 @@ from homeassistant.components.humidifier import (
|
||||
DOMAIN as HUMIDIFIER_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_WEATHER_HUMIDITY,
|
||||
DOMAIN as WEATHER_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
@@ -24,6 +28,9 @@ HUMIDITY_DOMAIN_SPECS = {
|
||||
value_source=HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
|
||||
),
|
||||
SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.HUMIDITY),
|
||||
WEATHER_DOMAIN: DomainSpec(
|
||||
value_source=ATTR_WEATHER_HUMIDITY,
|
||||
),
|
||||
}
|
||||
|
||||
CONDITIONS: dict[str, type[Condition]] = {
|
||||
|
||||
@@ -19,6 +19,7 @@ is_value:
|
||||
device_class: humidity
|
||||
- domain: climate
|
||||
- domain: humidifier
|
||||
- domain: weather
|
||||
fields:
|
||||
behavior:
|
||||
required: true
|
||||
|
||||
@@ -11,6 +11,7 @@ from homeassistant.components.climate import (
|
||||
from homeassistant.components.humidifier import (
|
||||
ATTR_CURRENT_HUMIDITY as HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
|
||||
)
|
||||
from homeassistant.components.weather import ATTR_WEATHER_HUMIDITY
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@@ -48,6 +49,12 @@ async def target_humidifiers(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
return await target_entities(hass, "humidifier")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_weathers(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
"""Create multiple weather entities associated with different targets."""
|
||||
return await target_entities(hass, "weather")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"condition",
|
||||
[
|
||||
@@ -275,3 +282,75 @@ async def test_humidity_humidifier_condition_behavior_all(
|
||||
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("weather"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("condition", "condition_options", "states"),
|
||||
parametrize_numerical_attribute_condition_above_below_any(
|
||||
"humidity.is_value",
|
||||
"sunny",
|
||||
ATTR_WEATHER_HUMIDITY,
|
||||
),
|
||||
)
|
||||
async def test_humidity_weather_condition_behavior_any(
|
||||
hass: HomeAssistant,
|
||||
target_weathers: 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 weather condition with 'any' behavior."""
|
||||
await assert_condition_behavior_any(
|
||||
hass,
|
||||
target_entities=target_weathers,
|
||||
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("weather"),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("condition", "condition_options", "states"),
|
||||
parametrize_numerical_attribute_condition_above_below_all(
|
||||
"humidity.is_value",
|
||||
"sunny",
|
||||
ATTR_WEATHER_HUMIDITY,
|
||||
),
|
||||
)
|
||||
async def test_humidity_weather_condition_behavior_all(
|
||||
hass: HomeAssistant,
|
||||
target_weathers: 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 weather condition with 'all' behavior."""
|
||||
await assert_condition_behavior_all(
|
||||
hass,
|
||||
target_entities=target_weathers,
|
||||
condition_target_config=condition_target_config,
|
||||
entity_id=entity_id,
|
||||
entities_in_target=entities_in_target,
|
||||
condition=condition,
|
||||
condition_options=condition_options,
|
||||
states=states,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user