Fix logbook not setting up with an recorder filter that has empty fields (#72869)
parent
7746715590
commit
c6e56c26b3
|
@ -36,7 +36,7 @@ def extract_include_exclude_filter_conf(conf: ConfigType) -> dict[str, Any]:
|
|||
"""
|
||||
return {
|
||||
filter_type: {
|
||||
matcher: set(conf.get(filter_type, {}).get(matcher, []))
|
||||
matcher: set(conf.get(filter_type, {}).get(matcher) or [])
|
||||
for matcher in FITLER_MATCHERS
|
||||
}
|
||||
for filter_type in FILTER_TYPES
|
||||
|
|
|
@ -11,7 +11,7 @@ from unittest.mock import Mock, patch
|
|||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import logbook
|
||||
from homeassistant.components import logbook, recorder
|
||||
from homeassistant.components.alexa.smart_home import EVENT_ALEXA_SMART_HOME
|
||||
from homeassistant.components.automation import EVENT_AUTOMATION_TRIGGERED
|
||||
from homeassistant.components.logbook.models import LazyEventPartialState
|
||||
|
@ -2796,3 +2796,39 @@ async def test_get_events_with_context_state(hass, hass_ws_client, recorder_mock
|
|||
assert results[3]["context_state"] == "off"
|
||||
assert results[3]["context_user_id"] == "b400facee45711eaa9308bfd3d19e474"
|
||||
assert "context_event_type" not in results[3]
|
||||
|
||||
|
||||
async def test_logbook_with_empty_config(hass, recorder_mock):
|
||||
"""Test we handle a empty configuration."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
logbook.DOMAIN,
|
||||
{
|
||||
logbook.DOMAIN: {},
|
||||
recorder.DOMAIN: {},
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_logbook_with_non_iterable_entity_filter(hass, recorder_mock):
|
||||
"""Test we handle a non-iterable entity filter."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
logbook.DOMAIN,
|
||||
{
|
||||
logbook.DOMAIN: {
|
||||
CONF_EXCLUDE: {
|
||||
CONF_ENTITIES: ["light.additional_excluded"],
|
||||
}
|
||||
},
|
||||
recorder.DOMAIN: {
|
||||
CONF_EXCLUDE: {
|
||||
CONF_ENTITIES: None,
|
||||
CONF_DOMAINS: None,
|
||||
CONF_ENTITY_GLOBS: None,
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -12,6 +12,13 @@ from homeassistant.helpers.entityfilter import (
|
|||
CONF_INCLUDE,
|
||||
)
|
||||
|
||||
EMPTY_INCLUDE_FILTER = {
|
||||
CONF_INCLUDE: {
|
||||
CONF_DOMAINS: None,
|
||||
CONF_ENTITIES: None,
|
||||
CONF_ENTITY_GLOBS: None,
|
||||
}
|
||||
}
|
||||
SIMPLE_INCLUDE_FILTER = {
|
||||
CONF_INCLUDE: {
|
||||
CONF_DOMAINS: ["homeassistant"],
|
||||
|
@ -87,6 +94,19 @@ def test_extract_include_exclude_filter_conf():
|
|||
assert SIMPLE_INCLUDE_EXCLUDE_FILTER[CONF_EXCLUDE][CONF_ENTITIES] != {
|
||||
"cover.altered"
|
||||
}
|
||||
empty_include_filter = extract_include_exclude_filter_conf(EMPTY_INCLUDE_FILTER)
|
||||
assert empty_include_filter == {
|
||||
CONF_EXCLUDE: {
|
||||
CONF_DOMAINS: set(),
|
||||
CONF_ENTITIES: set(),
|
||||
CONF_ENTITY_GLOBS: set(),
|
||||
},
|
||||
CONF_INCLUDE: {
|
||||
CONF_DOMAINS: set(),
|
||||
CONF_ENTITIES: set(),
|
||||
CONF_ENTITY_GLOBS: set(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_merge_include_exclude_filters():
|
||||
|
|
Loading…
Reference in New Issue