Fix logbook with empty filter and remove unused code (#40565)
This commit is contained in:
1 parent
729ed1cab6
commit
aada6a1d88
5 files changed
+126
-82
No files matched your search
@@ -940,3 +940,33 @@ async def test_fetch_period_api_with_entity_glob_include_and_exclude(hass, hass_
|
||||
assert response_json[0][0]["entity_id"] == "light.match"
|
||||
assert response_json[1][0]["entity_id"] == "media_player.test"
|
||||
assert response_json[2][0]["entity_id"] == "switch.match"
|
||||
|
||||
|
||||
async def test_entity_ids_limit_via_api(hass, hass_client):
|
||||
"""Test limiting history to entity_ids."""
|
||||
await hass.async_add_executor_job(init_recorder_component, hass)
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"history",
|
||||
{"history": {}},
|
||||
)
|
||||
await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
|
||||
hass.states.async_set("light.kitchen", "on")
|
||||
hass.states.async_set("light.cow", "on")
|
||||
hass.states.async_set("light.nomatch", "on")
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.async_add_executor_job(trigger_db_commit, hass)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get(
|
||||
f"/api/history/period/{dt_util.utcnow().isoformat()}?filter_entity_id=light.kitchen,light.cow",
|
||||
)
|
||||
assert response.status == 200
|
||||
response_json = await response.json()
|
||||
assert len(response_json) == 2
|
||||
assert response_json[0][0]["entity_id"] == "light.kitchen"
|
||||
assert response_json[1][0]["entity_id"] == "light.cow"
|
||||
@@ -2223,6 +2223,36 @@ async def test_include_exclude_events_with_glob_filters(hass, hass_client):
|
||||
_assert_entry(entries[2], name="included", domain="light", entity_id=entity_id4)
|
||||
|
||||
|
||||
async def test_empty_config(hass, hass_client):
|
||||
"""Test we can handle an empty entity filter."""
|
||||
entity_id = "sensor.blu"
|
||||
|
||||
config = logbook.CONFIG_SCHEMA(
|
||||
{
|
||||
ha.DOMAIN: {},
|
||||
logbook.DOMAIN: {},
|
||||
}
|
||||
)
|
||||
await hass.async_add_executor_job(init_recorder_component, hass)
|
||||
await async_setup_component(hass, "logbook", config)
|
||||
await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
hass.states.async_set(entity_id, None)
|
||||
hass.states.async_set(entity_id, 10)
|
||||
|
||||
await _async_commit_and_wait(hass)
|
||||
client = await hass_client()
|
||||
entries = await _async_fetch_logbook(client)
|
||||
|
||||
assert len(entries) == 2
|
||||
_assert_entry(
|
||||
entries[0], name="Home Assistant", message="started", domain=ha.DOMAIN
|
||||
)
|
||||
_assert_entry(entries[1], name="blu", domain="sensor", entity_id=entity_id)
|
||||
|
||||
|
||||
async def _async_fetch_logbook(client):
|
||||
|
||||
# Today time 00:00:00
|
||||
|
||||
Reference in new issue
Block a user