Validate generated condition (#27263)

This commit is contained in:
Erik Montnemery 2019-10-07 06:06:16 +02:00 committed by Paulus Schoutsen
parent 0915d927df
commit 5d1dd6390d
5 changed files with 12 additions and 16 deletions

View file

@ -248,7 +248,7 @@ def async_condition_from_config(
if CONF_FOR in config: if CONF_FOR in config:
state_config[CONF_FOR] = config[CONF_FOR] state_config[CONF_FOR] = config[CONF_FOR]
return condition.state_from_config(state_config, config_validation) return condition.state_from_config(state_config)
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict: async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:

View file

@ -119,9 +119,7 @@ async def async_call_action_from_config(
) )
def async_condition_from_config( def async_condition_from_config(config: ConfigType) -> condition.ConditionCheckerType:
config: ConfigType, config_validation: bool
) -> condition.ConditionCheckerType:
"""Evaluate state based on configuration.""" """Evaluate state based on configuration."""
condition_type = config[CONF_TYPE] condition_type = config[CONF_TYPE]
if condition_type == CONF_IS_ON: if condition_type == CONF_IS_ON:
@ -136,7 +134,7 @@ def async_condition_from_config(
if CONF_FOR in config: if CONF_FOR in config:
state_config[CONF_FOR] = config[CONF_FOR] state_config[CONF_FOR] = config[CONF_FOR]
return condition.state_from_config(state_config, config_validation) return condition.state_from_config(state_config)
async def async_attach_trigger( async def async_attach_trigger(

View file

@ -21,7 +21,7 @@ def async_condition_from_config(
"""Evaluate state based on configuration.""" """Evaluate state based on configuration."""
if config_validation: if config_validation:
config = CONDITION_SCHEMA(config) config = CONDITION_SCHEMA(config)
return toggle_entity.async_condition_from_config(config, config_validation) return toggle_entity.async_condition_from_config(config)
async def async_get_conditions(hass: HomeAssistant, device_id: str) -> List[dict]: async def async_get_conditions(hass: HomeAssistant, device_id: str) -> List[dict]:

View file

@ -3,14 +3,12 @@ from typing import List
import voluptuous as vol import voluptuous as vol
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.components.automation.numeric_state as numeric_state_automation
from homeassistant.const import ( from homeassistant.const import (
ATTR_DEVICE_CLASS, ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT, ATTR_UNIT_OF_MEASUREMENT,
CONF_ABOVE, CONF_ABOVE,
CONF_BELOW, CONF_BELOW,
CONF_ENTITY_ID, CONF_ENTITY_ID,
CONF_FOR,
CONF_TYPE, CONF_TYPE,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
@ -132,12 +130,12 @@ def async_condition_from_config(
if config_validation: if config_validation:
config = CONDITION_SCHEMA(config) config = CONDITION_SCHEMA(config)
numeric_state_config = { numeric_state_config = {
numeric_state_automation.CONF_ENTITY_ID: config[CONF_ENTITY_ID], condition.CONF_CONDITION: "numeric_state",
numeric_state_automation.CONF_ABOVE: config.get(CONF_ABOVE), condition.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
numeric_state_automation.CONF_BELOW: config.get(CONF_BELOW),
numeric_state_automation.CONF_FOR: config.get(CONF_FOR),
} }
if CONF_ABOVE in config:
numeric_state_config[condition.CONF_ABOVE] = config[CONF_ABOVE]
if CONF_BELOW in config:
numeric_state_config[condition.CONF_BELOW] = config[CONF_BELOW]
return condition.async_numeric_state_from_config( return condition.async_numeric_state_from_config(numeric_state_config)
numeric_state_config, config_validation
)

View file

@ -21,7 +21,7 @@ def async_condition_from_config(
"""Evaluate state based on configuration.""" """Evaluate state based on configuration."""
if config_validation: if config_validation:
config = CONDITION_SCHEMA(config) config = CONDITION_SCHEMA(config)
return toggle_entity.async_condition_from_config(config, config_validation) return toggle_entity.async_condition_from_config(config)
async def async_get_conditions(hass: HomeAssistant, device_id: str) -> List[dict]: async def async_get_conditions(hass: HomeAssistant, device_id: str) -> List[dict]: