Add logbook platforms (#37078)
* Add logbook platforms * Fix logbook describe test
This commit is contained in:
1 parent
7968cd650a
commit
5bc6ed4cef
19 files changed
+215
-116
No files matched your search
@@ -8,7 +8,9 @@ from tests.components.logbook.test_init import MockLazyEventPartialState
|
||||
|
||||
async def test_humanify_alexa_event(hass):
|
||||
"""Test humanifying Alexa event."""
|
||||
hass.config.components.add("recorder")
|
||||
await async_setup_component(hass, "alexa", {})
|
||||
await async_setup_component(hass, "logbook", {})
|
||||
hass.states.async_set("light.kitchen", "on", {"friendly_name": "Kitchen Light"})
|
||||
entity_attr_cache = logbook.EntityAttributeCache(hass)
|
||||
|
||||
|
||||
@@ -1039,7 +1039,9 @@ async def test_extraction_functions(hass):
|
||||
|
||||
async def test_logbook_humanify_automation_triggered_event(hass):
|
||||
"""Test humanifying Automation Trigger event."""
|
||||
hass.config.components.add("recorder")
|
||||
await async_setup_component(hass, automation.DOMAIN, {})
|
||||
await async_setup_component(hass, "logbook", {})
|
||||
entity_attr_cache = logbook.EntityAttributeCache(hass)
|
||||
|
||||
event1, event2 = list(
|
||||
|
||||
@@ -15,8 +15,10 @@ from tests.components.logbook.test_init import MockLazyEventPartialState
|
||||
|
||||
async def test_humanify_homekit_changed_event(hass, hk_driver):
|
||||
"""Test humanifying HomeKit changed event."""
|
||||
hass.config.components.add("recorder")
|
||||
with patch("homeassistant.components.homekit.HomeKit"):
|
||||
assert await async_setup_component(hass, "homekit", {"homekit": {}})
|
||||
assert await async_setup_component(hass, "logbook", {})
|
||||
entity_attr_cache = logbook.EntityAttributeCache(hass)
|
||||
|
||||
event1, event2 = list(
|
||||
|
||||
@@ -36,8 +36,8 @@ from homeassistant.helpers.json import JSONEncoder
|
||||
from homeassistant.setup import async_setup_component, setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import get_test_home_assistant, init_recorder_component
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import get_test_home_assistant, init_recorder_component, mock_platform
|
||||
from tests.components.recorder.common import trigger_db_commit
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -1563,6 +1563,22 @@ async def test_logbook_view_period_entity(hass, hass_client):
|
||||
async def test_logbook_describe_event(hass, hass_client):
|
||||
"""Test teaching logbook about a new event."""
|
||||
await hass.async_add_executor_job(init_recorder_component, hass)
|
||||
|
||||
def _describe(event):
|
||||
"""Describe an event."""
|
||||
return {"name": "Test Name", "message": "tested a message"}
|
||||
|
||||
hass.config.components.add("fake_integration")
|
||||
mock_platform(
|
||||
hass,
|
||||
"fake_integration.logbook",
|
||||
Mock(
|
||||
async_describe_events=lambda hass, async_describe_event: async_describe_event(
|
||||
"test_domain", "some_event", _describe
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
assert await async_setup_component(hass, "logbook", {})
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow",
|
||||
@@ -1574,12 +1590,6 @@ async def test_logbook_describe_event(hass, hass_client):
|
||||
hass.data[recorder.DATA_INSTANCE].block_till_done
|
||||
)
|
||||
|
||||
def _describe(event):
|
||||
"""Describe an event."""
|
||||
return {"name": "Test Name", "message": "tested a message"}
|
||||
|
||||
hass.components.logbook.async_describe_event("test_domain", "some_event", _describe)
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get("/api/logbook")
|
||||
results = await response.json()
|
||||
@@ -1597,6 +1607,26 @@ async def test_exclude_described_event(hass, hass_client):
|
||||
entity_id2 = "automation.included_rule"
|
||||
entity_id3 = "sensor.excluded_domain"
|
||||
|
||||
def _describe(event):
|
||||
"""Describe an event."""
|
||||
return {
|
||||
"name": "Test Name",
|
||||
"message": "tested a message",
|
||||
"entity_id": event.data.get(ATTR_ENTITY_ID),
|
||||
}
|
||||
|
||||
def async_describe_events(hass, async_describe_event):
|
||||
"""Mock to describe events."""
|
||||
async_describe_event("automation", "some_automation_event", _describe)
|
||||
async_describe_event("sensor", "some_event", _describe)
|
||||
|
||||
hass.config.components.add("fake_integration")
|
||||
mock_platform(
|
||||
hass,
|
||||
"fake_integration.logbook",
|
||||
Mock(async_describe_events=async_describe_events),
|
||||
)
|
||||
|
||||
await hass.async_add_executor_job(init_recorder_component, hass)
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1631,19 +1661,6 @@ async def test_exclude_described_event(hass, hass_client):
|
||||
hass.data[recorder.DATA_INSTANCE].block_till_done
|
||||
)
|
||||
|
||||
def _describe(event):
|
||||
"""Describe an event."""
|
||||
return {
|
||||
"name": "Test Name",
|
||||
"message": "tested a message",
|
||||
"entity_id": event.data.get(ATTR_ENTITY_ID),
|
||||
}
|
||||
|
||||
hass.components.logbook.async_describe_event(
|
||||
"automation", "some_automation_event", _describe
|
||||
)
|
||||
hass.components.logbook.async_describe_event("sensor", "some_event", _describe)
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get("/api/logbook")
|
||||
results = await response.json()
|
||||
|
||||
@@ -472,7 +472,9 @@ async def test_config(hass):
|
||||
|
||||
async def test_logbook_humanify_script_started_event(hass):
|
||||
"""Test humanifying script started event."""
|
||||
hass.config.components.add("recorder")
|
||||
await async_setup_component(hass, DOMAIN, {})
|
||||
await async_setup_component(hass, "logbook", {})
|
||||
entity_attr_cache = logbook.EntityAttributeCache(hass)
|
||||
|
||||
event1, event2 = list(
|
||||
|
||||
Reference in new issue
Block a user