mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 09:38:58 +01:00
Use NumericThresholdSelector in numeric conditions (#166507)
This commit is contained in:
committed by
Franck Nijhof
parent
5a7abc0a92
commit
a3c9d35a13
@@ -11,8 +11,6 @@ from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_ABOVE,
|
||||
CONF_BELOW,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
@@ -32,11 +30,9 @@ from tests.components.common import (
|
||||
target_entities,
|
||||
)
|
||||
|
||||
_UGM3_CONDITION_OPTIONS = {"unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER}
|
||||
_UGM3_UNIT_ATTRIBUTES = {
|
||||
ATTR_UNIT_OF_MEASUREMENT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
}
|
||||
_PPB_CONDITION_OPTIONS = {"unit": CONCENTRATION_PARTS_PER_BILLION}
|
||||
_PPB_UNIT_ATTRIBUTES = {ATTR_UNIT_OF_MEASUREMENT: CONCENTRATION_PARTS_PER_BILLION}
|
||||
_PPM_UNIT_ATTRIBUTES = {ATTR_UNIT_OF_MEASUREMENT: CONCENTRATION_PARTS_PER_MILLION}
|
||||
|
||||
@@ -241,43 +237,43 @@ async def test_air_quality_binary_condition_behavior_all(
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_co_value",
|
||||
device_class="carbon_monoxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_ozone_value",
|
||||
device_class="ozone",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_voc_value",
|
||||
device_class="volatile_organic_compounds",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_voc_ratio_value",
|
||||
device_class="volatile_organic_compounds_parts",
|
||||
condition_options=_PPB_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_PARTS_PER_BILLION,
|
||||
unit_attributes=_PPB_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_no_value",
|
||||
device_class="nitrogen_monoxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_no2_value",
|
||||
device_class="nitrogen_dioxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_any(
|
||||
"air_quality.is_so2_value",
|
||||
device_class="sulphur_dioxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
],
|
||||
@@ -316,43 +312,43 @@ async def test_air_quality_numerical_with_unit_condition_behavior_any(
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_co_value",
|
||||
device_class="carbon_monoxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_ozone_value",
|
||||
device_class="ozone",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_voc_value",
|
||||
device_class="volatile_organic_compounds",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_voc_ratio_value",
|
||||
device_class="volatile_organic_compounds_parts",
|
||||
condition_options=_PPB_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_PARTS_PER_BILLION,
|
||||
unit_attributes=_PPB_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_no_value",
|
||||
device_class="nitrogen_monoxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_no2_value",
|
||||
device_class="nitrogen_dioxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_condition_above_below_all(
|
||||
"air_quality.is_so2_value",
|
||||
device_class="sulphur_dioxide",
|
||||
condition_options=_UGM3_CONDITION_OPTIONS,
|
||||
threshold_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
unit_attributes=_UGM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
],
|
||||
@@ -539,19 +535,38 @@ async def test_air_quality_condition_unit_conversion_co(
|
||||
],
|
||||
numerical_condition_options=[
|
||||
{
|
||||
CONF_ABOVE: 0.2,
|
||||
CONF_BELOW: 0.8,
|
||||
"unit": CONCENTRATION_PARTS_PER_MILLION,
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 0.2,
|
||||
"unit_of_measurement": CONCENTRATION_PARTS_PER_MILLION,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 0.8,
|
||||
"unit_of_measurement": CONCENTRATION_PARTS_PER_MILLION,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
CONF_ABOVE: 200,
|
||||
CONF_BELOW: 800,
|
||||
"unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 200,
|
||||
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 800,
|
||||
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
limit_entity_condition_options={
|
||||
CONF_ABOVE: "sensor.above",
|
||||
CONF_BELOW: "sensor.below",
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"entity": "sensor.above"},
|
||||
"value_max": {"entity": "sensor.below"},
|
||||
}
|
||||
},
|
||||
limit_entities=("sensor.above", "sensor.below"),
|
||||
limit_entity_states=[
|
||||
|
||||
@@ -13,8 +13,6 @@ from homeassistant.components.climate.const import (
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_ABOVE,
|
||||
CONF_BELOW,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -34,8 +32,6 @@ from tests.components.common import (
|
||||
target_entities,
|
||||
)
|
||||
|
||||
_TEMPERATURE_CONDITION_OPTIONS = {"unit": UnitOfTemperature.CELSIUS}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_climates(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
@@ -275,7 +271,7 @@ async def test_climate_attribute_condition_behavior_all(
|
||||
"climate.target_temperature",
|
||||
HVACMode.AUTO,
|
||||
ATTR_TEMPERATURE,
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -319,7 +315,7 @@ async def test_climate_numerical_condition_behavior_any(
|
||||
"climate.target_temperature",
|
||||
HVACMode.AUTO,
|
||||
ATTR_TEMPERATURE,
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -365,12 +361,39 @@ async def test_climate_numerical_condition_unit_conversion(hass: HomeAssistant)
|
||||
}
|
||||
],
|
||||
numerical_condition_options=[
|
||||
{CONF_ABOVE: 75, CONF_BELOW: 90, "unit": UnitOfTemperature.FAHRENHEIT},
|
||||
{CONF_ABOVE: 24, CONF_BELOW: 30, "unit": UnitOfTemperature.CELSIUS},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 75,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 90,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 24,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 30,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
limit_entity_condition_options={
|
||||
CONF_ABOVE: "sensor.above",
|
||||
CONF_BELOW: "sensor.below",
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"entity": "sensor.above"},
|
||||
"value_max": {"entity": "sensor.below"},
|
||||
}
|
||||
},
|
||||
limit_entities=("sensor.above", "sensor.below"),
|
||||
limit_entity_states=[
|
||||
|
||||
+104
-14
@@ -14,8 +14,6 @@ from homeassistant.const import (
|
||||
ATTR_FLOOR_ID,
|
||||
ATTR_LABEL_ID,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_ABOVE,
|
||||
CONF_BELOW,
|
||||
CONF_CONDITION,
|
||||
CONF_ENTITY_ID,
|
||||
CONF_OPTIONS,
|
||||
@@ -1300,6 +1298,7 @@ def parametrize_numerical_condition_above_below_any(
|
||||
*,
|
||||
device_class: str,
|
||||
condition_options: dict[str, Any] | None = None,
|
||||
threshold_unit: str | None | UndefinedType = UNDEFINED,
|
||||
unit_attributes: dict | None = None,
|
||||
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
|
||||
"""Parametrize above/below threshold test cases for numerical conditions.
|
||||
@@ -1315,7 +1314,13 @@ def parametrize_numerical_condition_above_below_any(
|
||||
return [
|
||||
*parametrize_condition_states_any(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "above", "value": {"number": 20}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
("21", unit_attributes),
|
||||
("50", unit_attributes),
|
||||
@@ -1330,7 +1335,13 @@ def parametrize_numerical_condition_above_below_any(
|
||||
),
|
||||
*parametrize_condition_states_any(
|
||||
condition=condition,
|
||||
condition_options={CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "below", "value": {"number": 80}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
("0", unit_attributes),
|
||||
("50", unit_attributes),
|
||||
@@ -1345,7 +1356,17 @@ def parametrize_numerical_condition_above_below_any(
|
||||
),
|
||||
*parametrize_condition_states_any(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"number": 20},
|
||||
"value_max": {"number": 80},
|
||||
},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
("21", unit_attributes),
|
||||
("50", unit_attributes),
|
||||
@@ -1367,6 +1388,7 @@ def parametrize_numerical_condition_above_below_all(
|
||||
*,
|
||||
device_class: str,
|
||||
condition_options: dict[str, Any] | None = None,
|
||||
threshold_unit: str | None | UndefinedType = UNDEFINED,
|
||||
unit_attributes: dict | None = None,
|
||||
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
|
||||
"""Parametrize above/below threshold test cases for numerical conditions with 'all' behavior.
|
||||
@@ -1382,7 +1404,13 @@ def parametrize_numerical_condition_above_below_all(
|
||||
return [
|
||||
*parametrize_condition_states_all(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "above", "value": {"number": 20}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
("21", unit_attributes),
|
||||
("50", unit_attributes),
|
||||
@@ -1397,7 +1425,13 @@ def parametrize_numerical_condition_above_below_all(
|
||||
),
|
||||
*parametrize_condition_states_all(
|
||||
condition=condition,
|
||||
condition_options={CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "below", "value": {"number": 80}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
("0", unit_attributes),
|
||||
("50", unit_attributes),
|
||||
@@ -1412,7 +1446,17 @@ def parametrize_numerical_condition_above_below_all(
|
||||
),
|
||||
*parametrize_condition_states_all(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"number": 20},
|
||||
"value_max": {"number": 80},
|
||||
},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
("21", unit_attributes),
|
||||
("50", unit_attributes),
|
||||
@@ -1436,6 +1480,7 @@ def parametrize_numerical_attribute_condition_above_below_any(
|
||||
*,
|
||||
condition_options: dict[str, Any] | None = None,
|
||||
required_filter_attributes: dict | None = None,
|
||||
threshold_unit: str | None | UndefinedType = UNDEFINED,
|
||||
unit_attributes: dict | None = None,
|
||||
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
|
||||
"""Parametrize above/below threshold test cases for attribute-based numerical conditions.
|
||||
@@ -1448,7 +1493,13 @@ def parametrize_numerical_attribute_condition_above_below_any(
|
||||
return [
|
||||
*parametrize_condition_states_any(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "above", "value": {"number": 20}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
(state, {attribute: 21} | unit_attributes),
|
||||
(state, {attribute: 50} | unit_attributes),
|
||||
@@ -1463,7 +1514,13 @@ def parametrize_numerical_attribute_condition_above_below_any(
|
||||
),
|
||||
*parametrize_condition_states_any(
|
||||
condition=condition,
|
||||
condition_options={CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "below", "value": {"number": 80}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
(state, {attribute: 0} | unit_attributes),
|
||||
(state, {attribute: 50} | unit_attributes),
|
||||
@@ -1478,7 +1535,17 @@ def parametrize_numerical_attribute_condition_above_below_any(
|
||||
),
|
||||
*parametrize_condition_states_any(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"number": 20},
|
||||
"value_max": {"number": 80},
|
||||
},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
(state, {attribute: 21} | unit_attributes),
|
||||
(state, {attribute: 50} | unit_attributes),
|
||||
@@ -1502,6 +1569,7 @@ def parametrize_numerical_attribute_condition_above_below_all(
|
||||
*,
|
||||
condition_options: dict[str, Any] | None = None,
|
||||
required_filter_attributes: dict | None = None,
|
||||
threshold_unit: str | None | UndefinedType = UNDEFINED,
|
||||
unit_attributes: dict | None = None,
|
||||
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
|
||||
"""Parametrize above/below threshold test cases for attribute-based numerical conditions with 'all' behavior.
|
||||
@@ -1514,7 +1582,13 @@ def parametrize_numerical_attribute_condition_above_below_all(
|
||||
return [
|
||||
*parametrize_condition_states_all(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "above", "value": {"number": 20}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
(state, {attribute: 21} | unit_attributes),
|
||||
(state, {attribute: 50} | unit_attributes),
|
||||
@@ -1529,7 +1603,13 @@ def parametrize_numerical_attribute_condition_above_below_all(
|
||||
),
|
||||
*parametrize_condition_states_all(
|
||||
condition=condition,
|
||||
condition_options={CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {"type": "below", "value": {"number": 80}},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
(state, {attribute: 0} | unit_attributes),
|
||||
(state, {attribute: 50} | unit_attributes),
|
||||
@@ -1544,7 +1624,17 @@ def parametrize_numerical_attribute_condition_above_below_all(
|
||||
),
|
||||
*parametrize_condition_states_all(
|
||||
condition=condition,
|
||||
condition_options={CONF_ABOVE: 20, CONF_BELOW: 80, **condition_options},
|
||||
condition_options=_add_threshold_unit(
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"number": 20},
|
||||
"value_max": {"number": 80},
|
||||
},
|
||||
**condition_options,
|
||||
},
|
||||
threshold_unit,
|
||||
),
|
||||
target_states=[
|
||||
(state, {attribute: 21} | unit_attributes),
|
||||
(state, {attribute: 50} | unit_attributes),
|
||||
|
||||
@@ -4,12 +4,7 @@ from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_ABOVE,
|
||||
CONF_BELOW,
|
||||
UnitOfPower,
|
||||
)
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfPower
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.components.common import (
|
||||
@@ -24,8 +19,6 @@ from tests.components.common import (
|
||||
target_entities,
|
||||
)
|
||||
|
||||
_POWER_CONDITION_OPTIONS = {"unit": UnitOfPower.WATT}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def target_sensors(hass: HomeAssistant) -> dict[str, list[str]]:
|
||||
@@ -60,7 +53,7 @@ async def test_power_conditions_gated_by_labs_flag(
|
||||
parametrize_numerical_condition_above_below_any(
|
||||
"power.is_value",
|
||||
device_class="power",
|
||||
condition_options=_POWER_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT},
|
||||
),
|
||||
)
|
||||
@@ -97,7 +90,7 @@ async def test_power_sensor_condition_behavior_any(
|
||||
parametrize_numerical_condition_above_below_all(
|
||||
"power.is_value",
|
||||
device_class="power",
|
||||
condition_options=_POWER_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT},
|
||||
),
|
||||
)
|
||||
@@ -134,7 +127,7 @@ async def test_power_sensor_condition_behavior_all(
|
||||
parametrize_numerical_condition_above_below_any(
|
||||
"power.is_value",
|
||||
device_class="power",
|
||||
condition_options=_POWER_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT},
|
||||
),
|
||||
)
|
||||
@@ -171,7 +164,7 @@ async def test_power_number_condition_behavior_any(
|
||||
parametrize_numerical_condition_above_below_all(
|
||||
"power.is_value",
|
||||
device_class="power",
|
||||
condition_options=_POWER_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfPower.WATT,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.WATT},
|
||||
),
|
||||
)
|
||||
@@ -230,12 +223,39 @@ async def test_power_condition_unit_conversion_sensor(
|
||||
}
|
||||
],
|
||||
numerical_condition_options=[
|
||||
{CONF_ABOVE: 0.2, CONF_BELOW: 0.8, "unit": UnitOfPower.KILO_WATT},
|
||||
{CONF_ABOVE: 200, CONF_BELOW: 800, "unit": UnitOfPower.WATT},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 0.2,
|
||||
"unit_of_measurement": UnitOfPower.KILO_WATT,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 0.8,
|
||||
"unit_of_measurement": UnitOfPower.KILO_WATT,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 200,
|
||||
"unit_of_measurement": UnitOfPower.WATT,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 800,
|
||||
"unit_of_measurement": UnitOfPower.WATT,
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
limit_entity_condition_options={
|
||||
CONF_ABOVE: "sensor.above",
|
||||
CONF_BELOW: "sensor.below",
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"entity": "sensor.above"},
|
||||
"value_max": {"entity": "sensor.below"},
|
||||
}
|
||||
},
|
||||
limit_entities=("sensor.above", "sensor.below"),
|
||||
limit_entity_states=[
|
||||
|
||||
@@ -6,12 +6,7 @@ import pytest
|
||||
|
||||
from homeassistant.components.climate import HVACMode
|
||||
from homeassistant.components.weather import ATTR_WEATHER_TEMPERATURE_UNIT
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_ABOVE,
|
||||
CONF_BELOW,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.components.common import (
|
||||
@@ -28,7 +23,6 @@ from tests.components.common import (
|
||||
target_entities,
|
||||
)
|
||||
|
||||
_TEMPERATURE_CONDITION_OPTIONS = {"unit": UnitOfTemperature.CELSIUS}
|
||||
_WEATHER_UNIT_ATTRIBUTES = {ATTR_WEATHER_TEMPERATURE_UNIT: UnitOfTemperature.CELSIUS}
|
||||
|
||||
|
||||
@@ -77,7 +71,7 @@ async def test_temperature_conditions_gated_by_labs_flag(
|
||||
parametrize_numerical_condition_above_below_any(
|
||||
"temperature.is_value",
|
||||
device_class="temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
),
|
||||
)
|
||||
@@ -114,7 +108,7 @@ async def test_temperature_sensor_condition_behavior_any(
|
||||
parametrize_numerical_condition_above_below_all(
|
||||
"temperature.is_value",
|
||||
device_class="temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
unit_attributes={ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||
),
|
||||
)
|
||||
@@ -152,7 +146,7 @@ async def test_temperature_sensor_condition_behavior_all(
|
||||
"temperature.is_value",
|
||||
HVACMode.AUTO,
|
||||
"current_temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
)
|
||||
async def test_temperature_climate_condition_behavior_any(
|
||||
@@ -189,7 +183,7 @@ async def test_temperature_climate_condition_behavior_any(
|
||||
"temperature.is_value",
|
||||
HVACMode.AUTO,
|
||||
"current_temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
)
|
||||
async def test_temperature_climate_condition_behavior_all(
|
||||
@@ -226,7 +220,7 @@ async def test_temperature_climate_condition_behavior_all(
|
||||
"temperature.is_value",
|
||||
"eco",
|
||||
"current_temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
)
|
||||
async def test_temperature_water_heater_condition_behavior_any(
|
||||
@@ -263,7 +257,7 @@ async def test_temperature_water_heater_condition_behavior_any(
|
||||
"temperature.is_value",
|
||||
"eco",
|
||||
"current_temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
)
|
||||
async def test_temperature_water_heater_condition_behavior_all(
|
||||
@@ -300,7 +294,7 @@ async def test_temperature_water_heater_condition_behavior_all(
|
||||
"temperature.is_value",
|
||||
"sunny",
|
||||
"temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
unit_attributes=_WEATHER_UNIT_ATTRIBUTES,
|
||||
),
|
||||
)
|
||||
@@ -338,7 +332,7 @@ async def test_temperature_weather_condition_behavior_any(
|
||||
"temperature.is_value",
|
||||
"sunny",
|
||||
"temperature",
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
unit_attributes=_WEATHER_UNIT_ATTRIBUTES,
|
||||
),
|
||||
)
|
||||
@@ -397,12 +391,39 @@ async def test_temperature_condition_unit_conversion_sensor(
|
||||
}
|
||||
],
|
||||
numerical_condition_options=[
|
||||
{CONF_ABOVE: 75, CONF_BELOW: 90, "unit": UnitOfTemperature.FAHRENHEIT},
|
||||
{CONF_ABOVE: 24, CONF_BELOW: 30, "unit": UnitOfTemperature.CELSIUS},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 75,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 90,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 24,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 30,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
limit_entity_condition_options={
|
||||
CONF_ABOVE: "sensor.above",
|
||||
CONF_BELOW: "sensor.below",
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"entity": "sensor.above"},
|
||||
"value_max": {"entity": "sensor.below"},
|
||||
}
|
||||
},
|
||||
limit_entities=("sensor.above", "sensor.below"),
|
||||
limit_entity_states=[
|
||||
@@ -448,12 +469,39 @@ async def test_temperature_condition_unit_conversion_climate(
|
||||
{"state": HVACMode.AUTO, "attributes": {"current_temperature": 20}}
|
||||
],
|
||||
numerical_condition_options=[
|
||||
{CONF_ABOVE: 75, CONF_BELOW: 90, "unit": UnitOfTemperature.FAHRENHEIT},
|
||||
{CONF_ABOVE: 24, CONF_BELOW: 30, "unit": UnitOfTemperature.CELSIUS},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 75,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 90,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 24,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 30,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
limit_entity_condition_options={
|
||||
CONF_ABOVE: "sensor.above",
|
||||
CONF_BELOW: "sensor.below",
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"entity": "sensor.above"},
|
||||
"value_max": {"entity": "sensor.below"},
|
||||
}
|
||||
},
|
||||
limit_entities=("sensor.above", "sensor.below"),
|
||||
limit_entity_states=[
|
||||
|
||||
@@ -15,8 +15,6 @@ from homeassistant.components.water_heater import (
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_ABOVE,
|
||||
CONF_BELOW,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
UnitOfTemperature,
|
||||
@@ -37,8 +35,6 @@ from tests.components.common import (
|
||||
target_entities,
|
||||
)
|
||||
|
||||
_TEMPERATURE_CONDITION_OPTIONS = {"unit": UnitOfTemperature.CELSIUS}
|
||||
|
||||
_ALL_STATES = [
|
||||
STATE_ECO,
|
||||
STATE_ELECTRIC,
|
||||
@@ -205,7 +201,7 @@ async def test_water_heater_state_condition_behavior_all(
|
||||
"water_heater.is_target_temperature",
|
||||
"eco",
|
||||
ATTR_TEMPERATURE,
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -244,7 +240,7 @@ async def test_water_heater_numerical_condition_behavior_any(
|
||||
"water_heater.is_target_temperature",
|
||||
"eco",
|
||||
ATTR_TEMPERATURE,
|
||||
condition_options=_TEMPERATURE_CONDITION_OPTIONS,
|
||||
threshold_unit=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -292,12 +288,39 @@ async def test_water_heater_numerical_condition_unit_conversion(
|
||||
}
|
||||
],
|
||||
numerical_condition_options=[
|
||||
{CONF_ABOVE: 120, CONF_BELOW: 140, "unit": UnitOfTemperature.FAHRENHEIT},
|
||||
{CONF_ABOVE: 49, CONF_BELOW: 60, "unit": UnitOfTemperature.CELSIUS},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 120,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 140,
|
||||
"unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {
|
||||
"number": 49,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
"value_max": {
|
||||
"number": 60,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
limit_entity_condition_options={
|
||||
CONF_ABOVE: "sensor.above",
|
||||
CONF_BELOW: "sensor.below",
|
||||
"threshold": {
|
||||
"type": "between",
|
||||
"value_min": {"entity": "sensor.above"},
|
||||
"value_max": {"entity": "sensor.below"},
|
||||
}
|
||||
},
|
||||
limit_entities=("sensor.above", "sensor.below"),
|
||||
limit_entity_states=[
|
||||
|
||||
Reference in New Issue
Block a user