1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Remove support for legacy logbook events created before 0.112 (#37822)

* Remove support for legacy logbook events created before 0.112

Reduce the complexity of the logbook code.  This
should also have a small performance boost.

* None is the default
This commit is contained in:
J. Nick Koston
2020-07-15 10:38:08 -10:00
committed by GitHub
parent 261f0b971c
commit 9db6318122
2 changed files with 40 additions and 82 deletions

View File

@@ -572,43 +572,6 @@ class TestComponentLogbook(unittest.TestCase):
entries[5], pointC, "included", domain="light", entity_id=entity_id4
)
def test_exclude_attribute_changes(self):
"""Test if events of attribute changes are filtered."""
pointA = dt_util.utcnow()
pointB = pointA + timedelta(minutes=1)
pointC = pointB + timedelta(minutes=1)
entity_attr_cache = logbook.EntityAttributeCache(self.hass)
state_off = ha.State("light.kitchen", "off", {}, pointA, pointA).as_dict()
state_100 = ha.State(
"light.kitchen", "on", {"brightness": 100}, pointB, pointB
).as_dict()
state_200 = ha.State(
"light.kitchen", "on", {"brightness": 200}, pointB, pointC
).as_dict()
eventA = self.create_state_changed_event_from_old_new(
"light.kitchen", pointB, state_off, state_100
)
eventB = self.create_state_changed_event_from_old_new(
"light.kitchen", pointC, state_100, state_200
)
entities_filter = convert_include_exclude_filter(
logbook.CONFIG_SCHEMA({logbook.DOMAIN: {}})[logbook.DOMAIN]
)
events = [
e
for e in (eventA, eventB)
if logbook._keep_event(self.hass, e, entities_filter)
]
entries = list(logbook.humanify(self.hass, events, entity_attr_cache))
assert len(entries) == 1
self.assert_entry(
entries[0], pointB, "kitchen", domain="light", entity_id="light.kitchen"
)
def test_home_assistant_start_stop_grouped(self):
"""Test if HA start and stop events are grouped.
@@ -1835,6 +1798,42 @@ async def test_exclude_removed_entities(hass, hass_client):
assert response_json[2]["entity_id"] == entity_id2
async def test_exclude_attribute_changes(hass, hass_client):
"""Test if events of attribute changes are filtered."""
await hass.async_add_executor_job(init_recorder_component, hass)
await async_setup_component(hass, "logbook", {})
await hass.async_add_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
hass.states.async_set("light.kitchen", STATE_OFF)
hass.states.async_set("light.kitchen", STATE_ON, {"brightness": 100})
hass.states.async_set("light.kitchen", STATE_ON, {"brightness": 200})
hass.states.async_set("light.kitchen", STATE_ON, {"brightness": 300})
hass.states.async_set("light.kitchen", STATE_ON, {"brightness": 400})
await hass.async_block_till_done()
await hass.async_add_job(partial(trigger_db_commit, hass))
await hass.async_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 without filters
response = await client.get(f"/api/logbook/{start_date.isoformat()}")
assert response.status == 200
response_json = await response.json()
assert len(response_json) == 2
assert response_json[0]["domain"] == "homeassistant"
assert response_json[1]["message"] == "turned on"
assert response_json[1]["entity_id"] == "light.kitchen"
class MockLazyEventPartialState(ha.Event):
"""Minimal mock of a Lazy event."""