1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 04:50:05 +00:00

Add NOT condition helper (#34624)

This commit is contained in:
Franck Nijhof
2020-04-24 18:40:23 +02:00
committed by GitHub
parent 6404882ec4
commit c93c6a66e8
4 changed files with 106 additions and 0 deletions

View File

@@ -137,6 +137,32 @@ async def async_or_from_config(
return if_or_condition
async def async_not_from_config(
hass: HomeAssistant, config: ConfigType, config_validation: bool = True
) -> ConditionCheckerType:
"""Create multi condition matcher using 'NOT'."""
if config_validation:
config = cv.NOT_CONDITION_SCHEMA(config)
checks = [
await async_from_config(hass, entry, False) for entry in config["conditions"]
]
def if_not_condition(
hass: HomeAssistant, variables: TemplateVarsType = None
) -> bool:
"""Test not condition."""
try:
for check in checks:
if check(hass, variables):
return False
except Exception as ex: # pylint: disable=broad-except
_LOGGER.warning("Error during not-condition: %s", ex)
return True
return if_not_condition
def numeric_state(
hass: HomeAssistant,
entity: Union[None, str, State],