Refactor logbook to reduce overhead and complexity (#71509)

This commit is contained in:
J. Nick Koston
2022-05-08 23:47:26 -05:00
committed by GitHub
parent 15a5878a39
commit 24d7a464e1
12 changed files with 573 additions and 680 deletions

View File

@@ -1,9 +1,9 @@
"""Test automation logbook."""
from homeassistant.components import automation, logbook
from homeassistant.components import automation
from homeassistant.core import Context
from homeassistant.setup import async_setup_component
from tests.components.logbook.test_init import MockLazyEventPartialState
from tests.components.logbook.common import MockRow, mock_humanify
async def test_humanify_automation_trigger_event(hass):
@@ -11,34 +11,29 @@ async def test_humanify_automation_trigger_event(hass):
hass.config.components.add("recorder")
assert await async_setup_component(hass, "automation", {})
assert await async_setup_component(hass, "logbook", {})
entity_attr_cache = logbook.EntityAttributeCache(hass)
context = Context()
event1, event2 = list(
logbook.humanify(
hass,
[
MockLazyEventPartialState(
automation.EVENT_AUTOMATION_TRIGGERED,
{
"name": "Bla",
"entity_id": "automation.bla",
"source": "state change of input_boolean.yo",
},
context=context,
),
MockLazyEventPartialState(
automation.EVENT_AUTOMATION_TRIGGERED,
{
"name": "Bla",
"entity_id": "automation.bla",
},
context=context,
),
],
entity_attr_cache,
{},
)
event1, event2 = mock_humanify(
hass,
[
MockRow(
automation.EVENT_AUTOMATION_TRIGGERED,
{
"name": "Bla",
"entity_id": "automation.bla",
"source": "state change of input_boolean.yo",
},
context=context,
),
MockRow(
automation.EVENT_AUTOMATION_TRIGGERED,
{
"name": "Bla",
"entity_id": "automation.bla",
},
context=context,
),
],
)
assert event1["name"] == "Bla"