mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 18:57:57 +00:00
Fix logbook entity_matches_only query mode (#55761)
The string matching template needs to match the same compact JSON format as the data is now written in.
This commit is contained in:
parent
b088ce601c
commit
4fa9871080
@ -48,7 +48,7 @@ from homeassistant.helpers.integration_platform import (
|
|||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
ENTITY_ID_JSON_TEMPLATE = '"entity_id": ?"{}"'
|
ENTITY_ID_JSON_TEMPLATE = '"entity_id":"{}"'
|
||||||
ENTITY_ID_JSON_EXTRACT = re.compile('"entity_id": ?"([^"]+)"')
|
ENTITY_ID_JSON_EXTRACT = re.compile('"entity_id": ?"([^"]+)"')
|
||||||
DOMAIN_JSON_EXTRACT = re.compile('"domain": ?"([^"]+)"')
|
DOMAIN_JSON_EXTRACT = re.compile('"domain": ?"([^"]+)"')
|
||||||
ICON_JSON_EXTRACT = re.compile('"icon": ?"([^"]+)"')
|
ICON_JSON_EXTRACT = re.compile('"icon": ?"([^"]+)"')
|
||||||
|
@ -1289,6 +1289,45 @@ async def test_logbook_entity_matches_only(hass, hass_client):
|
|||||||
assert json_dict[1]["context_user_id"] == "9400facee45711eaa9308bfd3d19e474"
|
assert json_dict[1]["context_user_id"] == "9400facee45711eaa9308bfd3d19e474"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_custom_log_entry_discoverable_via_entity_matches_only(hass, hass_client):
|
||||||
|
"""Test if a custom log entry is later discoverable via entity_matches_only."""
|
||||||
|
await hass.async_add_executor_job(init_recorder_component, hass)
|
||||||
|
await async_setup_component(hass, "logbook", {})
|
||||||
|
await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
|
||||||
|
|
||||||
|
logbook.async_log_entry(
|
||||||
|
hass,
|
||||||
|
"Alarm",
|
||||||
|
"is triggered",
|
||||||
|
"switch",
|
||||||
|
"switch.test_switch",
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
|
||||||
|
# Today time 00:00:00
|
||||||
|
start = dt_util.utcnow().date()
|
||||||
|
start_date = datetime(start.year, start.month, start.day)
|
||||||
|
|
||||||
|
# Test today entries with filter by end_time
|
||||||
|
end_time = start + timedelta(hours=24)
|
||||||
|
response = await client.get(
|
||||||
|
f"/api/logbook/{start_date.isoformat()}?end_time={end_time.isoformat()}&entity=switch.test_switch&entity_matches_only"
|
||||||
|
)
|
||||||
|
assert response.status == 200
|
||||||
|
json_dict = await response.json()
|
||||||
|
|
||||||
|
assert len(json_dict) == 1
|
||||||
|
|
||||||
|
assert json_dict[0]["name"] == "Alarm"
|
||||||
|
assert json_dict[0]["message"] == "is triggered"
|
||||||
|
assert json_dict[0]["entity_id"] == "switch.test_switch"
|
||||||
|
|
||||||
|
|
||||||
async def test_logbook_entity_matches_only_multiple(hass, hass_client):
|
async def test_logbook_entity_matches_only_multiple(hass, hass_client):
|
||||||
"""Test the logbook view with a multiple entities and entity_matches_only."""
|
"""Test the logbook view with a multiple entities and entity_matches_only."""
|
||||||
await hass.async_add_executor_job(init_recorder_component, hass)
|
await hass.async_add_executor_job(init_recorder_component, hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user