mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 08:26:41 +01:00
Adjust some trigger and condition schemas (#166568)
This commit is contained in:
committed by
Franck Nijhof
parent
35c4b4ff5b
commit
d501d8cb28
@@ -5,14 +5,12 @@ from typing import TYPE_CHECKING
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.input_text import DOMAIN as INPUT_TEXT_DOMAIN
|
||||
from homeassistant.const import CONF_OPTIONS, CONF_TARGET
|
||||
from homeassistant.const import CONF_OPTIONS
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
from homeassistant.helpers.condition import (
|
||||
ATTR_BEHAVIOR,
|
||||
BEHAVIOR_ALL,
|
||||
BEHAVIOR_ANY,
|
||||
ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL,
|
||||
Condition,
|
||||
ConditionConfig,
|
||||
EntityConditionBase,
|
||||
@@ -22,13 +20,9 @@ from .const import DOMAIN
|
||||
|
||||
CONF_VALUE = "value"
|
||||
|
||||
_TEXT_CONDITION_SCHEMA = vol.Schema(
|
||||
_TEXT_CONDITION_SCHEMA = ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL.extend(
|
||||
{
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
vol.Required(CONF_OPTIONS): {
|
||||
vol.Required(ATTR_BEHAVIOR, default=BEHAVIOR_ANY): vol.In(
|
||||
[BEHAVIOR_ANY, BEHAVIOR_ALL]
|
||||
),
|
||||
vol.Required(CONF_VALUE): cv.string,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import voluptuous as vol
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_OPTIONS,
|
||||
CONF_TARGET,
|
||||
STATE_OFF,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
@@ -17,9 +16,7 @@ from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.automation import DomainSpec, NumericalDomainSpec
|
||||
from homeassistant.helpers.condition import (
|
||||
ATTR_BEHAVIOR,
|
||||
BEHAVIOR_ALL,
|
||||
BEHAVIOR_ANY,
|
||||
ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL,
|
||||
Condition,
|
||||
ConditionConfig,
|
||||
EntityConditionBase,
|
||||
@@ -33,13 +30,9 @@ from .const import DOMAIN
|
||||
ATTR_OPERATION_MODE = "operation_mode"
|
||||
|
||||
|
||||
_OPERATION_MODE_CONDITION_SCHEMA = vol.Schema(
|
||||
_OPERATION_MODE_CONDITION_SCHEMA = ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL.extend(
|
||||
{
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
vol.Required(CONF_OPTIONS): {
|
||||
vol.Required(ATTR_BEHAVIOR, default=BEHAVIOR_ANY): vol.In(
|
||||
[BEHAVIOR_ANY, BEHAVIOR_ALL]
|
||||
),
|
||||
vol.Required(ATTR_OPERATION_MODE): vol.All(
|
||||
cv.ensure_list, vol.Length(min=1), [str]
|
||||
),
|
||||
|
||||
@@ -462,19 +462,13 @@ def make_entity_state_condition(
|
||||
return CustomCondition
|
||||
|
||||
|
||||
NUMERICAL_CONDITION_SCHEMA = vol.Schema(
|
||||
NUMERICAL_CONDITION_SCHEMA = ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL.extend(
|
||||
{
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
vol.Required(CONF_OPTIONS): vol.All(
|
||||
{
|
||||
vol.Required(ATTR_BEHAVIOR, default=BEHAVIOR_ANY): vol.In(
|
||||
[BEHAVIOR_ANY, BEHAVIOR_ALL]
|
||||
),
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(mode=NumericThresholdMode.IS)
|
||||
),
|
||||
},
|
||||
),
|
||||
vol.Required(CONF_OPTIONS): {
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(mode=NumericThresholdMode.IS)
|
||||
),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -588,22 +582,16 @@ def _make_numerical_condition_with_unit_schema(
|
||||
unit_converter: type[BaseUnitConverter],
|
||||
) -> vol.Schema:
|
||||
"""Factory for numerical condition schema with unit option."""
|
||||
return vol.Schema(
|
||||
return ENTITY_STATE_CONDITION_SCHEMA_ANY_ALL.extend(
|
||||
{
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
vol.Required(CONF_OPTIONS): vol.All(
|
||||
{
|
||||
vol.Required(ATTR_BEHAVIOR, default=BEHAVIOR_ANY): vol.In(
|
||||
[BEHAVIOR_ANY, BEHAVIOR_ALL]
|
||||
),
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(
|
||||
mode=NumericThresholdMode.IS,
|
||||
unit_of_measurement=list(unit_converter.VALID_UNITS),
|
||||
)
|
||||
),
|
||||
},
|
||||
),
|
||||
vol.Required(CONF_OPTIONS): {
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(
|
||||
mode=NumericThresholdMode.IS,
|
||||
unit_of_measurement=list(unit_converter.VALID_UNITS),
|
||||
)
|
||||
),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -336,7 +336,6 @@ ENTITY_STATE_TRIGGER_SCHEMA_FIRST_LAST = ENTITY_STATE_TRIGGER_SCHEMA.extend(
|
||||
[BEHAVIOR_FIRST, BEHAVIOR_LAST, BEHAVIOR_ANY]
|
||||
),
|
||||
},
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -746,19 +745,16 @@ class EntityNumericalStateChangedTriggerWithUnitBase(
|
||||
cls._schema = make_numerical_state_changed_with_unit_schema(cls._unit_converter)
|
||||
|
||||
|
||||
NUMERICAL_ATTRIBUTE_CROSSED_THRESHOLD_SCHEMA = ENTITY_STATE_TRIGGER_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_OPTIONS): vol.All(
|
||||
{
|
||||
vol.Required(ATTR_BEHAVIOR, default=BEHAVIOR_ANY): vol.In(
|
||||
[BEHAVIOR_FIRST, BEHAVIOR_LAST, BEHAVIOR_ANY]
|
||||
),
|
||||
NUMERICAL_ATTRIBUTE_CROSSED_THRESHOLD_SCHEMA = (
|
||||
ENTITY_STATE_TRIGGER_SCHEMA_FIRST_LAST.extend(
|
||||
{
|
||||
vol.Required(CONF_OPTIONS): {
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(mode=NumericThresholdMode.CROSSED)
|
||||
),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -787,21 +783,16 @@ def _make_numerical_state_crossed_threshold_with_unit_schema(
|
||||
This trigger only fires when the observed attribute changes from not within to within
|
||||
the defined threshold.
|
||||
"""
|
||||
return ENTITY_STATE_TRIGGER_SCHEMA.extend(
|
||||
return ENTITY_STATE_TRIGGER_SCHEMA_FIRST_LAST.extend(
|
||||
{
|
||||
vol.Required(CONF_OPTIONS, default={}): vol.All(
|
||||
{
|
||||
vol.Required(ATTR_BEHAVIOR, default=BEHAVIOR_ANY): vol.In(
|
||||
[BEHAVIOR_FIRST, BEHAVIOR_LAST, BEHAVIOR_ANY]
|
||||
),
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(
|
||||
mode=NumericThresholdMode.CROSSED,
|
||||
unit_of_measurement=list(unit_converter.VALID_UNITS),
|
||||
)
|
||||
),
|
||||
},
|
||||
)
|
||||
vol.Required(CONF_OPTIONS, default={}): {
|
||||
vol.Required("threshold"): NumericThresholdSelector(
|
||||
NumericThresholdSelectorConfig(
|
||||
mode=NumericThresholdMode.CROSSED,
|
||||
unit_of_measurement=list(unit_converter.VALID_UNITS),
|
||||
)
|
||||
),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user