Reorganize trigger code (#38655)

This commit is contained in:
Phil Bruckner authored and GitHub committed 2020-08-17 11:54:56 -05:00
1 parent fca071742d
commit ca9dd0c833
51 files changed
+306 -194

No files matched your search

+16
View File
@@ -861,6 +861,22 @@ async def test_automation_not_trigger_on_bootstrap(hass):
assert ["hello.world"] == calls[0].data.get(ATTR_ENTITY_ID)
async def test_automation_bad_trigger(hass, caplog):
"""Test bad trigger configuration."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "automation"},
"action": [],
}
},
)
assert "Integration 'automation' does not provide trigger support." in caplog.text
async def test_automation_with_error_in_script(hass, caplog):
"""Test automation with an error in script."""
assert await async_setup_component(
@@ -0,0 +1 @@
"""Test core triggers."""
@@ -5,7 +5,9 @@ import pytest
import voluptuous as vol
import homeassistant.components.automation as automation
from homeassistant.components.automation import numeric_state
from homeassistant.components.homeassistant.triggers import (
numeric_state as numeric_state_trigger,
)
from homeassistant.core import Context
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@@ -776,7 +778,7 @@ async def test_if_fails_setup_bad_for(hass, calls):
},
)
with patch.object(automation.numeric_state, "_LOGGER") as mock_logger:
with patch.object(numeric_state_trigger, "_LOGGER") as mock_logger:
hass.states.async_set("test.entity", 9)
await hass.async_block_till_done()
assert mock_logger.error.called
@@ -1164,7 +1166,7 @@ async def test_invalid_for_template(hass, calls):
},
)
with patch.object(automation.numeric_state, "_LOGGER") as mock_logger:
with patch.object(numeric_state_trigger, "_LOGGER") as mock_logger:
hass.states.async_set("test.entity", 9)
await hass.async_block_till_done()
assert mock_logger.error.called
@@ -1234,6 +1236,6 @@ async def test_if_fires_on_entities_change_overlap_for_template(hass, calls):
def test_below_above():
"""Test above cannot be above below."""
with pytest.raises(vol.Invalid):
numeric_state.TRIGGER_SCHEMA(
numeric_state_trigger.TRIGGER_SCHEMA(
{"platform": "numeric_state", "above": 1200, "below": 1000}
)
@@ -4,6 +4,7 @@ from datetime import timedelta
import pytest
import homeassistant.components.automation as automation
from homeassistant.components.homeassistant.triggers import state as state_trigger
from homeassistant.core import Context
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@@ -327,7 +328,7 @@ async def test_if_fails_setup_bad_for(hass, calls):
},
)
with patch.object(automation.state, "_LOGGER") as mock_logger:
with patch.object(state_trigger, "_LOGGER") as mock_logger:
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert mock_logger.error.called
@@ -942,7 +943,7 @@ async def test_invalid_for_template_1(hass, calls):
},
)
with patch.object(automation.state, "_LOGGER") as mock_logger:
with patch.object(state_trigger, "_LOGGER") as mock_logger:
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert mock_logger.error.called
@@ -361,7 +361,7 @@ async def test_untrack_time_change(hass):
"""Test for removing tracked time changes."""
mock_track_time_change = Mock()
with patch(
"homeassistant.components.automation.time.async_track_time_change",
"homeassistant.components.homeassistant.triggers.time.async_track_time_change",
return_value=mock_track_time_change,
):
assert await async_setup_component(
+2
View File
@@ -419,6 +419,8 @@ async def test_missing_discover_abbreviations(hass, mqtt_mock, caplog):
missing = []
regex = re.compile(r"(CONF_[a-zA-Z\d_]*) *= *[\'\"]([a-zA-Z\d_]*)[\'\"]")
for fil in Path(mqtt.__file__).parent.rglob("*.py"):
if fil.name == "trigger.py":
continue
with open(fil) as file:
matches = re.findall(regex, file.read())
for match in matches:
File renamed without changes.
@@ -5,6 +5,7 @@ from unittest import mock
import pytest
import homeassistant.components.automation as automation
from homeassistant.components.template import trigger as template_trigger
from homeassistant.core import Context, callback
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@@ -782,7 +783,7 @@ async def test_invalid_for_template_1(hass, calls):
},
)
with mock.patch.object(automation.template, "_LOGGER") as mock_logger:
with mock.patch.object(template_trigger, "_LOGGER") as mock_logger:
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert mock_logger.error.called