Remove support for deprecated hidden attribute from logbook and history (#37039)
parent
b61b0321d6
commit
5b79c1f9ef
|
@ -20,7 +20,6 @@ from homeassistant.components.recorder.models import (
|
|||
)
|
||||
from homeassistant.components.recorder.util import execute, session_scope
|
||||
from homeassistant.const import (
|
||||
ATTR_HIDDEN,
|
||||
CONF_DOMAINS,
|
||||
CONF_ENTITIES,
|
||||
CONF_EXCLUDE,
|
||||
|
@ -228,7 +227,7 @@ def _get_states_with_session(
|
|||
.order_by(States.last_updated.desc())
|
||||
.limit(1)
|
||||
)
|
||||
return _dbquery_to_non_hidden_states(query)
|
||||
return [LazyState(row) for row in execute(query)]
|
||||
|
||||
if run is None:
|
||||
run = recorder.run_information_with_session(session, utc_point_in_time)
|
||||
|
@ -276,16 +275,7 @@ def _get_states_with_session(
|
|||
if filters:
|
||||
query = filters.apply(query, entity_ids)
|
||||
|
||||
return _dbquery_to_non_hidden_states(query)
|
||||
|
||||
|
||||
def _dbquery_to_non_hidden_states(query):
|
||||
"""Return states that are not hidden."""
|
||||
return [
|
||||
state
|
||||
for state in (LazyState(row) for row in execute(query))
|
||||
if not state.hidden
|
||||
]
|
||||
return [LazyState(row) for row in execute(query)]
|
||||
|
||||
|
||||
def _sorted_states_to_json(
|
||||
|
@ -347,7 +337,6 @@ def _sorted_states_to_json(
|
|||
domain != SCRIPT_DOMAIN
|
||||
or native_state.attributes.get(ATTR_CAN_CANCEL)
|
||||
)
|
||||
and not native_state.hidden
|
||||
]
|
||||
)
|
||||
continue
|
||||
|
@ -363,11 +352,6 @@ def _sorted_states_to_json(
|
|||
initial_state_count = len(ent_results)
|
||||
|
||||
for db_state in group:
|
||||
if ATTR_HIDDEN in db_state.attributes and LazyState(
|
||||
db_state
|
||||
).attributes.get(ATTR_HIDDEN, False):
|
||||
continue
|
||||
|
||||
# With minimal response we do not care about attribute
|
||||
# changes so we can filter out duplicate states
|
||||
if db_state.state == prev_state.state:
|
||||
|
@ -636,13 +620,6 @@ class LazyState(State):
|
|||
self._attributes = {}
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def hidden(self):
|
||||
"""Determine if a state is hidden."""
|
||||
if ATTR_HIDDEN not in self._row.attributes:
|
||||
return False
|
||||
return self.attributes.get(ATTR_HIDDEN, False)
|
||||
|
||||
@property
|
||||
def context(self):
|
||||
"""State context."""
|
||||
|
|
|
@ -27,7 +27,6 @@ from homeassistant.const import (
|
|||
ATTR_DOMAIN,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_HIDDEN,
|
||||
ATTR_NAME,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_EXCLUDE,
|
||||
|
@ -481,10 +480,6 @@ def _keep_event(hass, event, entities_filter, entity_attr_cache):
|
|||
if not event.has_old_and_new_state:
|
||||
return False
|
||||
|
||||
# exclude entities which are customized hidden
|
||||
if event.hidden:
|
||||
return False
|
||||
|
||||
if event.domain in CONTINUOUS_DOMAINS and entity_attr_cache.get(
|
||||
entity_id, ATTR_UNIT_OF_MEASUREMENT, event
|
||||
):
|
||||
|
@ -698,13 +693,6 @@ class LazyEventPartialState:
|
|||
and '"new_state": {' in self._row.event_data
|
||||
)
|
||||
|
||||
@property
|
||||
def hidden(self):
|
||||
"""Check the json to see if hidden."""
|
||||
if '"hidden":' in self._row.attributes:
|
||||
return self.attributes.get(ATTR_HIDDEN, False)
|
||||
return False
|
||||
|
||||
|
||||
class EntityAttributeCache:
|
||||
"""A cache to lookup static entity_id attribute.
|
||||
|
|
|
@ -696,12 +696,6 @@ class TestComponentHistory(unittest.TestCase):
|
|||
):
|
||||
# This state will be skipped only different in time
|
||||
set_state(mp, "YouTube", attributes={"media_title": str(sentinel.mt3)})
|
||||
# This state will be skipped as it hidden
|
||||
set_state(
|
||||
mp3,
|
||||
"Apple TV",
|
||||
attributes={"media_title": str(sentinel.mt2), "hidden": True},
|
||||
)
|
||||
# This state will be skipped because domain blacklisted
|
||||
set_state(zone, "zoning")
|
||||
set_state(script_nc, "off")
|
||||
|
@ -728,8 +722,6 @@ class TestComponentHistory(unittest.TestCase):
|
|||
states[therm].append(
|
||||
set_state(therm, 21, attributes={"current_temperature": 20})
|
||||
)
|
||||
# state will be skipped since entity is hidden
|
||||
set_state(therm, 22, attributes={"current_temperature": 21, "hidden": True})
|
||||
|
||||
return zero, four, states
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ from homeassistant.components.recorder.models import process_timestamp_to_utc_is
|
|||
from homeassistant.components.script import EVENT_SCRIPT_STARTED
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_HIDDEN,
|
||||
ATTR_NAME,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
|
@ -231,39 +230,6 @@ class TestComponentLogbook(unittest.TestCase):
|
|||
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
|
||||
)
|
||||
|
||||
def test_exclude_events_hidden(self):
|
||||
"""Test if events are excluded if entity is hidden."""
|
||||
entity_id = "sensor.bla"
|
||||
entity_id2 = "sensor.blu"
|
||||
pointA = dt_util.utcnow()
|
||||
pointB = pointA + timedelta(minutes=logbook.GROUP_BY_MINUTES)
|
||||
entity_attr_cache = logbook.EntityAttributeCache(self.hass)
|
||||
|
||||
eventA = self.create_state_changed_event(
|
||||
pointA, entity_id, 10, {ATTR_HIDDEN: "true"}
|
||||
)
|
||||
eventB = self.create_state_changed_event(pointB, entity_id2, 20)
|
||||
|
||||
entities_filter = logbook._generate_filter_from_config({})
|
||||
events = [
|
||||
e
|
||||
for e in (
|
||||
MockLazyEventPartialState(EVENT_HOMEASSISTANT_STOP),
|
||||
eventA,
|
||||
eventB,
|
||||
)
|
||||
if logbook._keep_event(self.hass, e, entities_filter, entity_attr_cache)
|
||||
]
|
||||
entries = list(logbook.humanify(self.hass, events, entity_attr_cache))
|
||||
|
||||
assert len(entries) == 2
|
||||
self.assert_entry(
|
||||
entries[0], name="Home Assistant", message="stopped", domain=ha.DOMAIN
|
||||
)
|
||||
self.assert_entry(
|
||||
entries[1], pointB, "blu", domain="sensor", entity_id=entity_id2
|
||||
)
|
||||
|
||||
def test_exclude_events_entity(self):
|
||||
"""Test if events are filtered if entity is excluded in config."""
|
||||
entity_id = "sensor.bla"
|
||||
|
|
Loading…
Reference in New Issue