mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Support dynamic schema validation in device conditions and actions (#52007)
* Allow integrations to provide dynamic schema validation in device conditions and actions * Add tests * re-add type * mypy
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
"""Test the condition helper."""
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import sun
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.sensor import DEVICE_CLASS_TIMESTAMP
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, SUN_EVENT_SUNRISE, SUN_EVENT_SUNSET
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
CONF_CONDITION,
|
||||
CONF_DEVICE_ID,
|
||||
CONF_DOMAIN,
|
||||
SUN_EVENT_SUNRISE,
|
||||
SUN_EVENT_SUNSET,
|
||||
)
|
||||
from homeassistant.exceptions import ConditionError, HomeAssistantError
|
||||
from homeassistant.helpers import condition, trace
|
||||
from homeassistant.helpers.template import Template
|
||||
@@ -2843,3 +2850,16 @@ async def test_trigger(hass):
|
||||
assert not test(hass, {"other_var": "123456"})
|
||||
assert not test(hass, {"trigger": {"trigger_id": "123456"}})
|
||||
assert test(hass, {"trigger": {"id": "123456"}})
|
||||
|
||||
|
||||
async def test_platform_async_validate_condition_config(hass):
|
||||
"""Test platform.async_validate_condition_config will be called if it exists."""
|
||||
config = {CONF_DEVICE_ID: "test", CONF_DOMAIN: "test", CONF_CONDITION: "device"}
|
||||
platform = AsyncMock()
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.async_get_device_automation_platform",
|
||||
return_value=platform,
|
||||
):
|
||||
platform.async_validate_condition_config.return_value = config
|
||||
await condition.async_validate_condition_config(hass, config)
|
||||
platform.async_validate_condition_config.assert_awaited()
|
||||
|
||||
Reference in New Issue
Block a user